[JS IR] Cleanup BackendContext flags
This commit is contained in:
committed by
Space Team
parent
4d37c1d49c
commit
041e755c70
+2
@@ -210,6 +210,7 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
|
|||||||
)
|
)
|
||||||
var irModuleName: String? by NullableStringFreezableVar(null)
|
var irModuleName: String? by NullableStringFreezableVar(null)
|
||||||
|
|
||||||
|
// TODO: REMOVE IT
|
||||||
@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)
|
||||||
|
|
||||||
@@ -235,6 +236,7 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
|
|||||||
@Argument(value = "-Xir-per-file", description = "Splits generated .js per-file")
|
@Argument(value = "-Xir-per-file", description = "Splits generated .js per-file")
|
||||||
var irPerFile: Boolean by FreezableVar(false)
|
var irPerFile: Boolean by FreezableVar(false)
|
||||||
|
|
||||||
|
// TODO: REMOVE IT
|
||||||
@Argument(value = "-Xir-new-ir2js", description = "New fragment-based ir2js")
|
@Argument(value = "-Xir-new-ir2js", description = "New fragment-based ir2js")
|
||||||
var irNewIr2Js: Boolean by FreezableVar(true)
|
var irNewIr2Js: Boolean by FreezableVar(true)
|
||||||
|
|
||||||
|
|||||||
@@ -94,14 +94,12 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
|||||||
arguments.irDceRuntimeDiagnostic,
|
arguments.irDceRuntimeDiagnostic,
|
||||||
messageCollector
|
messageCollector
|
||||||
),
|
),
|
||||||
baseClassIntoMetadata = arguments.irBaseClassInMetadata,
|
|
||||||
safeExternalBoolean = arguments.irSafeExternalBoolean,
|
safeExternalBoolean = arguments.irSafeExternalBoolean,
|
||||||
safeExternalBooleanDiagnostic = RuntimeDiagnostic.resolve(
|
safeExternalBooleanDiagnostic = RuntimeDiagnostic.resolve(
|
||||||
arguments.irSafeExternalBooleanDiagnostic,
|
arguments.irSafeExternalBooleanDiagnostic,
|
||||||
messageCollector
|
messageCollector
|
||||||
),
|
),
|
||||||
granularity = arguments.granularity,
|
granularity = arguments.granularity
|
||||||
icCompatibleIr2Js = true,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,12 +53,6 @@ import org.jetbrains.kotlin.util.collectionUtils.filterIsInstanceMapNotNull
|
|||||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
enum class IcCompatibleIr2Js(val isCompatible: Boolean, val incrementalCacheEnabled: Boolean) {
|
|
||||||
DISABLED(false, false),
|
|
||||||
COMPATIBLE(true, false),
|
|
||||||
IC_MODE(true, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||||
class JsIrBackendContext(
|
class JsIrBackendContext(
|
||||||
val module: ModuleDescriptor,
|
val module: ModuleDescriptor,
|
||||||
@@ -68,16 +62,16 @@ class JsIrBackendContext(
|
|||||||
val additionalExportedDeclarationNames: Set<FqName>,
|
val additionalExportedDeclarationNames: Set<FqName>,
|
||||||
keep: Set<String>,
|
keep: Set<String>,
|
||||||
override val configuration: CompilerConfiguration, // TODO: remove configuration from backend context
|
override val configuration: CompilerConfiguration, // TODO: remove configuration from backend context
|
||||||
override val scriptMode: Boolean = false,
|
|
||||||
override val es6mode: Boolean = false,
|
override val es6mode: Boolean = false,
|
||||||
val dceRuntimeDiagnostic: RuntimeDiagnostic? = null,
|
val dceRuntimeDiagnostic: RuntimeDiagnostic? = null,
|
||||||
val baseClassIntoMetadata: Boolean = false,
|
|
||||||
val safeExternalBoolean: Boolean = false,
|
val safeExternalBoolean: Boolean = false,
|
||||||
val safeExternalBooleanDiagnostic: RuntimeDiagnostic? = null,
|
val safeExternalBooleanDiagnostic: RuntimeDiagnostic? = null,
|
||||||
override val mapping: JsMapping = JsMapping(),
|
override val mapping: JsMapping = JsMapping(),
|
||||||
val granularity: JsGenerationGranularity = JsGenerationGranularity.WHOLE_PROGRAM,
|
val granularity: JsGenerationGranularity = JsGenerationGranularity.WHOLE_PROGRAM,
|
||||||
val icCompatibleIr2Js: IcCompatibleIr2Js = IcCompatibleIr2Js.DISABLED,
|
val incrementalCacheEnabled: Boolean = false
|
||||||
) : JsCommonBackendContext {
|
) : JsCommonBackendContext {
|
||||||
|
override val scriptMode: Boolean get() = false
|
||||||
|
|
||||||
val polyfills = JsPolyfills()
|
val polyfills = JsPolyfills()
|
||||||
val fieldToInitializer: MutableMap<IrField, IrExpression> = mutableMapOf()
|
val fieldToInitializer: MutableMap<IrField, IrExpression> = mutableMapOf()
|
||||||
|
|
||||||
|
|||||||
@@ -54,12 +54,10 @@ fun compile(
|
|||||||
dceRuntimeDiagnostic: RuntimeDiagnostic? = null,
|
dceRuntimeDiagnostic: RuntimeDiagnostic? = null,
|
||||||
es6mode: Boolean = false,
|
es6mode: Boolean = false,
|
||||||
verifySignatures: Boolean = true,
|
verifySignatures: Boolean = true,
|
||||||
baseClassIntoMetadata: Boolean = false,
|
|
||||||
safeExternalBoolean: Boolean = false,
|
safeExternalBoolean: Boolean = false,
|
||||||
safeExternalBooleanDiagnostic: RuntimeDiagnostic? = null,
|
safeExternalBooleanDiagnostic: RuntimeDiagnostic? = null,
|
||||||
filesToLower: Set<String>? = null,
|
filesToLower: Set<String>? = null,
|
||||||
granularity: JsGenerationGranularity = JsGenerationGranularity.WHOLE_PROGRAM,
|
granularity: JsGenerationGranularity = JsGenerationGranularity.WHOLE_PROGRAM,
|
||||||
icCompatibleIr2Js: Boolean = false,
|
|
||||||
): LoweredIr {
|
): LoweredIr {
|
||||||
|
|
||||||
val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer, moduleToName) =
|
val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer, moduleToName) =
|
||||||
@@ -79,11 +77,9 @@ fun compile(
|
|||||||
keep,
|
keep,
|
||||||
dceRuntimeDiagnostic,
|
dceRuntimeDiagnostic,
|
||||||
es6mode,
|
es6mode,
|
||||||
baseClassIntoMetadata,
|
|
||||||
safeExternalBoolean,
|
safeExternalBoolean,
|
||||||
safeExternalBooleanDiagnostic,
|
safeExternalBooleanDiagnostic,
|
||||||
granularity,
|
granularity,
|
||||||
icCompatibleIr2Js,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,11 +97,9 @@ fun compileIr(
|
|||||||
keep: Set<String>,
|
keep: Set<String>,
|
||||||
dceRuntimeDiagnostic: RuntimeDiagnostic?,
|
dceRuntimeDiagnostic: RuntimeDiagnostic?,
|
||||||
es6mode: Boolean,
|
es6mode: Boolean,
|
||||||
baseClassIntoMetadata: Boolean,
|
|
||||||
safeExternalBoolean: Boolean,
|
safeExternalBoolean: Boolean,
|
||||||
safeExternalBooleanDiagnostic: RuntimeDiagnostic?,
|
safeExternalBooleanDiagnostic: RuntimeDiagnostic?,
|
||||||
granularity: JsGenerationGranularity,
|
granularity: JsGenerationGranularity,
|
||||||
icCompatibleIr2Js: Boolean,
|
|
||||||
): LoweredIr {
|
): LoweredIr {
|
||||||
val moduleDescriptor = moduleFragment.descriptor
|
val moduleDescriptor = moduleFragment.descriptor
|
||||||
val irFactory = symbolTable.irFactory
|
val irFactory = symbolTable.irFactory
|
||||||
@@ -126,11 +120,10 @@ fun compileIr(
|
|||||||
configuration,
|
configuration,
|
||||||
es6mode = es6mode,
|
es6mode = es6mode,
|
||||||
dceRuntimeDiagnostic = dceRuntimeDiagnostic,
|
dceRuntimeDiagnostic = dceRuntimeDiagnostic,
|
||||||
baseClassIntoMetadata = baseClassIntoMetadata,
|
|
||||||
safeExternalBoolean = safeExternalBoolean,
|
safeExternalBoolean = safeExternalBoolean,
|
||||||
safeExternalBooleanDiagnostic = safeExternalBooleanDiagnostic,
|
safeExternalBooleanDiagnostic = safeExternalBooleanDiagnostic,
|
||||||
granularity = granularity,
|
granularity = granularity,
|
||||||
icCompatibleIr2Js = if (icCompatibleIr2Js) IcCompatibleIr2Js.COMPATIBLE else IcCompatibleIr2Js.DISABLED,
|
incrementalCacheEnabled = false
|
||||||
)
|
)
|
||||||
|
|
||||||
// Load declarations referenced during `context` initialization
|
// Load declarations referenced during `context` initialization
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class JsIrCompilerWithIC(
|
|||||||
configuration = configuration,
|
configuration = configuration,
|
||||||
es6mode = es6mode,
|
es6mode = es6mode,
|
||||||
granularity = granularity,
|
granularity = granularity,
|
||||||
icCompatibleIr2Js = IcCompatibleIr2Js.IC_MODE,
|
incrementalCacheEnabled = true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-24
@@ -21,7 +21,7 @@ class JsPropertyAccessorInlineLowering(
|
|||||||
return false
|
return false
|
||||||
|
|
||||||
// Member properties could be safely inlined, because initialization processed via parent declaration
|
// Member properties could be safely inlined, because initialization processed via parent declaration
|
||||||
if (!isTopLevel && !context.icCompatibleIr2Js.incrementalCacheEnabled)
|
if (!isTopLevel && !context.incrementalCacheEnabled)
|
||||||
return true
|
return true
|
||||||
|
|
||||||
// Just undefined value
|
// Just undefined value
|
||||||
@@ -30,29 +30,9 @@ class JsPropertyAccessorInlineLowering(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: teach the deserializer to load constant property initializers
|
// TODO: teach the deserializer to load constant property initializers
|
||||||
if (context.icCompatibleIr2Js.isCompatible) {
|
val accessFile = accessContainer.fileOrNull ?: return false
|
||||||
val accessFile = accessContainer.fileOrNull ?: return false
|
val file = 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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -203,8 +203,7 @@ abstract class AbstractJsKLibABITestCase : KtUsefulTestCase() {
|
|||||||
PhaseConfig(jsPhases),
|
PhaseConfig(jsPhases),
|
||||||
IrFactoryImplForJsIC(WholeWorldStageController()),
|
IrFactoryImplForJsIC(WholeWorldStageController()),
|
||||||
exportedDeclarations = setOf(BOX_FUN_FQN),
|
exportedDeclarations = setOf(BOX_FUN_FQN),
|
||||||
granularity = JsGenerationGranularity.PER_MODULE,
|
granularity = JsGenerationGranularity.PER_MODULE
|
||||||
icCompatibleIr2Js = true
|
|
||||||
)
|
)
|
||||||
|
|
||||||
val transformer = IrModuleToJsTransformerTmp(
|
val transformer = IrModuleToJsTransformerTmp(
|
||||||
|
|||||||
@@ -143,11 +143,9 @@ class JsIrBackendFacade(
|
|||||||
keep = keep,
|
keep = keep,
|
||||||
dceRuntimeDiagnostic = null,
|
dceRuntimeDiagnostic = null,
|
||||||
es6mode = false,
|
es6mode = false,
|
||||||
baseClassIntoMetadata = false,
|
|
||||||
safeExternalBoolean = JsEnvironmentConfigurationDirectives.SAFE_EXTERNAL_BOOLEAN in module.directives,
|
safeExternalBoolean = JsEnvironmentConfigurationDirectives.SAFE_EXTERNAL_BOOLEAN in module.directives,
|
||||||
safeExternalBooleanDiagnostic = module.directives[JsEnvironmentConfigurationDirectives.SAFE_EXTERNAL_BOOLEAN_DIAGNOSTIC].singleOrNull(),
|
safeExternalBooleanDiagnostic = module.directives[JsEnvironmentConfigurationDirectives.SAFE_EXTERNAL_BOOLEAN_DIAGNOSTIC].singleOrNull(),
|
||||||
granularity = granularity,
|
granularity = granularity,
|
||||||
icCompatibleIr2Js = true,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return loweredIr2JsArtifact(module, loweredIr, granularity)
|
return loweredIr2JsArtifact(module, loweredIr, granularity)
|
||||||
|
|||||||
Reference in New Issue
Block a user