[IR] Rewrite generator for interpreter map

1. Reuse `DisabledIdSignatureDescriptor` to create `IrBuiltIns`
2. Provide FQ names for types to ensure method find correctness
This commit is contained in:
Ivan Kylchik
2023-05-31 15:41:33 +02:00
committed by Space Team
parent 6501d0b743
commit fe538a6174
5 changed files with 592 additions and 636 deletions
@@ -155,7 +155,7 @@ internal class DefaultCallInterceptor(override val interpreter: IrInterpreter) :
}
val receiverType = irFunction.dispatchReceiverParameter?.type ?: irFunction.extensionReceiverParameter?.type
val argsType = (listOfNotNull(receiverType) + irFunction.valueParameters.map { it.type }).map { it.getOnlyName() }
val argsType = (listOfNotNull(receiverType) + irFunction.valueParameters.map { it.type }).map { it.fqNameWithNullability() }
val argsValues = args.wrap(this, irFunction)
withExceptionHandler(environment) {
@@ -170,8 +170,8 @@ internal class DefaultCallInterceptor(override val interpreter: IrInterpreter) :
if (environment.configuration.platform.isJs()) {
if (signature.name == "toString") return signature.args[0].value.specialToStringForJs()
if (signature.name == "toFloat") signature.name = "toDouble"
signature.args.filter { it.type == "Float" }.forEach {
it.type = "Double"
signature.args.filter { it.type == "kotlin.Float" }.forEach {
it.type = "kotlin.Double"
it.value = it.value.toString().toDouble()
}
}
@@ -204,6 +204,14 @@ internal fun IrFunction.getArgsForMethodInvocation(
return argsValues
}
internal fun IrType.fqNameWithNullability(): String {
val fqName = classFqName?.toString()
?: (this.classifierOrNull?.owner as? IrDeclarationWithName)?.name?.asString()
?: render()
val nullability = if (this is IrSimpleType && this.nullability == SimpleTypeNullability.MARKED_NULLABLE) "?" else ""
return fqName + nullability
}
internal fun IrType.getOnlyName(): String {
if (this !is IrSimpleType) return this.render()
return (this.classifierOrFail.owner as IrDeclarationWithName).name.asString() + when (nullability) {