[KLIB] Use queue to track classes required fake override resolve
- Avoid module visiting to prevent lazy bodies loading
This commit is contained in:
+3
-16
@@ -170,21 +170,8 @@ class FakeOverrideBuilder(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun provideFakeOverrides(module: IrModuleFragment) {
|
fun provideFakeOverrides(klass: IrClass) {
|
||||||
module.acceptVoid(object : IrElementVisitorVoid {
|
buildFakeOverrideChainsForClass(klass)
|
||||||
override fun visitElement(element: IrElement) {
|
haveFakeOverrides.add(klass)
|
||||||
element.acceptChildrenVoid(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitClass(declaration: IrClass) {
|
|
||||||
buildFakeOverrideChainsForClass(declaration)
|
|
||||||
haveFakeOverrides.add(declaration)
|
|
||||||
super.visitClass(declaration)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitFunction(declaration: IrFunction) {
|
|
||||||
// Don't go for function local classes
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-1
@@ -110,7 +110,8 @@ abstract class IrFileDeserializer(
|
|||||||
val builtIns: IrBuiltIns,
|
val builtIns: IrBuiltIns,
|
||||||
val symbolTable: SymbolTable,
|
val symbolTable: SymbolTable,
|
||||||
protected var deserializeBodies: Boolean,
|
protected var deserializeBodies: Boolean,
|
||||||
private val deserializeFakeOverrides: Boolean
|
private val deserializeFakeOverrides: Boolean,
|
||||||
|
private val fakeOverrideQueue: MutableList<IrClass>
|
||||||
) {
|
) {
|
||||||
|
|
||||||
abstract fun deserializeIrSymbolToDeclare(code: Long): Pair<IrSymbol, IdSignature>
|
abstract fun deserializeIrSymbolToDeclare(code: Long): Pair<IrSymbol, IdSignature>
|
||||||
@@ -1051,6 +1052,12 @@ abstract class IrFileDeserializer(
|
|||||||
thisReceiver = deserializeIrValueParameter(proto.thisReceiver, -1)
|
thisReceiver = deserializeIrValueParameter(proto.thisReceiver, -1)
|
||||||
|
|
||||||
(descriptor as? WrappedClassDescriptor)?.bind(this)
|
(descriptor as? WrappedClassDescriptor)?.bind(this)
|
||||||
|
|
||||||
|
if (!deserializeFakeOverrides) {
|
||||||
|
if (symbol.isPublicApi) {
|
||||||
|
fakeOverrideQueue.add(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-8
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.impl.EmptyPackageFragmentDescriptor
|
import org.jetbrains.kotlin.descriptors.impl.EmptyPackageFragmentDescriptor
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||||
@@ -71,6 +72,7 @@ abstract class KotlinIrLinker(
|
|||||||
abstract val fakeOverrideBuilder: FakeOverrideBuilder
|
abstract val fakeOverrideBuilder: FakeOverrideBuilder
|
||||||
|
|
||||||
private val haveSeen = mutableSetOf<IrSymbol>()
|
private val haveSeen = mutableSetOf<IrSymbol>()
|
||||||
|
private val fakeOverrideClassQueue = mutableListOf<IrClass>()
|
||||||
|
|
||||||
private lateinit var linkerExtensions: Collection<IrDeserializer.IrLinkerExtension>
|
private lateinit var linkerExtensions: Collection<IrDeserializer.IrLinkerExtension>
|
||||||
|
|
||||||
@@ -228,7 +230,7 @@ abstract class KotlinIrLinker(
|
|||||||
inlineBodies: Boolean,
|
inlineBodies: Boolean,
|
||||||
deserializeFakeOverrides: Boolean,
|
deserializeFakeOverrides: Boolean,
|
||||||
private val moduleDeserializer: IrModuleDeserializer
|
private val moduleDeserializer: IrModuleDeserializer
|
||||||
) : IrFileDeserializer(logger, builtIns, symbolTable, !onlyHeaders, deserializeFakeOverrides) {
|
) : IrFileDeserializer(logger, builtIns, symbolTable, !onlyHeaders, deserializeFakeOverrides, fakeOverrideClassQueue) {
|
||||||
|
|
||||||
private var fileLoops = mutableMapOf<Int, IrLoop>()
|
private var fileLoops = mutableMapOf<Int, IrLoop>()
|
||||||
|
|
||||||
@@ -588,13 +590,10 @@ abstract class KotlinIrLinker(
|
|||||||
|
|
||||||
override fun postProcess() {
|
override fun postProcess() {
|
||||||
finalizeExpectActualLinker()
|
finalizeExpectActualLinker()
|
||||||
|
|
||||||
if (!deserializeFakeOverrides) {
|
while (fakeOverrideClassQueue.isNotEmpty()) {
|
||||||
deserializersForModules.values.forEach {
|
val klass = fakeOverrideClassQueue.removeLast()
|
||||||
it.postProcess {
|
fakeOverrideBuilder.provideFakeOverrides(klass)
|
||||||
fakeOverrideBuilder.provideFakeOverrides(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: fix IrPluginContext to make it not produce additional external reference
|
// TODO: fix IrPluginContext to make it not produce additional external reference
|
||||||
|
|||||||
Reference in New Issue
Block a user