From 194efac68cb299427faf63071e37cf82456ca8d9 Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Wed, 13 Dec 2023 21:30:06 +0100 Subject: [PATCH] [Manglers] Uniform handling of the error type in signature mangled names in all manglers ^KT-63723 --- .../kotlin/fir/backend/FirMangleComputer.kt | 4 ++ .../descriptor/DescriptorMangleComputer.kt | 5 ++ .../errors/unresolvedReference.fir.ir.txt | 29 +++++++++++ .../errors/unresolvedReference.fir.kt.txt | 11 ++++ .../irText/errors/unresolvedReference.ir.txt | 9 ---- .../ir/irText/errors/unresolvedReference.kt | 12 ++--- .../irText/errors/unresolvedReference.kt.txt | 4 -- .../errors/unresolvedReference.sig.kt.txt | 52 +++++++------------ .../test/ClassicFrontend2NativeIrConverter.kt | 6 ++- 9 files changed, 76 insertions(+), 56 deletions(-) create mode 100644 compiler/testData/ir/irText/errors/unresolvedReference.fir.ir.txt create mode 100644 compiler/testData/ir/irText/errors/unresolvedReference.fir.kt.txt diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/FirMangleComputer.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/FirMangleComputer.kt index 0d4db91d14b..0d35e00aec8 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/FirMangleComputer.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/FirMangleComputer.kt @@ -134,6 +134,10 @@ open class FirMangleComputer( override fun mangleType(tBuilder: StringBuilder, type: ConeKotlinType, declarationSiteSession: FirSession) { when (type) { + is ConeErrorType -> { + tBuilder.appendSignature(MangleConstant.ERROR_MARK) + } + is ConeLookupTagBasedType -> { when (val symbol = type.lookupTag.toSymbol(declarationSiteSession)) { is FirTypeAliasSymbol -> { diff --git a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/mangle/descriptor/DescriptorMangleComputer.kt b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/mangle/descriptor/DescriptorMangleComputer.kt index 8a213e27eff..6088a8818d4 100644 --- a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/mangle/descriptor/DescriptorMangleComputer.kt +++ b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/mangle/descriptor/DescriptorMangleComputer.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.ir.descriptors.IrPropertyDelegateDescriptor import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext +import org.jetbrains.kotlin.types.error.ErrorClassDescriptor import org.jetbrains.kotlin.types.model.TypeSystemContext import org.jetbrains.kotlin.types.typeUtil.isUnit @@ -92,6 +93,10 @@ open class DescriptorMangleComputer(builder: StringBuilder, mode: MangleMode) : is SimpleType -> { when (val classifier = type.constructor.declarationDescriptor) { + is ErrorClassDescriptor -> { + tBuilder.appendSignature(MangleConstant.ERROR_MARK) + return + } is ClassDescriptor -> with(copy(MangleMode.FQNAME)) { classifier.visit() } is TypeParameterDescriptor -> tBuilder.mangleTypeParameterReference(classifier) else -> error("Unexpected classifier: $classifier") diff --git a/compiler/testData/ir/irText/errors/unresolvedReference.fir.ir.txt b/compiler/testData/ir/irText/errors/unresolvedReference.fir.ir.txt new file mode 100644 index 00000000000..fd6d4b6f2cb --- /dev/null +++ b/compiler/testData/ir/irText/errors/unresolvedReference.fir.ir.txt @@ -0,0 +1,29 @@ +FILE fqName: fileName:/unresolvedReference.kt + PROPERTY name:test1 visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:test1 type:IrErrorType(null) visibility:private [final,static] + EXPRESSION_BODY + ERROR_CALL 'Unresolved reference: #' type=IrErrorType(null) + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:IrErrorType(null) + correspondingProperty: PROPERTY name:test1 visibility:public modality:FINAL [val] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): IrErrorType(null) declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test1 type:IrErrorType(null) visibility:private [final,static]' type=IrErrorType(null) origin=null + PROPERTY name:test2 visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:test2 type:IrErrorType(null) visibility:private [final,static] + EXPRESSION_BODY + ERROR_CALL 'Unresolved reference: #' type=IrErrorType(null) + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:IrErrorType(null) + correspondingProperty: PROPERTY name:test2 visibility:public modality:FINAL [val] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): IrErrorType(null) declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test2 type:IrErrorType(null) visibility:private [final,static]' type=IrErrorType(null) origin=null + PROPERTY name:test3 visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:test3 type:IrErrorType(null) visibility:private [final,static] + EXPRESSION_BODY + ERROR_CALL 'Unresolved reference: #' type=IrErrorType(null) + CONST Int type=kotlin.Int value=56 + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:IrErrorType(null) + correspondingProperty: PROPERTY name:test3 visibility:public modality:FINAL [val] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): IrErrorType(null) declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test3 type:IrErrorType(null) visibility:private [final,static]' type=IrErrorType(null) origin=null diff --git a/compiler/testData/ir/irText/errors/unresolvedReference.fir.kt.txt b/compiler/testData/ir/irText/errors/unresolvedReference.fir.kt.txt new file mode 100644 index 00000000000..e13c75cdc3b --- /dev/null +++ b/compiler/testData/ir/irText/errors/unresolvedReference.fir.kt.txt @@ -0,0 +1,11 @@ +val test1: ErrorType + field = error("") /* ErrorCallExpression */ + get + +val test2: ErrorType + field = error("") /* ErrorCallExpression */ + get + +val test3: ErrorType + field = error("") /* ErrorCallExpression */56; + get diff --git a/compiler/testData/ir/irText/errors/unresolvedReference.ir.txt b/compiler/testData/ir/irText/errors/unresolvedReference.ir.txt index b765f8750d0..a6c30854c84 100644 --- a/compiler/testData/ir/irText/errors/unresolvedReference.ir.txt +++ b/compiler/testData/ir/irText/errors/unresolvedReference.ir.txt @@ -28,12 +28,3 @@ FILE fqName: fileName:/unresolvedReference.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun (): IrErrorType([Error type: Not found recorded type for 42.unresolved(56)]) declared in ' GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test3 type:IrErrorType([Error type: Not found recorded type for 42.unresolved(56)]) visibility:private [final,static]' type=IrErrorType([Error type: Not found recorded type for 42.unresolved(56)]) origin=null - PROPERTY name:test4 visibility:public modality:FINAL [val] - FIELD PROPERTY_BACKING_FIELD name:test4 type:IrErrorType([Error type: Not found recorded type for 42 *]) visibility:private [final,static] - EXPRESSION_BODY - ERROR_EXPR '42 *' type=IrErrorType([Error type: Error expression type]) - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:IrErrorType([Error type: Not found recorded type for 42 *]) - correspondingProperty: PROPERTY name:test4 visibility:public modality:FINAL [val] - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): IrErrorType([Error type: Not found recorded type for 42 *]) declared in ' - GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test4 type:IrErrorType([Error type: Not found recorded type for 42 *]) visibility:private [final,static]' type=IrErrorType([Error type: Not found recorded type for 42 *]) origin=null diff --git a/compiler/testData/ir/irText/errors/unresolvedReference.kt b/compiler/testData/ir/irText/errors/unresolvedReference.kt index 445c7e2e350..5ff6a9bf1d3 100644 --- a/compiler/testData/ir/irText/errors/unresolvedReference.kt +++ b/compiler/testData/ir/irText/errors/unresolvedReference.kt @@ -1,10 +1,8 @@ -// IGNORE_BACKEND_K2: JVM_IR -// IGNORE_BACKEND: JS_IR -// !IGNORE_ERRORS +// IGNORE_ERRORS +// IGNORE_FIR_DIAGNOSTICS // DIAGNOSTICS: -UNRESOLVED_REFERENCE -OVERLOAD_RESOLUTION_AMBIGUITY - -// KT-61141: org.jetbrains.kotlin.psi2ir.generators.ErrorExpressionException: null: KtNameReferenceExpression: unresolved -// IGNORE_BACKEND: NATIVE +// ERROR_POLICY: SEMANTIC +// SKIP_KLIB_TEST val test1 = unresolved @@ -12,5 +10,3 @@ val test2: Unresolved = unresolved() val test3 = 42.unresolved(56) - -val test4 = 42 * diff --git a/compiler/testData/ir/irText/errors/unresolvedReference.kt.txt b/compiler/testData/ir/irText/errors/unresolvedReference.kt.txt index dea28a89ce8..5cbb83d8cf4 100644 --- a/compiler/testData/ir/irText/errors/unresolvedReference.kt.txt +++ b/compiler/testData/ir/irText/errors/unresolvedReference.kt.txt @@ -9,7 +9,3 @@ val test2: ErrorType val test3: ErrorType field = error("") /* ErrorCallExpression */42; 56; get - -val test4: ErrorType - field = error("") /* ErrorExpression */ - get diff --git a/compiler/testData/ir/irText/errors/unresolvedReference.sig.kt.txt b/compiler/testData/ir/irText/errors/unresolvedReference.sig.kt.txt index 188fd404085..ed23897e5ce 100644 --- a/compiler/testData/ir/irText/errors/unresolvedReference.sig.kt.txt +++ b/compiler/testData/ir/irText/errors/unresolvedReference.sig.kt.txt @@ -5,12 +5,12 @@ val test1: ErrorType // CHECK JVM_IR: // Mangled name: #(){} - // Mangled name for the signature computed from Ir: (){} - // Mangled name for the signature computed from Descriptor: (){} - // Public signature by IR: /test1.|3342025465423582211[0] - // Public signature by IR debug description: (){} - // Public signature by Frontend: /test1.|-4817139884021780494[0] - // Public signature by Frontend debug description: (){} + // Public signature: /test1.|3342025465423582211[0] + // Public signature debug description: (){} + // CHECK JS_IR NATIVE: + // Mangled name: #(){} + // Public signature: /test1.|-5735092642142423279[0] + // Public signature debug description: (){} get // CHECK: @@ -20,12 +20,12 @@ val test1: ErrorType val test2: ErrorType // CHECK JVM_IR: // Mangled name: #(){} - // Mangled name for the signature computed from Ir: (){} - // Mangled name for the signature computed from Descriptor: (){} - // Public signature by IR: /test2.|-7934828597056891230[0] - // Public signature by IR debug description: (){} - // Public signature by Frontend: /test2.|1859255286326922853[0] - // Public signature by Frontend debug description: (){} + // Public signature: /test2.|-7934828597056891230[0] + // Public signature debug description: (){} + // CHECK JS_IR NATIVE: + // Mangled name: #(){} + // Public signature: /test2.|-5218942532816206869[0] + // Public signature debug description: (){} get // CHECK: @@ -35,26 +35,10 @@ val test2: ErrorType val test3: ErrorType // CHECK JVM_IR: // Mangled name: #(){} - // Mangled name for the signature computed from Ir: (){} - // Mangled name for the signature computed from Descriptor: (){} - // Public signature by IR: /test3.|3662345001344960274[0] - // Public signature by IR debug description: (){} - // Public signature by Frontend: /test3.|-2322568342617474229[0] - // Public signature by Frontend debug description: (){} + // Public signature: /test3.|3662345001344960274[0] + // Public signature debug description: (){} + // CHECK JS_IR NATIVE: + // Mangled name: #(){} + // Public signature: /test3.|-7333791615083236686[0] + // Public signature debug description: (){} get - -// CHECK: -// Mangled name: {}test4 -// Public signature: /test4|-9115637610245762085[0] -// Public signature debug description: {}test4 -val test4: ErrorType - // CHECK JVM_IR: - // Mangled name: #(){} - // Mangled name for the signature computed from Ir: (){} - // Mangled name for the signature computed from Descriptor: (){} - // Public signature by IR: /test4.|-8718941795621950036[0] - // Public signature by IR debug description: (){} - // Public signature by Frontend: /test4.|-5181690683324812065[0] - // Public signature by Frontend debug description: (){} - get - diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/ClassicFrontend2NativeIrConverter.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/ClassicFrontend2NativeIrConverter.kt index c9d464653de..4b118695860 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/ClassicFrontend2NativeIrConverter.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/ClassicFrontend2NativeIrConverter.kt @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.psi2ir.Psi2IrTranslator import org.jetbrains.kotlin.psi2ir.generators.DeclarationStubGeneratorImpl import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.backend.ir.IrBackendInput +import org.jetbrains.kotlin.test.directives.CodegenTestDirectives import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendOutputArtifact import org.jetbrains.kotlin.test.model.BackendKinds import org.jetbrains.kotlin.test.model.Frontend2BackendConverter @@ -69,7 +70,10 @@ class ClassicFrontend2NativeIrConverter( val sourceFiles: List = psiFiles.values.toList() val translator = Psi2IrTranslator( configuration.languageVersionSettings, - Psi2IrConfiguration(ignoreErrors = false, configuration.partialLinkageConfig.isEnabled), + Psi2IrConfiguration( + ignoreErrors = CodegenTestDirectives.IGNORE_ERRORS in module.directives, + configuration.partialLinkageConfig.isEnabled + ), configuration.irMessageLogger::checkNoUnboundSymbols ) val manglerDesc = KonanManglerDesc