Fir2Ir: enable IR-based fake override builder

Invert the logic of IR/FIR2IR-based generators: change the CLI argument
to -Xuse-fir-fake-override-builder, test directive to
USE_FIR_BASED_FAKE_OVERRIDE_GENERATOR, etc.

The changes in test data caused by using IR fake override builder by
default are in the subsequent commit.

 #KT-61514
This commit is contained in:
Alexander Udalov
2024-02-26 16:19:04 +01:00
committed by Space Team
parent 09db7dbd22
commit f98a22e8e4
30 changed files with 72 additions and 81 deletions
@@ -75,9 +75,9 @@ fun copyCommonCompilerArguments(from: CommonCompilerArguments, to: CommonCompile
to.unrestrictedBuilderInference = from.unrestrictedBuilderInference to.unrestrictedBuilderInference = from.unrestrictedBuilderInference
to.useExperimental = from.useExperimental?.copyOf() to.useExperimental = from.useExperimental?.copyOf()
to.useFirExtendedCheckers = from.useFirExtendedCheckers to.useFirExtendedCheckers = from.useFirExtendedCheckers
to.useFirFakeOverrideBuilder = from.useFirFakeOverrideBuilder
to.useFirIC = from.useFirIC to.useFirIC = from.useFirIC
to.useFirLT = from.useFirLT to.useFirLT = from.useFirLT
to.useIrFakeOverrideBuilder = from.useIrFakeOverrideBuilder
to.useK2 = from.useK2 to.useK2 = from.useK2
to.verbosePhases = from.verbosePhases?.copyOf() to.verbosePhases = from.verbosePhases?.copyOf()
@@ -88,4 +88,4 @@ fun copyK2JVMCompilerArguments(from: K2JVMCompilerArguments, to: K2JVMCompilerAr
to.valueClasses = from.valueClasses to.valueClasses = from.valueClasses
return to return to
} }
@@ -503,10 +503,10 @@ They should be a subset of sources passed as free arguments."""
} }
@Argument( @Argument(
value = "-Xuse-ir-fake-override-builder", value = "-Xuse-fir-fake-override-builder",
description = "Generate fake overrides via IR. See KT-61514" description = "Generate all fake overrides via FIR2IR instead of IR, i.e. revert to behavior before KT-61514 was resolved."
) )
var useIrFakeOverrideBuilder = false var useFirFakeOverrideBuilder = false
set(value) { set(value) {
checkFrozen() checkFrozen()
field = value field = value
@@ -34,7 +34,7 @@ fun CompilerConfiguration.setupCommonArguments(
put(CommonConfigurationKeys.INCREMENTAL_COMPILATION, incrementalCompilationIsEnabled(arguments)) put(CommonConfigurationKeys.INCREMENTAL_COMPILATION, incrementalCompilationIsEnabled(arguments))
put(CommonConfigurationKeys.ALLOW_ANY_SCRIPTS_IN_SOURCE_ROOTS, arguments.allowAnyScriptsInSourceRoots) put(CommonConfigurationKeys.ALLOW_ANY_SCRIPTS_IN_SOURCE_ROOTS, arguments.allowAnyScriptsInSourceRoots)
put(CommonConfigurationKeys.IGNORE_CONST_OPTIMIZATION_ERRORS, arguments.ignoreConstOptimizationErrors) put(CommonConfigurationKeys.IGNORE_CONST_OPTIMIZATION_ERRORS, arguments.ignoreConstOptimizationErrors)
put(CommonConfigurationKeys.USE_IR_FAKE_OVERRIDE_BUILDER, arguments.useIrFakeOverrideBuilder) put(CommonConfigurationKeys.USE_FIR_BASED_FAKE_OVERRIDE_GENERATOR, arguments.useFirFakeOverrideBuilder)
val metadataVersionString = arguments.metadataVersion val metadataVersionString = arguments.metadataVersion
if (metadataVersionString != null) { if (metadataVersionString != null) {
@@ -98,8 +98,9 @@ object CommonConfigurationKeys {
CompilerConfigurationKey.create<EvaluatedConstTracker>("Keeps track of all evaluated by IrInterpreter constants") CompilerConfigurationKey.create<EvaluatedConstTracker>("Keeps track of all evaluated by IrInterpreter constants")
@JvmField @JvmField
val USE_IR_FAKE_OVERRIDE_BUILDER = val USE_FIR_BASED_FAKE_OVERRIDE_GENERATOR = CompilerConfigurationKey.create<Boolean>(
CompilerConfigurationKey.create<Boolean>("Generate fake overrides via IR. See KT-61514") "Generate all fake overrides via FIR2IR instead of IR, i.e. revert to behavior before KT-61514 was resolved."
)
} }
var CompilerConfiguration.languageVersionSettings: LanguageVersionSettings var CompilerConfiguration.languageVersionSettings: LanguageVersionSettings
@@ -107,12 +107,12 @@ fun FirResult.convertToIrAndActualize(
), ),
actualizerTypeContextProvider(irModuleFragment.irBuiltins), actualizerTypeContextProvider(irModuleFragment.irBuiltins),
fir2IrConfiguration.expectActualTracker, fir2IrConfiguration.expectActualTracker,
fir2IrConfiguration.useIrFakeOverrideBuilder, fir2IrConfiguration.useFirBasedFakeOverrideGenerator,
irModuleFragment, irModuleFragment,
allIrModules.dropLast(1), allIrModules.dropLast(1),
) )
if (fir2IrConfiguration.useIrFakeOverrideBuilder) { if (!fir2IrConfiguration.useFirBasedFakeOverrideGenerator) {
// actualizeCallablesAndMergeModules call below in fact can also actualize classifiers. // actualizeCallablesAndMergeModules call below in fact can also actualize classifiers.
// So to avoid even more changes, when this mode is disabled, we don't run classifiers // So to avoid even more changes, when this mode is disabled, we don't run classifiers
// actualization separately. This should go away, after useIrFakeOverrideBuilder becomes // actualization separately. This should go away, after useIrFakeOverrideBuilder becomes
@@ -122,7 +122,7 @@ fun FirResult.convertToIrAndActualize(
components.fakeOverrideBuilder.buildForAll(allIrModules, temporaryResolver) components.fakeOverrideBuilder.buildForAll(allIrModules, temporaryResolver)
} }
val expectActualMap = irActualizer?.actualizeCallablesAndMergeModules() ?: emptyMap() val expectActualMap = irActualizer?.actualizeCallablesAndMergeModules() ?: emptyMap()
if (components.configuration.useIrFakeOverrideBuilder) { if (!components.configuration.useFirBasedFakeOverrideGenerator) {
val fakeOverrideResolver = SpecialFakeOverrideSymbolsResolver(expectActualMap) val fakeOverrideResolver = SpecialFakeOverrideSymbolsResolver(expectActualMap)
irModuleFragment.acceptVoid(SpecialFakeOverrideSymbolsResolverVisitor(fakeOverrideResolver)) irModuleFragment.acceptVoid(SpecialFakeOverrideSymbolsResolverVisitor(fakeOverrideResolver))
@OptIn(Fir2IrSymbolsMappingForLazyClasses.SymbolRemapperInternals::class) @OptIn(Fir2IrSymbolsMappingForLazyClasses.SymbolRemapperInternals::class)
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.constant.EvaluatedConstTracker
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.incremental.components.ExpectActualTracker import org.jetbrains.kotlin.incremental.components.ExpectActualTracker
import org.jetbrains.kotlin.incremental.components.InlineConstTracker import org.jetbrains.kotlin.incremental.components.InlineConstTracker
import org.jetbrains.kotlin.ir.util.SymbolTable
/** /**
* @param allowNonCachedDeclarations * @param allowNonCachedDeclarations
@@ -30,8 +29,9 @@ import org.jetbrains.kotlin.ir.util.SymbolTable
* Code generation in the IDE is trickier, though, as declarations from any module can be potentially referenced. * Code generation in the IDE is trickier, though, as declarations from any module can be potentially referenced.
* For such a scenario, there is a flag that relaxes consistency checks. * For such a scenario, there is a flag that relaxes consistency checks.
* *
* @param useIrFakeOverrideBuilder Enables creation of fake-overrides using the IR f/o generator instead of the FIR2IR one. * @param useFirBasedFakeOverrideGenerator
* See [KT-61514](https://youtrack.jetbrains.com/issue/KT-61514). * Generate all fake overrides via FIR2IR instead of IR, i.e. revert to behavior before
* [KT-61514](https://youtrack.jetbrains.com/issue/KT-61514) was resolved.
*/ */
class Fir2IrConfiguration private constructor( class Fir2IrConfiguration private constructor(
val languageVersionSettings: LanguageVersionSettings, val languageVersionSettings: LanguageVersionSettings,
@@ -40,9 +40,8 @@ class Fir2IrConfiguration private constructor(
val inlineConstTracker: InlineConstTracker?, val inlineConstTracker: InlineConstTracker?,
val expectActualTracker: ExpectActualTracker?, val expectActualTracker: ExpectActualTracker?,
val allowNonCachedDeclarations: Boolean, val allowNonCachedDeclarations: Boolean,
val useIrFakeOverrideBuilder: Boolean, val useFirBasedFakeOverrideGenerator: Boolean,
) { ) {
companion object { companion object {
fun forJvmCompilation( fun forJvmCompilation(
compilerConfiguration: CompilerConfiguration, compilerConfiguration: CompilerConfiguration,
@@ -58,7 +57,7 @@ class Fir2IrConfiguration private constructor(
inlineConstTracker = compilerConfiguration[CommonConfigurationKeys.INLINE_CONST_TRACKER], inlineConstTracker = compilerConfiguration[CommonConfigurationKeys.INLINE_CONST_TRACKER],
expectActualTracker = compilerConfiguration[CommonConfigurationKeys.EXPECT_ACTUAL_TRACKER], expectActualTracker = compilerConfiguration[CommonConfigurationKeys.EXPECT_ACTUAL_TRACKER],
allowNonCachedDeclarations = false, allowNonCachedDeclarations = false,
useIrFakeOverrideBuilder = compilerConfiguration.getBoolean(CommonConfigurationKeys.USE_IR_FAKE_OVERRIDE_BUILDER), useFirBasedFakeOverrideGenerator = compilerConfiguration.getBoolean(CommonConfigurationKeys.USE_FIR_BASED_FAKE_OVERRIDE_GENERATOR),
) )
fun forKlibCompilation( fun forKlibCompilation(
@@ -75,7 +74,7 @@ class Fir2IrConfiguration private constructor(
inlineConstTracker = null, inlineConstTracker = null,
expectActualTracker = compilerConfiguration[CommonConfigurationKeys.EXPECT_ACTUAL_TRACKER], expectActualTracker = compilerConfiguration[CommonConfigurationKeys.EXPECT_ACTUAL_TRACKER],
allowNonCachedDeclarations = false, allowNonCachedDeclarations = false,
useIrFakeOverrideBuilder = true, useFirBasedFakeOverrideGenerator = false,
) )
fun forAnalysisApi( fun forAnalysisApi(
@@ -93,7 +92,7 @@ class Fir2IrConfiguration private constructor(
inlineConstTracker = compilerConfiguration[CommonConfigurationKeys.INLINE_CONST_TRACKER], inlineConstTracker = compilerConfiguration[CommonConfigurationKeys.INLINE_CONST_TRACKER],
expectActualTracker = compilerConfiguration[CommonConfigurationKeys.EXPECT_ACTUAL_TRACKER], expectActualTracker = compilerConfiguration[CommonConfigurationKeys.EXPECT_ACTUAL_TRACKER],
allowNonCachedDeclarations = true, allowNonCachedDeclarations = true,
useIrFakeOverrideBuilder = compilerConfiguration.getBoolean(CommonConfigurationKeys.USE_IR_FAKE_OVERRIDE_BUILDER), useFirBasedFakeOverrideGenerator = compilerConfiguration.getBoolean(CommonConfigurationKeys.USE_FIR_BASED_FAKE_OVERRIDE_GENERATOR),
) )
} }
} }
@@ -93,8 +93,8 @@ class Fir2IrConverter(
processFileAndClassMembers(firFile) processFileAndClassMembers(firFile)
} }
// 4. Override processing which sets overridden symbols for everything inside non-local regular classes // 4. Override processing which sets overridden symbols for everything inside non-local regular classes
@OptIn(FirBasedFakeOverrideGenerator::class) // checked for useIrFakeOverrideBuilder @OptIn(FirBasedFakeOverrideGenerator::class)
if (!configuration.useIrFakeOverrideBuilder) { if (configuration.useFirBasedFakeOverrideGenerator) {
for (firFile in allFirFiles) { for (firFile in allFirFiles) {
bindFakeOverridesInFile(firFile) bindFakeOverridesInFile(firFile)
} }
@@ -119,7 +119,7 @@ class Fir2IrConverter(
} }
if ( if (
!configuration.useIrFakeOverrideBuilder && configuration.useFirBasedFakeOverrideGenerator &&
components.session.languageVersionSettings.supportsFeature(LanguageFeature.MultiPlatformProjects) components.session.languageVersionSettings.supportsFeature(LanguageFeature.MultiPlatformProjects)
) { ) {
// See the comment to generateUnboundFakeOverrides function itself // See the comment to generateUnboundFakeOverrides function itself
@@ -287,8 +287,8 @@ class Fir2IrConverter(
declarationStorage.leaveScope(irConstructor.symbol) declarationStorage.leaveScope(irConstructor.symbol)
} }
if (!configuration.useIrFakeOverrideBuilder) { if (configuration.useFirBasedFakeOverrideGenerator) {
@OptIn(FirBasedFakeOverrideGenerator::class) // checked for useIrFakeOverrideBuilder @OptIn(FirBasedFakeOverrideGenerator::class)
fakeOverrideGenerator.computeFakeOverrides(klass, irClass, allDeclarations) fakeOverrideGenerator.computeFakeOverrides(klass, irClass, allDeclarations)
} }
@@ -392,10 +392,9 @@ class Fir2IrConverter(
} }
// `irClass` is a source class and definitely is not a lazy class // `irClass` is a source class and definitely is not a lazy class
// checked for useIrFakeOverrideBuilder
@OptIn(UnsafeDuringIrConstructionAPI::class, FirBasedFakeOverrideGenerator::class) @OptIn(UnsafeDuringIrConstructionAPI::class, FirBasedFakeOverrideGenerator::class)
fun bindFakeOverridesInClass(klass: IrClass) { fun bindFakeOverridesInClass(klass: IrClass) {
if (configuration.useIrFakeOverrideBuilder) return if (!configuration.useFirBasedFakeOverrideGenerator) return
require(klass !is Fir2IrLazyClass) require(klass !is Fir2IrLazyClass)
fakeOverrideGenerator.bindOverriddenSymbols(klass.declarations) fakeOverrideGenerator.bindOverriddenSymbols(klass.declarations)
delegatedMemberGenerator.bindDelegatedMembersOverriddenSymbols(klass) delegatedMemberGenerator.bindDelegatedMembersOverriddenSymbols(klass)
@@ -395,7 +395,7 @@ class Fir2IrDeclarationStorage(
parentIsExternal: Boolean parentIsExternal: Boolean
): IrSimpleFunctionSymbol { ): IrSimpleFunctionSymbol {
if ( if (
!configuration.useIrFakeOverrideBuilder || configuration.useFirBasedFakeOverrideGenerator ||
parentIsExternal || parentIsExternal ||
function !is FirSimpleFunction || function !is FirSimpleFunction ||
!function.isFakeOverride(fakeOverrideOwnerLookupTag) !function.isFakeOverride(fakeOverrideOwnerLookupTag)
@@ -592,7 +592,7 @@ class Fir2IrDeclarationStorage(
parentIsExternal: Boolean parentIsExternal: Boolean
): PropertySymbols { ): PropertySymbols {
if ( if (
configuration.useIrFakeOverrideBuilder && !configuration.useFirBasedFakeOverrideGenerator &&
!parentIsExternal && !parentIsExternal &&
property.isFakeOverride(fakeOverrideOwnerLookupTag) property.isFakeOverride(fakeOverrideOwnerLookupTag)
) { ) {
@@ -1189,7 +1189,7 @@ class Fir2IrDeclarationStorage(
) )
irForFirSessionDependantDeclarationMap[key] = cachedInSymbolTable irForFirSessionDependantDeclarationMap[key] = cachedInSymbolTable
} }
configuration.useIrFakeOverrideBuilder -> { !configuration.useFirBasedFakeOverrideGenerator -> {
/* /*
* If IR fake override builder is used for building fake-overrides, they are generated bypassing Fir2IrDeclarationStorage, * If IR fake override builder is used for building fake-overrides, they are generated bypassing Fir2IrDeclarationStorage,
* and are written directly to SymbolTable. So in this case it is normal to save the result from symbol table into * and are written directly to SymbolTable. So in this case it is normal to save the result from symbol table into
@@ -215,7 +215,7 @@ internal class ClassMemberGenerator(
* In useIrFakeOverrideBuilder it would be dropped anyway, as [org.jetbrains.kotlin.ir.overrides.IrFakeOverrideBuilder.buildFakeOverridesForClass] * In useIrFakeOverrideBuilder it would be dropped anyway, as [org.jetbrains.kotlin.ir.overrides.IrFakeOverrideBuilder.buildFakeOverridesForClass]
* recalculates this value from scratch. Also, it's quite meaningless in non-platform modules anyway. * recalculates this value from scratch. Also, it's quite meaningless in non-platform modules anyway.
*/ */
if (!configuration.useIrFakeOverrideBuilder) { if (configuration.useFirBasedFakeOverrideGenerator) {
@OptIn(FirBasedFakeOverrideGenerator::class) @OptIn(FirBasedFakeOverrideGenerator::class)
irFunction.overriddenSymbols = firFunction.generateOverriddenFunctionSymbols(containingClass) irFunction.overriddenSymbols = firFunction.generateOverriddenFunctionSymbols(containingClass)
} }
@@ -234,7 +234,7 @@ internal class ClassMemberGenerator(
* In useIrFakeOverrideBuilder it would be dropped anyway, as [org.jetbrains.kotlin.ir.overrides.IrFakeOverrideBuilder.buildFakeOverridesForClass] * In useIrFakeOverrideBuilder it would be dropped anyway, as [org.jetbrains.kotlin.ir.overrides.IrFakeOverrideBuilder.buildFakeOverridesForClass]
* recalculates this value from scratch. Also, it's quite meaningless in non-platform modules anyway. * recalculates this value from scratch. Also, it's quite meaningless in non-platform modules anyway.
*/ */
if (!configuration.useIrFakeOverrideBuilder) { if (configuration.useFirBasedFakeOverrideGenerator) {
@OptIn(FirBasedFakeOverrideGenerator::class) // checked for useIrFakeOverrideBuilder @OptIn(FirBasedFakeOverrideGenerator::class) // checked for useIrFakeOverrideBuilder
irProperty.overriddenSymbols = property.generateOverriddenPropertySymbols(containingClass) irProperty.overriddenSymbols = property.generateOverriddenPropertySymbols(containingClass)
} }
@@ -349,8 +349,8 @@ internal class ClassMemberGenerator(
declarationStorage.leaveScope(this.symbol) declarationStorage.leaveScope(this.symbol)
} }
} }
if (containingClass != null && !components.configuration.useIrFakeOverrideBuilder) { if (containingClass != null && components.configuration.useFirBasedFakeOverrideGenerator) {
@OptIn(FirBasedFakeOverrideGenerator::class) // checked for useIrFakeOverrideBuilder @OptIn(FirBasedFakeOverrideGenerator::class)
this.overriddenSymbols = property.generateOverriddenAccessorSymbols(containingClass, isGetter) this.overriddenSymbols = property.generateOverriddenAccessorSymbols(containingClass, isGetter)
} }
@@ -197,9 +197,9 @@ class DelegatedMemberGenerator(private val components: Fir2IrComponents) : Fir2I
return result return result
} }
@OptIn(FirBasedFakeOverrideGenerator::class) // checked for useIrFakeOverrideBuilder @OptIn(FirBasedFakeOverrideGenerator::class)
fun bindDelegatedMembersOverriddenSymbols(irClass: IrClass) { fun bindDelegatedMembersOverriddenSymbols(irClass: IrClass) {
if (components.configuration.useIrFakeOverrideBuilder) return if (!components.configuration.useFirBasedFakeOverrideGenerator) return
val superClasses by lazy(LazyThreadSafetyMode.NONE) { val superClasses by lazy(LazyThreadSafetyMode.NONE) {
irClass.superTypes.mapNotNullTo(mutableSetOf()) { irClass.superTypes.mapNotNullTo(mutableSetOf()) {
// All class symbols should be already bound at this moment // All class symbols should be already bound at this moment
@@ -233,9 +233,9 @@ class Fir2IrLazyProperty(
} }
override var overriddenSymbols: List<IrPropertySymbol> by symbolsMappingForLazyClasses.lazyMappedPropertyListVar(lock) { override var overriddenSymbols: List<IrPropertySymbol> by symbolsMappingForLazyClasses.lazyMappedPropertyListVar(lock) {
when (configuration.useIrFakeOverrideBuilder) { when (configuration.useFirBasedFakeOverrideGenerator) {
true -> computeOverriddenSymbolsForIrFakeOverrideGenerator() true -> computeOverriddenUsingFir2IrFakeOverrideGenerator()
false -> computeOverriddenUsingFir2IrFakeOverrideGenerator() false -> computeOverriddenSymbolsForIrFakeOverrideGenerator()
} }
} }
@@ -96,13 +96,12 @@ class Fir2IrLazySimpleFunction(
} }
override var overriddenSymbols: List<IrSimpleFunctionSymbol> by symbolsMappingForLazyClasses.lazyMappedFunctionListVar(lock) { override var overriddenSymbols: List<IrSimpleFunctionSymbol> by symbolsMappingForLazyClasses.lazyMappedFunctionListVar(lock) {
when (configuration.useIrFakeOverrideBuilder) { when (configuration.useFirBasedFakeOverrideGenerator) {
true -> computeOverriddenSymbolsForIrFakeOverrideGenerator() true -> computeOverriddenUsingFir2IrFakeOverrideGenerator()
false -> computeOverriddenUsingFir2IrFakeOverrideGenerator() false -> computeOverriddenSymbolsForIrFakeOverrideGenerator()
} }
} }
// TODO: drop this function after migration to IR f/o generator will be complete (KT-64202) // TODO: drop this function after migration to IR f/o generator will be complete (KT-64202)
private fun computeOverriddenUsingFir2IrFakeOverrideGenerator(): List<IrSimpleFunctionSymbol> { private fun computeOverriddenUsingFir2IrFakeOverrideGenerator(): List<IrSimpleFunctionSymbol> {
if (firParent == null) return emptyList() if (firParent == null) return emptyList()
@@ -20,7 +20,7 @@ import java.util.regex.Pattern;
@SuppressWarnings("all") @SuppressWarnings("all")
@TestMetadata("compiler/testData/codegen/box") @TestMetadata("compiler/testData/codegen/box")
@TestDataPath("$PROJECT_ROOT") @TestDataPath("$PROJECT_ROOT")
public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated extends AbstractFirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTest { public class FirLightTreeBlackBoxCodegenWithFir2IrFakeOverrideGeneratorTestGenerated extends AbstractFirLightTreeBlackBoxCodegenWithFir2IrFakeOverrideGeneratorTest {
@Test @Test
public void testAllFilesPresentInBox() { public void testAllFilesPresentInBox() {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true, "script"); KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true, "script");
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.types.IrTypeSystemContext import org.jetbrains.kotlin.ir.types.IrTypeSystemContext
import org.jetbrains.kotlin.ir.types.classOrFail import org.jetbrains.kotlin.ir.types.classOrFail
import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.utils.addToStdlib.shouldNotBeCalled
data class IrActualizedResult( data class IrActualizedResult(
val actualizedExpectDeclarations: List<IrDeclaration>, val actualizedExpectDeclarations: List<IrDeclaration>,
@@ -33,7 +32,7 @@ class IrActualizer(
val ktDiagnosticReporter: IrDiagnosticReporter, val ktDiagnosticReporter: IrDiagnosticReporter,
val typeSystemContext: IrTypeSystemContext, val typeSystemContext: IrTypeSystemContext,
expectActualTracker: ExpectActualTracker?, expectActualTracker: ExpectActualTracker?,
val useIrFakeOverrideBuilder: Boolean, val useFirBasedFakeOverrideGenerator: Boolean,
val mainFragment: IrModuleFragment, val mainFragment: IrModuleFragment,
val dependentFragments: List<IrModuleFragment> val dependentFragments: List<IrModuleFragment>
) { ) {
@@ -80,7 +79,7 @@ class IrActualizer(
// 1. Collect expect-actual links for members of classes found on step 1. // 1. Collect expect-actual links for members of classes found on step 1.
val expectActualMap = collector.collect(classActualizationInfo) val expectActualMap = collector.collect(classActualizationInfo)
if (!useIrFakeOverrideBuilder) { if (useFirBasedFakeOverrideGenerator) {
// 2. Actualize expect fake overrides in non-expect classes inside common or multi-platform module. // 2. Actualize expect fake overrides in non-expect classes inside common or multi-platform module.
// It's probably important to run FakeOverridesActualizer before ActualFakeOverridesAdder // It's probably important to run FakeOverridesActualizer before ActualFakeOverridesAdder
FakeOverridesActualizer(expectActualMap, ktDiagnosticReporter).apply { dependentFragments.forEach { visitModuleFragment(it) } } FakeOverridesActualizer(expectActualMap, ktDiagnosticReporter).apply { dependentFragments.forEach { visitModuleFragment(it) } }
+2 -1
View File
@@ -137,10 +137,11 @@ where advanced options include:
Eliminate builder inference restrictions, for example by allowing type variables to be returned from builder inference calls. Eliminate builder inference restrictions, for example by allowing type variables to be returned from builder inference calls.
-Xuse-fir-extended-checkers Use extended analysis mode based on the frontend IR. -Xuse-fir-extended-checkers Use extended analysis mode based on the frontend IR.
Warning: This feature is not yet production-ready. Warning: This feature is not yet production-ready.
-Xuse-fir-fake-override-builder
Generate all fake overrides via FIR2IR instead of IR, i.e. revert to behavior before KT-61514 was resolved.
-Xuse-fir-ic Compile using frontend IR internal incremental compilation. -Xuse-fir-ic Compile using frontend IR internal incremental compilation.
Warning: This feature is not yet production-ready. Warning: This feature is not yet production-ready.
-Xuse-fir-lt Compile using the LightTree parser with the frontend IR. -Xuse-fir-lt Compile using the LightTree parser with the frontend IR.
-Xuse-ir-fake-override-builder Generate fake overrides via IR. See KT-61514
-Xuse-k2 Compile using the experimental K2 compiler pipeline. No compatibility guarantees are provided yet. -Xuse-k2 Compile using the experimental K2 compiler pipeline. No compatibility guarantees are provided yet.
-Xverbose-phases Be verbose while performing the given backend phases. -Xverbose-phases Be verbose while performing the given backend phases.
+2 -1
View File
@@ -229,10 +229,11 @@ where advanced options include:
Eliminate builder inference restrictions, for example by allowing type variables to be returned from builder inference calls. Eliminate builder inference restrictions, for example by allowing type variables to be returned from builder inference calls.
-Xuse-fir-extended-checkers Use extended analysis mode based on the frontend IR. -Xuse-fir-extended-checkers Use extended analysis mode based on the frontend IR.
Warning: This feature is not yet production-ready. Warning: This feature is not yet production-ready.
-Xuse-fir-fake-override-builder
Generate all fake overrides via FIR2IR instead of IR, i.e. revert to behavior before KT-61514 was resolved.
-Xuse-fir-ic Compile using frontend IR internal incremental compilation. -Xuse-fir-ic Compile using frontend IR internal incremental compilation.
Warning: This feature is not yet production-ready. Warning: This feature is not yet production-ready.
-Xuse-fir-lt Compile using the LightTree parser with the frontend IR. -Xuse-fir-lt Compile using the LightTree parser with the frontend IR.
-Xuse-ir-fake-override-builder Generate fake overrides via IR. See KT-61514
-Xuse-k2 Compile using the experimental K2 compiler pipeline. No compatibility guarantees are provided yet. -Xuse-k2 Compile using the experimental K2 compiler pipeline. No compatibility guarantees are provided yet.
-Xverbose-phases Be verbose while performing the given backend phases. -Xverbose-phases Be verbose while performing the given backend phases.
@@ -1,5 +1,4 @@
// FIR_IDENTICAL // FIR_IDENTICAL
// ENABLE_IR_FAKE_OVERRIDE_GENERATION
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
open class Base open class Base
@@ -1,6 +1,5 @@
// FIR_IDENTICAL // FIR_IDENTICAL
// WITH_STDLIB // WITH_STDLIB
// ENABLE_IR_FAKE_OVERRIDE_GENERATION
// KT-64692 // KT-64692
// test data differs - no getOrDefault in AbstractMap for non-jvm. // test data differs - no getOrDefault in AbstractMap for non-jvm.
@@ -11,4 +10,4 @@ class MyMap : AbstractMap<Int, Int>() {
// clash with stdlib internal function // clash with stdlib internal function
fun containsEntry(entry: Map.Entry<*, *>?) = false fun containsEntry(entry: Map.Entry<*, *>?) = false
} }
+1 -2
View File
@@ -1,5 +1,4 @@
// FIR_IDENTICAL // FIR_IDENTICAL
// ENABLE_IR_FAKE_OVERRIDE_GENERATION
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// FILE: J.java // FILE: J.java
@@ -29,4 +28,4 @@ class E : D() {
fun foo(x : I) { fun foo(x : I) {
x.foo() x.foo()
} }
+3 -6
View File
@@ -1,10 +1,7 @@
// WITH_STDLIB
// ENABLE_IR_FAKE_OVERRIDE_GENERATION
// SEPARATE_SIGNATURE_DUMP_FOR_K2
// ^ Value parameters in fake overrides generated by K1 and K2 are different
// WITH_REFLECT // WITH_REFLECT
// TARGET_BACKEND: JVM_IR // TARGET_BACKEND: JVM_IR
// SEPARATE_SIGNATURE_DUMP_FOR_K2
// ^ Value parameters in fake overrides generated by K1 and K2 are different
// FILE: Java1.java // FILE: Java1.java
public class Java1 extends KotlinClass { } public class Java1 extends KotlinClass { }
@@ -14,4 +11,4 @@ import java.util.ArrayList
class A : Java1() class A : Java1()
open class KotlinClass : ArrayList<Int>() open class KotlinClass : ArrayList<Int>()
@@ -1,7 +1,6 @@
// TARGET_BACKEND: JVM_IR // TARGET_BACKEND: JVM_IR
// WITH_STDLIB // WITH_STDLIB
// FULL_JDK // FULL_JDK
// ENABLE_IR_FAKE_OVERRIDE_GENERATION
// SEPARATE_SIGNATURE_DUMP_FOR_K2 // SEPARATE_SIGNATURE_DUMP_FOR_K2
// ISSUE: KT-65302 // ISSUE: KT-65302
@@ -1,5 +1,4 @@
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// ENABLE_IR_FAKE_OVERRIDE_GENERATION
// ISSUE: KT-65207 // ISSUE: KT-65207
// FILE: Java1.java // FILE: Java1.java
@@ -1,5 +1,4 @@
// FIR_IDENTICAL // FIR_IDENTICAL
// ENABLE_IR_FAKE_OVERRIDE_GENERATION
// TARGET_BACKEND: JVM_IR // TARGET_BACKEND: JVM_IR
// ISSUE: KT-65493 // ISSUE: KT-65493
@@ -7,21 +7,21 @@ package org.jetbrains.kotlin.test.backend.ir
import org.jetbrains.kotlin.test.WrappedException import org.jetbrains.kotlin.test.WrappedException
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives import org.jetbrains.kotlin.test.directives.CodegenTestDirectives
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.ENABLE_IR_FAKE_OVERRIDE_GENERATION import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.ENABLE_FIR_FAKE_OVERRIDE_GENERATION
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.IGNORE_CODEGEN_WITH_IR_FAKE_OVERRIDE_GENERATION import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.IGNORE_CODEGEN_WITH_FIR2IR_FAKE_OVERRIDE_GENERATION
import org.jetbrains.kotlin.test.model.AfterAnalysisChecker import org.jetbrains.kotlin.test.model.AfterAnalysisChecker
import org.jetbrains.kotlin.test.services.TestServices import org.jetbrains.kotlin.test.services.TestServices
import org.jetbrains.kotlin.test.services.defaultsProvider import org.jetbrains.kotlin.test.services.defaultsProvider
import org.jetbrains.kotlin.test.services.moduleStructure import org.jetbrains.kotlin.test.services.moduleStructure
class CodegenWithIrFakeOverrideGeneratorSuppressor(testServices: TestServices) : AfterAnalysisChecker(testServices) { class CodegenWithFir2IrFakeOverrideGeneratorSuppressor(testServices: TestServices) : AfterAnalysisChecker(testServices) {
override fun suppressIfNeeded(failedAssertions: List<WrappedException>): List<WrappedException> { override fun suppressIfNeeded(failedAssertions: List<WrappedException>): List<WrappedException> {
return when { return when {
!mainDirectiveEnabled -> failedAssertions !mainDirectiveEnabled -> failedAssertions
suppressDirectiveEnabled -> suppressDirectiveEnabled ->
if (failedAssertions.isEmpty()) if (failedAssertions.isEmpty())
listOf( listOf(
AssertionError("Looks like this test can be unmuted. Remove $IGNORE_CODEGEN_WITH_IR_FAKE_OVERRIDE_GENERATION directive.").wrap() AssertionError("Looks like this test can be unmuted. Remove $IGNORE_CODEGEN_WITH_FIR2IR_FAKE_OVERRIDE_GENERATION directive.").wrap()
) )
else emptyList() else emptyList()
testServices.defaultsProvider.defaultTargetBackend testServices.defaultsProvider.defaultTargetBackend
@@ -32,8 +32,8 @@ class CodegenWithIrFakeOverrideGeneratorSuppressor(testServices: TestServices) :
} }
private val mainDirectiveEnabled: Boolean private val mainDirectiveEnabled: Boolean
get() = ENABLE_IR_FAKE_OVERRIDE_GENERATION in testServices.moduleStructure.allDirectives get() = ENABLE_FIR_FAKE_OVERRIDE_GENERATION in testServices.moduleStructure.allDirectives
private val suppressDirectiveEnabled: Boolean private val suppressDirectiveEnabled: Boolean
get() = IGNORE_CODEGEN_WITH_IR_FAKE_OVERRIDE_GENERATION in testServices.moduleStructure.allDirectives get() = IGNORE_CODEGEN_WITH_FIR2IR_FAKE_OVERRIDE_GENERATION in testServices.moduleStructure.allDirectives
} }
@@ -250,16 +250,16 @@ object CodegenTestDirectives : SimpleDirectivesContainer() {
""".trimIndent() """.trimIndent()
) )
val ENABLE_IR_FAKE_OVERRIDE_GENERATION by directive( val ENABLE_FIR_FAKE_OVERRIDE_GENERATION by directive(
description = """ description = """
Enables fake-override generation in FIR2IR using IR f/o generator on JVM. KT-61514 Enables fake-override generation in FIR2IR using FIR2IR f/o generator on JVM, i.e. revert to behavior before KT-61514 was resolved
""".trimIndent() """.trimIndent()
) )
// String to allow and enforce issue id. Value is not actually used. // String to allow and enforce issue id. Value is not actually used.
val IGNORE_CODEGEN_WITH_IR_FAKE_OVERRIDE_GENERATION by stringDirective( val IGNORE_CODEGEN_WITH_FIR2IR_FAKE_OVERRIDE_GENERATION by stringDirective(
description = """ description = """
Suppresses test if $ENABLE_IR_FAKE_OVERRIDE_GENERATION directive enabled Suppresses test if $ENABLE_FIR_FAKE_OVERRIDE_GENERATION directive enabled
""".trimIndent() """.trimIndent()
) )
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.test.backend.ir.*
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
import org.jetbrains.kotlin.test.builders.configureFirHandlersStep import org.jetbrains.kotlin.test.builders.configureFirHandlersStep
import org.jetbrains.kotlin.test.builders.configureIrHandlersStep import org.jetbrains.kotlin.test.builders.configureIrHandlersStep
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.ENABLE_IR_FAKE_OVERRIDE_GENERATION import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.ENABLE_FIR_FAKE_OVERRIDE_GENERATION
import org.jetbrains.kotlin.test.directives.ConfigurationDirectives.WITH_STDLIB import org.jetbrains.kotlin.test.directives.ConfigurationDirectives.WITH_STDLIB
import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.USE_PSI_CLASS_FILES_READING import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.USE_PSI_CLASS_FILES_READING
import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives
@@ -97,15 +97,15 @@ open class AbstractFirLightTreeBlackBoxCodegenTest : AbstractFirBlackBoxCodegenT
@FirPsiCodegenTest @FirPsiCodegenTest
open class AbstractFirPsiBlackBoxCodegenTest : AbstractFirBlackBoxCodegenTestBase(FirParser.Psi) open class AbstractFirPsiBlackBoxCodegenTest : AbstractFirBlackBoxCodegenTestBase(FirParser.Psi)
open class AbstractFirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTest : AbstractFirLightTreeBlackBoxCodegenTest() { open class AbstractFirLightTreeBlackBoxCodegenWithFir2IrFakeOverrideGeneratorTest : AbstractFirLightTreeBlackBoxCodegenTest() {
override fun configure(builder: TestConfigurationBuilder) { override fun configure(builder: TestConfigurationBuilder) {
super.configure(builder) super.configure(builder)
with(builder) { with(builder) {
defaultDirectives { defaultDirectives {
+ENABLE_IR_FAKE_OVERRIDE_GENERATION +ENABLE_FIR_FAKE_OVERRIDE_GENERATION
} }
useAfterAnalysisCheckers(::CodegenWithIrFakeOverrideGeneratorSuppressor) useAfterAnalysisCheckers(::CodegenWithFir2IrFakeOverrideGeneratorSuppressor)
} }
} }
} }
@@ -130,9 +130,10 @@ fun createCompilerConfiguration(module: TestModule, configurators: List<Abstract
val configuration = CompilerConfiguration() val configuration = CompilerConfiguration()
configuration[CommonConfigurationKeys.MODULE_NAME] = module.name configuration[CommonConfigurationKeys.MODULE_NAME] = module.name
if (module.targetPlatform.isJvm() && CodegenTestDirectives.ENABLE_IR_FAKE_OVERRIDE_GENERATION in module.directives) { if (module.targetPlatform.isJvm() && CodegenTestDirectives.ENABLE_FIR_FAKE_OVERRIDE_GENERATION in module.directives) {
// For non-JVM platforms, the IR-based fake override builder is enabled unconditionally; on JVM it must be enabled manually. // IR-based fake override generator is enabled by default on all platforms.
configuration.put(CommonConfigurationKeys.USE_IR_FAKE_OVERRIDE_BUILDER, true) // On JVM, we can also test FIR2IR-based fake override generator.
configuration.put(CommonConfigurationKeys.USE_FIR_BASED_FAKE_OVERRIDE_GENERATOR, true)
} }
if (JsEnvironmentConfigurationDirectives.GENERATE_STRICT_IMPLICIT_EXPORT in module.directives) { if (JsEnvironmentConfigurationDirectives.GENERATE_STRICT_IMPLICIT_EXPORT in module.directives) {
@@ -333,7 +333,7 @@ fun generateJUnit5CompilerTests(args: Array<String>, mainClassName: String?) {
model("codegen/box") model("codegen/box")
} }
testClass<AbstractFirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTest> { testClass<AbstractFirLightTreeBlackBoxCodegenWithFir2IrFakeOverrideGeneratorTest> {
model("codegen/box", excludeDirs = excludedScriptDirs) model("codegen/box", excludeDirs = excludedScriptDirs)
} }
@@ -172,7 +172,7 @@ class KonanDriver(
copy(BinaryOptions.objcExportDisableSwiftMemberNameMangling) copy(BinaryOptions.objcExportDisableSwiftMemberNameMangling)
copy(BinaryOptions.objcExportIgnoreInterfaceMethodCollisions) copy(BinaryOptions.objcExportIgnoreInterfaceMethodCollisions)
copy(KonanConfigKeys.OBJC_GENERICS) copy(KonanConfigKeys.OBJC_GENERICS)
copy(CommonConfigurationKeys.USE_IR_FAKE_OVERRIDE_BUILDER) copy(CommonConfigurationKeys.USE_FIR_BASED_FAKE_OVERRIDE_GENERATOR)
} }
// For the second stage, remove already compiled source files from the configuration. // For the second stage, remove already compiled source files from the configuration.