[Wasm] Better preserve IR types after inlining

This commit is contained in:
Igor Laevsky
2021-12-30 18:19:24 +02:00
parent 9ae452e489
commit cfcbe9e1e2
15 changed files with 49 additions and 62 deletions
@@ -98,7 +98,7 @@ private val wrapInlineDeclarationsWithReifiedTypeParametersPhase = makeWasmModul
private val functionInliningPhase = makeCustomWasmModulePhase(
{ context, module ->
FunctionInlining(context).inline(module)
FunctionInlining(context, null, true).inline(module)
module.patchDeclarationParents()
},
name = "FunctionInliningPhase",
@@ -177,6 +177,12 @@ class WasmBaseTypeOperatorTransformer(val context: WasmBackendContext) : IrEleme
}
}
// A bit of a hack. Inliner tends to insert null casts from nothing to any. It's hard to express in wasm, so we simply replace
// them with single const null.
if (toType == builtIns.anyNType && fromType == builtIns.nothingNType && value is IrConst<*> && value.kind == IrConstKind.Null) {
return builder.irNull(builtIns.nothingNType)
}
// Handled by autoboxing transformer
if (toType.isInlined() && !fromType.isInlined()) {
return builder.irCall(