From 1ae042edc35b0c6a62b098d3c931540c813d7b18 Mon Sep 17 00:00:00 2001 From: Anton Bannykh Date: Fri, 29 Oct 2021 12:31:53 +0300 Subject: [PATCH] [JS IR] make old Ir2Js pass all tests --- .../jetbrains/kotlin/cli/js/K2JsIrCompiler.kt | 3 +- .../ir/backend/js/JsIrBackendContext.kt | 1 + .../kotlin/ir/backend/js/compiler.kt | 8 +++- .../kotlin/ir/backend/js/compilerWithIC.kt | 3 +- .../lower/JsPropertyAccessorInlineLowering.kt | 42 ++++++++++--------- .../js/test/converters/JsIrBackendFacade.kt | 4 +- .../box/jsName/jsNamePropertyAccessors.kt | 1 + .../selectiveExport/selectiveExport.d.ts | 8 ++-- 8 files changed, 41 insertions(+), 29 deletions(-) diff --git a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt index 728d8c1b88c..ab2b3d9228a 100644 --- a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt +++ b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt @@ -379,7 +379,8 @@ class K2JsIrCompiler : CLICompiler() { messageCollector ), lowerPerModule = icCaches.isNotEmpty(), - granularity = granularity + granularity = granularity, + icCompatibleIr2Js = arguments.irNewIr2Js, ) val compiledModule: CompilerResult = if (arguments.irNewIr2Js) { diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt index f241fbd11ac..2c915b9958b 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt @@ -60,6 +60,7 @@ class JsIrBackendContext( val safeExternalBooleanDiagnostic: RuntimeDiagnostic? = null, override val mapping: JsMapping = JsMapping(symbolTable.irFactory), val granularity: JsGenerationGranularity = JsGenerationGranularity.WHOLE_PROGRAM, + val icCompatibleIr2Js: Boolean = false, ) : JsCommonBackendContext { val fileToInitializationFuns: MutableMap = mutableMapOf() val fileToInitializerPureness: MutableMap = mutableMapOf() diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt index bc6321dc501..c65f3e48024 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt @@ -63,6 +63,7 @@ fun compile( safeExternalBooleanDiagnostic: RuntimeDiagnostic? = null, filesToLower: Set? = null, granularity: JsGenerationGranularity = JsGenerationGranularity.WHOLE_PROGRAM, + icCompatibleIr2Js: Boolean = false, ): LoweredIr { if (lowerPerModule) { @@ -99,7 +100,8 @@ fun compile( lowerPerModule, safeExternalBoolean, safeExternalBooleanDiagnostic, - granularity + granularity, + icCompatibleIr2Js, ) } @@ -122,6 +124,7 @@ fun compileIr( safeExternalBoolean: Boolean, safeExternalBooleanDiagnostic: RuntimeDiagnostic?, granularity: JsGenerationGranularity, + icCompatibleIr2Js: Boolean, ): LoweredIr { val moduleDescriptor = moduleFragment.descriptor val irFactory = symbolTable.irFactory @@ -144,7 +147,8 @@ fun compileIr( baseClassIntoMetadata = baseClassIntoMetadata, safeExternalBoolean = safeExternalBoolean, safeExternalBooleanDiagnostic = safeExternalBooleanDiagnostic, - granularity = granularity + granularity = granularity, + icCompatibleIr2Js = icCompatibleIr2Js, ) // Load declarations referenced during `context` initialization diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compilerWithIC.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compilerWithIC.kt index 80c273ce251..e1a5c8765ab 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compilerWithIC.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compilerWithIC.kt @@ -70,7 +70,8 @@ fun compileWithIC( propertyLazyInitialization = propertyLazyInitialization, baseClassIntoMetadata = baseClassIntoMetadata, safeExternalBoolean = safeExternalBoolean, - safeExternalBooleanDiagnostic = safeExternalBooleanDiagnostic + safeExternalBooleanDiagnostic = safeExternalBooleanDiagnostic, + icCompatibleIr2Js = true, ) // Load declarations referenced during `context` initialization diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/JsPropertyAccessorInlineLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/JsPropertyAccessorInlineLowering.kt index dc1366cd8de..1f296b8fde6 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/JsPropertyAccessorInlineLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/JsPropertyAccessorInlineLowering.kt @@ -20,27 +20,29 @@ class JsPropertyAccessorInlineLowering( return false // TODO: teach the deserializer to load constant property initializers - val accessFile = accessContainer.fileOrNull ?: return false - val file = fileOrNull ?: return false + if (context.icCompatibleIr2Js) { + val accessFile = accessContainer.fileOrNull ?: return false + val file = fileOrNull ?: return false - return accessFile == file + return accessFile == file + } -// if (isConst) -// return true -// -// return when (context.granularity) { -// JsGenerationGranularity.WHOLE_PROGRAM -> -// true -// JsGenerationGranularity.PER_MODULE -> { -// val accessModule = accessContainer.fileOrNull?.module ?: return false -// val module = fileOrNull?.module ?: return false -// accessModule == module -// } -// JsGenerationGranularity.PER_FILE -> -// // Not inlining because -// // 1. we need a way to distinguish per-file generation units -// // 2. per-file mode intended for debug builds only at the moment -// false -// } + if (isConst) + return true + + return when (context.granularity) { + JsGenerationGranularity.WHOLE_PROGRAM -> + true + JsGenerationGranularity.PER_MODULE -> { + val accessModule = accessContainer.fileOrNull?.module ?: return false + val module = fileOrNull?.module ?: return false + accessModule == module + } + JsGenerationGranularity.PER_FILE -> + // Not inlining because + // 1. we need a way to distinguish per-file generation units + // 2. per-file mode intended for debug builds only at the moment + false + } } } \ No newline at end of file diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/converters/JsIrBackendFacade.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/converters/JsIrBackendFacade.kt index ce2674b1687..9c57e7483d1 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/converters/JsIrBackendFacade.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/converters/JsIrBackendFacade.kt @@ -72,6 +72,7 @@ class JsIrBackendFacade( val splitPerModule = JsEnvironmentConfigurationDirectives.SPLIT_PER_MODULE in module.directives val splitPerFile = JsEnvironmentConfigurationDirectives.SPLIT_PER_FILE in module.directives val perModule = JsEnvironmentConfigurationDirectives.PER_MODULE in module.directives + val runNewIr2Js = JsEnvironmentConfigurationDirectives.RUN_NEW_IR_2_JS in module.directives val granularity = when { !firstTimeCompilation -> JsGenerationGranularity.WHOLE_PROGRAM @@ -117,7 +118,8 @@ class JsIrBackendFacade( lowerPerModule = lowerPerModule, safeExternalBoolean = JsEnvironmentConfigurationDirectives.SAFE_EXTERNAL_BOOLEAN in module.directives, safeExternalBooleanDiagnostic = module.directives[JsEnvironmentConfigurationDirectives.SAFE_EXTERNAL_BOOLEAN_DIAGNOSTIC].singleOrNull(), - granularity = granularity + granularity = granularity, + icCompatibleIr2Js = runNewIr2Js, ) return loweredIr2JsArtifact(module, loweredIr, granularity) diff --git a/js/js.translator/testData/box/jsName/jsNamePropertyAccessors.kt b/js/js.translator/testData/box/jsName/jsNamePropertyAccessors.kt index 9d88c81778d..c7c100eb248 100644 --- a/js/js.translator/testData/box/jsName/jsNamePropertyAccessors.kt +++ b/js/js.translator/testData/box/jsName/jsNamePropertyAccessors.kt @@ -1,4 +1,5 @@ // EXPECTED_REACHABLE_NODES: 1285 +// IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR_ES6 package foo diff --git a/js/js.translator/testData/typescript-export/selectiveExport/selectiveExport.d.ts b/js/js.translator/testData/typescript-export/selectiveExport/selectiveExport.d.ts index 03fc662dcd5..1080cdfff6d 100644 --- a/js/js.translator/testData/typescript-export/selectiveExport/selectiveExport.d.ts +++ b/js/js.translator/testData/typescript-export/selectiveExport/selectiveExport.d.ts @@ -6,6 +6,10 @@ declare namespace JS_TESTS { interface ExportedInternalInterface { } } + namespace foo { + interface FileLevelExportedExternalInterface { + } + } namespace foo { const exportedVal: number; function exportedFun(): number; @@ -14,10 +18,6 @@ declare namespace JS_TESTS { readonly value: number; } } - namespace foo { - interface FileLevelExportedExternalInterface { - } - } namespace foo { const fileLevelExportedVal: number; function fileLevelExportedFun(): number;