From f5a00c788a1ce4319299c36b72178ce632bba078 Mon Sep 17 00:00:00 2001 From: Sergej Jaskiewicz Date: Mon, 24 Jul 2023 17:58:08 +0200 Subject: [PATCH] [klib] Disable ManglerChecker on K2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `ManglerChecker` is a class that verifies that for each IR declaration (except some, see its `needsChecking` property) its mangled name (computed from IR) is the same as the mangled name computed from its frontend representation — `DeclarationDescriptor` on K1 or `FirDeclaration` on K2. The way it does it is as follows. On K1, `ManglerChecker` looks if the declaration has a true, non-IR-based descriptor, it if it does, then it checks it (see ManglerChecker.Companion#hasDescriptor). On K2, since we don’t have any descriptors, `ManglerChecker` looks if the declaration’s metadata property is `null` (because the corresponding `FirDeclaration` is stored there). If it’s not, it checks it (see ManglerChecker.Companion#hasMetadata). The issue is that those two conditions are not equivalent. When the Compose compiler plugin transforms an IR function, it copies its `metadata` property (as it should, because `metadata` can contain anything, not necessarily the frontend representation), but doesn't set the descriptor. Because of that, on K1 that transformed function is skipped in `ManglerChecker`, and on K2 it’s not. The correct usage would be to properly distinguish which declarations come from the FE as is, and which are transformed/synthesized, and skip the latter. But it is unclear how to implement this. For now, the easiest way to fix this on K2 is to not run ManglerChecker at all. KT-60648 ^KT-59448 Fixed --- .../backend/common/serialization/mangle/ManglerChecker.kt | 1 - .../src/org/jetbrains/kotlin/backend/konan/Fir2Ir.kt | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/mangle/ManglerChecker.kt b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/mangle/ManglerChecker.kt index 0ffeebc1808..e9b4882faa2 100644 --- a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/mangle/ManglerChecker.kt +++ b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/mangle/ManglerChecker.kt @@ -22,7 +22,6 @@ class ManglerChecker( companion object { val hasDescriptor: (IrDeclarationBase) -> Boolean = { it.symbol.hasDescriptor } - val hasMetadata: (IrDeclarationBase) -> Boolean = { (it as? IrMetadataSourceOwner)?.metadata != null } } private val manglers = _manglers.toList() diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Fir2Ir.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Fir2Ir.kt index aa32d40ed9f..a5d118c3f48 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Fir2Ir.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Fir2Ir.kt @@ -93,7 +93,11 @@ internal fun PhaseContext.fir2Ir( fir2IrResultPostCompute = { // it's important to compare manglers before actualization, since IR will be actualized, while FIR won't irModuleFragment.acceptVoid( - ManglerChecker(KonanManglerIr, Ir2FirManglerAdapter(FirNativeKotlinMangler()), needsChecking = ManglerChecker.hasMetadata) + ManglerChecker( + KonanManglerIr, + Ir2FirManglerAdapter(FirNativeKotlinMangler()), + needsChecking = { false }, // FIXME(KT-60648): Re-enable + ) ) } ).also {