[JS IR] Remove redundant legacy property access property

This commit is contained in:
Ilya Goncharov
2021-09-23 18:55:03 +03:00
committed by Space
parent 440856f593
commit 064744fae7
10 changed files with 1 additions and 55 deletions
@@ -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)
@@ -347,7 +347,6 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
multiModule = arguments.irPerModule,
relativeRequirePath = true,
propertyLazyInitialization = arguments.irPropertyLazyInitialization,
legacyPropertyAccess = arguments.irLegacyPropertyAccess,
baseClassIntoMetadata = arguments.irBaseClassInMetadata,
safeExternalBoolean = arguments.irSafeExternalBoolean,
safeExternalBooleanDiagnostic = RuntimeDiagnostic.resolve(
@@ -94,11 +94,6 @@ private fun buildRoots(modules: Iterable<IrModuleFragment>, 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) {
@@ -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:
@@ -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,
@@ -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
@@ -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,
@@ -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)
}
}
-1
View File
@@ -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=<name> Specify a compilation module name for IR backend
-Xir-only Disables pre-IR backend
-Xir-per-module Splits generated .js per-module
@@ -13,18 +13,6 @@ internal fun <T : Enum<T>> enumValuesIntrinsic(): Array<T> =
internal fun <T : Enum<T>> 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