diff --git a/Interop/Indexer/build.gradle b/Interop/Indexer/build.gradle index ac4abdc9ced..93d3ae019fd 100644 --- a/Interop/Indexer/build.gradle +++ b/Interop/Indexer/build.gradle @@ -141,6 +141,12 @@ kotlinNativeInterop { } } +compileKotlin { + kotlinOptions { + allWarningsAsErrors=true + } +} + tasks.matching { it.name == 'linkClangstubsSharedLibrary' }.all { it.dependsOn libclangextTask it.inputs.dir libclangextDir diff --git a/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/MacroConstants.kt b/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/MacroConstants.kt index f83443c3344..225e4b7b024 100644 --- a/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/MacroConstants.kt +++ b/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/MacroConstants.kt @@ -178,7 +178,7 @@ private fun reparseWithCodeSnippets(library: CompilationWithPCH, } assert(codeSnippetLines.size == CODE_SNIPPET_LINES_NUMBER) - codeSnippetLines.forEach { writer.appendln(it) } + codeSnippetLines.forEach { writer.appendLine(it) } } } clang_reparseTranslationUnit(translationUnit, 0, null, 0) diff --git a/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Utils.kt b/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Utils.kt index 5edc439fb42..f51bab67c61 100644 --- a/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Utils.kt +++ b/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Utils.kt @@ -233,7 +233,7 @@ val Compilation.preambleLines: List internal fun Appendable.appendPreamble(compilation: Compilation) = this.apply { compilation.preambleLines.forEach { - this.appendln(it) + this.appendLine(it) } } @@ -340,7 +340,7 @@ fun List>.mapFragmentIsCompilable(originalLibrary: CompilationWithP fragmentsToCheck.forEach { it.value.forEach { assert(!it.contains('\n')) - writer.appendln(it) + writer.appendLine(it) } } } diff --git a/Interop/Runtime/build.gradle b/Interop/Runtime/build.gradle index 3965f849e61..273e3b2e962 100644 --- a/Interop/Runtime/build.gradle +++ b/Interop/Runtime/build.gradle @@ -75,7 +75,9 @@ sourceSets.main.kotlin.srcDirs += "src/jvm/kotlin" compileKotlin { kotlinOptions { - freeCompilerArgs = ['-Xopt-in=kotlin.ExperimentalUnsignedTypes', '-Xinline-classes'] + freeCompilerArgs = ['-Xuse-experimental=kotlin.ExperimentalUnsignedTypes', '-Xuse-experimental=kotlin.Experimental', + '-Xopt-in=kotlin.RequiresOptIn', "-XXLanguage:+InlineClasses"] + allWarningsAsErrors=true } } diff --git a/Interop/StubGenerator/build.gradle b/Interop/StubGenerator/build.gradle index a71dba8192f..1a07effa41b 100644 --- a/Interop/StubGenerator/build.gradle +++ b/Interop/StubGenerator/build.gradle @@ -47,5 +47,6 @@ dependencies { compileKotlin { kotlinOptions { freeCompilerArgs = ['-Xopt-in=kotlin.ExperimentalUnsignedTypes', '-Xskip-metadata-version-check'] + allWarningsAsErrors=true } } diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrBridgeBuilder.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrBridgeBuilder.kt index 647943df5d8..e30ad7ad7a1 100644 --- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrBridgeBuilder.kt +++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrBridgeBuilder.kt @@ -71,7 +71,7 @@ class StubIrBridgeBuilder( private val bridgeGeneratingVisitor = object : StubIrVisitor { - override fun visitClass(element: ClassStub, owner: StubContainer?) { + override fun visitClass(element: ClassStub, data: StubContainer?) { element.annotations.filterIsInstance().firstOrNull()?.let { val origin = element.origin if (it.protocolGetter.isNotEmpty() && origin is StubOrigin.ObjCProtocol && !origin.isMeta) { @@ -85,16 +85,16 @@ class StubIrBridgeBuilder( } } - override fun visitTypealias(element: TypealiasStub, owner: StubContainer?) { + override fun visitTypealias(element: TypealiasStub, data: StubContainer?) { } - override fun visitFunction(element: FunctionStub, owner: StubContainer?) { + override fun visitFunction(element: FunctionStub, data: StubContainer?) { try { when { element.external -> tryProcessCCallAnnotation(element) element.isOptionalObjCMethod() -> { } element.origin is StubOrigin.Synthetic.EnumByValue -> { } - owner != null && owner.isInterface -> { } + data != null && data.isInterface -> { } else -> generateBridgeBody(element) } } catch (e: Throwable) { @@ -112,17 +112,17 @@ class StubIrBridgeBuilder( simpleBridgeGenerator.insertNativeBridge(function, emptyList(), wrapper.lines) } - override fun visitProperty(element: PropertyStub, owner: StubContainer?) { + override fun visitProperty(element: PropertyStub, data: StubContainer?) { try { when (val kind = element.kind) { is PropertyStub.Kind.Constant -> { } is PropertyStub.Kind.Val -> { - visitPropertyAccessor(kind.getter, owner) + visitPropertyAccessor(kind.getter, data) } is PropertyStub.Kind.Var -> { - visitPropertyAccessor(kind.getter, owner) - visitPropertyAccessor(kind.setter, owner) + visitPropertyAccessor(kind.getter, data) + visitPropertyAccessor(kind.setter, data) } } } catch (e: Throwable) { @@ -131,49 +131,49 @@ class StubIrBridgeBuilder( } } - override fun visitConstructor(constructorStub: ConstructorStub, owner: StubContainer?) { + override fun visitConstructor(constructorStub: ConstructorStub, data: StubContainer?) { } - override fun visitPropertyAccessor(accessor: PropertyAccessor, owner: StubContainer?) { - when (accessor) { + override fun visitPropertyAccessor(propertyAccessor: PropertyAccessor, data: StubContainer?) { + when (propertyAccessor) { is PropertyAccessor.Getter.SimpleGetter -> { - when (accessor) { + when (propertyAccessor) { in builderResult.bridgeGenerationComponents.getterToBridgeInfo -> { - val extra = builderResult.bridgeGenerationComponents.getterToBridgeInfo.getValue(accessor) + val extra = builderResult.bridgeGenerationComponents.getterToBridgeInfo.getValue(propertyAccessor) val typeInfo = extra.typeInfo - propertyAccessorBridgeBodies[accessor] = typeInfo.argFromBridged(simpleBridgeGenerator.kotlinToNative( - nativeBacked = accessor, + propertyAccessorBridgeBodies[propertyAccessor] = typeInfo.argFromBridged(simpleBridgeGenerator.kotlinToNative( + nativeBacked = propertyAccessor, returnType = typeInfo.bridgedType, kotlinValues = emptyList(), independent = false ) { typeInfo.cToBridged(expr = extra.cGlobalName) - }, kotlinFile, nativeBacked = accessor) + }, kotlinFile, nativeBacked = propertyAccessor) } in builderResult.bridgeGenerationComponents.arrayGetterInfo -> { - val extra = builderResult.bridgeGenerationComponents.arrayGetterInfo.getValue(accessor) + val extra = builderResult.bridgeGenerationComponents.arrayGetterInfo.getValue(propertyAccessor) val typeInfo = extra.typeInfo - val getAddressExpression = getGlobalAddressExpression(extra.cGlobalName, accessor) - propertyAccessorBridgeBodies[accessor] = typeInfo.argFromBridged(getAddressExpression, kotlinFile, nativeBacked = accessor) + "!!" + val getAddressExpression = getGlobalAddressExpression(extra.cGlobalName, propertyAccessor) + propertyAccessorBridgeBodies[propertyAccessor] = typeInfo.argFromBridged(getAddressExpression, kotlinFile, nativeBacked = propertyAccessor) + "!!" } } } is PropertyAccessor.Getter.ReadBits -> { - val extra = builderResult.bridgeGenerationComponents.getterToBridgeInfo.getValue(accessor) + val extra = builderResult.bridgeGenerationComponents.getterToBridgeInfo.getValue(propertyAccessor) val rawType = extra.typeInfo.bridgedType - val readBits = "readBits(this.rawPtr, ${accessor.offset}, ${accessor.size}, ${accessor.signed}).${rawType.convertor!!}()" + val readBits = "readBits(this.rawPtr, ${propertyAccessor.offset}, ${propertyAccessor.size}, ${propertyAccessor.signed}).${rawType.convertor!!}()" val getExpr = extra.typeInfo.argFromBridged(readBits, kotlinFile, object : NativeBacked {}) - propertyAccessorBridgeBodies[accessor] = getExpr + propertyAccessorBridgeBodies[propertyAccessor] = getExpr } - is PropertyAccessor.Setter.SimpleSetter -> when (accessor) { + is PropertyAccessor.Setter.SimpleSetter -> when (propertyAccessor) { in builderResult.bridgeGenerationComponents.setterToBridgeInfo -> { - val extra = builderResult.bridgeGenerationComponents.setterToBridgeInfo.getValue(accessor) + val extra = builderResult.bridgeGenerationComponents.setterToBridgeInfo.getValue(propertyAccessor) val typeInfo = extra.typeInfo val bridgedValue = BridgeTypedKotlinValue(typeInfo.bridgedType, typeInfo.argToBridged("value")) val setter = simpleBridgeGenerator.kotlinToNative( - nativeBacked = accessor, + nativeBacked = propertyAccessor, returnType = BridgedType.VOID, kotlinValues = listOf(bridgedValue), independent = false @@ -181,52 +181,52 @@ class StubIrBridgeBuilder( out("${extra.cGlobalName} = ${typeInfo.cFromBridged( nativeValues.single(), scope, - nativeBacked = accessor + nativeBacked = propertyAccessor )};") "" } - propertyAccessorBridgeBodies[accessor] = setter + propertyAccessorBridgeBodies[propertyAccessor] = setter } } is PropertyAccessor.Setter.WriteBits -> { - val extra = builderResult.bridgeGenerationComponents.setterToBridgeInfo.getValue(accessor) + val extra = builderResult.bridgeGenerationComponents.setterToBridgeInfo.getValue(propertyAccessor) val rawValue = extra.typeInfo.argToBridged("value") - propertyAccessorBridgeBodies[accessor] = "writeBits(this.rawPtr, ${accessor.offset}, ${accessor.size}, $rawValue.toLong())" + propertyAccessorBridgeBodies[propertyAccessor] = "writeBits(this.rawPtr, ${propertyAccessor.offset}, ${propertyAccessor.size}, $rawValue.toLong())" } is PropertyAccessor.Getter.InterpretPointed -> { - val getAddressExpression = getGlobalAddressExpression(accessor.cGlobalName, accessor) - propertyAccessorBridgeBodies[accessor] = getAddressExpression + val getAddressExpression = getGlobalAddressExpression(propertyAccessor.cGlobalName, propertyAccessor) + propertyAccessorBridgeBodies[propertyAccessor] = getAddressExpression } is PropertyAccessor.Getter.ExternalGetter -> { - if (accessor in builderResult.wrapperGenerationComponents.getterToWrapperInfo) { - val extra = builderResult.wrapperGenerationComponents.getterToWrapperInfo.getValue(accessor) - val cCallAnnotation = accessor.annotations.firstIsInstanceOrNull() + if (propertyAccessor in builderResult.wrapperGenerationComponents.getterToWrapperInfo) { + val extra = builderResult.wrapperGenerationComponents.getterToWrapperInfo.getValue(propertyAccessor) + val cCallAnnotation = propertyAccessor.annotations.firstIsInstanceOrNull() ?: error("external getter for ${extra.global.name} wasn't marked with @CCall") val wrapper = if (extra.passViaPointer) { wrapperGenerator.generateCGlobalByPointerGetter(extra.global, cCallAnnotation.symbolName) } else { wrapperGenerator.generateCGlobalGetter(extra.global, cCallAnnotation.symbolName) } - simpleBridgeGenerator.insertNativeBridge(accessor, emptyList(), wrapper.lines) + simpleBridgeGenerator.insertNativeBridge(propertyAccessor, emptyList(), wrapper.lines) } } is PropertyAccessor.Setter.ExternalSetter -> { - if (accessor in builderResult.wrapperGenerationComponents.setterToWrapperInfo) { - val extra = builderResult.wrapperGenerationComponents.setterToWrapperInfo.getValue(accessor) - val cCallAnnotation = accessor.annotations.firstIsInstanceOrNull() + if (propertyAccessor in builderResult.wrapperGenerationComponents.setterToWrapperInfo) { + val extra = builderResult.wrapperGenerationComponents.setterToWrapperInfo.getValue(propertyAccessor) + val cCallAnnotation = propertyAccessor.annotations.firstIsInstanceOrNull() ?: error("external setter for ${extra.global.name} wasn't marked with @CCall") val wrapper = wrapperGenerator.generateCGlobalSetter(extra.global, cCallAnnotation.symbolName) - simpleBridgeGenerator.insertNativeBridge(accessor, emptyList(), wrapper.lines) + simpleBridgeGenerator.insertNativeBridge(propertyAccessor, emptyList(), wrapper.lines) } } } } - override fun visitSimpleStubContainer(simpleStubContainer: SimpleStubContainer, owner: StubContainer?) { + override fun visitSimpleStubContainer(simpleStubContainer: SimpleStubContainer, data: StubContainer?) { simpleStubContainer.classes.forEach { it.accept(this, simpleStubContainer) } diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrDriver.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrDriver.kt index 2befe0a95a9..4b30749529c 100644 --- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrDriver.kt +++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrDriver.kt @@ -147,7 +147,7 @@ class StubIrDriver( ) = Result.Metadata(StubIrMetadataEmitter(context, builderResult, moduleName, bridgeBuilderResult).emit()) private fun emitCFile(context: StubIrContext, cFile: Appendable, entryPoint: String?, nativeBridges: NativeBridges) { - val out = { it: String -> cFile.appendln(it) } + val out = { it: String -> cFile.appendLine(it) } context.libraryForCStubs.preambleLines.forEach { out(it) diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrTextEmitter.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrTextEmitter.kt index 4951f0b354e..249d6d80cac 100644 --- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrTextEmitter.kt +++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrTextEmitter.kt @@ -57,7 +57,7 @@ class StubIrTextEmitter( } private fun withOutput(appendable: Appendable, action: () -> R): R { - return withOutput({ appendable.appendln(it) }, action) + return withOutput({ appendable.appendLine(it) }, action) } private fun generateLinesBy(action: () -> Unit): List { @@ -148,7 +148,7 @@ class StubIrTextEmitter( } private val printer = object : StubIrVisitor { - override fun visitClass(element: ClassStub, owner: StubContainer?) { + override fun visitClass(element: ClassStub, data: StubContainer?) { element.annotations.forEach { out(renderAnnotation(it)) } @@ -173,13 +173,13 @@ class StubIrTextEmitter( } } - override fun visitTypealias(element: TypealiasStub, owner: StubContainer?) { + override fun visitTypealias(element: TypealiasStub, data: StubContainer?) { val alias = renderClassifierDeclaration(element.alias) val aliasee = renderStubType(element.aliasee) out("typealias $alias = $aliasee") } - override fun visitFunction(element: FunctionStub, owner: StubContainer?) { + override fun visitFunction(element: FunctionStub, data: StubContainer?) { if (element in bridgeBuilderResult.excludedStubs) return val header = run { @@ -187,7 +187,7 @@ class StubIrTextEmitter( val receiver = element.receiver?.let { renderFunctionReceiver(it) + "." } ?: "" val typeParameters = renderTypeParameters(element.typeParameters) val override = if (element.isOverride) "override " else "" - val modality = renderMemberModality(element.modality, owner) + val modality = renderMemberModality(element.modality, data) "$override${modality}fun$typeParameters $receiver${element.name.asSimpleName()}$parameters: ${renderStubType(element.returnType)}" } if (!nativeBridges.isSupported(element)) { @@ -205,17 +205,17 @@ class StubIrTextEmitter( element.isOptionalObjCMethod() -> out("$header = optional()") element.origin is StubOrigin.Synthetic.EnumByValue -> out("$header = values().find { it.value == value }!!") - owner != null && owner.isInterface -> out(header) + data != null && data.isInterface -> out(header) else -> block(header) { functionBridgeBodies.getValue(element).forEach(out) } } } - override fun visitProperty(element: PropertyStub, owner: StubContainer?) = - emitProperty(element, owner) + override fun visitProperty(element: PropertyStub, data: StubContainer?) = + emitProperty(element, data) - override fun visitConstructor(constructorStub: ConstructorStub, owner: StubContainer?) { + override fun visitConstructor(constructorStub: ConstructorStub, data: StubContainer?) { constructorStub.annotations.forEach { out(renderAnnotation(it)) } @@ -223,11 +223,11 @@ class StubIrTextEmitter( out("${visibility}constructor(${constructorStub.parameters.joinToString { renderFunctionParameter(it) }}) {}") } - override fun visitPropertyAccessor(propertyAccessor: PropertyAccessor, owner: StubContainer?) { + override fun visitPropertyAccessor(propertyAccessor: PropertyAccessor, data: StubContainer?) { } - override fun visitSimpleStubContainer(simpleStubContainer: SimpleStubContainer, owner: StubContainer?) { + override fun visitSimpleStubContainer(simpleStubContainer: SimpleStubContainer, data: StubContainer?) { if (simpleStubContainer.meta.textAtStart.isNotEmpty()) { out(simpleStubContainer.meta.textAtStart) } diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/defFileDependencies.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/defFileDependencies.kt index 841cf845fa4..3badf996c6b 100644 --- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/defFileDependencies.kt +++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/defFileDependencies.kt @@ -7,7 +7,6 @@ import org.jetbrains.kotlin.native.interop.gen.jvm.prepareTool import org.jetbrains.kotlin.native.interop.indexer.NativeLibraryHeaders import org.jetbrains.kotlin.native.interop.indexer.getHeaderPaths import org.jetbrains.kotlin.native.interop.tool.CInteropArguments -import kotlinx.cli.ArgParser import java.io.File fun defFileDependencies(args: Array) { @@ -40,7 +39,7 @@ private fun makeDependencyAssigner(targets: List, defFiles: List) private fun makeDependencyAssignerForTarget(target: String, defFiles: List): SingleTargetDependencyAssigner { val tool = prepareTool(target, KotlinPlatform.NATIVE) val cinteropArguments = CInteropArguments() - cinteropArguments.argParser.parse(arrayOf()) + cinteropArguments.argParser.parse(arrayOf()) val libraries = defFiles.associateWith { buildNativeLibrary( tool, @@ -73,7 +72,7 @@ private fun patchDepends(file: File, newDepends: List) { val newDefFileLines = listOf(dependsLine) + defFileLines.filter { !it.startsWith("depends =") } file.bufferedWriter().use { writer -> - newDefFileLines.forEach { writer.appendln(it) } + newDefFileLines.forEach { writer.appendLine(it) } } } diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/InteropLibraryCreation.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/InteropLibraryCreation.kt index 6b1754fe802..9aab4724226 100644 --- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/InteropLibraryCreation.kt +++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/InteropLibraryCreation.kt @@ -54,8 +54,8 @@ fun createInteropLibrary( nopack = nopack, shortName = shortName ).apply { - val metadata = metadata.write(ChunkingWriteStrategy()) - addMetadata(SerializedMetadata(metadata.header, metadata.fragments, metadata.fragmentNames)) + val serializedMetadata = metadata.write(ChunkingWriteStrategy()) + addMetadata(SerializedMetadata(serializedMetadata.header, serializedMetadata.fragments, serializedMetadata.fragmentNames)) nativeBitcodeFiles.forEach(this::addNativeBitcode) addManifestAddend(manifest) addLinkDependencies(dependencies) diff --git a/backend.native/build.gradle b/backend.native/build.gradle index 521bf829c2f..110d99b697d 100644 --- a/backend.native/build.gradle +++ b/backend.native/build.gradle @@ -56,7 +56,8 @@ compileCompilerKotlin { // but not for Kotlin. dependsOn('generateCompilerProto') kotlinOptions.jvmTarget = "1.8" - kotlinOptions.freeCompilerArgs += "-Xopt-in=org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI" + kotlinOptions.allWarningsAsErrors=true + kotlinOptions.freeCompilerArgs += ['-Xopt-in=kotlin.RequiresOptIn', '-Xopt-in=org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI'] } compileCompilerJava { @@ -200,7 +201,9 @@ final List stdLibSrc = [ targetList.each { target -> def konanJvmArgs = [*HostManager.regularJvmArgs] - def defaultArgs = ['-nopack', '-nostdlib', '-no-default-libs', '-no-endorsed-libs'] + def defaultArgs = ['-nopack', '-nostdlib', '-no-default-libs', '-no-endorsed-libs', + //Uncomment this '-Werror' when common stdlib will be ready + ] if (target != "wasm32") defaultArgs += '-g' def konanArgs = [*defaultArgs, '-target', target, diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/BuiltInFictitiousFunctionIrClassFactory.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/BuiltInFictitiousFunctionIrClassFactory.kt index 4f79ed3c4e7..59e8860073b 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/BuiltInFictitiousFunctionIrClassFactory.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/BuiltInFictitiousFunctionIrClassFactory.kt @@ -19,10 +19,7 @@ import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol import org.jetbrains.kotlin.ir.symbols.IrSymbol -import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl -import org.jetbrains.kotlin.ir.symbols.impl.IrPropertySymbolImpl -import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl -import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl +import org.jetbrains.kotlin.ir.symbols.impl.* import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.classOrNull import org.jetbrains.kotlin.ir.types.defaultType @@ -113,7 +110,7 @@ internal class BuiltInFictitiousFunctionIrClassFactory( val builtFunctionNClasses get() = builtClassesMap.values - .filter { (it.descriptor as FunctionClassDescriptor).functionKind == FunctionClassDescriptor.Kind.Function } + .filter { it -> (it.descriptor as FunctionClassDescriptor).functionKind == FunctionClassDescriptor.Kind.Function } .map { FunctionalInterface(it, (it.descriptor as FunctionClassDescriptor).arity) } private fun createTypeParameter(descriptor: TypeParameterDescriptor) = @@ -122,8 +119,14 @@ internal class BuiltInFictitiousFunctionIrClassFactory( descriptor ) ?: IrTypeParameterImpl( - SYNTHETIC_OFFSET, SYNTHETIC_OFFSET, DECLARATION_ORIGIN_FUNCTION_CLASS, - descriptor + SYNTHETIC_OFFSET, + SYNTHETIC_OFFSET, + DECLARATION_ORIGIN_FUNCTION_CLASS, + IrTypeParameterSymbolImpl(descriptor), + descriptor.name, + descriptor.index, + descriptor.isReified, + descriptor.variance ) private fun createSimpleFunction( @@ -301,7 +304,23 @@ internal class BuiltInFictitiousFunctionIrClassFactory( fun createFakeOverrideProperty(descriptor: PropertyDescriptor): IrProperty { val propertyDeclare = { s: IrPropertySymbol -> - IrPropertyImpl(offset, offset, memberOrigin, descriptor, s, descriptor.name) + @Suppress("DEPRECATION") + /* TODO: [PropertyDescriptor::isDelegated] is deprecated. */ + IrPropertyImpl( + startOffset = offset, + endOffset = offset, + origin = memberOrigin, + symbol = s, + name = descriptor.name, + visibility = descriptor.visibility, + modality = descriptor.modality, + isVar = descriptor.isVar, + isConst = descriptor.isConst, + isLateinit = descriptor.isLateInit, + isDelegated = descriptor.isDelegated, + isExternal = descriptor.isExternal, + isExpect = descriptor.isExpect, + isFakeOverride = memberOrigin == IrDeclarationOrigin.FAKE_OVERRIDE) } val property = symbolTable?.declareProperty(offset, offset, memberOrigin, descriptor, propertyFactory = propertyDeclare) ?: propertyDeclare(IrPropertySymbolImpl(descriptor)) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Context.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Context.kt index c633658725b..3949dba6622 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Context.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Context.kt @@ -46,9 +46,11 @@ import org.jetbrains.kotlin.backend.konan.objcexport.ObjCExport import org.jetbrains.kotlin.backend.konan.llvm.coverage.CoverageManager import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor import org.jetbrains.kotlin.ir.symbols.IrSymbol +import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.konan.library.KonanLibraryLayout import org.jetbrains.kotlin.library.SerializedIrModule +import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal /** * Offset for synthetic elements created by lowerings and not attributable to other places in the source code. @@ -56,7 +58,7 @@ import org.jetbrains.kotlin.library.SerializedIrModule internal class SpecialDeclarationsFactory(val context: Context) { private val enumSpecialDeclarationsFactory by lazy { EnumSpecialDeclarationsFactory(context) } - private val outerThisFields = mutableMapOf() + private val outerThisFields = mutableMapOf() private val bridgesDescriptors = mutableMapOf, IrSimpleFunction>() private val loweredEnums = mutableMapOf() private val ordinals = mutableMapOf>() @@ -67,8 +69,8 @@ internal class SpecialDeclarationsFactory(val context: Context) { IrDeclarationOriginImpl("FIELD_FOR_OUTER_THIS") fun getOuterThisField(innerClass: IrClass): IrField = - if (!innerClass.descriptor.isInner) throw AssertionError("Class is not inner: ${innerClass.descriptor}") - else outerThisFields.getOrPut(innerClass.descriptor) { + if (!innerClass.isInner) throw AssertionError("Class is not inner: ${innerClass.descriptor}") + else outerThisFields.getOrPut(innerClass) { val outerClass = innerClass.parent as? IrClass ?: throw AssertionError("No containing class for inner class ${innerClass.descriptor}") @@ -87,11 +89,16 @@ internal class SpecialDeclarationsFactory(val context: Context) { } IrFieldImpl( - innerClass.startOffset, - innerClass.endOffset, - DECLARATION_ORIGIN_FIELD_FOR_OUTER_THIS, - descriptor, - outerClass.defaultType + startOffset = innerClass.startOffset, + endOffset = innerClass.endOffset, + origin = DECLARATION_ORIGIN_FIELD_FOR_OUTER_THIS, + symbol = IrFieldSymbolImpl(descriptor), + name = descriptor.name, + type = outerClass.defaultType, + visibility = descriptor.visibility, + isFinal = !descriptor.isVar, + isExternal = descriptor.isEffectivelyExternal(), + isStatic = descriptor.dispatchReceiverParameter == null ).apply { parent = innerClass } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/FeaturedLibraries.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/FeaturedLibraries.kt index 3f57cc1f4d6..9138796d0a4 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/FeaturedLibraries.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/FeaturedLibraries.kt @@ -15,6 +15,7 @@ import org.jetbrains.kotlin.konan.library.KonanLibrary import org.jetbrains.kotlin.library.SearchPathResolver import org.jetbrains.kotlin.library.isInterop import org.jetbrains.kotlin.library.toUnresolvedLibraries +import org.jetbrains.kotlin.utils.addToStdlib.cast internal fun Context.getExportedDependencies(): List = getDescriptorsFromLibraries((config.resolve.exportedLibraries + config.resolve.includedLibraries).toSet()) internal fun Context.getIncludedLibraryDescriptors(): List = getDescriptorsFromLibraries(config.resolve.includedLibraries.toSet()) @@ -93,11 +94,11 @@ private sealed class FeaturedLibrariesReporter { override fun reportNotIncludedLibraries(includedLibraries: List, remainingFeaturedLibraries: Set) { val message = buildString { - appendln(notIncludedLibraryMessageTitle()) - remainingFeaturedLibraries.forEach { appendln(it) } - appendln() - appendln("Included libraries:") - includedLibraries.forEach { appendln(it.libraryFile) } + appendLine(notIncludedLibraryMessageTitle()) + remainingFeaturedLibraries.forEach { appendLine(it) } + appendLine() + appendLine("Included libraries:") + includedLibraries.forEach { appendLine(it.libraryFile) } } configuration.report(CompilerMessageSeverity.STRONG_WARNING, message) @@ -163,7 +164,8 @@ private fun getFeaturedLibraries( ) : List { val remainingFeaturedLibraries = featuredLibraryFiles.toMutableSet() val result = mutableListOf() - val libraries = resolvedLibraries.getFullList(null) as List + //TODO: please add type checks before cast. + val libraries = resolvedLibraries.getFullList(null).cast>() for (library in libraries) { val libraryFile = library.libraryFile diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt index eb7d2b8dcf8..59eca4b9ffd 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.konan.target.* import org.jetbrains.kotlin.konan.util.KonanHomeProvider import org.jetbrains.kotlin.library.KotlinLibrary import org.jetbrains.kotlin.library.resolver.TopologicalLibraryOrder +import org.jetbrains.kotlin.utils.addToStdlib.cast class KonanConfig(val project: Project, val configuration: CompilerConfiguration) { @@ -32,7 +33,7 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration configuration.get(KonanConfigKeys.RUNTIME_FILE) ) - internal val platformManager = PlatformManager(distribution) + private val platformManager = PlatformManager(distribution) internal val targetManager = platformManager.targetManager(configuration.get(KonanConfigKeys.TARGET)) internal val target = targetManager.target internal val phaseConfig = configuration.get(CLIConfigurationKeys.PHASE_CONFIG)!! @@ -78,7 +79,7 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration internal val resolvedLibraries get() = resolve.resolvedLibraries - internal val cacheSupport = CacheSupport(configuration, resolvedLibraries, target, produce) + private val cacheSupport = CacheSupport(configuration, resolvedLibraries, target, produce) internal val cachedLibraries: CachedLibraries get() = cacheSupport.cachedLibraries @@ -106,12 +107,11 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration fun librariesWithDependencies(moduleDescriptor: ModuleDescriptor?): List { if (moduleDescriptor == null) error("purgeUnneeded() only works correctly after resolve is over, and we have successfully marked package files as needed or not needed.") - - return resolvedLibraries.filterRoots { (!it.isDefault && !this.purgeUserLibs) || it.isNeededForLink }.getFullList(TopologicalLibraryOrder) as List + return resolvedLibraries.filterRoots { (!it.isDefault && !this.purgeUserLibs) || it.isNeededForLink }.getFullList(TopologicalLibraryOrder).cast() } val shouldCoverSources = configuration.getBoolean(KonanConfigKeys.COVERAGE) - val shouldCoverLibraries = !configuration.getList(KonanConfigKeys.LIBRARIES_TO_COVER).isNullOrEmpty() + private val shouldCoverLibraries = !configuration.getList(KonanConfigKeys.LIBRARIES_TO_COVER).isNullOrEmpty() internal val runtimeNativeLibraries: List = mutableListOf().apply { add(if (debug) "debug.bc" else "release.bc") diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanDriver.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanDriver.kt index a13a92813cd..aab93ee9f87 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanDriver.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanDriver.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.backend.konan import org.jetbrains.kotlin.backend.common.phaser.CompilerPhase import org.jetbrains.kotlin.backend.common.phaser.invokeToplevel import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment +import org.jetbrains.kotlin.utils.addToStdlib.cast fun runTopLevelPhases(konanConfig: KonanConfig, environment: KotlinCoreEnvironment) { @@ -25,7 +26,7 @@ fun runTopLevelPhases(konanConfig: KonanConfig, environment: KotlinCoreEnvironme if (konanConfig.infoArgsOnly) return try { - (toplevelPhase as CompilerPhase).invokeToplevel(context.phaseConfig, context, Unit) + toplevelPhase.cast>().invokeToplevel(context.phaseConfig, context, Unit) } finally { context.disposeLlvm() } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ObjCInterop.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ObjCInterop.kt index 40fca960114..60ddd6222eb 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ObjCInterop.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ObjCInterop.kt @@ -39,7 +39,6 @@ private val objCConstructorFqName = FqName("kotlinx.cinterop.ObjCConstructor") private val objCFactoryFqName = interopPackageName.child(Name.identifier("ObjCFactory")) private val objcnamesForwardDeclarationsPackageName = Name.identifier("objcnames") -@Deprecated("Use IR version rather than descriptor version") fun ClassDescriptor.isObjCClass(): Boolean = this.getAllSuperClassifiers().any { it.fqNameSafe == objCObjectFqName } && // TODO: this is not cheap. Cache me! this.containingDeclaration.fqNameSafe != interopPackageName @@ -53,7 +52,6 @@ private fun IrClass.getAllSuperClassifiers(): List = internal fun IrClass.isObjCClass() = this.getAllSuperClassifiers().any { it.fqNameForIrSerialization == objCObjectFqName } && this.parent.fqNameForIrSerialization != interopPackageName -@Deprecated("Use IR version rather than descriptor version") fun ClassDescriptor.isExternalObjCClass(): Boolean = this.isObjCClass() && this.parentsWithSelf.filterIsInstance().any { it.annotations.findAnnotation(externalObjCClassFqName) != null @@ -86,7 +84,6 @@ fun FunctionDescriptor.isObjCClassMethod() = fun IrFunction.isObjCClassMethod() = this.parent.let { it is IrClass && it.isObjCClass() } -@Deprecated("Use IR version rather than descriptor version") fun FunctionDescriptor.isExternalObjCClassMethod() = this.containingDeclaration.let { it is ClassDescriptor && it.isExternalObjCClass() } @@ -94,14 +91,12 @@ internal fun IrFunction.isExternalObjCClassMethod() = this.parent.let {it is IrClass && it.isExternalObjCClass()} // Special case: methods from Kotlin Objective-C classes can be called virtually from bridges. -@Deprecated("Use IR version rather than descriptor version") fun FunctionDescriptor.canObjCClassMethodBeCalledVirtually(overriddenDescriptor: FunctionDescriptor) = overriddenDescriptor.isOverridable && this.kind.isReal && !this.isExternalObjCClassMethod() internal fun IrFunction.canObjCClassMethodBeCalledVirtually(overridden: IrFunction) = overridden.isOverridable && this.origin != IrDeclarationOrigin.FAKE_OVERRIDE && !this.isExternalObjCClassMethod() -@Deprecated("Use IR version rather than descriptor version") fun ClassDescriptor.isKotlinObjCClass(): Boolean = this.isObjCClass() && !this.isExternalObjCClass() fun IrClass.isKotlinObjCClass(): Boolean = this.isObjCClass() && !this.isExternalObjCClass() @@ -249,7 +244,6 @@ fun IrConstructor.objCConstructorIsDesignated(): Boolean = this.getAnnotationArgumentValue(objCConstructorFqName, "designated") ?: error("Could not find 'designated' argument") -@Deprecated("Use IR version rather than descriptor version") fun ConstructorDescriptor.objCConstructorIsDesignated(): Boolean { val annotation = this.annotations.findAnnotation(objCConstructorFqName)!! val value = annotation.allValueArguments[Name.identifier("designated")]!! diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/cgen/CBridgeGenUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/cgen/CBridgeGenUtils.kt index ca0af6c4ce7..cb119be41cb 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/cgen/CBridgeGenUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/cgen/CBridgeGenUtils.kt @@ -20,7 +20,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrTryImpl import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl import org.jetbrains.kotlin.ir.types.IrType -import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType +import org.jetbrains.kotlin.ir.types.impl.* import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.name.Name @@ -103,7 +103,7 @@ private fun createKotlinBridge( isExternal: Boolean ): IrFunctionImpl { val bridgeDescriptor = WrappedSimpleFunctionDescriptor() - val bridge = IrFunctionImpl( + @Suppress("DEPRECATION") val bridge = IrFunctionImpl( startOffset, endOffset, IrDeclarationOrigin.DEFINED, diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/ClassLayoutBuilder.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/ClassLayoutBuilder.kt index 7902b89f91c..f8fb6db6419 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/ClassLayoutBuilder.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/ClassLayoutBuilder.kt @@ -120,7 +120,7 @@ internal class GlobalHierarchyAnalysis(val context: Context, val irModule: IrMod * else binary_search(0, -size) */ val interfaceColors = assignColorsToInterfaces() - val maxColor = interfaceColors.values.max() ?: 0 + val maxColor = interfaceColors.values.maxOrNull() ?: 0 var bitsPerColor = 0 var x = maxColor while (x > 0) { diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/DescriptorUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/DescriptorUtils.kt index 9597fd434ad..789d6dc450a 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/DescriptorUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/DescriptorUtils.kt @@ -6,12 +6,8 @@ package org.jetbrains.kotlin.backend.konan.descriptors import org.jetbrains.kotlin.backend.common.atMostOne -import org.jetbrains.kotlin.backend.konan.KonanFqNames -import org.jetbrains.kotlin.backend.konan.RuntimeNames -import org.jetbrains.kotlin.backend.konan.binaryTypeIsReference -import org.jetbrains.kotlin.backend.konan.ir.getSuperClassNotAny -import org.jetbrains.kotlin.backend.konan.ir.getSuperInterfaces -import org.jetbrains.kotlin.backend.konan.isInlinedNative +import org.jetbrains.kotlin.backend.konan.* +import org.jetbrains.kotlin.backend.konan.ir.* import org.jetbrains.kotlin.backend.konan.llvm.longName import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor @@ -27,6 +23,7 @@ import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.resolve.annotations.argumentValue import org.jetbrains.kotlin.resolve.constants.StringValue import org.jetbrains.kotlin.resolve.descriptorUtil.module +import org.jetbrains.kotlin.utils.addToStdlib.cast import org.jetbrains.kotlin.utils.addToStdlib.safeAs /** @@ -214,11 +211,11 @@ internal val IrClass.isFrozen: Boolean // RTTI is used for non-reference type box: !this.defaultType.binaryTypeIsReference() -fun IrConstructorCall.getAnnotationStringValue() = (getValueArgument(0) as? IrConst)?.value +fun IrConstructorCall.getAnnotationStringValue() = getValueArgument(0).safeAs>()?.value fun IrConstructorCall.getAnnotationStringValue(name: String): String { val parameter = symbol.owner.valueParameters.single { it.name.asString() == name } - return (getValueArgument(parameter.index) as IrConst).value + return getValueArgument(parameter.index).cast>().value } fun AnnotationDescriptor.getAnnotationStringValue(name: String): String { @@ -227,7 +224,7 @@ fun AnnotationDescriptor.getAnnotationStringValue(name: String): String { fun IrConstructorCall.getAnnotationValueOrNull(name: String): T? { val parameter = symbol.owner.valueParameters.atMostOne { it.name.asString() == name } - return parameter?.let { getValueArgument(it.index)?.let { (it as IrConst).value } } + return parameter?.let { getValueArgument(it.index)?.let { (it.cast>()).value } } } fun IrFunction.externalSymbolOrThrow(): String? { diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/LegacyDescriptorUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/LegacyDescriptorUtils.kt index 056fa33eeb9..4ba4de92f67 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/LegacyDescriptorUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/LegacyDescriptorUtils.kt @@ -7,20 +7,17 @@ package org.jetbrains.kotlin.backend.konan.descriptors import org.jetbrains.kotlin.backend.common.atMostOne import org.jetbrains.kotlin.backend.konan.RuntimeNames +import org.jetbrains.kotlin.builtins.konan.KonanBuiltIns import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor -import org.jetbrains.kotlin.builtins.konan.KonanBuiltIns import org.jetbrains.kotlin.descriptors.konan.DeserializedKlibModuleOrigin import org.jetbrains.kotlin.descriptors.konan.klibModuleOrigin -import org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.resolve.OverridingUtil import org.jetbrains.kotlin.resolve.checkers.ExpectedActualDeclarationChecker import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.resolve.descriptorUtil.module import org.jetbrains.kotlin.resolve.scopes.MemberScope -import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPropertyDescriptor -import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedSimpleFunctionDescriptor import org.jetbrains.kotlin.types.typeUtil.isNothing import org.jetbrains.kotlin.types.typeUtil.isUnit @@ -119,7 +116,7 @@ fun AnnotationDescriptor.getStringValueOrNull(name: String): String? { return constantValue?.value as String? } -fun AnnotationDescriptor.getArgumentValueOrNull(name: String): T? { +inline fun AnnotationDescriptor.getArgumentValueOrNull(name: String): T? { val constantValue = this.allValueArguments.entries.atMostOne { it.key.asString() == name }?.value diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/NewIrUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/NewIrUtils.kt index 1622bcb76e9..c95e3d0a1ee 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/NewIrUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/NewIrUtils.kt @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.ir.types.isMarkedNullable import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.utils.addToStdlib.safeAs val IrField.fqNameForIrSerialization: FqName get() = this.parent.fqNameForIrSerialization.child(this.name) @@ -67,12 +68,12 @@ val IrClass.isFinalClass: Boolean fun IrClass.isSpecialClassWithNoSupertypes() = this.isAny() || this.isNothing() -fun IrDeclaration.getAnnotationArgumentValue(fqName: FqName, argumentName: String): T? { +inline fun IrDeclaration.getAnnotationArgumentValue(fqName: FqName, argumentName: String): T? { val annotation = this.annotations.findAnnotation(fqName) ?: return null for (index in 0 until annotation.valueArgumentsCount) { val parameter = annotation.symbol.owner.valueParameters[index] if (parameter.name == Name.identifier(argumentName)) { - val actual = annotation.getValueArgument(index) as? IrConst + val actual = annotation.getValueArgument(index).safeAs>() return actual?.value } } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/interop/DescriptorToIrTranslationUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/interop/DescriptorToIrTranslationUtils.kt index fad00fa25af..a2de5a6abbb 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/interop/DescriptorToIrTranslationUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/interop/DescriptorToIrTranslationUtils.kt @@ -16,7 +16,7 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.impl.IrInstanceInitializerCallImpl import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.symbols.IrSymbol -import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType +import org.jetbrains.kotlin.ir.types.impl.* import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperInterfaces @@ -79,12 +79,14 @@ internal interface DescriptorToIrTranslationMixin { is PropertyDescriptor -> createProperty(it) is FunctionDescriptor -> createFunction(it, IrDeclarationOrigin.FAKE_OVERRIDE) else -> error("Unexpected fake override descriptor: $it") - } as IrDeclaration // Assistance for type inference. + } } } fun createConstructor(constructorDescriptor: ClassConstructorDescriptor): IrConstructor { val irConstructor = symbolTable.declareConstructor(constructorDescriptor) { + // TODO: [IrUninitializedType] is deprecated. + @Suppress("DEPRECATION") IrConstructorImpl( SYNTHETIC_OFFSET, SYNTHETIC_OFFSET, IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB, diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/BinaryInterface.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/BinaryInterface.kt index 219082c0d04..4d321fbfea6 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/BinaryInterface.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/BinaryInterface.kt @@ -133,7 +133,7 @@ internal fun RuntimeAware.getLlvmFunctionType(function: IrFunction): LLVMTypeRef paramTypes.add(kObjHeaderPtr) // Suspend functions have implicit parameter of type Continuation<>. if (isObjectType(returnType)) paramTypes.add(kObjHeaderPtrPtr) - return functionType(returnType, isVarArg = false, paramTypes = *paramTypes.toTypedArray()) + return functionType(returnType, isVarArg = false, paramTypes = paramTypes.toTypedArray()) } internal val IrClass.typeInfoHasVtableAttached: Boolean diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/BitcodePhases.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/BitcodePhases.kt index 4849c40a9df..033141e2919 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/BitcodePhases.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/BitcodePhases.kt @@ -20,6 +20,7 @@ import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.visitors.* import org.jetbrains.kotlin.konan.file.File import org.jetbrains.kotlin.util.OperatorNameConventions +import org.jetbrains.kotlin.utils.addToStdlib.cast internal val contextLLVMSetupPhase = makeKonanModuleOpPhase( name = "ContextLLVMSetup", @@ -45,7 +46,7 @@ internal val contextLLVMSetupPhase = makeKonanModuleOpPhase( producer = DWARF.producer, isOptimized = 0, flags = "", - rv = DWARF.runtimeVersion(context.config)) as DIScopeOpaqueRef? + rv = DWARF.runtimeVersion(context.config)).cast() else null } ) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/ContextUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/ContextUtils.kt index f0bdd4d3a19..d438ff14f1a 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/ContextUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/ContextUtils.kt @@ -5,9 +5,11 @@ package org.jetbrains.kotlin.backend.konan.llvm -import kotlinx.cinterop.* +import kotlinx.cinterop.allocArray +import kotlinx.cinterop.get +import kotlinx.cinterop.memScoped +import kotlinx.cinterop.toKString import llvm.* -import org.jetbrains.kotlin.library.resolver.TopologicalLibraryOrder import org.jetbrains.kotlin.backend.konan.Context import org.jetbrains.kotlin.backend.konan.hash.GlobalHash import org.jetbrains.kotlin.backend.konan.ir.llvmSymbolOrigin @@ -15,18 +17,16 @@ import org.jetbrains.kotlin.descriptors.konan.CompiledKlibModuleOrigin import org.jetbrains.kotlin.descriptors.konan.CurrentKlibModuleOrigin import org.jetbrains.kotlin.descriptors.konan.DeserializedKlibModuleOrigin import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl import org.jetbrains.kotlin.ir.util.file import org.jetbrains.kotlin.ir.util.fqNameForIrSerialization import org.jetbrains.kotlin.ir.util.isReal -import org.jetbrains.kotlin.ir.util.render import org.jetbrains.kotlin.konan.library.KonanLibrary import org.jetbrains.kotlin.konan.target.KonanTarget import org.jetbrains.kotlin.library.KotlinLibrary -import org.jetbrains.kotlin.library.uniqueName -import org.jetbrains.kotlin.library.unresolvedDependencies +import org.jetbrains.kotlin.library.resolver.TopologicalLibraryOrder import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.utils.addToStdlib.cast import kotlin.properties.ReadOnlyProperty import kotlin.reflect.KProperty @@ -208,7 +208,7 @@ internal interface ContextUtils : RuntimeAware { */ fun GlobalHash.getBytes(): ByteArray { val size = GlobalHash.size - assert(size.toLong() == LLVMStoreSizeOfType(llvmTargetData, runtime.globalHashType)) + assert(size == LLVMStoreSizeOfType(llvmTargetData, runtime.globalHashType)) return this.bits.getBytes(size) } @@ -394,7 +394,7 @@ internal class Llvm(val context: Context, val llvmModule: LLVMModuleRef) { .filter { require(it is KonanLibrary) (!it.isDefault && !context.config.purgeUserLibs) || imports.nativeDependenciesAreUsed(it) - } as List + }.cast>() } @@ -406,7 +406,7 @@ internal class Llvm(val context: Context, val llvmModule: LLVMModuleRef) { } val bitcodeToLink: List by lazy { - (context.config.resolvedLibraries.getFullList(TopologicalLibraryOrder) as List) + (context.config.resolvedLibraries.getFullList(TopologicalLibraryOrder).cast>()) .filter { shouldContainBitcode(it) } } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/DebugUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/DebugUtils.kt index 632b9550d8d..f19a8c6e4eb 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/DebugUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/DebugUtils.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.ir.util.render import org.jetbrains.kotlin.konan.CURRENT import org.jetbrains.kotlin.konan.CompilerVersion import org.jetbrains.kotlin.konan.file.File +import org.jetbrains.kotlin.utils.addToStdlib.cast internal object DWARF { val producer = "konanc ${CompilerVersion.CURRENT} / kotlin-compiler: ${KotlinVersion.CURRENT}" @@ -173,7 +174,7 @@ internal fun generateDebugInfoHeader(context: Context) { derivedFrom = null, elements = null, elementsCount = 0, - refPlace = null)!! as DITypeOpaqueRef + refPlace = null).cast() context.debugInfo.objHeaderPointerType = dwarfPointerType(context, objHeaderType) } } @@ -181,7 +182,7 @@ internal fun generateDebugInfoHeader(context: Context) { @Suppress("UNCHECKED_CAST") internal fun IrType.dwarfType(context: Context, targetData: LLVMTargetDataRef): DITypeOpaqueRef { when { - this.computePrimitiveBinaryTypeOrNull() != null -> return debugInfoBaseType(context, targetData, this.render(), llvmType(context), encoding(context).value.toInt()) + this.computePrimitiveBinaryTypeOrNull() != null -> return debugInfoBaseType(context, targetData, this.render(), llvmType(context), encoding().value.toInt()) else -> { return when { classOrNull != null || this.isTypeParameter() -> context.debugInfo.objHeaderPointerType!! @@ -225,7 +226,7 @@ internal fun IrType.llvmType(context:Context): LLVMTypeRef = context.debugInfo.l } } -internal fun IrType.encoding(context: Context): DwarfTypeKind = when(computePrimitiveBinaryTypeOrNull()) { +internal fun IrType.encoding(): DwarfTypeKind = when(computePrimitiveBinaryTypeOrNull()) { PrimitiveBinaryType.FLOAT -> DwarfTypeKind.DW_ATE_float PrimitiveBinaryType.DOUBLE -> DwarfTypeKind.DW_ATE_float PrimitiveBinaryType.BOOLEAN -> DwarfTypeKind.DW_ATE_boolean diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt index 510312abb47..d70aa43c3ef 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt @@ -13,7 +13,6 @@ import org.jetbrains.kotlin.backend.konan.* import org.jetbrains.kotlin.backend.konan.descriptors.* import org.jetbrains.kotlin.backend.konan.ir.* import org.jetbrains.kotlin.backend.konan.llvm.coverage.LLVMCoverageInstrumentation -import org.jetbrains.kotlin.backend.konan.optimizations.DataFlowIR import org.jetbrains.kotlin.builtins.UnsignedType import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.ir.IrElement @@ -424,7 +423,6 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map - val expression = irField.initializer?.expression if (irField.initializer != null && irField.storageKind == FieldStorageKind.THREAD_LOCAL) { val initialization = evaluateExpression(irField.initializer!!.expression) val address = context.llvmDeclarations.forStaticField(irField).storageAddressAccess.getAddress( @@ -713,15 +711,15 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map body.statements.forEach { generateStatement(it) } @@ -1669,7 +1667,6 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map, - resultLifetime: Lifetime): LLVMValueRef { - val result = call(function, args, resultLifetime) - if (symbol.returnsNothing) { - functionGenerationContext.unreachable() - } - - if (LLVMGetReturnType(getFunctionType(function)) == voidType) { - return codegen.theUnitInstanceRef.llvm - } - - return result - } - private fun call(function: LLVMValueRef, args: List, resultLifetime: Lifetime = Lifetime.IRRELEVANT, exceptionHandler: ExceptionHandler = currentCodeContext.exceptionHandler): LLVMValueRef { @@ -2513,8 +2489,6 @@ private fun Name.debugNameConversion(): Name = when(this) { else -> this } -class NoContextFound : Throwable() - internal class LocationInfo(val scope: DIScopeOpaqueRef, val line: Int, val column: Int, diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/coverage/CoverageInformation.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/coverage/CoverageInformation.kt index be9d4b98868..c318cdebaaa 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/coverage/CoverageInformation.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/coverage/CoverageInformation.kt @@ -87,8 +87,8 @@ class FunctionRegions( val structuralHash: Long = 0 override fun toString(): String = buildString { - appendln("${function.symbolName} regions:") - regions.forEach { (irElem, region) -> appendln("${ir2string(irElem)} -> ($region)") } + appendLine("${function.symbolName} regions:") + regions.forEach { (irElem, region) -> appendLine("${ir2string(irElem)} -> ($region)") } } } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/objcexport/ObjCExportCodeGenerator.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/objcexport/ObjCExportCodeGenerator.kt index bfe0c88a02c..329d04e1667 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/objcexport/ObjCExportCodeGenerator.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/objcexport/ObjCExportCodeGenerator.kt @@ -622,7 +622,7 @@ private fun ObjCExportBlockCodeGenerator.emitBlockToKotlinFunctionConverters() { val functionClassesByArity = context.ir.symbols.functionIrClassFactory.builtFunctionNClasses.associateBy { it.arity } - var count = ((functionClassesByArity.keys.max() ?: -1) + 1) + var count = ((functionClassesByArity.keys.maxOrNull() ?: -1) + 1) // TODO: ugly hack to avoid huge unneeded adaptors linked into every binary, needs rework. if (context.config.produce.isCache) { count = count.coerceAtMost(maxConvertorsInCache) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/CallableReferenceLowering.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/CallableReferenceLowering.kt index 729999ee81d..460d36aea2b 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/CallableReferenceLowering.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/CallableReferenceLowering.kt @@ -279,8 +279,8 @@ internal class CallableReferenceLowering(val context: Context): FileLoweringPass isKSuspendFunction -> kSuspendFunctionImplConstructorSymbol.owner else -> irBuiltIns.anyClass.owner.constructors.single() } - +irDelegatingConstructorCall(superConstructor).apply { - if (!isKFunction && !isKSuspendFunction) return@apply + +irDelegatingConstructorCall(superConstructor).apply applyIrDelegationConstructorCall@ { + if (!isKFunction && !isKSuspendFunction) return@applyIrDelegationConstructorCall // TODO: Remove as soon as IR declarations have their originalDescriptor. val name = (referencedFunction.descriptor as? WrappedSimpleFunctionDescriptor)?.originalDescriptor?.name ?: referencedFunction.name diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/EnumClassLowering.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/EnumClassLowering.kt index 2a180353459..97853436cdb 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/EnumClassLowering.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/EnumClassLowering.kt @@ -253,6 +253,7 @@ internal class EnumClassLowering(val context: Context) : ClassLoweringPass { createValuesPropertyInitializer(enumEntries) + @Suppress("DEPRECATION") return IrPropertyImpl(startOffset, endOffset, DECLARATION_ORIGIN_ENUM, false, loweredEnum.valuesField.descriptor, irField, getter, null).apply { parent = implObject diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropCallConvertors.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropCallConvertors.kt index 5f52bad4de8..359112514f9 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropCallConvertors.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropCallConvertors.kt @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.ir.expressions.IrConst import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.types.* import org.jetbrains.kotlin.ir.util.* +import org.jetbrains.kotlin.utils.addToStdlib.cast /** * Check given function is a getter or setter @@ -230,8 +231,7 @@ private fun InteropCallContext.writePointerToMemory( private fun InteropCallContext.writeObjCReferenceToMemory( nativePtr: IrExpression, - value: IrExpression, - pointerType: IrType + value: IrExpression ): IrExpression { val valueToWrite = builder.irCall(symbols.interopObjCObjectRawValueGetter).also { it.extensionReceiver = value @@ -316,7 +316,7 @@ private fun InteropCallContext.generateEnumVarValueAccess(callSite: IrCall): IrE private fun InteropCallContext.generateMemberAtAccess(callSite: IrCall): IrExpression { val accessor = callSite.symbol.owner val memberAt = accessor.getAnnotation(RuntimeNames.cStructMemberAt)!! - val offset = (memberAt.getValueArgument(0) as IrConst).value + val offset = memberAt.getValueArgument(0).cast>().value val fieldPointer = calculateFieldPointer(callSite.dispatchReceiver!!, offset) return when { accessor.isGetter -> { @@ -337,7 +337,7 @@ private fun InteropCallContext.generateMemberAtAccess(callSite: IrCall): IrExpre type.isCEnumType() -> writeEnumValueToMemory(fieldPointer, value, type) type.isStoredInMemoryDirectly() -> writeValueToMemory(fieldPointer, value, type) type.isCPointer() -> writePointerToMemory(fieldPointer, value, type) - type.isSupportedReference() -> writeObjCReferenceToMemory(fieldPointer, value, type) + type.isSupportedReference() -> writeObjCReferenceToMemory(fieldPointer, value) else -> failCompilation("Unsupported struct field type: ${type.getClass()?.name}") } } @@ -348,7 +348,7 @@ private fun InteropCallContext.generateMemberAtAccess(callSite: IrCall): IrExpre private fun InteropCallContext.generateArrayMemberAtAccess(callSite: IrCall): IrExpression { val accessor = callSite.symbol.owner val memberAt = accessor.getAnnotation(RuntimeNames.cStructArrayMemberAt)!! - val offset = (memberAt.getValueArgument(0) as IrConst).value + val offset = memberAt.getValueArgument(0).cast>().value val fieldPointer = calculateFieldPointer(callSite.dispatchReceiver!!, offset) return builder.irCall(symbols.interopInterpretCPointer).also { it.putValueArgument(0, fieldPointer) @@ -407,8 +407,8 @@ private fun InteropCallContext.readBits( private fun InteropCallContext.generateBitFieldAccess(callSite: IrCall): IrExpression { val accessor = callSite.symbol.owner val bitField = accessor.getAnnotation(RuntimeNames.cStructBitField)!! - val offset = (bitField.getValueArgument(0) as IrConst).value - val size = (bitField.getValueArgument(1) as IrConst).value + val offset = bitField.getValueArgument(0).cast>().value + val size = bitField.getValueArgument(1).cast>().value val base = builder.irCall(symbols.interopNativePointedRawPtrGetter).also { it.dispatchReceiver = callSite.dispatchReceiver!! } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExport.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExport.kt index 4f1ff49c332..0a852dd8a67 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExport.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExport.kt @@ -313,6 +313,6 @@ internal class ObjCExport(val context: Context, symbolTable: SymbolTable) { return allPackages.map { it.fqName }.distinct() .filter { candidate -> nonEmptyPackages.all { it.isSubpackageOf(candidate) } } // Now there are all common ancestors of non-empty packages. Longest of them is the least common accessor: - .maxBy { it.asString().length }!! + .maxByOrNull { it.asString().length }!! } } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt index 83e505944f0..e030c530f2e 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt @@ -201,7 +201,7 @@ internal class ObjCExportTranslatorImpl( return translateClassOrInterfaceName(descriptor).also { val objcName = forwardDeclarationObjcClassName(objcGenerics, descriptor, namer) - generator?.referenceClass(objcName, descriptor) + generator?.referenceClass(objcName) } } @@ -211,7 +211,7 @@ internal class ObjCExportTranslatorImpl( generator?.requireClassOrInterface(descriptor) return translateClassOrInterfaceName(descriptor).also { - generator?.referenceProtocol(it.objCName, descriptor) + generator?.referenceProtocol(it.objCName) } } @@ -1137,11 +1137,11 @@ abstract class ObjCExportHeaderGenerator internal constructor( } } - internal fun referenceClass(objCName: String, descriptor: ClassDescriptor? = null) { + internal fun referenceClass(objCName: String) { classForwardDeclarations += objCName } - internal fun referenceProtocol(objCName: String, descriptor: ClassDescriptor? = null) { + internal fun referenceProtocol(objCName: String) { protocolForwardDeclarations += objCName } } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportMapper.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportMapper.kt index a7594d3252a..0b5991c0dce 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportMapper.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportMapper.kt @@ -97,7 +97,7 @@ private fun ObjCExportMapper.isHiddenByDeprecation(descriptor: CallableMemberDes } internal fun ObjCExportMapper.getDeprecation(descriptor: DeclarationDescriptor): Deprecation? { - deprecationResolver?.getDeprecations(descriptor).orEmpty().maxBy { + deprecationResolver?.getDeprecations(descriptor).orEmpty().maxByOrNull { when (it.deprecationLevel) { DeprecationLevelValue.WARNING -> 1 DeprecationLevelValue.ERROR -> 2 diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/CallGraphBuilder.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/CallGraphBuilder.kt index 9effd0ee852..21b524645bb 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/CallGraphBuilder.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/CallGraphBuilder.kt @@ -229,7 +229,7 @@ internal class CallGraphBuilder(val context: Context, } val body = function.body body.forEachCallSite { call -> - val devirtualizedCallSite = (call as? DataFlowIR.Node.VirtualCall)?.let { devirtualizedCallSites?.get(it) } + val devirtualizedCallSite = (call as? DataFlowIR.Node.VirtualCall)?.let { devirtualizedCallSites.get(it) } if (devirtualizedCallSite == null) { val callee = call.callee.resolved() if (moduleDFG.functions.containsKey(callee)) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/DFGBuilder.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/DFGBuilder.kt index e3382a4e258..f9ef8ebf56a 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/DFGBuilder.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/DFGBuilder.kt @@ -133,8 +133,7 @@ private class ExpressionValuesExtractor(val context: Context, else { // Propagate cast to sub-values. forEachValue(expression.argument) { value -> with(expression) { - block(IrTypeOperatorCallImpl(startOffset, endOffset, type, operator, typeOperand, - typeOperand.classifierOrFail, value)) + block(IrTypeOperatorCallImpl(startOffset, endOffset, type, operator, typeOperand, value)) } } } @@ -404,7 +403,6 @@ internal class ModuleDFGBuilder(val context: Context, val irModule: IrModuleFrag .filterIsInstance().single { it.name.asString() == "invokeSuspend" }.symbol private val getContinuationSymbol = symbols.getContinuation - private val continuationType = getContinuationSymbol.owner.returnType private val arrayGetSymbols = symbols.arrayGet.values private val arraySetSymbols = symbols.arraySet.values diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/DataFlowIR.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/DataFlowIR.kt index 5c4ae6e40b5..1840201f363 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/DataFlowIR.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/DataFlowIR.kt @@ -5,17 +5,20 @@ package org.jetbrains.kotlin.backend.konan.optimizations -import org.jetbrains.kotlin.backend.common.ir.ir2stringWhole import org.jetbrains.kotlin.backend.konan.* import org.jetbrains.kotlin.backend.konan.descriptors.isAbstract +import org.jetbrains.kotlin.backend.konan.descriptors.isBuiltInOperator import org.jetbrains.kotlin.backend.konan.descriptors.target -import org.jetbrains.kotlin.backend.konan.ir.* -import org.jetbrains.kotlin.backend.konan.llvm.* +import org.jetbrains.kotlin.backend.konan.ir.allParameters +import org.jetbrains.kotlin.backend.konan.ir.isOverridableOrOverrides +import org.jetbrains.kotlin.backend.konan.llvm.functionName +import org.jetbrains.kotlin.backend.konan.llvm.isExported +import org.jetbrains.kotlin.backend.konan.llvm.localHash +import org.jetbrains.kotlin.backend.konan.llvm.symbolName import org.jetbrains.kotlin.backend.konan.lower.DECLARATION_ORIGIN_BRIDGE_METHOD import org.jetbrains.kotlin.backend.konan.lower.bridgeTarget import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.ModuleDescriptor -import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.* @@ -29,7 +32,6 @@ import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.backend.konan.descriptors.isBuiltInOperator internal object DataFlowIR { @@ -305,137 +307,137 @@ internal object DataFlowIR { " FUNCTION REFERENCE ${node.symbol}\n" is Node.StaticCall -> { - val result = StringBuilder() - result.appendln(" STATIC CALL ${node.callee}. Return type = ${node.returnType}") - node.arguments.forEach { - result.append(" ARG #${ids[it.node]!!}") - if (it.castToType == null) - result.appendln() - else - result.appendln(" CASTED TO ${it.castToType}") + buildString { + appendLine(" STATIC CALL ${node.callee}. Return type = ${node.returnType}") + node.arguments.forEach { + append(" ARG #${ids[it.node]!!}") + if (it.castToType == null) + appendLine() + else + appendLine(" CASTED TO ${it.castToType}") + } } - result.toString() } is Node.VtableCall -> { - val result = StringBuilder() - result.appendln(" VIRTUAL CALL ${node.callee}. Return type = ${node.returnType}") - result.appendln(" RECEIVER: ${node.receiverType}") - result.appendln(" VTABLE INDEX: ${node.calleeVtableIndex}") - node.arguments.forEach { - result.append(" ARG #${ids[it.node]!!}") - if (it.castToType == null) - result.appendln() - else - result.appendln(" CASTED TO ${it.castToType}") + buildString { + appendLine(" VIRTUAL CALL ${node.callee}. Return type = ${node.returnType}") + appendLine(" RECEIVER: ${node.receiverType}") + appendLine(" VTABLE INDEX: ${node.calleeVtableIndex}") + node.arguments.forEach { + append(" ARG #${ids[it.node]!!}") + if (it.castToType == null) + appendLine() + else + appendLine(" CASTED TO ${it.castToType}") + } } - result.toString() } is Node.ItableCall -> { - val result = StringBuilder() - result.appendln(" INTERFACE CALL ${node.callee}. Return type = ${node.returnType}") - result.appendln(" RECEIVER: ${node.receiverType}") - result.appendln(" METHOD HASH: ${node.calleeHash}") - node.arguments.forEach { - result.append(" ARG #${ids[it.node]!!}") - if (it.castToType == null) - result.appendln() - else - result.appendln(" CASTED TO ${it.castToType}") + buildString { + appendLine(" INTERFACE CALL ${node.callee}. Return type = ${node.returnType}") + appendLine(" RECEIVER: ${node.receiverType}") + appendLine(" METHOD HASH: ${node.calleeHash}") + node.arguments.forEach { + append(" ARG #${ids[it.node]!!}") + if (it.castToType == null) + appendLine() + else + appendLine(" CASTED TO ${it.castToType}") + } } - result.toString() } is Node.NewObject -> { - val result = StringBuilder() - result.appendln(" NEW OBJECT ${node.callee}") - result.appendln(" CONSTRUCTED TYPE ${node.constructedType}") - node.arguments.forEach { - result.append(" ARG #${ids[it.node]!!}") - if (it.castToType == null) - result.appendln() - else - result.appendln(" CASTED TO ${it.castToType}") + buildString { + appendLine(" NEW OBJECT ${node.callee}") + appendLine(" CONSTRUCTED TYPE ${node.constructedType}") + node.arguments.forEach { + append(" ARG #${ids[it.node]!!}") + if (it.castToType == null) + appendLine() + else + appendLine(" CASTED TO ${it.castToType}") + } } - result.toString() } is Node.FieldRead -> { - val result = StringBuilder() - result.appendln(" FIELD READ ${node.field}") - result.append(" RECEIVER #${node.receiver?.node?.let { ids[it]!! } ?: "null"}") - if (node.receiver?.castToType == null) - result.appendln() - else - result.appendln(" CASTED TO ${node.receiver.castToType}") - result.toString() + buildString { + appendLine(" FIELD READ ${node.field}") + append(" RECEIVER #${node.receiver?.node?.let { ids[it]!! } ?: "null"}") + if (node.receiver?.castToType == null) + appendLine() + else + appendLine(" CASTED TO ${node.receiver.castToType}") + } } is Node.FieldWrite -> { - val result = StringBuilder() - result.appendln(" FIELD WRITE ${node.field}") - result.append(" RECEIVER #${node.receiver?.node?.let { ids[it]!! } ?: "null"}") - if (node.receiver?.castToType == null) - result.appendln() - else - result.appendln(" CASTED TO ${node.receiver.castToType}") - print(" VALUE #${ids[node.value.node]!!}") - if (node.value.castToType == null) - result.appendln() - else - result.appendln(" CASTED TO ${node.value.castToType}") - result.toString() + buildString { + appendLine(" FIELD WRITE ${node.field}") + append(" RECEIVER #${node.receiver?.node?.let { ids[it]!! } ?: "null"}") + if (node.receiver?.castToType == null) + appendLine() + else + appendLine(" CASTED TO ${node.receiver.castToType}") + print(" VALUE #${ids[node.value.node]!!}") + if (node.value.castToType == null) + appendLine() + else + appendLine(" CASTED TO ${node.value.castToType}") + } } is Node.ArrayRead -> { - val result = StringBuilder() - result.appendln(" ARRAY READ") - result.append(" ARRAY #${ids[node.array.node]}") - if (node.array.castToType == null) - result.appendln() - else - result.appendln(" CASTED TO ${node.array.castToType}") - result.append(" INDEX #${ids[node.index.node]!!}") - if (node.index.castToType == null) - result.appendln() - else - result.appendln(" CASTED TO ${node.index.castToType}") - result.toString() + buildString { + appendLine(" ARRAY READ") + append(" ARRAY #${ids[node.array.node]}") + if (node.array.castToType == null) + appendLine() + else + appendLine(" CASTED TO ${node.array.castToType}") + append(" INDEX #${ids[node.index.node]!!}") + if (node.index.castToType == null) + appendLine() + else + appendLine(" CASTED TO ${node.index.castToType}") + } } is Node.ArrayWrite -> { - val result = StringBuilder() - result.appendln(" ARRAY WRITE") - result.append(" ARRAY #${ids[node.array.node]}") - if (node.array.castToType == null) - result.appendln() - else - result.appendln(" CASTED TO ${node.array.castToType}") - result.append(" INDEX #${ids[node.index.node]!!}") - if (node.index.castToType == null) - result.appendln() - else - result.appendln(" CASTED TO ${node.index.castToType}") - print(" VALUE #${ids[node.value.node]!!}") - if (node.value.castToType == null) - result.appendln() - else - result.appendln(" CASTED TO ${node.value.castToType}") - result.toString() + buildString { + appendLine(" ARRAY WRITE") + append(" ARRAY #${ids[node.array.node]}") + if (node.array.castToType == null) + appendLine() + else + appendLine(" CASTED TO ${node.array.castToType}") + append(" INDEX #${ids[node.index.node]!!}") + if (node.index.castToType == null) + appendLine() + else + appendLine(" CASTED TO ${node.index.castToType}") + print(" VALUE #${ids[node.value.node]!!}") + if (node.value.castToType == null) + appendLine() + else + appendLine(" CASTED TO ${node.value.castToType}") + } } is Node.Variable -> { - val result = StringBuilder() - result.appendln(" ${node.kind}") - node.values.forEach { - result.append(" VAL #${ids[it.node]!!}") - if (it.castToType == null) - result.appendln() - else - result.appendln(" CASTED TO ${it.castToType}") + buildString { + appendLine(" ${node.kind}") + node.values.forEach { + append(" VAL #${ids[it.node]!!}") + if (it.castToType == null) + appendLine() + else + appendLine(" CASTED TO ${it.castToType}") + } } - result.toString() } else -> { @@ -463,13 +465,6 @@ internal object DataFlowIR { private val FQ_NAME_POINTS_TO = FQ_NAME_KONAN.child(NAME_POINTS_TO) private val konanPackage = context.builtIns.builtInsModule.getPackage(FQ_NAME_KONAN).memberScope - private val escapesAnnotationDescriptor = konanPackage.getContributedClassifier( - NAME_ESCAPES, NoLookupLocation.FROM_BACKEND) as org.jetbrains.kotlin.descriptors.ClassDescriptor - private val escapesWhoDescriptor = escapesAnnotationDescriptor.unsubstitutedPrimaryConstructor!!.valueParameters.single() - private val pointsToAnnotationDescriptor = konanPackage.getContributedClassifier( - NAME_POINTS_TO, NoLookupLocation.FROM_BACKEND) as org.jetbrains.kotlin.descriptors.ClassDescriptor - private val pointsToOnWhomDescriptor = pointsToAnnotationDescriptor.unsubstitutedPrimaryConstructor!!.valueParameters.single() - private val getContinuationSymbol = context.ir.symbols.getContinuation private val continuationType = getContinuationSymbol.owner.returnType @@ -613,7 +608,7 @@ internal object DataFlowIR { val pointsToBitMask = (pointsToAnnotation?.getValueArgument(0) as? IrVararg)?.elements?.map { (it as IrConst).value } FunctionSymbol.External(name.localHash.value, attributes, it, takeName { name }, it.isExported()).apply { escapes = escapesBitMask - pointsTo = pointsToBitMask?.let { it.toIntArray() } + pointsTo = pointsToBitMask?.toIntArray() } } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/Devirtualization.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/Devirtualization.kt index 1532a88e7ed..b604cf59d7d 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/Devirtualization.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/Devirtualization.kt @@ -132,24 +132,6 @@ internal object Devirtualization { private val symbolTable = moduleDFG.symbolTable - // TODO: Make custom hashtable. - class IntHashSet : Iterable { - private val hashSet = HashSet() - val size get() = hashSet.size - fun isEmpty() = size == 0 - fun add(x: Int) = hashSet.add(x) - - override operator fun iterator(): Iterator = Itr() - - private inner class Itr : Iterator { - private val itr = hashSet.iterator() - override fun hasNext() = itr.hasNext() - - override fun next() = itr.next() - - } - } - sealed class Node(val id: Int) { var directCastEdges: MutableList? = null var reversedCastEdges: MutableList? = null @@ -818,8 +800,8 @@ internal object Devirtualization { return true } - private fun makePrime(x: Int): Int { - var x = x + private fun makePrime(p: Int): Int { + var x = p while (true) { if (isPrime(x)) return x ++x @@ -832,6 +814,7 @@ internal object Devirtualization { val directEdgesCount = IntArrayList() val reversedEdgesCount = IntArrayList() + @OptIn(ExperimentalUnsignedTypes::class) private fun addEdge(from: Node, to: Node) { val fromId = from.id val toId = to.id @@ -1600,7 +1583,7 @@ internal object Devirtualization { expression else with (cast) { IrTypeOperatorCallImpl(startOffset, endOffset, type, operator, - typeOperand, typeOperandClassifier, expression) + typeOperand, expression) } with (coercion) { return IrCallImpl(startOffset, endOffset, type, symbol, typeArgumentsCount, origin).apply { diff --git a/endorsedLibraries/kotlinx.cli/build.gradle b/endorsedLibraries/kotlinx.cli/build.gradle index 002440a53d0..512b5cb5f25 100644 --- a/endorsedLibraries/kotlinx.cli/build.gradle +++ b/endorsedLibraries/kotlinx.cli/build.gradle @@ -61,7 +61,7 @@ kotlin { jvm().compilations.all { kotlinOptions { - freeCompilerArgs = ["-Xopt-in=kotlinx.cli.ExperimentalCli"] + freeCompilerArgs = ["-Xopt-in=kotlinx.cli.ExperimentalCli", "-Xopt-in=kotlin.RequiresOptIn"] suppressWarnings = true } } @@ -100,7 +100,7 @@ targetList.each { target -> '-produce', 'library', '-module-name', moduleName, '-XXLanguage:+AllowContractsForCustomFunctions', '-Xmulti-platform', '-Xopt-in=kotlinx.cli.ExperimentalCli', '-Xopt-in=kotlin.ExperimentalMultiplatform', - '-Xallow-result-return-type', + '-Xallow-result-return-type', '-Werror', '-Xopt-in=kotlin.RequiresOptIn', commonSrc.absolutePath, "-Xcommon-sources=${commonSrc.absolutePath}", nativeSrc] diff --git a/endorsedLibraries/kotlinx.cli/src/main/kotlin-jvm/kotlinx/cli/Utils.kt b/endorsedLibraries/kotlinx.cli/src/main/kotlin-jvm/kotlinx/cli/nonStdlibUtils.kt similarity index 100% rename from endorsedLibraries/kotlinx.cli/src/main/kotlin-jvm/kotlinx/cli/Utils.kt rename to endorsedLibraries/kotlinx.cli/src/main/kotlin-jvm/kotlinx/cli/nonStdlibUtils.kt diff --git a/endorsedLibraries/kotlinx.cli/src/main/kotlin/kotlinx/cli/ArgParser.kt b/endorsedLibraries/kotlinx.cli/src/main/kotlin/kotlinx/cli/ArgParser.kt index 321d5ac3f7e..241ececc491 100644 --- a/endorsedLibraries/kotlinx.cli/src/main/kotlin/kotlinx/cli/ArgParser.kt +++ b/endorsedLibraries/kotlinx.cli/src/main/kotlin/kotlinx/cli/ArgParser.kt @@ -471,18 +471,18 @@ open class ArgParser( // Form with several short forms as one string. val otherBooleanOptions = option.substring(1) saveOptionWithoutParameter(firstOption) - for (option in otherBooleanOptions) { - shortNames["$option"]?.let { + for (opt in otherBooleanOptions) { + shortNames["$opt"]?.let { if (it.descriptor.type.hasParameter) { printError( - "Option $optionShortFromPrefix$option can't be used in option combination $candidate, " + + "Option $optionShortFromPrefix$opt can't be used in option combination $candidate, " + "because parameter value of type ${it.descriptor.type.description} should be " + "provided for current option." ) } - }?: printError("Unknown option $optionShortFromPrefix$option in option combination $candidate.") + }?: printError("Unknown option $optionShortFromPrefix$opt in option combination $candidate.") - saveOptionWithoutParameter(shortNames["$option"]!!) + saveOptionWithoutParameter(shortNames["$opt"]!!) } } } diff --git a/endorsedLibraries/kotlinx.cli/src/main/kotlin/kotlinx/cli/Arguments.kt b/endorsedLibraries/kotlinx.cli/src/main/kotlin/kotlinx/cli/Arguments.kt index 7a02502bba6..e25d860e5dc 100644 --- a/endorsedLibraries/kotlinx.cli/src/main/kotlin/kotlinx/cli/Arguments.kt +++ b/endorsedLibraries/kotlinx.cli/src/main/kotlin/kotlinx/cli/Arguments.kt @@ -159,7 +159,7 @@ class MultipleArgument internal c fun AbstractSingleArgument.multiple(number: Int): MultipleArgument { require(number >= 2) { "multiple() modifier with value less than 2 is unavailable. It's already set to 1." } - val newArgument = with((delegate as ParsingValue).descriptor as ArgDescriptor) { + val newArgument = with(delegate.cast>().descriptor as ArgDescriptor) { MultipleArgument(ArgDescriptor(type, fullName, number, description, listOfNotNull(defaultValue), required, deprecatedWarning), owner) } @@ -172,7 +172,7 @@ fun */ fun AbstractSingleArgument.vararg(): MultipleArgument { - val newArgument = with((delegate as ParsingValue).descriptor as ArgDescriptor) { + val newArgument = with(delegate.cast>().descriptor as ArgDescriptor) { MultipleArgument(ArgDescriptor(type, fullName, null, description, listOfNotNull(defaultValue), required, deprecatedWarning), owner) } @@ -189,7 +189,7 @@ fun AbstractSingleArgum * @param value the default value. */ fun SingleNullableArgument.default(value: T): SingleArgument { - val newArgument = with((delegate as ParsingValue).descriptor as ArgDescriptor) { + val newArgument = with(delegate.cast>().descriptor as ArgDescriptor) { SingleArgument(ArgDescriptor(type, fullName, number, description, value, false, deprecatedWarning), owner) } @@ -208,7 +208,7 @@ fun SingleNullableArgument.default(value: T): SingleArgument MultipleArgument.default(value: Collection): MultipleArgument { require (value.isNotEmpty()) { "Default value for argument can't be empty collection." } - val newArgument = with((delegate as ParsingValue>).descriptor as ArgDescriptor) { + val newArgument = with(delegate.cast>>().descriptor as ArgDescriptor) { MultipleArgument(ArgDescriptor(type, fullName, number, description, value.toList(), required, deprecatedWarning), owner) } @@ -224,7 +224,7 @@ fun MultipleArgument.default(value: Collec * Note that only trailing arguments can be optional, i.e. no required arguments can follow optional ones. */ fun SingleArgument.optional(): SingleNullableArgument { - val newArgument = with((delegate as ParsingValue).descriptor as ArgDescriptor) { + val newArgument = with(delegate.cast>().descriptor as ArgDescriptor) { SingleNullableArgument(ArgDescriptor(type, fullName, number, description, defaultValue, false, deprecatedWarning), owner) } @@ -240,7 +240,7 @@ fun SingleArgument.optional(): SingleN * Note that only trailing arguments can be optional: no required arguments can follow the optional ones. */ fun MultipleArgument.optional(): MultipleArgument { - val newArgument = with((delegate as ParsingValue>).descriptor as ArgDescriptor) { + val newArgument = with(delegate.cast>>().descriptor as ArgDescriptor) { MultipleArgument(ArgDescriptor(type, fullName, number, description, defaultValue?.toList() ?: listOf(), false, deprecatedWarning), owner) } @@ -248,4 +248,6 @@ fun MultipleArgument.optional(): Multi return newArgument } -internal fun failAssertion(message: String): Nothing = throw AssertionError(message) \ No newline at end of file +internal fun failAssertion(message: String): Nothing = throw AssertionError(message) + +internal inline fun Any?.cast(): T = this as T \ No newline at end of file diff --git a/endorsedLibraries/kotlinx.cli/src/main/kotlin/kotlinx/cli/ExperimentalCli.kt b/endorsedLibraries/kotlinx.cli/src/main/kotlin/kotlinx/cli/ExperimentalCli.kt index 7f8f2e9fc14..d35f6be01bf 100644 --- a/endorsedLibraries/kotlinx.cli/src/main/kotlin/kotlinx/cli/ExperimentalCli.kt +++ b/endorsedLibraries/kotlinx.cli/src/main/kotlin/kotlinx/cli/ExperimentalCli.kt @@ -17,7 +17,7 @@ import kotlin.annotation.AnnotationTarget.* * annotating that usage with the [UseExperimental] annotation, e.g. `@UseExperimental(ExperimentalCli::class)`, * or by using the compiler argument `-Xuse-experimental=kotlinx.cli.ExperimentalCli`. */ -@RequiresOptIn("This API is experimental. It may be changed in the future without notice.", RequiresOptIn.Level.WARNING) +@RequiresOptIn("This API is experimental. It may be changed in the future without notice.", level = RequiresOptIn.Level.WARNING) @Retention(AnnotationRetention.BINARY) @Target( CLASS, diff --git a/endorsedLibraries/kotlinx.cli/src/main/kotlin/kotlinx/cli/Options.kt b/endorsedLibraries/kotlinx.cli/src/main/kotlin/kotlinx/cli/Options.kt index 2a5508acd30..69999451842 100644 --- a/endorsedLibraries/kotlinx.cli/src/main/kotlin/kotlinx/cli/Options.kt +++ b/endorsedLibraries/kotlinx.cli/src/main/kotlin/kotlinx/cli/Options.kt @@ -103,7 +103,7 @@ class MultipleOption AbstractSingleOption.multiple(): MultipleOption { - val newOption = with((delegate as ParsingValue).descriptor as OptionDescriptor) { + val newOption = with(delegate.cast>().descriptor as OptionDescriptor) { MultipleOption( OptionDescriptor( optionFullFormPrefix, optionShortFromPrefix, type, fullName, shortName, @@ -122,7 +122,7 @@ fun AbstractSingleOption MultipleOption.multiple(): MultipleOption { - val newOption = with((delegate as ParsingValue>).descriptor as OptionDescriptor) { + val newOption = with(delegate.cast>>().descriptor as OptionDescriptor) { if (multiple) { error("Try to use modifier multiple() twice on option ${fullName ?: ""}") } @@ -145,7 +145,7 @@ fun MultipleOption SingleNullableOption.default(value: T): SingleOption { - val newOption = with((delegate as ParsingValue).descriptor as OptionDescriptor) { + val newOption = with(delegate.cast>().descriptor as OptionDescriptor) { SingleOption( OptionDescriptor( optionFullFormPrefix, optionShortFromPrefix, type, fullName, shortName, @@ -167,7 +167,7 @@ fun SingleNullableOption.default(value: T): SingleOption MultipleOption.default(value: Collection): MultipleOption { - val newOption = with((delegate as ParsingValue>).descriptor as OptionDescriptor) { + val newOption = with(delegate.cast>>().descriptor as OptionDescriptor) { require(value.isNotEmpty()) { "Default value for option can't be empty collection." } MultipleOption( OptionDescriptor( @@ -185,7 +185,7 @@ fun * Requires the option to be always provided in command line. */ fun SingleNullableOption.required(): SingleOption { - val newOption = with((delegate as ParsingValue).descriptor as OptionDescriptor) { + val newOption = with(delegate.cast>().descriptor as OptionDescriptor) { SingleOption( OptionDescriptor( optionFullFormPrefix, optionShortFromPrefix, type, fullName, @@ -204,7 +204,7 @@ fun SingleNullableOption.required(): SingleOption MultipleOption.required(): MultipleOption { - val newOption = with((delegate as ParsingValue>).descriptor as OptionDescriptor) { + val newOption = with(delegate.cast>>().descriptor as OptionDescriptor) { MultipleOption( OptionDescriptor( optionFullFormPrefix, optionShortFromPrefix, type, fullName, shortName, @@ -228,7 +228,7 @@ fun fun AbstractSingleOption.delimiter( delimiterValue: String): MultipleOption { - val newOption = with((delegate as ParsingValue).descriptor as OptionDescriptor) { + val newOption = with(delegate.cast>().descriptor as OptionDescriptor) { MultipleOption( OptionDescriptor( optionFullFormPrefix, optionShortFromPrefix, type, fullName, shortName, @@ -252,7 +252,7 @@ fun AbstractSingleOption MultipleOption.delimiter( delimiterValue: String): MultipleOption { - val newOption = with((delegate as ParsingValue>).descriptor as OptionDescriptor) { + val newOption = with(delegate.cast>>().descriptor as OptionDescriptor) { MultipleOption( OptionDescriptor( optionFullFormPrefix, optionShortFromPrefix, type, fullName, shortName,