[JS IR] Remove redundant legacy property access property
This commit is contained in:
-3
@@ -148,9 +148,6 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
|
|||||||
)
|
)
|
||||||
var irModuleName: String? by NullableStringFreezableVar(null)
|
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")
|
@Argument(value = "-Xir-base-class-in-metadata", description = "Write base class into metadata")
|
||||||
var irBaseClassInMetadata: Boolean by FreezableVar(false)
|
var irBaseClassInMetadata: Boolean by FreezableVar(false)
|
||||||
|
|
||||||
|
|||||||
@@ -347,7 +347,6 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
|||||||
multiModule = arguments.irPerModule,
|
multiModule = arguments.irPerModule,
|
||||||
relativeRequirePath = true,
|
relativeRequirePath = true,
|
||||||
propertyLazyInitialization = arguments.irPropertyLazyInitialization,
|
propertyLazyInitialization = arguments.irPropertyLazyInitialization,
|
||||||
legacyPropertyAccess = arguments.irLegacyPropertyAccess,
|
|
||||||
baseClassIntoMetadata = arguments.irBaseClassInMetadata,
|
baseClassIntoMetadata = arguments.irBaseClassInMetadata,
|
||||||
safeExternalBoolean = arguments.irSafeExternalBoolean,
|
safeExternalBoolean = arguments.irSafeExternalBoolean,
|
||||||
safeExternalBooleanDiagnostic = RuntimeDiagnostic.resolve(
|
safeExternalBooleanDiagnostic = RuntimeDiagnostic.resolve(
|
||||||
|
|||||||
@@ -94,11 +94,6 @@ private fun buildRoots(modules: Iterable<IrModuleFragment>, context: JsIrBackend
|
|||||||
rootDeclarations += dceRuntimeDiagnostic.unreachableDeclarationMethod(context).owner
|
rootDeclarations += dceRuntimeDiagnostic.unreachableDeclarationMethod(context).owner
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.legacyPropertyAccess) {
|
|
||||||
rootDeclarations += context.intrinsics.safePropertyGet.owner
|
|
||||||
rootDeclarations += context.intrinsics.safePropertySet.owner
|
|
||||||
}
|
|
||||||
|
|
||||||
JsMainFunctionDetector.getMainFunctionOrNull(modules.last())?.let { mainFunction ->
|
JsMainFunctionDetector.getMainFunctionOrNull(modules.last())?.let { mainFunction ->
|
||||||
rootDeclarations += mainFunction
|
rootDeclarations += mainFunction
|
||||||
if (mainFunction.isSuspend) {
|
if (mainFunction.isSuspend) {
|
||||||
|
|||||||
@@ -311,10 +311,6 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC
|
|||||||
val readSharedBox = getInternalFunction("sharedBoxRead")
|
val readSharedBox = getInternalFunction("sharedBoxRead")
|
||||||
val writeSharedBox = getInternalFunction("sharedBoxWrite")
|
val writeSharedBox = getInternalFunction("sharedBoxWrite")
|
||||||
|
|
||||||
|
|
||||||
val safePropertyGet = getInternalFunction("safePropertyGet")
|
|
||||||
val safePropertySet = getInternalFunction("safePropertySet")
|
|
||||||
|
|
||||||
val jsUndefined = getInternalFunction("jsUndefined")
|
val jsUndefined = getInternalFunction("jsUndefined")
|
||||||
|
|
||||||
// Helpers:
|
// Helpers:
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ class JsIrBackendContext(
|
|||||||
override val es6mode: Boolean = false,
|
override val es6mode: Boolean = false,
|
||||||
val dceRuntimeDiagnostic: RuntimeDiagnostic? = null,
|
val dceRuntimeDiagnostic: RuntimeDiagnostic? = null,
|
||||||
val propertyLazyInitialization: Boolean = false,
|
val propertyLazyInitialization: Boolean = false,
|
||||||
val legacyPropertyAccess: Boolean = false,
|
|
||||||
val baseClassIntoMetadata: Boolean = false,
|
val baseClassIntoMetadata: Boolean = false,
|
||||||
val safeExternalBoolean: Boolean = false,
|
val safeExternalBoolean: Boolean = false,
|
||||||
val safeExternalBooleanDiagnostic: RuntimeDiagnostic? = null,
|
val safeExternalBooleanDiagnostic: RuntimeDiagnostic? = null,
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ fun compile(
|
|||||||
relativeRequirePath: Boolean = false,
|
relativeRequirePath: Boolean = false,
|
||||||
propertyLazyInitialization: Boolean,
|
propertyLazyInitialization: Boolean,
|
||||||
verifySignatures: Boolean = true,
|
verifySignatures: Boolean = true,
|
||||||
legacyPropertyAccess: Boolean = false,
|
|
||||||
baseClassIntoMetadata: Boolean = false,
|
baseClassIntoMetadata: Boolean = false,
|
||||||
lowerPerModule: Boolean = false,
|
lowerPerModule: Boolean = false,
|
||||||
safeExternalBoolean: Boolean = false,
|
safeExternalBoolean: Boolean = false,
|
||||||
@@ -70,7 +69,6 @@ fun compile(
|
|||||||
relativeRequirePath,
|
relativeRequirePath,
|
||||||
propertyLazyInitialization,
|
propertyLazyInitialization,
|
||||||
baseClassIntoMetadata,
|
baseClassIntoMetadata,
|
||||||
legacyPropertyAccess,
|
|
||||||
safeExternalBoolean,
|
safeExternalBoolean,
|
||||||
safeExternalBooleanDiagnostic,
|
safeExternalBooleanDiagnostic,
|
||||||
)
|
)
|
||||||
@@ -98,7 +96,6 @@ fun compile(
|
|||||||
es6mode = es6mode,
|
es6mode = es6mode,
|
||||||
dceRuntimeDiagnostic = dceRuntimeDiagnostic,
|
dceRuntimeDiagnostic = dceRuntimeDiagnostic,
|
||||||
propertyLazyInitialization = propertyLazyInitialization,
|
propertyLazyInitialization = propertyLazyInitialization,
|
||||||
legacyPropertyAccess = legacyPropertyAccess,
|
|
||||||
baseClassIntoMetadata = baseClassIntoMetadata,
|
baseClassIntoMetadata = baseClassIntoMetadata,
|
||||||
safeExternalBoolean = safeExternalBoolean,
|
safeExternalBoolean = safeExternalBoolean,
|
||||||
safeExternalBooleanDiagnostic = safeExternalBooleanDiagnostic
|
safeExternalBooleanDiagnostic = safeExternalBooleanDiagnostic
|
||||||
|
|||||||
@@ -132,7 +132,6 @@ fun icCompile(
|
|||||||
multiModule: Boolean = false,
|
multiModule: Boolean = false,
|
||||||
relativeRequirePath: Boolean = false,
|
relativeRequirePath: Boolean = false,
|
||||||
propertyLazyInitialization: Boolean,
|
propertyLazyInitialization: Boolean,
|
||||||
legacyPropertyAccess: Boolean = false,
|
|
||||||
baseClassIntoMetadata: Boolean = false,
|
baseClassIntoMetadata: Boolean = false,
|
||||||
safeExternalBoolean: Boolean = false,
|
safeExternalBoolean: Boolean = false,
|
||||||
safeExternalBooleanDiagnostic: RuntimeDiagnostic? = null,
|
safeExternalBooleanDiagnostic: RuntimeDiagnostic? = null,
|
||||||
@@ -150,7 +149,6 @@ fun icCompile(
|
|||||||
propertyLazyInitialization,
|
propertyLazyInitialization,
|
||||||
irFactory,
|
irFactory,
|
||||||
baseClassIntoMetadata,
|
baseClassIntoMetadata,
|
||||||
legacyPropertyAccess,
|
|
||||||
safeExternalBoolean,
|
safeExternalBoolean,
|
||||||
safeExternalBooleanDiagnostic
|
safeExternalBooleanDiagnostic
|
||||||
)
|
)
|
||||||
@@ -215,7 +213,6 @@ private fun prepareIr(
|
|||||||
es6mode: Boolean = false,
|
es6mode: Boolean = false,
|
||||||
propertyLazyInitialization: Boolean,
|
propertyLazyInitialization: Boolean,
|
||||||
irFactory: PersistentIrFactory,
|
irFactory: PersistentIrFactory,
|
||||||
legacyPropertyAccess: Boolean = false,
|
|
||||||
baseClassIntoMetadata: Boolean = false,
|
baseClassIntoMetadata: Boolean = false,
|
||||||
safeExternalBoolean: Boolean = false,
|
safeExternalBoolean: Boolean = false,
|
||||||
safeExternalBooleanDiagnostic: RuntimeDiagnostic? = null,
|
safeExternalBooleanDiagnostic: RuntimeDiagnostic? = null,
|
||||||
@@ -240,7 +237,6 @@ private fun prepareIr(
|
|||||||
es6mode = es6mode,
|
es6mode = es6mode,
|
||||||
dceRuntimeDiagnostic = dceRuntimeDiagnostic,
|
dceRuntimeDiagnostic = dceRuntimeDiagnostic,
|
||||||
propertyLazyInitialization = propertyLazyInitialization,
|
propertyLazyInitialization = propertyLazyInitialization,
|
||||||
legacyPropertyAccess = legacyPropertyAccess,
|
|
||||||
baseClassIntoMetadata = baseClassIntoMetadata,
|
baseClassIntoMetadata = baseClassIntoMetadata,
|
||||||
safeExternalBoolean = safeExternalBoolean,
|
safeExternalBoolean = safeExternalBoolean,
|
||||||
safeExternalBooleanDiagnostic = safeExternalBooleanDiagnostic,
|
safeExternalBooleanDiagnostic = safeExternalBooleanDiagnostic,
|
||||||
|
|||||||
+1
-21
@@ -224,27 +224,7 @@ fun translateCall(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val defaultResult = JsInvocation(ref, listOfNotNull(jsExtensionReceiver) + arguments)
|
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
-1
@@ -18,7 +18,6 @@ where advanced options include:
|
|||||||
Print declarations' reachability info to stdout during performing DCE
|
Print declarations' reachability info to stdout during performing DCE
|
||||||
-Xir-dce-runtime-diagnostic={log|exception}
|
-Xir-dce-runtime-diagnostic={log|exception}
|
||||||
Enable runtime diagnostics when performing DCE instead of removing declarations
|
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-module-name=<name> Specify a compilation module name for IR backend
|
||||||
-Xir-only Disables pre-IR backend
|
-Xir-only Disables pre-IR backend
|
||||||
-Xir-per-module Splits generated .js per-module
|
-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 =
|
internal fun <T : Enum<T>> enumValueOfIntrinsic(@Suppress("UNUSED_PARAMETER") name: String): T =
|
||||||
throw IllegalStateException("Should be replaced by compiler")
|
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.
|
* Implements annotated function in JavaScript.
|
||||||
* [code] string must contain JS expression that evaluates to JS function with signature that matches annotated kotlin function
|
* [code] string must contain JS expression that evaluates to JS function with signature that matches annotated kotlin function
|
||||||
|
|||||||
Reference in New Issue
Block a user