FIR2IR: Postpone binding overrides for lazy classes until sources processed

This commit is contained in:
Denis.Zharkov
2021-11-25 20:10:28 +03:00
committed by Space
parent 78ba49ddd8
commit 6082f0b712
15 changed files with 76 additions and 1 deletions
@@ -52,6 +52,9 @@ class Fir2IrConverter(
private val generatorExtensions = session.extensionService.declarationGenerators
private var wereSourcesFakeOverridesBound = false
private val postponedDeclarationsForFakeOverridesBinding = mutableListOf<IrDeclaration>()
fun runSourcesConversion(
allFirFiles: List<FirFile>,
irModuleFragment: IrModuleFragmentImpl,
@@ -90,6 +93,11 @@ class Fir2IrConverter(
for (firFile in allFirFiles) {
bindFakeOverridesInFile(firFile)
}
wereSourcesFakeOverridesBound = true
fakeOverrideGenerator.bindOverriddenSymbols(postponedDeclarationsForFakeOverridesBinding)
postponedDeclarationsForFakeOverridesBinding.clear()
// Do (3) and (4) for local classes encountered during (3)
classifierStorage.processMembersOfClassesCreatedOnTheFly()
@@ -120,6 +128,15 @@ class Fir2IrConverter(
}
fun bindFakeOverridesOrPostpone(declarations: List<IrDeclaration>) {
// Do not run binding for lazy classes until all sources declarations are processed
if (wereSourcesFakeOverridesBound) {
fakeOverrideGenerator.bindOverriddenSymbols(declarations)
} else {
postponedDeclarationsForFakeOverridesBinding += declarations
}
}
fun processLocalClassAndNestedClassesOnTheFly(regularClass: FirRegularClass, parent: IrDeclarationParent): IrClass {
val irClass = registerClassAndNestedClasses(regularClass, parent)
processClassAndNestedClassHeaders(regularClass)
@@ -141,7 +141,7 @@ class Fir2IrLazyClass(
fun getFakeOverridesByName(name: Name): Collection<IrDeclaration> = fakeOverridesByName.getOrPut(name) {
fakeOverrideGenerator.generateFakeOverridesForName(this@Fir2IrLazyClass, name, fir)
.also(fakeOverrideGenerator::bindOverriddenSymbols)
.also(converter::bindFakeOverridesOrPostpone)
}
override val declarations: MutableList<IrDeclaration> by lazyVar(lock) {
@@ -617,6 +617,11 @@ public class IncrementalFirJvmCompilerRunnerTestGenerated extends AbstractIncrem
runTest("jps-plugin/testData/incremental/pureKotlin/secondaryConstructorInlined/");
}
@TestMetadata("serializedSubClassAndChangedInterfaces")
public void testSerializedSubClassAndChangedInterfaces() throws Exception {
runTest("jps-plugin/testData/incremental/pureKotlin/serializedSubClassAndChangedInterfaces/");
}
@TestMetadata("simpleClassDependency")
public void testSimpleClassDependency() throws Exception {
runTest("jps-plugin/testData/incremental/pureKotlin/simpleClassDependency/");
@@ -616,6 +616,11 @@ public class IncrementalJsCompilerRunnerTestGenerated extends AbstractIncrementa
runTest("jps-plugin/testData/incremental/pureKotlin/secondaryConstructorInlined/");
}
@TestMetadata("serializedSubClassAndChangedInterfaces")
public void testSerializedSubClassAndChangedInterfaces() throws Exception {
runTest("jps-plugin/testData/incremental/pureKotlin/serializedSubClassAndChangedInterfaces/");
}
@TestMetadata("simpleClassDependency")
public void testSimpleClassDependency() throws Exception {
runTest("jps-plugin/testData/incremental/pureKotlin/simpleClassDependency/");
@@ -616,6 +616,11 @@ public class IncrementalJsCompilerRunnerWithMetadataOnlyTestGenerated extends Ab
runTest("jps-plugin/testData/incremental/pureKotlin/secondaryConstructorInlined/");
}
@TestMetadata("serializedSubClassAndChangedInterfaces")
public void testSerializedSubClassAndChangedInterfaces() throws Exception {
runTest("jps-plugin/testData/incremental/pureKotlin/serializedSubClassAndChangedInterfaces/");
}
@TestMetadata("simpleClassDependency")
public void testSimpleClassDependency() throws Exception {
runTest("jps-plugin/testData/incremental/pureKotlin/simpleClassDependency/");
@@ -591,6 +591,11 @@ public class IncrementalJsKlibCompilerRunnerTestGenerated extends AbstractIncrem
runTest("jps-plugin/testData/incremental/pureKotlin/secondaryConstructorInlined/");
}
@TestMetadata("serializedSubClassAndChangedInterfaces")
public void testSerializedSubClassAndChangedInterfaces() throws Exception {
runTest("jps-plugin/testData/incremental/pureKotlin/serializedSubClassAndChangedInterfaces/");
}
@TestMetadata("simpleClassDependency")
public void testSimpleClassDependency() throws Exception {
runTest("jps-plugin/testData/incremental/pureKotlin/simpleClassDependency/");
@@ -591,6 +591,11 @@ public class IncrementalJsKlibCompilerWithScopeExpansionRunnerTestGenerated exte
runTest("jps-plugin/testData/incremental/pureKotlin/secondaryConstructorInlined/");
}
@TestMetadata("serializedSubClassAndChangedInterfaces")
public void testSerializedSubClassAndChangedInterfaces() throws Exception {
runTest("jps-plugin/testData/incremental/pureKotlin/serializedSubClassAndChangedInterfaces/");
}
@TestMetadata("simpleClassDependency")
public void testSimpleClassDependency() throws Exception {
runTest("jps-plugin/testData/incremental/pureKotlin/simpleClassDependency/");
@@ -617,6 +617,11 @@ public class IncrementalJvmCompilerRunnerTestGenerated extends AbstractIncrement
runTest("jps-plugin/testData/incremental/pureKotlin/secondaryConstructorInlined/");
}
@TestMetadata("serializedSubClassAndChangedInterfaces")
public void testSerializedSubClassAndChangedInterfaces() throws Exception {
runTest("jps-plugin/testData/incremental/pureKotlin/serializedSubClassAndChangedInterfaces/");
}
@TestMetadata("simpleClassDependency")
public void testSimpleClassDependency() throws Exception {
runTest("jps-plugin/testData/incremental/pureKotlin/simpleClassDependency/");
@@ -617,6 +617,11 @@ public class IncrementalJvmOldBackendCompilerRunnerTestGenerated extends Abstrac
runTest("jps-plugin/testData/incremental/pureKotlin/secondaryConstructorInlined/");
}
@TestMetadata("serializedSubClassAndChangedInterfaces")
public void testSerializedSubClassAndChangedInterfaces() throws Exception {
runTest("jps-plugin/testData/incremental/pureKotlin/serializedSubClassAndChangedInterfaces/");
}
@TestMetadata("simpleClassDependency")
public void testSimpleClassDependency() throws Exception {
runTest("jps-plugin/testData/incremental/pureKotlin/simpleClassDependency/");
@@ -0,0 +1,3 @@
package test
class A : I1, I2
@@ -0,0 +1,3 @@
package test
data class B(val a: A) // generates a call to A::hashCode that is a fake override in A
@@ -0,0 +1,13 @@
================ Step #1 =================
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/test/BKt.class
out/production/module/test/UsageKt.class
End of files
Compiling files:
src/b.kt
src/interfaces.kt
End of files
Exit code: OK
------------------------------------------
@@ -0,0 +1,4 @@
package test
interface I1
interface I2