From 62041192199227fc21ec175db32644812de2b379 Mon Sep 17 00:00:00 2001 From: Ivan Kylchik Date: Tue, 18 Jul 2023 16:13:07 +0200 Subject: [PATCH] [IR] Simplify logic of constructing unsigned number in interpreter This way it is a little less "hacky". We are looking only for "data" property, and as long as this property is declared in constructor, we can safely assume we will get the correct one even if it is renamed. --- .../kotlin/ir/interpreter/CallInterceptor.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/CallInterceptor.kt b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/CallInterceptor.kt index 11a474e5d36..ebe491cece9 100644 --- a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/CallInterceptor.kt +++ b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/CallInterceptor.kt @@ -19,7 +19,10 @@ import org.jetbrains.kotlin.ir.interpreter.intrinsics.IntrinsicEvaluator import org.jetbrains.kotlin.ir.interpreter.proxy.wrap import org.jetbrains.kotlin.ir.interpreter.stack.CallStack import org.jetbrains.kotlin.ir.interpreter.state.* -import org.jetbrains.kotlin.ir.types.* +import org.jetbrains.kotlin.ir.types.IrType +import org.jetbrains.kotlin.ir.types.classOrNull +import org.jetbrains.kotlin.ir.types.isArray +import org.jetbrains.kotlin.ir.types.isUnsignedType import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.util.hasAnnotation import org.jetbrains.kotlin.name.FqName @@ -89,11 +92,10 @@ internal class DefaultCallInterceptor(override val interpreter: IrInterpreter) : verify(handleIntrinsicMethods(irConstructor)) { "Unsupported intrinsic constructor: ${irConstructor.render()}" } } irClass.defaultType.isUnsignedType() -> { - // Check for type is a hack needed for Native; - // in UInt, for example, we may have (after lowerings, I guess) additional property "$companion". - // Check for fake overrides is a hack needed for Wasm; - // in UInt, for example, we may have additional typeInfo and hashCode properties declared in "Any" - val propertySymbol = irClass.declarations.single { it is IrProperty && !it.isFakeOverride && it.getter?.returnType?.isPrimitiveType() == true }.symbol + val propertyName = irClass.inlineClassRepresentation?.underlyingPropertyName + val propertySymbol = irClass.declarations.filterIsInstance() + .single { it.name == propertyName && it.getter?.extensionReceiverParameter == null } + .symbol callStack.pushState(receiver.apply { this.setField(propertySymbol, args.single()) }) } else -> defaultAction()