[K/N][codegen] Removed FieldInfo.hasConstInitializer

If a property is a const val, it can't have non-const initializer
This commit is contained in:
Igor Chevdar
2021-10-05 12:42:53 +05:00
parent cb71240938
commit 0a4fe94717
3 changed files with 8 additions and 14 deletions
@@ -260,10 +260,11 @@ internal class GlobalHierarchyAnalysis(val context: Context, val irModule: IrMod
}
}
internal fun IrField.toFieldInfo() =
ClassLayoutBuilder.FieldInfo(name.asString(), type,
correspondingPropertySymbol?.owner?.isConst ?: false,
initializer?.expression is IrConst<*>, this)
internal fun IrField.toFieldInfo(): ClassLayoutBuilder.FieldInfo {
val isConst = correspondingPropertySymbol?.owner?.isConst ?: false
require(!isConst || initializer?.expression is IrConst<*>) { "A const val field ${render()} must have constant initializer" }
return ClassLayoutBuilder.FieldInfo(name.asString(), type, isConst, this)
}
internal class ClassLayoutBuilder(val irClass: IrClass, val context: Context) {
val vtableEntries: List<OverriddenFunctionInfo> by lazy {
@@ -399,7 +400,7 @@ internal class ClassLayoutBuilder(val irClass: IrClass, val context: Context) {
return context.getLayoutBuilder(superFunction.parentAsClass).itablePlace(superFunction)
}
class FieldInfo(val name: String, val type: IrType, val isConst: Boolean, val hasConstInitializer: Boolean, val irField: IrField?) {
class FieldInfo(val name: String, val type: IrType, val isConst: Boolean, val irField: IrField?) {
var index = -1
}
@@ -43,8 +43,7 @@ internal fun IrClass.hasConstStateAndNoSideEffects(context: Context): Boolean {
if (!context.shouldOptimize()) return false
if (this.hasAnnotation(KonanFqNames.canBePrecreated)) return true
val fields = context.getLayoutBuilder(this).fields
return fields.all { it.isConst && it.hasConstInitializer } &&
this.constructors.all { it.isAutogeneratedSimpleConstructor(context) }
return fields.all { it.isConst } && this.constructors.all { it.isAutogeneratedSimpleConstructor(context) }
}
internal class CodeGenerator(override val context: Context) : ContextUtils {
@@ -154,7 +154,6 @@ internal object InlineFunctionBodyReferenceSerializer {
class SerializedClassFieldInfo(val name: Int, val binaryType: Int, val type: Int, val flags: Int) {
companion object {
const val FLAG_IS_CONST = 1
const val FLAG_CONST_INITIALIZER = 2
}
}
@@ -541,8 +540,6 @@ internal class KonanIrLinker(
var flags = 0
if (field.isConst)
flags = flags or SerializedClassFieldInfo.FLAG_IS_CONST
if (field.hasConstInitializer)
flags = flags or SerializedClassFieldInfo.FLAG_CONST_INITIALIZER
val classifier = irField.type.classifierOrNull
?: error("Fields of type ${irField.type.render()} are not supported")
val primitiveBinaryType = irField.type.computePrimitiveBinaryTypeOrNull()
@@ -840,10 +837,7 @@ internal class KonanIrLinker(
}
}
ClassLayoutBuilder.FieldInfo(
name, type,
isConst = (field.flags and SerializedClassFieldInfo.FLAG_IS_CONST) != 0,
hasConstInitializer = (field.flags and SerializedClassFieldInfo.FLAG_CONST_INITIALIZER) != 0,
irField = null)
name, type, isConst = (field.flags and SerializedClassFieldInfo.FLAG_IS_CONST) != 0, irField = null)
}
}
}