IR: use inlineClassRepresentation in getInlineClassUnderlyingType
Looking for the primary constructor manually doesn't work if it's private in the other module on JVM, because private declarations are skipped in IrLazyClass.
This commit is contained in:
+1
-2
@@ -481,8 +481,7 @@ internal class LambdaMetafactoryArgumentsBuilder(
|
||||
if (erasedAdapteeClass.isInline) {
|
||||
// Inline classes mapped to non-null reference types are a special case because they can't be boxed trivially.
|
||||
// TODO consider adding a special type annotation to force boxing on an inline class type regardless of its underlying type.
|
||||
val underlyingAdapteeType = getInlineClassUnderlyingType(erasedAdapteeClass) as? IrSimpleType
|
||||
?: throw AssertionError("Underlying type for inline class should be a simple type: ${erasedAdapteeClass.render()}")
|
||||
val underlyingAdapteeType = getInlineClassUnderlyingType(erasedAdapteeClass)
|
||||
if (!underlyingAdapteeType.hasQuestionMark && !underlyingAdapteeType.isPrimitiveType()) {
|
||||
return TypeAdaptationConstraint.CONFLICT
|
||||
}
|
||||
|
||||
+1
-2
@@ -14,7 +14,6 @@ import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.classifierOrNull
|
||||
import org.jetbrains.kotlin.ir.types.getClass
|
||||
import org.jetbrains.kotlin.ir.util.getInlineClassUnderlyingType
|
||||
import org.jetbrains.kotlin.ir.util.isInterface
|
||||
import org.jetbrains.kotlin.wasm.ir.*
|
||||
|
||||
@@ -97,7 +96,7 @@ class WasmTypeTransformer(
|
||||
if (klass != null && klass.hasWasmForeignAnnotation()) {
|
||||
WasmExternRef
|
||||
} else if (ic != null) {
|
||||
getInlineClassUnderlyingType(ic).toWasmValueType()
|
||||
context.backendContext.inlineClassesUtils.getInlineClassUnderlyingType(ic).toWasmValueType()
|
||||
} else {
|
||||
this.toWasmGcRefType()
|
||||
}
|
||||
|
||||
+16
-1
@@ -9,10 +9,12 @@ import org.jetbrains.kotlin.backend.wasm.WasmSymbols
|
||||
import org.jetbrains.kotlin.ir.backend.js.InlineClassesUtils
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.erase
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.isNullable
|
||||
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
|
||||
|
||||
class WasmInlineClassesUtils(private val wasmSymbols: WasmSymbols) : InlineClassesUtils {
|
||||
override fun isTypeInlined(type: IrType): Boolean {
|
||||
@@ -42,4 +44,17 @@ class WasmInlineClassesUtils(private val wasmSymbols: WasmSymbols) : InlineClass
|
||||
|
||||
override val unboxIntrinsic: IrSimpleFunctionSymbol
|
||||
get() = wasmSymbols.unboxIntrinsic
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlike [org.jetbrains.kotlin.ir.util.getInlineClassUnderlyingType], doesn't use [IrClass.inlineClassRepresentation] because
|
||||
* for some reason it can be called for classes which are not inline, e.g. `kotlin.Double`.
|
||||
*/
|
||||
fun getInlineClassUnderlyingType(irClass: IrClass): IrType {
|
||||
for (declaration in irClass.declarations) {
|
||||
if (declaration is IrConstructor && declaration.isPrimary) {
|
||||
return declaration.valueParameters[0].type
|
||||
}
|
||||
}
|
||||
error("Class has no primary constructor: ${irClass.fqNameWhenAvailable}")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,18 +6,13 @@
|
||||
package org.jetbrains.kotlin.ir.util
|
||||
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
||||
import org.jetbrains.kotlin.ir.declarations.IrField
|
||||
import org.jetbrains.kotlin.ir.declarations.IrProperty
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
|
||||
fun getInlineClassUnderlyingType(irClass: IrClass): IrType {
|
||||
for (declaration in irClass.declarations) {
|
||||
if (declaration is IrConstructor && declaration.isPrimary) {
|
||||
return declaration.valueParameters[0].type
|
||||
}
|
||||
}
|
||||
error("Inline class has no primary constructor: ${irClass.fqNameWhenAvailable}")
|
||||
fun getInlineClassUnderlyingType(irClass: IrClass): IrSimpleType {
|
||||
val representation = irClass.inlineClassRepresentation ?: error("Not an inline class: ${irClass.render()}")
|
||||
return representation.underlyingType
|
||||
}
|
||||
|
||||
fun getInlineClassBackingField(irClass: IrClass): IrField {
|
||||
|
||||
Reference in New Issue
Block a user