[JS IR] Cleanup BackendContext flags

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