From 064744fae7887accd5e9c9ace60531d2114cb90b Mon Sep 17 00:00:00 2001 From: Ilya Goncharov Date: Thu, 23 Sep 2021 18:55:03 +0300 Subject: [PATCH] [JS IR] Remove redundant legacy property access property --- .../common/arguments/K2JSCompilerArguments.kt | 3 --- .../jetbrains/kotlin/cli/js/K2JsIrCompiler.kt | 1 - .../org/jetbrains/kotlin/ir/backend/js/Dce.kt | 5 ----- .../kotlin/ir/backend/js/JsIntrinsics.kt | 4 ---- .../ir/backend/js/JsIrBackendContext.kt | 1 - .../kotlin/ir/backend/js/compiler.kt | 3 --- .../jetbrains/kotlin/ir/backend/js/ic/ic.kt | 4 ---- .../js/transformers/irToJs/jsAstUtils.kt | 22 +------------------ compiler/testData/cli/js/jsExtraHelp.out | 1 - .../stdlib/js-ir/runtime/kotlinJsHacks.kt | 12 ---------- 10 files changed, 1 insertion(+), 55 deletions(-) diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt index ab5237a271e..1122c32d90e 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt @@ -148,9 +148,6 @@ class K2JSCompilerArguments : CommonCompilerArguments() { ) var irModuleName: String? by NullableStringFreezableVar(null) - @Argument(value = "-Xir-legacy-property-access", description = "Force property access via JS properties (requires -Xir-export-all)") - var irLegacyPropertyAccess: Boolean by FreezableVar(false) - @Argument(value = "-Xir-base-class-in-metadata", description = "Write base class into metadata") var irBaseClassInMetadata: Boolean by FreezableVar(false) 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 3a4f2a51e4b..cffa821633a 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 @@ -347,7 +347,6 @@ class K2JsIrCompiler : CLICompiler() { multiModule = arguments.irPerModule, relativeRequirePath = true, propertyLazyInitialization = arguments.irPropertyLazyInitialization, - legacyPropertyAccess = arguments.irLegacyPropertyAccess, baseClassIntoMetadata = arguments.irBaseClassInMetadata, safeExternalBoolean = arguments.irSafeExternalBoolean, safeExternalBooleanDiagnostic = RuntimeDiagnostic.resolve( diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/Dce.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/Dce.kt index 8aa8ba912ec..61c4b2778c6 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/Dce.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/Dce.kt @@ -94,11 +94,6 @@ private fun buildRoots(modules: Iterable, context: JsIrBackend rootDeclarations += dceRuntimeDiagnostic.unreachableDeclarationMethod(context).owner } - if (context.legacyPropertyAccess) { - rootDeclarations += context.intrinsics.safePropertyGet.owner - rootDeclarations += context.intrinsics.safePropertySet.owner - } - JsMainFunctionDetector.getMainFunctionOrNull(modules.last())?.let { mainFunction -> rootDeclarations += mainFunction if (mainFunction.isSuspend) { diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIntrinsics.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIntrinsics.kt index 969b95279e3..e4db6cf9652 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIntrinsics.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIntrinsics.kt @@ -311,10 +311,6 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC val readSharedBox = getInternalFunction("sharedBoxRead") val writeSharedBox = getInternalFunction("sharedBoxWrite") - - val safePropertyGet = getInternalFunction("safePropertyGet") - val safePropertySet = getInternalFunction("safePropertySet") - val jsUndefined = getInternalFunction("jsUndefined") // Helpers: 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 c2fd65f71d2..cdfa4a49415 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 @@ -57,7 +57,6 @@ class JsIrBackendContext( override val es6mode: Boolean = false, val dceRuntimeDiagnostic: RuntimeDiagnostic? = null, val propertyLazyInitialization: Boolean = false, - val legacyPropertyAccess: Boolean = false, val baseClassIntoMetadata: Boolean = false, val safeExternalBoolean: Boolean = false, val safeExternalBooleanDiagnostic: RuntimeDiagnostic? = null, 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 0d212027431..b59d13423dd 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 @@ -50,7 +50,6 @@ fun compile( relativeRequirePath: Boolean = false, propertyLazyInitialization: Boolean, verifySignatures: Boolean = true, - legacyPropertyAccess: Boolean = false, baseClassIntoMetadata: Boolean = false, lowerPerModule: Boolean = false, safeExternalBoolean: Boolean = false, @@ -70,7 +69,6 @@ fun compile( relativeRequirePath, propertyLazyInitialization, baseClassIntoMetadata, - legacyPropertyAccess, safeExternalBoolean, safeExternalBooleanDiagnostic, ) @@ -98,7 +96,6 @@ fun compile( es6mode = es6mode, dceRuntimeDiagnostic = dceRuntimeDiagnostic, propertyLazyInitialization = propertyLazyInitialization, - legacyPropertyAccess = legacyPropertyAccess, baseClassIntoMetadata = baseClassIntoMetadata, safeExternalBoolean = safeExternalBoolean, safeExternalBooleanDiagnostic = safeExternalBooleanDiagnostic diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/ic/ic.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/ic/ic.kt index 5cdb367416f..25437888a50 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/ic/ic.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/ic/ic.kt @@ -132,7 +132,6 @@ fun icCompile( multiModule: Boolean = false, relativeRequirePath: Boolean = false, propertyLazyInitialization: Boolean, - legacyPropertyAccess: Boolean = false, baseClassIntoMetadata: Boolean = false, safeExternalBoolean: Boolean = false, safeExternalBooleanDiagnostic: RuntimeDiagnostic? = null, @@ -150,7 +149,6 @@ fun icCompile( propertyLazyInitialization, irFactory, baseClassIntoMetadata, - legacyPropertyAccess, safeExternalBoolean, safeExternalBooleanDiagnostic ) @@ -215,7 +213,6 @@ private fun prepareIr( es6mode: Boolean = false, propertyLazyInitialization: Boolean, irFactory: PersistentIrFactory, - legacyPropertyAccess: Boolean = false, baseClassIntoMetadata: Boolean = false, safeExternalBoolean: Boolean = false, safeExternalBooleanDiagnostic: RuntimeDiagnostic? = null, @@ -240,7 +237,6 @@ private fun prepareIr( es6mode = es6mode, dceRuntimeDiagnostic = dceRuntimeDiagnostic, propertyLazyInitialization = propertyLazyInitialization, - legacyPropertyAccess = legacyPropertyAccess, baseClassIntoMetadata = baseClassIntoMetadata, safeExternalBoolean = safeExternalBoolean, safeExternalBooleanDiagnostic = safeExternalBooleanDiagnostic, diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/jsAstUtils.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/jsAstUtils.kt index fd3360888c9..4be7a82fc87 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/jsAstUtils.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/jsAstUtils.kt @@ -224,27 +224,7 @@ fun translateCall( } } } else { - val defaultResult = JsInvocation(ref, listOfNotNull(jsExtensionReceiver) + arguments) - - val alternativeResult = - if (jsDispatchReceiver != null && jsExtensionReceiver == null && context.staticContext.backendContext.legacyPropertyAccess) { - val property = function.correspondingPropertySymbol?.owner - if (property != null) { - val propertyName = context.getNameForProperty(property) - val args = mutableListOf(jsDispatchReceiver, JsStringLiteral(symbolName.ident), JsStringLiteral(propertyName.ident)) - val fnName = when (function) { - property.getter -> context.getNameForStaticFunction(context.staticContext.backendContext.intrinsics.safePropertyGet.owner) - property.setter -> { - args += arguments - context.getNameForStaticFunction(context.staticContext.backendContext.intrinsics.safePropertySet.owner) - } - else -> error("Function must be an accessor of corresponding property") - } - JsInvocation(fnName.makeRef(), args) - } else null - } else null - - alternativeResult ?: defaultResult + JsInvocation(ref, listOfNotNull(jsExtensionReceiver) + arguments) } } diff --git a/compiler/testData/cli/js/jsExtraHelp.out b/compiler/testData/cli/js/jsExtraHelp.out index 511f8af39ab..8650b354f09 100644 --- a/compiler/testData/cli/js/jsExtraHelp.out +++ b/compiler/testData/cli/js/jsExtraHelp.out @@ -18,7 +18,6 @@ where advanced options include: Print declarations' reachability info to stdout during performing DCE -Xir-dce-runtime-diagnostic={log|exception} Enable runtime diagnostics when performing DCE instead of removing declarations - -Xir-legacy-property-access Force property access via JS properties (requires -Xir-export-all) -Xir-module-name= Specify a compilation module name for IR backend -Xir-only Disables pre-IR backend -Xir-per-module Splits generated .js per-module diff --git a/libraries/stdlib/js-ir/runtime/kotlinJsHacks.kt b/libraries/stdlib/js-ir/runtime/kotlinJsHacks.kt index c4d6699ffb6..4f2f6c169ca 100644 --- a/libraries/stdlib/js-ir/runtime/kotlinJsHacks.kt +++ b/libraries/stdlib/js-ir/runtime/kotlinJsHacks.kt @@ -13,18 +13,6 @@ internal fun > enumValuesIntrinsic(): Array = internal fun > enumValueOfIntrinsic(@Suppress("UNUSED_PARAMETER") name: String): T = throw IllegalStateException("Should be replaced by compiler") -@PublishedApi -internal fun safePropertyGet(self: dynamic, getterName: String, propName: String): dynamic { - val getter = self[getterName] - return if (getter != null) getter.call(self) else self[propName] -} - -@PublishedApi -internal fun safePropertySet(self: dynamic, setterName: String, propName: String, value: dynamic) { - val setter = self[setterName] - if (setter != null) setter.call(self, value) else self[propName] = value -} - /** * Implements annotated function in JavaScript. * [code] string must contain JS expression that evaluates to JS function with signature that matches annotated kotlin function