From 86404b8027834286a6e218fea684c8511bc8bbcb Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Wed, 1 Dec 2021 16:23:33 +0300 Subject: [PATCH] [FIR] Implement IR body generators for all FIR declarations generators in plugin prototype --- .../kotlin/ir/util/AdditionalIrUtils.kt | 4 +- .../jetbrains/kotlin/ir/util/DumpIrTree.kt | 5 + .../backend/handlers/IrTextDumpHandler.kt | 6 +- .../backend/handlers/IrTreeVerifierHandler.kt | 2 + .../kotlin/generators/tests/GenerateTests.kt | 4 - .../kotlin/fir/plugin/SomePluginKey.kt | 14 -- .../plugin/generators/CompanionGenerator.kt | 26 +++- .../TopLevelDeclarationsGenerator.kt | 9 +- .../fir/plugin/generators/generationUtils.kt | 1 - .../plugin/AbstractTransformerForGenerator.kt | 96 +++++++++++++ .../GeneratedDeclarationsIrBodyFiller.kt | 80 ++--------- ...ransformerForAdditionalMembersGenerator.kt | 27 ++++ .../TransformerForCompanionGenerator.kt | 32 +++++ .../TransformerForExternalClassGenerator.kt | 27 ++++ ...sformerForTopLevelDeclarationsGenerator.kt | 34 +++++ .../box/classWithCompanionObject.fir.txt | 30 ++++ .../testData/box/classWithCompanionObject.kt | 19 +++ ...WithGeneratedMembersAndNestedClass.fir.txt | 9 +- ...classWithGeneratedMembersAndNestedClass.kt | 9 +- ...lassWithMembersAndNestedClasses.fir.ir.txt | 52 +------ .../testData/box/newSupertype.fir.txt | 38 +++++ .../testData/box/newSupertype.kt | 33 +++++ .../testData/box/topLevelCallables.fir.txt | 37 +++++ .../testData/box/topLevelCallables.kt | 19 +++ .../classWithCompanionObject.fir.txt | 4 +- ...hGeneratedMembersAndNestedClass.fir.ir.txt | 86 ----------- ...lassWithMembersAndNestedClasses.fir.ir.txt | 133 ------------------ ...edClassWithMembersAndNestedClasses.fir.txt | 51 ------- ...neratedClassWithMembersAndNestedClasses.kt | 27 ---- .../memberGen/topLevelCallables.fir.ir.txt | 36 ----- .../memberGen/topLevelCallables.fir.txt | 20 --- .../fir2ir/memberGen/topLevelCallables.kt | 13 -- .../AllOpenBlackBoxCodegenTestGenerated.java | 24 ++++ .../runners/Fir2IrAllOpenTestGenerated.java | 55 -------- .../runners/AbstractFir2IrAllOpenTest.kt | 33 ----- 35 files changed, 485 insertions(+), 610 deletions(-) delete mode 100644 plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/SomePluginKey.kt create mode 100644 plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/AbstractTransformerForGenerator.kt create mode 100644 plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/TransformerForAdditionalMembersGenerator.kt create mode 100644 plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/TransformerForCompanionGenerator.kt create mode 100644 plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/TransformerForExternalClassGenerator.kt create mode 100644 plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/TransformerForTopLevelDeclarationsGenerator.kt create mode 100644 plugins/fir/fir-plugin-prototype/testData/box/classWithCompanionObject.fir.txt create mode 100644 plugins/fir/fir-plugin-prototype/testData/box/classWithCompanionObject.kt rename plugins/fir/fir-plugin-prototype/testData/{fir2ir/memberGen => box}/classWithGeneratedMembersAndNestedClass.fir.txt (73%) rename plugins/fir/fir-plugin-prototype/testData/{fir2ir/memberGen => box}/classWithGeneratedMembersAndNestedClass.kt (64%) create mode 100644 plugins/fir/fir-plugin-prototype/testData/box/newSupertype.fir.txt create mode 100644 plugins/fir/fir-plugin-prototype/testData/box/newSupertype.kt create mode 100644 plugins/fir/fir-plugin-prototype/testData/box/topLevelCallables.fir.txt create mode 100644 plugins/fir/fir-plugin-prototype/testData/box/topLevelCallables.kt delete mode 100644 plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/classWithGeneratedMembersAndNestedClass.fir.ir.txt delete mode 100644 plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/generatedClassWithMembersAndNestedClasses.fir.ir.txt delete mode 100644 plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/generatedClassWithMembersAndNestedClasses.fir.txt delete mode 100644 plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/generatedClassWithMembersAndNestedClasses.kt delete mode 100644 plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/topLevelCallables.fir.ir.txt delete mode 100644 plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/topLevelCallables.fir.txt delete mode 100644 plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/topLevelCallables.kt delete mode 100644 plugins/fir/fir-plugin-prototype/tests-gen/org/jetbrains/kotlin/fir/plugin/runners/Fir2IrAllOpenTestGenerated.java delete mode 100644 plugins/fir/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/runners/AbstractFir2IrAllOpenTest.kt diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/AdditionalIrUtils.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/AdditionalIrUtils.kt index b8852357880..106185663bb 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/AdditionalIrUtils.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/AdditionalIrUtils.kt @@ -187,6 +187,8 @@ class NaiveSourceBasedFileEntryImpl( override val name: String, private val lineStartOffsets: IntArray = intArrayOf() ) : IrFileEntry { + val lineStartOffsetsAreEmpty: Boolean + get() = lineStartOffsets.isEmpty() private val MAX_SAVED_LINE_NUMBERS = 50 @@ -254,4 +256,4 @@ inline fun MemberScope.findFirstFunction(name: String, predicate: (CallableMembe fun filterOutAnnotations(fqName: FqName, annotations: List): List { return annotations.filterNot { it.annotationClass.hasEqualFqName(fqName) } -} \ No newline at end of file +} diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DumpIrTree.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DumpIrTree.kt index d29bdb30dff..ab4aae8cfb2 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DumpIrTree.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DumpIrTree.kt @@ -42,6 +42,11 @@ fun IrFile.dumpTreesFromLineNumber(lineNumber: Int, normalizeNames: Boolean = fa return sb.toString() } +fun IrFile.shouldSkipDump(): Boolean { + val entry = fileEntry as? NaiveSourceBasedFileEntryImpl ?: return false + return entry.lineStartOffsetsAreEmpty +} + class DumpIrTreeVisitor( out: Appendable, normalizeNames: Boolean = false, diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrTextDumpHandler.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrTextDumpHandler.kt index c7e6cf91725..e3cf28aca67 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrTextDumpHandler.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrTextDumpHandler.kt @@ -13,10 +13,7 @@ import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc import org.jetbrains.kotlin.ir.declarations.IrClass import org.jetbrains.kotlin.ir.declarations.IrFile import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl -import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator -import org.jetbrains.kotlin.ir.util.SymbolTable -import org.jetbrains.kotlin.ir.util.dump -import org.jetbrains.kotlin.ir.util.dumpTreesFromLineNumber +import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi2ir.generators.DeclarationStubGeneratorImpl @@ -68,6 +65,7 @@ class IrTextDumpHandler(testServices: TestServices) : AbstractIrHandler(testServ val builder = baseDumper.builderForModule(module) for ((testFile, irFile) in testFileToIrFile) { if (testFile?.directives?.contains(EXTERNAL_FILE) == true) continue + if (irFile.shouldSkipDump()) continue var actualDump = irFile.dumpTreesFromLineNumber(lineNumber = 0, normalizeNames = true) if (actualDump.isEmpty()) { actualDump = irFile.dumpTreesFromLineNumber(lineNumber = UNDEFINED_OFFSET, normalizeNames = true) diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrTreeVerifierHandler.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrTreeVerifierHandler.kt index 847efd67203..a0cadb0f8ed 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrTreeVerifierHandler.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrTreeVerifierHandler.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.test.backend.handlers import org.jetbrains.kotlin.ir.IrVerifier import org.jetbrains.kotlin.ir.util.deepCopyWithSymbols import org.jetbrains.kotlin.ir.util.dumpTreesFromLineNumber +import org.jetbrains.kotlin.ir.util.shouldSkipDump import org.jetbrains.kotlin.test.backend.handlers.IrTextDumpHandler.Companion.groupWithTestFiles import org.jetbrains.kotlin.test.backend.ir.IrBackendInput import org.jetbrains.kotlin.test.directives.CodegenTestDirectives @@ -29,6 +30,7 @@ class IrTreeVerifierHandler(testServices: TestServices) : AbstractIrHandler(test IrVerifier(assertions).verifyWithAssert(irFile) + if (irFile.shouldSkipDump()) continue val actualDump = irFile.dumpTreesFromLineNumber(lineNumber = 0, normalizeNames = true) val irFileCopy = irFile.deepCopyWithSymbols() diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index 95036338de0..7390a150113 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -388,10 +388,6 @@ fun main(args: Array) { model("diagnostics") } - testClass { - model("fir2ir") - } - testClass { model("box") } diff --git a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/SomePluginKey.kt b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/SomePluginKey.kt deleted file mode 100644 index 05e487bc46c..00000000000 --- a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/SomePluginKey.kt +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.fir.plugin - -import org.jetbrains.kotlin.fir.declarations.FirPluginKey - -object SomePluginKey : FirPluginKey() { - override fun toString(): String { - return "AllOpenPlugin" - } -} diff --git a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/CompanionGenerator.kt b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/CompanionGenerator.kt index f8c7f8adf60..661fc540e94 100644 --- a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/CompanionGenerator.kt +++ b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/CompanionGenerator.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.descriptors.EffectiveVisibility import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin import org.jetbrains.kotlin.fir.declarations.FirPluginKey import org.jetbrains.kotlin.fir.declarations.builder.buildRegularClass import org.jetbrains.kotlin.fir.declarations.builder.buildSimpleFunction @@ -23,10 +24,7 @@ import org.jetbrains.kotlin.fir.plugin.fqn import org.jetbrains.kotlin.fir.resolve.defaultType import org.jetbrains.kotlin.fir.scopes.kotlinScopeProvider import org.jetbrains.kotlin.fir.symbols.SymbolInternals -import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol +import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.name.CallableId import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.Name @@ -59,7 +57,9 @@ class CompanionGenerator(session: FirSession) : FirDeclarationGenerationExtensio Visibilities.Public, Modality.FINAL, EffectiveVisibility.Public - ) + ).apply { + isCompanion = true + } name = SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT symbol = FirRegularClassSymbol(classId) superTypeRefs += session.builtinTypes.anyType @@ -86,8 +86,22 @@ class CompanionGenerator(session: FirSession) : FirDeclarationGenerationExtensio return listOf(function.symbol) } + override fun generateConstructors(owner: FirClassSymbol<*>): List { + val constructor = buildConstructor(owner.classId, isInner = false, Key) + return listOf(constructor.symbol) + } + override fun getCallableNamesForClass(classSymbol: FirClassSymbol<*>): Set { - return setOf(FOO_NAME) + if (classSymbol.classKind != ClassKind.OBJECT) return emptySet() + if (classSymbol !is FirRegularClassSymbol) return emptySet() + val classId = classSymbol.classId + if (!classId.isNestedClass || classId.shortClassName != SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT) return emptySet() + val origin = classSymbol.origin as? FirDeclarationOrigin.Plugin + return if (origin?.key == Key) { + setOf(FOO_NAME, SpecialNames.INIT) + } else { + setOf(FOO_NAME) + } } @OptIn(SymbolInternals::class) diff --git a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/TopLevelDeclarationsGenerator.kt b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/TopLevelDeclarationsGenerator.kt index 182dac64673..333b422abc8 100644 --- a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/TopLevelDeclarationsGenerator.kt +++ b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/TopLevelDeclarationsGenerator.kt @@ -9,6 +9,7 @@ import org.jetbrains.kotlin.descriptors.EffectiveVisibility import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.declarations.FirPluginKey import org.jetbrains.kotlin.fir.declarations.builder.buildSimpleFunction import org.jetbrains.kotlin.fir.declarations.builder.buildValueParameter import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedDeclarationStatusImpl @@ -18,7 +19,6 @@ import org.jetbrains.kotlin.fir.extensions.predicate.DeclarationPredicate import org.jetbrains.kotlin.fir.extensions.predicate.has import org.jetbrains.kotlin.fir.extensions.predicateBasedProvider import org.jetbrains.kotlin.fir.moduleData -import org.jetbrains.kotlin.fir.plugin.SomePluginKey import org.jetbrains.kotlin.fir.plugin.fqn import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef @@ -45,7 +45,7 @@ class TopLevelDeclarationsGenerator(session: FirSession) : FirDeclarationGenerat val matchedClassSymbol = findMatchedClassForFunction(callableId) ?: return emptyList() val function = buildSimpleFunction { moduleData = session.moduleData - origin = key.origin + origin = Key.origin status = FirResolvedDeclarationStatusImpl( Visibilities.Public, Modality.FINAL, @@ -54,7 +54,7 @@ class TopLevelDeclarationsGenerator(session: FirSession) : FirDeclarationGenerat returnTypeRef = session.builtinTypes.stringType valueParameters += buildValueParameter { moduleData = session.moduleData - origin = key.origin + origin = Key.origin returnTypeRef = buildResolvedTypeRef { type = ConeClassLikeTypeImpl(ConeClassLikeLookupTagImpl(matchedClassSymbol.classId), emptyArray(), isNullable = false) } @@ -89,8 +89,7 @@ class TopLevelDeclarationsGenerator(session: FirSession) : FirDeclarationGenerat } } - private val key: SomePluginKey - get() = SomePluginKey + object Key : FirPluginKey() override fun FirDeclarationPredicateRegistrar.registerPredicates() { register(PREDICATE) diff --git a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/generationUtils.kt b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/generationUtils.kt index 93933f196f2..5434fd131e6 100644 --- a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/generationUtils.kt +++ b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/generationUtils.kt @@ -18,7 +18,6 @@ import org.jetbrains.kotlin.fir.declarations.builder.buildSimpleFunction import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedDeclarationStatusImpl import org.jetbrains.kotlin.fir.extensions.FirDeclarationGenerationExtension import org.jetbrains.kotlin.fir.moduleData -import org.jetbrains.kotlin.fir.plugin.SomePluginKey import org.jetbrains.kotlin.fir.resolve.defaultType import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider import org.jetbrains.kotlin.fir.symbols.SymbolInternals diff --git a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/AbstractTransformerForGenerator.kt b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/AbstractTransformerForGenerator.kt new file mode 100644 index 00000000000..2ccd14b63eb --- /dev/null +++ b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/AbstractTransformerForGenerator.kt @@ -0,0 +1,96 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.ir.plugin + +import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext +import org.jetbrains.kotlin.fir.backend.IrPluginDeclarationOrigin +import org.jetbrains.kotlin.fir.declarations.FirPluginKey +import org.jetbrains.kotlin.ir.IrElement +import org.jetbrains.kotlin.ir.declarations.* +import org.jetbrains.kotlin.ir.expressions.IrBody +import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrDelegatingConstructorCallImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrInstanceInitializerCallImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl +import org.jetbrains.kotlin.ir.types.IrSimpleType +import org.jetbrains.kotlin.ir.util.primaryConstructor +import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid +import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid + +abstract class AbstractTransformerForGenerator(protected val context: IrPluginContext) : IrElementVisitorVoid { + protected val irFactory = context.irFactory + protected val irBuiltIns = context.irBuiltIns + + abstract fun interestedIn(key: FirPluginKey): Boolean + abstract fun generateBodyForFunction(function: IrSimpleFunction, key: FirPluginKey): IrBody? + abstract fun generateBodyForConstructor(constructor: IrConstructor, key: FirPluginKey): IrBody? + + final override fun visitElement(element: IrElement) { + when (element) { + is IrDeclaration, + is IrFile, + is IrModuleFragment -> element.acceptChildrenVoid(this) + else -> {} + } + } + + final override fun visitSimpleFunction(declaration: IrSimpleFunction) { + val origin = declaration.origin + if (origin !is IrPluginDeclarationOrigin || !interestedIn(origin.pluginKey)) return + require(declaration.body == null) + declaration.body = generateBodyForFunction(declaration, origin.pluginKey) + } + + final override fun visitConstructor(declaration: IrConstructor) { + val origin = declaration.origin + if (origin !is IrPluginDeclarationOrigin || !interestedIn(origin.pluginKey)) return + require(declaration.body == null) + declaration.body = generateBodyForConstructor(declaration, origin.pluginKey) + } + + // ------------------------ utilities ------------------------ + + protected fun generateDefaultBodyForMaterializeFunction(function: IrSimpleFunction): IrBody? { + val constructedType = function.returnType as? IrSimpleType ?: return null + val constructedClassSymbol = constructedType.classifier + val constructedClass = constructedClassSymbol.owner as? IrClass ?: return null + val constructor = constructedClass.primaryConstructor ?: return null + val constructorCall = IrConstructorCallImpl( + -1, + -1, + constructedType, + constructor.symbol, + typeArgumentsCount = 0, + constructorTypeArgumentsCount = 0, + valueArgumentsCount = 0 + ) + val returnStatement = IrReturnImpl(-1, -1, irBuiltIns.nothingType, function.symbol, constructorCall) + return irFactory.createBlockBody(-1, -1, listOf(returnStatement)) + } + + protected fun generateBodyForDefaultConstructor(declaration: IrConstructor): IrBody? { + val type = declaration.returnType as? IrSimpleType ?: return null + + val delegatingAnyCall = IrDelegatingConstructorCallImpl( + -1, + -1, + irBuiltIns.anyType, + irBuiltIns.anyClass.owner.primaryConstructor?.symbol ?: return null, + typeArgumentsCount = 0, + valueArgumentsCount = 0 + ) + + val initializerCall = IrInstanceInitializerCallImpl( + -1, + -1, + (declaration.parent as? IrClass)?.symbol ?: return null, + type + ) + + return irFactory.createBlockBody(-1, -1, listOf(delegatingAnyCall, initializerCall)) + } +} + diff --git a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/GeneratedDeclarationsIrBodyFiller.kt b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/GeneratedDeclarationsIrBodyFiller.kt index 11aa55f4848..8e86ed598a6 100644 --- a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/GeneratedDeclarationsIrBodyFiller.kt +++ b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/GeneratedDeclarationsIrBodyFiller.kt @@ -7,81 +7,21 @@ package org.jetbrains.kotlin.ir.plugin import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext -import org.jetbrains.kotlin.fir.backend.IrPluginDeclarationOrigin -import org.jetbrains.kotlin.fir.plugin.generators.ExternalClassGenerator -import org.jetbrains.kotlin.ir.IrElement -import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl -import org.jetbrains.kotlin.ir.expressions.impl.IrDelegatingConstructorCallImpl -import org.jetbrains.kotlin.ir.expressions.impl.IrInstanceInitializerCallImpl -import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl -import org.jetbrains.kotlin.ir.types.IrSimpleType -import org.jetbrains.kotlin.ir.util.primaryConstructor -import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid +import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid class GeneratedDeclarationsIrBodyFiller : IrGenerationExtension { override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) { - moduleFragment.acceptChildrenVoid(Transformer(pluginContext)) - } -} + val transformers = listOf( + TransformerForExternalClassGenerator(pluginContext), + TransformerForCompanionGenerator(pluginContext), + TransformerForAdditionalMembersGenerator(pluginContext), + TransformerForTopLevelDeclarationsGenerator(pluginContext), + ) -private class Transformer(val context: IrPluginContext) : IrElementVisitorVoid { - private val irFactory = context.irFactory - private val irBuiltIns = context.irBuiltIns - - override fun visitElement(element: IrElement) { - when (element) { - is IrDeclaration, - is IrFile, - is IrModuleFragment -> element.acceptChildrenVoid(this) - else -> {} + for (transformer in transformers) { + moduleFragment.acceptChildrenVoid(transformer) } } - - override fun visitSimpleFunction(declaration: IrSimpleFunction) { - val origin = declaration.origin - if (origin !is IrPluginDeclarationOrigin || origin.pluginKey != ExternalClassGenerator.Key) return - require(declaration.body == null) - val constructedType = declaration.returnType as? IrSimpleType ?: return - val constructedClassSymbol = constructedType.classifier - val constructedClass = constructedClassSymbol.owner as? IrClass ?: return - val constructor = constructedClass.primaryConstructor ?: return - val constructorCall = IrConstructorCallImpl( - -1, - -1, - constructedType, - constructor.symbol, - typeArgumentsCount = 0, - constructorTypeArgumentsCount = 0, - valueArgumentsCount = 0 - ) - val returnStatement = IrReturnImpl(-1, -1, irBuiltIns.nothingType, declaration.symbol, constructorCall) - declaration.body = irFactory.createBlockBody(-1, -1, listOf(returnStatement)) - } - - override fun visitConstructor(declaration: IrConstructor) { - val origin = declaration.origin - if (origin !is IrPluginDeclarationOrigin || origin.pluginKey != ExternalClassGenerator.Key) return - require(declaration.body == null) - val type = declaration.returnType as? IrSimpleType ?: return - - val delegatingAnyCall = IrDelegatingConstructorCallImpl( - -1, - -1, - irBuiltIns.anyType, - irBuiltIns.anyClass.owner.primaryConstructor?.symbol ?: return, - typeArgumentsCount = 0, - valueArgumentsCount = 0 - ) - - val initializerCall = IrInstanceInitializerCallImpl( - -1, - -1, - (declaration.parent as? IrClass)?.symbol ?: return, - type - ) - - declaration.body = irFactory.createBlockBody(-1, -1, listOf(delegatingAnyCall, initializerCall)) - } } + diff --git a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/TransformerForAdditionalMembersGenerator.kt b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/TransformerForAdditionalMembersGenerator.kt new file mode 100644 index 00000000000..e244e0bfb06 --- /dev/null +++ b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/TransformerForAdditionalMembersGenerator.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.ir.plugin + +import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext +import org.jetbrains.kotlin.fir.declarations.FirPluginKey +import org.jetbrains.kotlin.fir.plugin.generators.AdditionalMembersGenerator +import org.jetbrains.kotlin.ir.declarations.IrConstructor +import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction +import org.jetbrains.kotlin.ir.expressions.IrBody + +class TransformerForAdditionalMembersGenerator(context: IrPluginContext) : AbstractTransformerForGenerator(context) { + override fun interestedIn(key: FirPluginKey): Boolean { + return key == AdditionalMembersGenerator.Key + } + + override fun generateBodyForFunction(function: IrSimpleFunction, key: FirPluginKey): IrBody? { + return generateDefaultBodyForMaterializeFunction(function) + } + + override fun generateBodyForConstructor(constructor: IrConstructor, key: FirPluginKey): IrBody? { + return generateBodyForDefaultConstructor(constructor) + } +} diff --git a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/TransformerForCompanionGenerator.kt b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/TransformerForCompanionGenerator.kt new file mode 100644 index 00000000000..687ed419916 --- /dev/null +++ b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/TransformerForCompanionGenerator.kt @@ -0,0 +1,32 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.ir.plugin + +import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext +import org.jetbrains.kotlin.fir.declarations.FirPluginKey +import org.jetbrains.kotlin.fir.plugin.generators.CompanionGenerator +import org.jetbrains.kotlin.ir.declarations.IrConstructor +import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction +import org.jetbrains.kotlin.ir.expressions.IrBody +import org.jetbrains.kotlin.ir.expressions.IrConstKind +import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl + +class TransformerForCompanionGenerator(context: IrPluginContext) : AbstractTransformerForGenerator(context) { + override fun interestedIn(key: FirPluginKey): Boolean { + return key == CompanionGenerator.Key + } + + override fun generateBodyForFunction(function: IrSimpleFunction, key: FirPluginKey): IrBody { + val const = IrConstImpl(-1, -1, irBuiltIns.intType, IrConstKind.Int, value = 10) + val returnStatement = IrReturnImpl(-1, -1, irBuiltIns.nothingType, function.symbol, const) + return irFactory.createBlockBody(-1, -1, listOf(returnStatement)) + } + + override fun generateBodyForConstructor(constructor: IrConstructor, key: FirPluginKey): IrBody? { + return generateBodyForDefaultConstructor(constructor) + } +} diff --git a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/TransformerForExternalClassGenerator.kt b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/TransformerForExternalClassGenerator.kt new file mode 100644 index 00000000000..a8e1cf28dcc --- /dev/null +++ b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/TransformerForExternalClassGenerator.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.ir.plugin + +import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext +import org.jetbrains.kotlin.fir.declarations.FirPluginKey +import org.jetbrains.kotlin.fir.plugin.generators.ExternalClassGenerator +import org.jetbrains.kotlin.ir.declarations.IrConstructor +import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction +import org.jetbrains.kotlin.ir.expressions.IrBody + +class TransformerForExternalClassGenerator(context: IrPluginContext) : AbstractTransformerForGenerator(context) { + override fun interestedIn(key: FirPluginKey): Boolean { + return key == ExternalClassGenerator.Key + } + + override fun generateBodyForFunction(function: IrSimpleFunction, key: FirPluginKey): IrBody? { + return generateDefaultBodyForMaterializeFunction(function) + } + + override fun generateBodyForConstructor(constructor: IrConstructor, key: FirPluginKey): IrBody? { + return generateBodyForDefaultConstructor(constructor) + } +} diff --git a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/TransformerForTopLevelDeclarationsGenerator.kt b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/TransformerForTopLevelDeclarationsGenerator.kt new file mode 100644 index 00000000000..620d4dad649 --- /dev/null +++ b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/TransformerForTopLevelDeclarationsGenerator.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.ir.plugin + +import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext +import org.jetbrains.kotlin.fir.declarations.FirPluginKey +import org.jetbrains.kotlin.fir.plugin.generators.TopLevelDeclarationsGenerator +import org.jetbrains.kotlin.ir.declarations.IrConstructor +import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction +import org.jetbrains.kotlin.ir.expressions.IrBody +import org.jetbrains.kotlin.ir.expressions.IrConstKind +import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl +import org.jetbrains.kotlin.ir.types.classFqName + +class TransformerForTopLevelDeclarationsGenerator(context: IrPluginContext) : AbstractTransformerForGenerator(context) { + override fun interestedIn(key: FirPluginKey): Boolean { + return key == TopLevelDeclarationsGenerator.Key + } + + override fun generateBodyForFunction(function: IrSimpleFunction, key: FirPluginKey): IrBody { + val className = function.valueParameters.single().type.classFqName?.asString() ?: "" + val const = IrConstImpl(-1, -1, irBuiltIns.stringType, IrConstKind.String, className) + val returnExpression = IrReturnImpl(-1, -1, irBuiltIns.nothingType, function.symbol, const) + return irFactory.createBlockBody(-1, -1, listOf(returnExpression)) + } + + override fun generateBodyForConstructor(constructor: IrConstructor, key: FirPluginKey): IrBody? { + return null + } +} diff --git a/plugins/fir/fir-plugin-prototype/testData/box/classWithCompanionObject.fir.txt b/plugins/fir/fir-plugin-prototype/testData/box/classWithCompanionObject.fir.txt new file mode 100644 index 00000000000..45bf16ba2d4 --- /dev/null +++ b/plugins/fir/fir-plugin-prototype/testData/box/classWithCompanionObject.fir.txt @@ -0,0 +1,30 @@ +FILE: classWithCompanionObject.kt + @R|org/jetbrains/kotlin/fir/plugin/CompanionWithFoo|() public final class SomeClass : R|kotlin/Any| { + public constructor(): R|SomeClass| { + super() + } + + public final companion object Companion : R|kotlin/Any| { + public final fun foo(): R|kotlin/Int| + + public constructor(): R|SomeClass.Companion| + + } + + } + public final fun takeInt(x: R|kotlin/Int|): R|kotlin/Unit| { + when () { + !=(R|/x|, Int(10)) -> { + throw R|java/lang/IllegalArgumentException.IllegalArgumentException|() + } + } + + } + public final fun test(): R|kotlin/Unit| { + R|/takeInt|(Q|SomeClass|.R|/SomeClass.Companion.foo|()) + R|/takeInt|(Q|SomeClass.Companion|.R|/SomeClass.Companion.foo|()) + } + public final fun box(): R|kotlin/String| { + R|/test|() + ^box String(OK) + } diff --git a/plugins/fir/fir-plugin-prototype/testData/box/classWithCompanionObject.kt b/plugins/fir/fir-plugin-prototype/testData/box/classWithCompanionObject.kt new file mode 100644 index 00000000000..c31fc30fc20 --- /dev/null +++ b/plugins/fir/fir-plugin-prototype/testData/box/classWithCompanionObject.kt @@ -0,0 +1,19 @@ +import org.jetbrains.kotlin.fir.plugin.CompanionWithFoo + +@CompanionWithFoo +class SomeClass + +fun takeInt(x: Int) { + if (x != 10) throw IllegalArgumentException() +} + +fun test() { + takeInt(SomeClass.foo()) + takeInt(SomeClass.Companion.foo()) +} + +fun box(): String { + test() + return "OK" +} + diff --git a/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/classWithGeneratedMembersAndNestedClass.fir.txt b/plugins/fir/fir-plugin-prototype/testData/box/classWithGeneratedMembersAndNestedClass.fir.txt similarity index 73% rename from plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/classWithGeneratedMembersAndNestedClass.fir.txt rename to plugins/fir/fir-plugin-prototype/testData/box/classWithGeneratedMembersAndNestedClass.fir.txt index a8a156df9fe..feb70cb4451 100644 --- a/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/classWithGeneratedMembersAndNestedClass.fir.txt +++ b/plugins/fir/fir-plugin-prototype/testData/box/classWithGeneratedMembersAndNestedClass.fir.txt @@ -11,6 +11,9 @@ FILE: classWithGeneratedMembersAndNestedClass.kt } + public final val result: R|kotlin/String| = String(OK) + public get(): R|kotlin/String| + public final fun materialize(): R|Foo| public final class Nested : R|kotlin/Any| { @@ -25,7 +28,11 @@ FILE: classWithGeneratedMembersAndNestedClass.kt } } - public final fun test_1(foo: R|Foo|): R|kotlin/Unit| { + public final fun test(foo: R|Foo|): R|kotlin/String| { lval foo2: R|Foo| = R|/foo|.R|/Foo.materialize|() lval nested: R|Foo.Nested| = Q|Foo|.R|/Foo.Nested|() + ^test R|/foo2|.R|/Foo.result| + } + public final fun box(): R|kotlin/String| { + ^box R|/test|(R|/Foo.Foo|()) } diff --git a/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/classWithGeneratedMembersAndNestedClass.kt b/plugins/fir/fir-plugin-prototype/testData/box/classWithGeneratedMembersAndNestedClass.kt similarity index 64% rename from plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/classWithGeneratedMembersAndNestedClass.kt rename to plugins/fir/fir-plugin-prototype/testData/box/classWithGeneratedMembersAndNestedClass.kt index b9b705a65ca..4292d5cd063 100644 --- a/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/classWithGeneratedMembersAndNestedClass.kt +++ b/plugins/fir/fir-plugin-prototype/testData/box/classWithGeneratedMembersAndNestedClass.kt @@ -3,11 +3,18 @@ import org.jetbrains.kotlin.fir.plugin.NestedClassAndMaterializeMember @NestedClassAndMaterializeMember class Foo { class MyNested + + val result = "OK" } class Bar -fun test_1(foo: Foo) { +fun test(foo: Foo): String { val foo2: Foo = foo.materialize() val nested = Foo.Nested() + return foo2.result +} + +fun box(): String { + return test(Foo()) } diff --git a/plugins/fir/fir-plugin-prototype/testData/box/generatedClassWithMembersAndNestedClasses.fir.ir.txt b/plugins/fir/fir-plugin-prototype/testData/box/generatedClassWithMembersAndNestedClasses.fir.ir.txt index ba212aeb88c..bcd37331d39 100644 --- a/plugins/fir/fir-plugin-prototype/testData/box/generatedClassWithMembersAndNestedClasses.fir.ir.txt +++ b/plugins/fir/fir-plugin-prototype/testData/box/generatedClassWithMembersAndNestedClasses.fir.ir.txt @@ -12,15 +12,15 @@ FILE fqName:bar fileName:/generatedClassWithMembersAndNestedClasses.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in bar.Foo' CONST String type=kotlin.String value="OK" - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any $this: VALUE_PARAMETER name: type:kotlin.Any VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] overridden: public open fun toString (): kotlin.String declared in kotlin.Any @@ -42,47 +42,3 @@ FILE fqName:bar fileName:/generatedClassWithMembersAndNestedClasses.kt CALL 'public final fun testConstructor (): kotlin.Unit declared in bar' type=kotlin.Unit origin=null RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in bar' CALL 'public final fun testNestedClasses (): kotlin.String declared in bar' type=kotlin.String origin=null -FILE fqName:foo fileName:__GENERATED DECLARATIONS__.kt - CLASS GENERATED[AllOpenClassGeneratorKey] CLASS name:AllOpenGenerated modality:FINAL visibility:public superTypes:[kotlin.Any] - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:foo.AllOpenGenerated - CONSTRUCTOR GENERATED[AllOpenClassGeneratorKey] visibility:public <> () returnType:foo.AllOpenGenerated [primary] - BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[AllOpenClassGeneratorKey] CLASS name:AllOpenGenerated modality:FINAL visibility:public superTypes:[kotlin.Any]' - CLASS GENERATED[AllOpenClassGeneratorKey] CLASS name:NestedFoo modality:FINAL visibility:public superTypes:[kotlin.Any] - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:foo.AllOpenGenerated.NestedFoo - CONSTRUCTOR GENERATED[AllOpenClassGeneratorKey] visibility:public <> () returnType:foo.AllOpenGenerated.NestedFoo [primary] - BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[AllOpenClassGeneratorKey] CLASS name:NestedFoo modality:FINAL visibility:public superTypes:[kotlin.Any]' - FUN GENERATED[AllOpenClassGeneratorKey] name:materialize visibility:public modality:FINAL <> ($this:foo.AllOpenGenerated.NestedFoo) returnType:bar.Foo - $this: VALUE_PARAMETER name: type:foo.AllOpenGenerated.NestedFoo - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun materialize (): bar.Foo declared in foo.AllOpenGenerated.NestedFoo' - CONSTRUCTOR_CALL 'public constructor () [primary] declared in bar.Foo' type=bar.Foo origin=null - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] - overridden: - public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] - overridden: - public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/plugins/fir/fir-plugin-prototype/testData/box/newSupertype.fir.txt b/plugins/fir/fir-plugin-prototype/testData/box/newSupertype.fir.txt new file mode 100644 index 00000000000..cd52a08065c --- /dev/null +++ b/plugins/fir/fir-plugin-prototype/testData/box/newSupertype.fir.txt @@ -0,0 +1,38 @@ +FILE: newSupertype.kt + package foo + + public abstract interface MyInterface : R|kotlin/Any| { + public open fun foo(): R|kotlin/Unit| { + } + + } + @R|org/jetbrains/kotlin/fir/plugin/MyInterfaceSupertype|() public final class FinalClassWithOverride : R|kotlin/Any|, R|foo/MyInterface| { + public constructor(): R|foo/FinalClassWithOverride| { + super() + } + + public final override fun foo(): R|kotlin/Unit| { + } + + } + @R|org/jetbrains/kotlin/fir/plugin/MyInterfaceSupertype|() public final class AnnotatedClassWithExplicitInheritance : R|foo/MyInterface| { + public constructor(): R|foo/AnnotatedClassWithExplicitInheritance| { + super() + } + + public final override fun foo(): R|kotlin/Unit| { + } + + } + public final fun test(x: R|foo/MyInterface|): R|kotlin/Unit| { + R|/x|.R|foo/MyInterface.foo|() + } + public final fun box(): R|kotlin/String| { + lval x: R|foo/FinalClassWithOverride| = R|foo/FinalClassWithOverride.FinalClassWithOverride|() + R|/x|.R|foo/FinalClassWithOverride.foo|() + R|foo/test|(R|/x|) + lval y: R|foo/AnnotatedClassWithExplicitInheritance| = R|foo/AnnotatedClassWithExplicitInheritance.AnnotatedClassWithExplicitInheritance|() + R|/y|.R|foo/AnnotatedClassWithExplicitInheritance.foo|() + R|foo/test|(R|/y|) + ^box String(OK) + } diff --git a/plugins/fir/fir-plugin-prototype/testData/box/newSupertype.kt b/plugins/fir/fir-plugin-prototype/testData/box/newSupertype.kt new file mode 100644 index 00000000000..99aeb0d2a44 --- /dev/null +++ b/plugins/fir/fir-plugin-prototype/testData/box/newSupertype.kt @@ -0,0 +1,33 @@ +package foo + +import org.jetbrains.kotlin.fir.plugin.MyInterfaceSupertype + +interface MyInterface { + fun foo() {} +} + +@MyInterfaceSupertype +class FinalClassWithOverride { + override fun foo() {} +} + +@MyInterfaceSupertype +class AnnotatedClassWithExplicitInheritance : MyInterface { + override fun foo() {} +} + +fun test(x: MyInterface) { + x.foo() +} + +fun box(): String { + val x = FinalClassWithOverride() + x.foo() + test(x) + + val y = AnnotatedClassWithExplicitInheritance() + y.foo() + test(y) + + return "OK" +} diff --git a/plugins/fir/fir-plugin-prototype/testData/box/topLevelCallables.fir.txt b/plugins/fir/fir-plugin-prototype/testData/box/topLevelCallables.fir.txt new file mode 100644 index 00000000000..02441a7fc83 --- /dev/null +++ b/plugins/fir/fir-plugin-prototype/testData/box/topLevelCallables.fir.txt @@ -0,0 +1,37 @@ +FILE: topLevelCallables.kt + package foo + + @R|org/jetbrains/kotlin/fir/plugin/DummyFunction|() public final class First : R|kotlin/Any| { + public constructor(): R|foo/First| { + super() + } + + } + @R|org/jetbrains/kotlin/fir/plugin/DummyFunction|() public final class Second : R|kotlin/Any| { + public constructor(): R|foo/Second| { + super() + } + + } + public final fun box(): R|kotlin/String| { + lval result1: R|kotlin/String| = R|foo/dummyFirst|(R|foo/First.First|()) + when () { + !=(R|/result1|, String(foo.First)) -> { + ^box (String(Error: ), R|/result1|) + } + } + + lval result2: R|kotlin/String| = R|foo/dummySecond|(R|foo/Second.Second|()) + when () { + !=(R|/result2|, String(foo.Second)) -> { + ^box (String(Error: ), R|/result2|) + } + } + + ^box String(OK) + } +FILE: __GENERATED DECLARATIONS__.kt + package foo + + public final fun dummyFirst(value: R|foo/First|): R|kotlin/String| + public final fun dummySecond(value: R|foo/Second|): R|kotlin/String| diff --git a/plugins/fir/fir-plugin-prototype/testData/box/topLevelCallables.kt b/plugins/fir/fir-plugin-prototype/testData/box/topLevelCallables.kt new file mode 100644 index 00000000000..4c2ec3e59f3 --- /dev/null +++ b/plugins/fir/fir-plugin-prototype/testData/box/topLevelCallables.kt @@ -0,0 +1,19 @@ +package foo + +import org.jetbrains.kotlin.fir.plugin.DummyFunction + +@DummyFunction +class First + +@DummyFunction +class Second + +fun box(): String { + val result1 = dummyFirst(First()) + if (result1 != "foo.First") return "Error: $result1" + + val result2 = dummySecond(Second()) + if (result2 != "foo.Second") return "Error: $result2" + + return "OK" +} diff --git a/plugins/fir/fir-plugin-prototype/testData/diagnostics/memberGen/classWithCompanionObject.fir.txt b/plugins/fir/fir-plugin-prototype/testData/diagnostics/memberGen/classWithCompanionObject.fir.txt index f48b9ed27c8..f7b4fbad003 100644 --- a/plugins/fir/fir-plugin-prototype/testData/diagnostics/memberGen/classWithCompanionObject.fir.txt +++ b/plugins/fir/fir-plugin-prototype/testData/diagnostics/memberGen/classWithCompanionObject.fir.txt @@ -4,9 +4,11 @@ FILE: classWithCompanionObject.kt super() } - public final object Companion : R|kotlin/Any| { + public final companion object Companion : R|kotlin/Any| { public final fun foo(): R|kotlin/Int| + public constructor(): R|SomeClass.Companion| + } } diff --git a/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/classWithGeneratedMembersAndNestedClass.fir.ir.txt b/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/classWithGeneratedMembersAndNestedClass.fir.ir.txt deleted file mode 100644 index 3928165a098..00000000000 --- a/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/classWithGeneratedMembersAndNestedClass.fir.ir.txt +++ /dev/null @@ -1,86 +0,0 @@ -FILE fqName: fileName:/classWithGeneratedMembersAndNestedClass.kt - CLASS CLASS name:Foo modality:FINAL visibility:public superTypes:[kotlin.Any] - annotations: - NestedClassAndMaterializeMember - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Foo - CONSTRUCTOR visibility:public <> () returnType:.Foo [primary] - BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Foo modality:FINAL visibility:public superTypes:[kotlin.Any]' - CLASS CLASS name:MyNested modality:FINAL visibility:public superTypes:[kotlin.Any] - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Foo.MyNested - CONSTRUCTOR visibility:public <> () returnType:.Foo.MyNested [primary] - BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:MyNested modality:FINAL visibility:public superTypes:[kotlin.Any]' - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] - overridden: - public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN GENERATED[AllOpenMembersGeneratorKey] name:materialize visibility:public modality:FINAL <> ($this:.Foo) returnType:.Foo - $this: VALUE_PARAMETER name: type:.Foo - CLASS GENERATED[AllOpenMembersGeneratorKey] CLASS name:Nested modality:FINAL visibility:public superTypes:[kotlin.Any] - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Foo.Nested - CONSTRUCTOR GENERATED[AllOpenMembersGeneratorKey] visibility:public <> () returnType:.Foo.Nested [primary] - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] - overridden: - public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] - overridden: - public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - CLASS CLASS name:Bar modality:FINAL visibility:public superTypes:[kotlin.Any] - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Bar - CONSTRUCTOR visibility:public <> () returnType:.Bar [primary] - BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Bar modality:FINAL visibility:public superTypes:[kotlin.Any]' - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] - overridden: - public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN name:test_1 visibility:public modality:FINAL <> (foo:.Foo) returnType:kotlin.Unit - VALUE_PARAMETER name:foo index:0 type:.Foo - BLOCK_BODY - VAR name:foo2 type:.Foo [val] - CALL 'public final fun materialize (): .Foo declared in .Foo' type=.Foo origin=null - $this: GET_VAR 'foo: .Foo declared in .test_1' type=.Foo origin=null - VAR name:nested type:.Foo.Nested [val] - CONSTRUCTOR_CALL 'public constructor () [primary] declared in .Foo.Nested' type=.Foo.Nested origin=null diff --git a/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/generatedClassWithMembersAndNestedClasses.fir.ir.txt b/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/generatedClassWithMembersAndNestedClasses.fir.ir.txt deleted file mode 100644 index c1ea8761c82..00000000000 --- a/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/generatedClassWithMembersAndNestedClasses.fir.ir.txt +++ /dev/null @@ -1,133 +0,0 @@ -FILE fqName:bar fileName:/generatedClassWithMembersAndNestedClasses.kt - CLASS CLASS name:Foo modality:FINAL visibility:public superTypes:[kotlin.Any] - annotations: - ExternalClassWithNested - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:bar.Foo - CONSTRUCTOR visibility:public <> () returnType:bar.Foo [primary] - BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Foo modality:FINAL visibility:public superTypes:[kotlin.Any]' - FUN name:foo visibility:public modality:FINAL <> ($this:bar.Foo) returnType:kotlin.Unit - $this: VALUE_PARAMETER name: type:bar.Foo - BLOCK_BODY - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] - overridden: - public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - CLASS CLASS name:Bar modality:FINAL visibility:public superTypes:[kotlin.Any] - annotations: - ExternalClassWithNested - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:bar.Bar - CONSTRUCTOR visibility:public <> () returnType:bar.Bar [primary] - BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Bar modality:FINAL visibility:public superTypes:[kotlin.Any]' - FUN name:bar visibility:public modality:FINAL <> ($this:bar.Bar) returnType:kotlin.Unit - $this: VALUE_PARAMETER name: type:bar.Bar - BLOCK_BODY - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] - overridden: - public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN name:testConstructor visibility:public modality:FINAL <> () returnType:kotlin.Unit - BLOCK_BODY - VAR name:generatedClass type:foo.AllOpenGenerated [val] - CONSTRUCTOR_CALL 'public constructor () [primary] declared in foo.AllOpenGenerated' type=foo.AllOpenGenerated origin=null - FUN name:testNestedClasses visibility:public modality:FINAL <> () returnType:kotlin.Unit - BLOCK_BODY - VAR name:nestedFoo type:foo.AllOpenGenerated.NestedFoo [val] - CONSTRUCTOR_CALL 'public constructor () [primary] declared in foo.AllOpenGenerated.NestedFoo' type=foo.AllOpenGenerated.NestedFoo origin=null - CALL 'public final fun foo (): kotlin.Unit declared in bar.Foo' type=kotlin.Unit origin=null - $this: CALL 'public final fun materialize (): bar.Foo declared in foo.AllOpenGenerated.NestedFoo' type=bar.Foo origin=null - $this: GET_VAR 'val nestedFoo: foo.AllOpenGenerated.NestedFoo [val] declared in bar.testNestedClasses' type=foo.AllOpenGenerated.NestedFoo origin=null - VAR name:nestedBar type:foo.AllOpenGenerated.NestedBar [val] - CONSTRUCTOR_CALL 'public constructor () [primary] declared in foo.AllOpenGenerated.NestedBar' type=foo.AllOpenGenerated.NestedBar origin=null - CALL 'public final fun bar (): kotlin.Unit declared in bar.Bar' type=kotlin.Unit origin=null - $this: CALL 'public final fun materialize (): bar.Bar declared in foo.AllOpenGenerated.NestedBar' type=bar.Bar origin=null - $this: GET_VAR 'val nestedBar: foo.AllOpenGenerated.NestedBar [val] declared in bar.testNestedClasses' type=foo.AllOpenGenerated.NestedBar origin=null -FILE fqName:foo fileName:__GENERATED DECLARATIONS__.kt - CLASS GENERATED[AllOpenClassGeneratorKey] CLASS name:AllOpenGenerated modality:FINAL visibility:public superTypes:[kotlin.Any] - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:foo.AllOpenGenerated - CONSTRUCTOR GENERATED[AllOpenClassGeneratorKey] visibility:public <> () returnType:foo.AllOpenGenerated [primary] - BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[AllOpenClassGeneratorKey] CLASS name:AllOpenGenerated modality:FINAL visibility:public superTypes:[kotlin.Any]' - CLASS GENERATED[AllOpenClassGeneratorKey] CLASS name:NestedFoo modality:FINAL visibility:public superTypes:[kotlin.Any] - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:foo.AllOpenGenerated.NestedFoo - CONSTRUCTOR GENERATED[AllOpenClassGeneratorKey] visibility:public <> () returnType:foo.AllOpenGenerated.NestedFoo [primary] - BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[AllOpenClassGeneratorKey] CLASS name:NestedFoo modality:FINAL visibility:public superTypes:[kotlin.Any]' - FUN GENERATED[AllOpenClassGeneratorKey] name:materialize visibility:public modality:FINAL <> ($this:foo.AllOpenGenerated.NestedFoo) returnType:bar.Foo - $this: VALUE_PARAMETER name: type:foo.AllOpenGenerated.NestedFoo - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun materialize (): bar.Foo declared in foo.AllOpenGenerated.NestedFoo' - CONSTRUCTOR_CALL 'public constructor () [primary] declared in bar.Foo' type=bar.Foo origin=null - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] - overridden: - public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - CLASS GENERATED[AllOpenClassGeneratorKey] CLASS name:NestedBar modality:FINAL visibility:public superTypes:[kotlin.Any] - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:foo.AllOpenGenerated.NestedBar - CONSTRUCTOR GENERATED[AllOpenClassGeneratorKey] visibility:public <> () returnType:foo.AllOpenGenerated.NestedBar [primary] - BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[AllOpenClassGeneratorKey] CLASS name:NestedBar modality:FINAL visibility:public superTypes:[kotlin.Any]' - FUN GENERATED[AllOpenClassGeneratorKey] name:materialize visibility:public modality:FINAL <> ($this:foo.AllOpenGenerated.NestedBar) returnType:bar.Bar - $this: VALUE_PARAMETER name: type:foo.AllOpenGenerated.NestedBar - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun materialize (): bar.Bar declared in foo.AllOpenGenerated.NestedBar' - CONSTRUCTOR_CALL 'public constructor () [primary] declared in bar.Bar' type=bar.Bar origin=null - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] - overridden: - public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] - overridden: - public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/generatedClassWithMembersAndNestedClasses.fir.txt b/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/generatedClassWithMembersAndNestedClasses.fir.txt deleted file mode 100644 index b29bc137dc3..00000000000 --- a/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/generatedClassWithMembersAndNestedClasses.fir.txt +++ /dev/null @@ -1,51 +0,0 @@ -FILE: generatedClassWithMembersAndNestedClasses.kt - package bar - - @R|org/jetbrains/kotlin/fir/plugin/ExternalClassWithNested|() public final class Foo : R|kotlin/Any| { - public constructor(): R|bar/Foo| { - super() - } - - public final fun foo(): R|kotlin/Unit| { - } - - } - @R|org/jetbrains/kotlin/fir/plugin/ExternalClassWithNested|() public final class Bar : R|kotlin/Any| { - public constructor(): R|bar/Bar| { - super() - } - - public final fun bar(): R|kotlin/Unit| { - } - - } - public final fun testConstructor(): R|kotlin/Unit| { - lval generatedClass: R|foo/AllOpenGenerated| = R|foo/AllOpenGenerated|() - } - public final fun testNestedClasses(): R|kotlin/Unit| { - lval nestedFoo: R|foo/AllOpenGenerated.NestedFoo| = Q|foo/AllOpenGenerated|.R|foo/AllOpenGenerated.NestedFoo|() - R|/nestedFoo|.R|foo/AllOpenGenerated.NestedFoo.materialize|().R|bar/Foo.foo|() - lval nestedBar: R|foo/AllOpenGenerated.NestedBar| = Q|foo/AllOpenGenerated|.R|foo/AllOpenGenerated.NestedBar|() - R|/nestedBar|.R|foo/AllOpenGenerated.NestedBar.materialize|().R|bar/Bar.bar|() - } -FILE: __GENERATED DECLARATIONS__.kt - package foo - - public final class AllOpenGenerated : R|kotlin/Any| { - public constructor(): R|foo/AllOpenGenerated| - - public final class NestedFoo : R|kotlin/Any| { - public final fun materialize(): R|bar/Foo| - - public constructor(): R|foo/AllOpenGenerated.NestedFoo| - - } - - public final class NestedBar : R|kotlin/Any| { - public final fun materialize(): R|bar/Bar| - - public constructor(): R|foo/AllOpenGenerated.NestedBar| - - } - - } diff --git a/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/generatedClassWithMembersAndNestedClasses.kt b/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/generatedClassWithMembersAndNestedClasses.kt deleted file mode 100644 index a0e3e587091..00000000000 --- a/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/generatedClassWithMembersAndNestedClasses.kt +++ /dev/null @@ -1,27 +0,0 @@ -package bar - -import foo.AllOpenGenerated -import org.jetbrains.kotlin.fir.plugin.ExternalClassWithNested - -@ExternalClassWithNested -class Foo { - fun foo() {} -} - -@ExternalClassWithNested -class Bar { - fun bar() {} -} - -fun testConstructor() { - val generatedClass: AllOpenGenerated = AllOpenGenerated() -} - -fun testNestedClasses() { - val nestedFoo = AllOpenGenerated.NestedFoo() - nestedFoo.materialize().foo() - - val nestedBar = AllOpenGenerated.NestedBar() - nestedBar.materialize().bar() -} - diff --git a/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/topLevelCallables.fir.ir.txt b/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/topLevelCallables.fir.ir.txt deleted file mode 100644 index 94bc64c9818..00000000000 --- a/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/topLevelCallables.fir.ir.txt +++ /dev/null @@ -1,36 +0,0 @@ -FILE fqName:foo fileName:/topLevelCallables.kt - CLASS CLASS name:MySuperClass modality:FINAL visibility:public superTypes:[kotlin.Any] - annotations: - DummyFunction - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:foo.MySuperClass - CONSTRUCTOR visibility:public <> () returnType:foo.MySuperClass [primary] - BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:MySuperClass modality:FINAL visibility:public superTypes:[kotlin.Any]' - FUN name:test visibility:public modality:FINAL <> ($this:foo.MySuperClass) returnType:kotlin.Unit - $this: VALUE_PARAMETER name: type:foo.MySuperClass - BLOCK_BODY - VAR name:s type:kotlin.String [val] - CALL 'public final fun dummyMySuperClass (value: foo.MySuperClass): kotlin.String declared in foo' type=kotlin.String origin=null - value: GET_VAR ': foo.MySuperClass declared in foo.MySuperClass.test' type=foo.MySuperClass origin=null - CALL 'public final fun takeString (s: kotlin.String): kotlin.Unit declared in foo' type=kotlin.Unit origin=null - s: GET_VAR 'val s: kotlin.String [val] declared in foo.MySuperClass.test' type=kotlin.String origin=null - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] - overridden: - public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN name:takeString visibility:public modality:FINAL <> (s:kotlin.String) returnType:kotlin.Unit - VALUE_PARAMETER name:s index:0 type:kotlin.String - BLOCK_BODY -FILE fqName:foo fileName:__GENERATED DECLARATIONS__.kt - FUN GENERATED[AllOpenPlugin] name:dummyMySuperClass visibility:public modality:FINAL <> (value:foo.MySuperClass) returnType:kotlin.String - VALUE_PARAMETER GENERATED[AllOpenPlugin] name:value index:0 type:foo.MySuperClass diff --git a/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/topLevelCallables.fir.txt b/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/topLevelCallables.fir.txt deleted file mode 100644 index 96c4c80cd4a..00000000000 --- a/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/topLevelCallables.fir.txt +++ /dev/null @@ -1,20 +0,0 @@ -FILE: topLevelCallables.kt - package foo - - @R|org/jetbrains/kotlin/fir/plugin/DummyFunction|() public final class MySuperClass : R|kotlin/Any| { - public constructor(): R|foo/MySuperClass| { - super() - } - - public final fun test(): R|kotlin/Unit| { - lval s: R|kotlin/String| = R|foo/dummyMySuperClass|(this@R|foo/MySuperClass|) - R|foo/takeString|(R|/s|) - } - - } - public final fun takeString(s: R|kotlin/String|): R|kotlin/Unit| { - } -FILE: __GENERATED DECLARATIONS__.kt - package foo - - public final fun dummyMySuperClass(value: R|foo/MySuperClass|): R|kotlin/String| diff --git a/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/topLevelCallables.kt b/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/topLevelCallables.kt deleted file mode 100644 index 2569676e569..00000000000 --- a/plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/topLevelCallables.kt +++ /dev/null @@ -1,13 +0,0 @@ -package foo - -import org.jetbrains.kotlin.fir.plugin.DummyFunction - -@DummyFunction -class MySuperClass { - fun test() { - val s = dummyMySuperClass(this) - takeString(s) - } -} - -fun takeString(s: String) {} diff --git a/plugins/fir/fir-plugin-prototype/tests-gen/org/jetbrains/kotlin/fir/plugin/runners/AllOpenBlackBoxCodegenTestGenerated.java b/plugins/fir/fir-plugin-prototype/tests-gen/org/jetbrains/kotlin/fir/plugin/runners/AllOpenBlackBoxCodegenTestGenerated.java index 70f8100c746..b47bf6f29ee 100644 --- a/plugins/fir/fir-plugin-prototype/tests-gen/org/jetbrains/kotlin/fir/plugin/runners/AllOpenBlackBoxCodegenTestGenerated.java +++ b/plugins/fir/fir-plugin-prototype/tests-gen/org/jetbrains/kotlin/fir/plugin/runners/AllOpenBlackBoxCodegenTestGenerated.java @@ -25,9 +25,33 @@ public class AllOpenBlackBoxCodegenTestGenerated extends AbstractAllOpenBlackBox KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/fir/fir-plugin-prototype/testData/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("classWithCompanionObject.kt") + public void testClassWithCompanionObject() throws Exception { + runTest("plugins/fir/fir-plugin-prototype/testData/box/classWithCompanionObject.kt"); + } + + @Test + @TestMetadata("classWithGeneratedMembersAndNestedClass.kt") + public void testClassWithGeneratedMembersAndNestedClass() throws Exception { + runTest("plugins/fir/fir-plugin-prototype/testData/box/classWithGeneratedMembersAndNestedClass.kt"); + } + @Test @TestMetadata("generatedClassWithMembersAndNestedClasses.kt") public void testGeneratedClassWithMembersAndNestedClasses() throws Exception { runTest("plugins/fir/fir-plugin-prototype/testData/box/generatedClassWithMembersAndNestedClasses.kt"); } + + @Test + @TestMetadata("newSupertype.kt") + public void testNewSupertype() throws Exception { + runTest("plugins/fir/fir-plugin-prototype/testData/box/newSupertype.kt"); + } + + @Test + @TestMetadata("topLevelCallables.kt") + public void testTopLevelCallables() throws Exception { + runTest("plugins/fir/fir-plugin-prototype/testData/box/topLevelCallables.kt"); + } } diff --git a/plugins/fir/fir-plugin-prototype/tests-gen/org/jetbrains/kotlin/fir/plugin/runners/Fir2IrAllOpenTestGenerated.java b/plugins/fir/fir-plugin-prototype/tests-gen/org/jetbrains/kotlin/fir/plugin/runners/Fir2IrAllOpenTestGenerated.java deleted file mode 100644 index 7dcd497176f..00000000000 --- a/plugins/fir/fir-plugin-prototype/tests-gen/org/jetbrains/kotlin/fir/plugin/runners/Fir2IrAllOpenTestGenerated.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.fir.plugin.runners; - -import com.intellij.testFramework.TestDataPath; -import org.jetbrains.kotlin.test.util.KtTestUtil; -import org.jetbrains.kotlin.test.TargetBackend; -import org.jetbrains.kotlin.test.TestMetadata; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; - -import java.io.File; -import java.util.regex.Pattern; - -/** This class is generated by {@link GenerateNewCompilerTests.kt}. DO NOT MODIFY MANUALLY */ -@SuppressWarnings("all") -@TestMetadata("plugins/fir/fir-plugin-prototype/testData/fir2ir") -@TestDataPath("$PROJECT_ROOT") -public class Fir2IrAllOpenTestGenerated extends AbstractFir2IrAllOpenTest { - @Test - public void testAllFilesPresentInFir2ir() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/fir/fir-plugin-prototype/testData/fir2ir"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); - } - - @Nested - @TestMetadata("plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen") - @TestDataPath("$PROJECT_ROOT") - public class MemberGen { - @Test - public void testAllFilesPresentInMemberGen() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); - } - - @Test - @TestMetadata("classWithGeneratedMembersAndNestedClass.kt") - public void testClassWithGeneratedMembersAndNestedClass() throws Exception { - runTest("plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/classWithGeneratedMembersAndNestedClass.kt"); - } - - @Test - @TestMetadata("generatedClassWithMembersAndNestedClasses.kt") - public void testGeneratedClassWithMembersAndNestedClasses() throws Exception { - runTest("plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/generatedClassWithMembersAndNestedClasses.kt"); - } - - @Test - @TestMetadata("topLevelCallables.kt") - public void testTopLevelCallables() throws Exception { - runTest("plugins/fir/fir-plugin-prototype/testData/fir2ir/memberGen/topLevelCallables.kt"); - } - } -} diff --git a/plugins/fir/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/runners/AbstractFir2IrAllOpenTest.kt b/plugins/fir/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/runners/AbstractFir2IrAllOpenTest.kt deleted file mode 100644 index 14efc103140..00000000000 --- a/plugins/fir/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/runners/AbstractFir2IrAllOpenTest.kt +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.fir.plugin.runners - -import org.jetbrains.kotlin.test.TargetBackend -import org.jetbrains.kotlin.test.backend.handlers.IrTextDumpHandler -import org.jetbrains.kotlin.test.backend.handlers.IrTreeVerifierHandler -import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder -import org.jetbrains.kotlin.test.builders.fir2IrStep -import org.jetbrains.kotlin.test.builders.irHandlersStep -import org.jetbrains.kotlin.test.directives.CodegenTestDirectives -import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.DUMP_IR -import org.jetbrains.kotlin.test.runners.AbstractKotlinCompilerWithTargetBackendTest - -open class AbstractFir2IrAllOpenTest : AbstractKotlinCompilerWithTargetBackendTest(TargetBackend.JVM_IR) { - override fun TestConfigurationBuilder.configuration() { - defaultDirectives { - +DUMP_IR - } - - commonFirWithPluginFrontendConfiguration() - fir2IrStep() - irHandlersStep { - useHandlers( - ::IrTextDumpHandler, - ::IrTreeVerifierHandler, - ) - } - } -}