Using const val from module doesn't mean we had to run initializers anymore.

This commit is contained in:
Nikolay Igotti
2019-03-01 08:55:24 +03:00
parent de6fa0e72f
commit 025a480247
3 changed files with 10 additions and 5 deletions
@@ -1425,11 +1425,15 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
fieldPtrOfClass(thisPtr, value.symbol.owner), value.descriptor.isVar())
} else {
assert(value.receiver == null)
if (context.config.threadsAreAllowed && value.symbol.owner.isMainOnlyNonPrimitive) {
functionGenerationContext.checkMainThread(currentCodeContext.exceptionHandler)
return if (value.symbol.owner.correspondingProperty?.isConst == true) {
evaluateConst(value.symbol.owner.initializer?.expression as IrConst<*>)
} else {
if (context.config.threadsAreAllowed && value.symbol.owner.isMainOnlyNonPrimitive) {
functionGenerationContext.checkMainThread(currentCodeContext.exceptionHandler)
}
val ptr = context.llvmDeclarations.forStaticField(value.symbol.owner).storage
functionGenerationContext.loadSlot(ptr, value.descriptor.isVar())
}
val ptr = context.llvmDeclarations.forStaticField(value.symbol.owner).storage
return functionGenerationContext.loadSlot(ptr, value.descriptor.isVar())
}
}
@@ -1080,7 +1080,7 @@ internal class IrModuleSerializer(
// Make sure that all top level properties are initialized on library's load.
file.declarations
.filterIsInstance<IrProperty>()
.filter { it.backingField?.initializer != null }
.filter { it.backingField?.initializer != null && !it.isConst }
.forEach { proto.addExplicitlyExportedToCompiler(serializeIrSymbol(it.backingField!!.symbol)) }
file.acceptVoid(object: IrElementVisitorVoid {
+1
View File
@@ -6,3 +6,4 @@ kotlin_version=1.3.21
# Use custom Kotlin/Native home:
org.jetbrains.kotlin.native.home=../../dist
org.gradle.workers.max=4