[JS_IR] Reuse common makeIrModulePhase to create lowerings
#KT-63073
This commit is contained in:
+128
-213
@@ -5,10 +5,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.ir.backend.js
|
package org.jetbrains.kotlin.ir.backend.js
|
||||||
|
|
||||||
import org.jetbrains.kotlin.backend.common.BodyLoweringPass
|
|
||||||
import org.jetbrains.kotlin.backend.common.DeclarationTransformer
|
|
||||||
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
|
||||||
import org.jetbrains.kotlin.backend.common.lower
|
|
||||||
import org.jetbrains.kotlin.backend.common.lower.*
|
import org.jetbrains.kotlin.backend.common.lower.*
|
||||||
import org.jetbrains.kotlin.backend.common.lower.coroutines.AddContinuationToLocalSuspendFunctionsLowering
|
import org.jetbrains.kotlin.backend.common.lower.coroutines.AddContinuationToLocalSuspendFunctionsLowering
|
||||||
import org.jetbrains.kotlin.backend.common.lower.coroutines.AddContinuationToNonLocalSuspendFunctionsLowering
|
import org.jetbrains.kotlin.backend.common.lower.coroutines.AddContinuationToNonLocalSuspendFunctionsLowering
|
||||||
@@ -31,246 +27,165 @@ import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
|||||||
import org.jetbrains.kotlin.ir.interpreter.IrInterpreterConfiguration
|
import org.jetbrains.kotlin.ir.interpreter.IrInterpreterConfiguration
|
||||||
import org.jetbrains.kotlin.platform.js.JsPlatforms
|
import org.jetbrains.kotlin.platform.js.JsPlatforms
|
||||||
|
|
||||||
private fun List<Lowering>.toCompilerPhase() =
|
private fun List<CompilerPhase<JsIrBackendContext, IrModuleFragment, IrModuleFragment>>.toCompilerPhase() =
|
||||||
map {
|
reduce { acc, lowering -> acc.then(lowering) }
|
||||||
@Suppress("USELESS_CAST")
|
|
||||||
it.modulePhase as CompilerPhase<JsIrBackendContext, IrModuleFragment, IrModuleFragment>
|
|
||||||
}.reduce { acc, lowering -> acc.then(lowering) }
|
|
||||||
|
|
||||||
private fun makeJsModulePhase(
|
private val validateIrBeforeLowering = makeCustomPhase<JsIrBackendContext>(
|
||||||
lowering: (JsIrBackendContext) -> FileLoweringPass,
|
|
||||||
name: String,
|
|
||||||
description: String,
|
|
||||||
prerequisite: Set<AbstractNamedCompilerPhase<JsIrBackendContext, *, *>> = emptySet()
|
|
||||||
): SameTypeNamedCompilerPhase<JsIrBackendContext, IrModuleFragment> = makeCustomJsModulePhase(
|
|
||||||
op = { context, modules -> lowering(context).lower(modules) },
|
|
||||||
name = name,
|
|
||||||
description = description,
|
|
||||||
prerequisite = prerequisite
|
|
||||||
)
|
|
||||||
|
|
||||||
private fun makeCustomJsModulePhase(
|
|
||||||
op: (JsIrBackendContext, IrModuleFragment) -> Unit,
|
|
||||||
description: String,
|
|
||||||
name: String,
|
|
||||||
prerequisite: Set<AbstractNamedCompilerPhase<JsIrBackendContext, *, *>> = emptySet()
|
|
||||||
): SameTypeNamedCompilerPhase<JsIrBackendContext, IrModuleFragment> = SameTypeNamedCompilerPhase(
|
|
||||||
name = name,
|
|
||||||
description = description,
|
|
||||||
prerequisite = prerequisite,
|
|
||||||
lower = object : SameTypeCompilerPhase<JsIrBackendContext, IrModuleFragment> {
|
|
||||||
override fun invoke(
|
|
||||||
phaseConfig: PhaseConfigurationService,
|
|
||||||
phaserState: PhaserState<IrModuleFragment>,
|
|
||||||
context: JsIrBackendContext,
|
|
||||||
input: IrModuleFragment
|
|
||||||
): IrModuleFragment {
|
|
||||||
op(context, input)
|
|
||||||
return input
|
|
||||||
}
|
|
||||||
},
|
|
||||||
actions = setOf(defaultDumper, validationAction),
|
|
||||||
)
|
|
||||||
|
|
||||||
sealed class Lowering(val name: String) {
|
|
||||||
abstract val modulePhase: SameTypeNamedCompilerPhase<JsIrBackendContext, IrModuleFragment>
|
|
||||||
}
|
|
||||||
|
|
||||||
class DeclarationLowering(
|
|
||||||
name: String,
|
|
||||||
description: String,
|
|
||||||
prerequisite: Set<AbstractNamedCompilerPhase<JsIrBackendContext, *, *>> = emptySet(),
|
|
||||||
factory: (JsIrBackendContext) -> DeclarationTransformer
|
|
||||||
) : Lowering(name) {
|
|
||||||
override val modulePhase = makeJsModulePhase(factory, name, description, prerequisite)
|
|
||||||
}
|
|
||||||
|
|
||||||
class BodyLowering(
|
|
||||||
name: String,
|
|
||||||
description: String,
|
|
||||||
prerequisite: Set<AbstractNamedCompilerPhase<JsIrBackendContext, *, *>> = emptySet(),
|
|
||||||
factory: (JsIrBackendContext) -> BodyLoweringPass
|
|
||||||
) : Lowering(name) {
|
|
||||||
override val modulePhase = makeJsModulePhase(factory, name, description, prerequisite)
|
|
||||||
}
|
|
||||||
|
|
||||||
class ModuleLowering(
|
|
||||||
name: String,
|
|
||||||
override val modulePhase: SameTypeNamedCompilerPhase<JsIrBackendContext, IrModuleFragment>
|
|
||||||
) : Lowering(name)
|
|
||||||
|
|
||||||
private fun makeDeclarationTransformerPhase(
|
|
||||||
lowering: (JsIrBackendContext) -> DeclarationTransformer,
|
|
||||||
name: String,
|
|
||||||
description: String,
|
|
||||||
prerequisite: Set<Lowering> = emptySet()
|
|
||||||
) = DeclarationLowering(name, description, prerequisite.map { it.modulePhase }.toSet(), lowering)
|
|
||||||
|
|
||||||
private fun makeBodyLoweringPhase(
|
|
||||||
lowering: (JsIrBackendContext) -> BodyLoweringPass,
|
|
||||||
name: String,
|
|
||||||
description: String,
|
|
||||||
prerequisite: Set<Lowering> = emptySet()
|
|
||||||
) = BodyLowering(name, description, prerequisite.map { it.modulePhase }.toSet(), lowering)
|
|
||||||
|
|
||||||
fun SameTypeNamedCompilerPhase<JsIrBackendContext, IrModuleFragment>.toModuleLowering() = ModuleLowering(this.name, this)
|
|
||||||
|
|
||||||
private val validateIrBeforeLowering = makeCustomJsModulePhase(
|
|
||||||
{ context, module -> validationCallback(context, module) },
|
{ context, module -> validationCallback(context, module) },
|
||||||
name = "ValidateIrBeforeLowering",
|
name = "ValidateIrBeforeLowering",
|
||||||
description = "Validate IR before lowering"
|
description = "Validate IR before lowering"
|
||||||
).toModuleLowering()
|
)
|
||||||
|
|
||||||
private val validateIrAfterLowering = makeCustomJsModulePhase(
|
private val validateIrAfterLowering = makeCustomPhase<JsIrBackendContext>(
|
||||||
{ context, module -> validationCallback(context, module) },
|
{ context, module -> validationCallback(context, module) },
|
||||||
name = "ValidateIrAfterLowering",
|
name = "ValidateIrAfterLowering",
|
||||||
description = "Validate IR after lowering"
|
description = "Validate IR after lowering"
|
||||||
).toModuleLowering()
|
)
|
||||||
|
|
||||||
private val collectClassDefaultConstructorsPhase = makeDeclarationTransformerPhase(
|
private val collectClassDefaultConstructorsPhase = makeIrModulePhase(
|
||||||
::CollectClassDefaultConstructorsLowering,
|
::CollectClassDefaultConstructorsLowering,
|
||||||
name = "CollectClassDefaultConstructorsLowering",
|
name = "CollectClassDefaultConstructorsLowering",
|
||||||
description = "Collect classes default constructors to add it to metadata on code generating phase"
|
description = "Collect classes default constructors to add it to metadata on code generating phase"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val preventExportOfSyntheticDeclarationsLowering = makeDeclarationTransformerPhase(
|
private val preventExportOfSyntheticDeclarationsLowering = makeIrModulePhase(
|
||||||
::ExcludeSyntheticDeclarationsFromExportLowering,
|
::ExcludeSyntheticDeclarationsFromExportLowering,
|
||||||
name = "ExcludeSyntheticDeclarationsFromExportLowering",
|
name = "ExcludeSyntheticDeclarationsFromExportLowering",
|
||||||
description = "Exclude synthetic declarations which we don't want to export such as `Enum.entries` or `DataClass::componentN`",
|
description = "Exclude synthetic declarations which we don't want to export such as `Enum.entries` or `DataClass::componentN`",
|
||||||
)
|
)
|
||||||
|
|
||||||
val scriptRemoveReceiverLowering = makeJsModulePhase(
|
val scriptRemoveReceiverLowering = makeIrModulePhase(
|
||||||
::ScriptRemoveReceiverLowering,
|
::ScriptRemoveReceiverLowering,
|
||||||
name = "ScriptRemoveReceiver",
|
name = "ScriptRemoveReceiver",
|
||||||
description = "Remove receivers for declarations in script"
|
description = "Remove receivers for declarations in script"
|
||||||
).toModuleLowering()
|
)
|
||||||
|
|
||||||
val createScriptFunctionsPhase = makeJsModulePhase(
|
val createScriptFunctionsPhase = makeIrModulePhase(
|
||||||
::CreateScriptFunctionsPhase,
|
::CreateScriptFunctionsPhase,
|
||||||
name = "CreateScriptFunctionsPhase",
|
name = "CreateScriptFunctionsPhase",
|
||||||
description = "Create functions for initialize and evaluate script"
|
description = "Create functions for initialize and evaluate script"
|
||||||
).toModuleLowering()
|
)
|
||||||
|
|
||||||
private val collectClassIdentifiersLowering = makeJsModulePhase(
|
private val collectClassIdentifiersLowering = makeIrModulePhase(
|
||||||
::JsCollectClassIdentifiersLowering,
|
::JsCollectClassIdentifiersLowering,
|
||||||
name = "CollectClassIdentifiersLowering",
|
name = "CollectClassIdentifiersLowering",
|
||||||
description = "Save classId before all the lowerings",
|
description = "Save classId before all the lowerings",
|
||||||
).toModuleLowering()
|
)
|
||||||
|
|
||||||
private val inventNamesForLocalClassesPhase = makeJsModulePhase(
|
private val inventNamesForLocalClassesPhase = makeIrModulePhase(
|
||||||
::JsInventNamesForLocalClasses,
|
::JsInventNamesForLocalClasses,
|
||||||
name = "InventNamesForLocalClasses",
|
name = "InventNamesForLocalClasses",
|
||||||
description = "Invent names for local classes and anonymous objects",
|
description = "Invent names for local classes and anonymous objects",
|
||||||
).toModuleLowering()
|
)
|
||||||
|
|
||||||
private val annotationInstantiationLowering = makeDeclarationTransformerPhase(
|
private val annotationInstantiationLowering = makeIrModulePhase(
|
||||||
::JsAnnotationImplementationTransformer,
|
::JsAnnotationImplementationTransformer,
|
||||||
name = "AnnotationImplementation",
|
name = "AnnotationImplementation",
|
||||||
description = "Create synthetic annotations implementations and use them in annotations constructor calls"
|
description = "Create synthetic annotations implementations and use them in annotations constructor calls"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val expectDeclarationsRemovingPhase = makeDeclarationTransformerPhase(
|
private val expectDeclarationsRemovingPhase = makeIrModulePhase(
|
||||||
::ExpectDeclarationsRemoveLowering,
|
::ExpectDeclarationsRemoveLowering,
|
||||||
name = "ExpectDeclarationsRemoving",
|
name = "ExpectDeclarationsRemoving",
|
||||||
description = "Remove expect declaration from module fragment"
|
description = "Remove expect declaration from module fragment"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val stringConcatenationLoweringPhase = makeJsModulePhase(
|
private val stringConcatenationLoweringPhase = makeIrModulePhase(
|
||||||
::JsStringConcatenationLowering,
|
::JsStringConcatenationLowering,
|
||||||
name = "JsStringConcatenationLowering",
|
name = "JsStringConcatenationLowering",
|
||||||
description = "Call toString() for values of some types when concatenating strings"
|
description = "Call toString() for values of some types when concatenating strings"
|
||||||
).toModuleLowering()
|
)
|
||||||
|
|
||||||
private val lateinitNullableFieldsPhase = makeDeclarationTransformerPhase(
|
private val lateinitNullableFieldsPhase = makeIrModulePhase(
|
||||||
::NullableFieldsForLateinitCreationLowering,
|
::NullableFieldsForLateinitCreationLowering,
|
||||||
name = "LateinitNullableFields",
|
name = "LateinitNullableFields",
|
||||||
description = "Create nullable fields for lateinit properties"
|
description = "Create nullable fields for lateinit properties"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val lateinitDeclarationLoweringPhase = makeDeclarationTransformerPhase(
|
private val lateinitDeclarationLoweringPhase = makeIrModulePhase(
|
||||||
::NullableFieldsDeclarationLowering,
|
::NullableFieldsDeclarationLowering,
|
||||||
name = "LateinitDeclarations",
|
name = "LateinitDeclarations",
|
||||||
description = "Reference nullable fields from properties and getters + insert checks"
|
description = "Reference nullable fields from properties and getters + insert checks"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val lateinitUsageLoweringPhase = makeBodyLoweringPhase(
|
private val lateinitUsageLoweringPhase = makeIrModulePhase(
|
||||||
::LateinitUsageLowering,
|
::LateinitUsageLowering,
|
||||||
name = "LateinitUsage",
|
name = "LateinitUsage",
|
||||||
description = "Insert checks for lateinit field references"
|
description = "Insert checks for lateinit field references"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val kotlinNothingValueExceptionPhase = makeBodyLoweringPhase(
|
private val kotlinNothingValueExceptionPhase = makeIrModulePhase(
|
||||||
::KotlinNothingValueExceptionLowering,
|
::KotlinNothingValueExceptionLowering,
|
||||||
name = "KotlinNothingValueException",
|
name = "KotlinNothingValueException",
|
||||||
description = "Throw proper exception for calls returning value of type 'kotlin.Nothing'"
|
description = "Throw proper exception for calls returning value of type 'kotlin.Nothing'"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val stripTypeAliasDeclarationsPhase = makeDeclarationTransformerPhase(
|
private val stripTypeAliasDeclarationsPhase = makeIrModulePhase<JsIrBackendContext>(
|
||||||
{ StripTypeAliasDeclarationsLowering() },
|
{ StripTypeAliasDeclarationsLowering() },
|
||||||
name = "StripTypeAliasDeclarations",
|
name = "StripTypeAliasDeclarations",
|
||||||
description = "Strip typealias declarations"
|
description = "Strip typealias declarations"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val jsCodeOutliningPhase = makeBodyLoweringPhase(
|
private val jsCodeOutliningPhase = makeIrModulePhase(
|
||||||
::JsCodeOutliningLowering,
|
::JsCodeOutliningLowering,
|
||||||
name = "JsCodeOutliningLowering",
|
name = "JsCodeOutliningLowering",
|
||||||
description = "Outline js() calls where JS code references Kotlin locals"
|
description = "Outline js() calls where JS code references Kotlin locals"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val arrayConstructorReferencePhase = makeBodyLoweringPhase(
|
private val arrayConstructorReferencePhase = makeIrModulePhase(
|
||||||
::ArrayConstructorReferenceLowering,
|
::ArrayConstructorReferenceLowering,
|
||||||
name = "ArrayConstructorReference",
|
name = "ArrayConstructorReference",
|
||||||
description = "Transform `::Array` into a lambda"
|
description = "Transform `::Array` into a lambda"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val arrayConstructorPhase = makeBodyLoweringPhase(
|
private val arrayConstructorPhase = makeIrModulePhase(
|
||||||
::ArrayConstructorLowering,
|
::ArrayConstructorLowering,
|
||||||
name = "ArrayConstructor",
|
name = "ArrayConstructor",
|
||||||
description = "Transform `Array(size) { index -> value }` into a loop",
|
description = "Transform `Array(size) { index -> value }` into a loop",
|
||||||
prerequisite = setOf(arrayConstructorReferencePhase)
|
prerequisite = setOf(arrayConstructorReferencePhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val sharedVariablesLoweringPhase = makeBodyLoweringPhase(
|
private val sharedVariablesLoweringPhase = makeIrModulePhase(
|
||||||
::SharedVariablesLowering,
|
::SharedVariablesLowering,
|
||||||
name = "SharedVariablesLowering",
|
name = "SharedVariablesLowering",
|
||||||
description = "Box captured mutable variables",
|
description = "Box captured mutable variables",
|
||||||
prerequisite = setOf(lateinitDeclarationLoweringPhase, lateinitUsageLoweringPhase)
|
prerequisite = setOf(lateinitDeclarationLoweringPhase, lateinitUsageLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val localClassesInInlineLambdasPhase = makeBodyLoweringPhase(
|
private val localClassesInInlineLambdasPhase = makeIrModulePhase(
|
||||||
::LocalClassesInInlineLambdasLowering,
|
::LocalClassesInInlineLambdasLowering,
|
||||||
name = "LocalClassesInInlineLambdasPhase",
|
name = "LocalClassesInInlineLambdasPhase",
|
||||||
description = "Extract local classes from inline lambdas",
|
description = "Extract local classes from inline lambdas",
|
||||||
prerequisite = setOf(inventNamesForLocalClassesPhase)
|
prerequisite = setOf(inventNamesForLocalClassesPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val localClassesInInlineFunctionsPhase = makeBodyLoweringPhase(
|
private val localClassesInInlineFunctionsPhase = makeIrModulePhase(
|
||||||
::LocalClassesInInlineFunctionsLowering,
|
::LocalClassesInInlineFunctionsLowering,
|
||||||
name = "LocalClassesInInlineFunctionsPhase",
|
name = "LocalClassesInInlineFunctionsPhase",
|
||||||
description = "Extract local classes from inline functions",
|
description = "Extract local classes from inline functions",
|
||||||
prerequisite = setOf(inventNamesForLocalClassesPhase)
|
prerequisite = setOf(inventNamesForLocalClassesPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val localClassesExtractionFromInlineFunctionsPhase = makeBodyLoweringPhase(
|
private val localClassesExtractionFromInlineFunctionsPhase = makeIrModulePhase(
|
||||||
{ context -> LocalClassesExtractionFromInlineFunctionsLowering(context) },
|
{ context -> LocalClassesExtractionFromInlineFunctionsLowering(context) },
|
||||||
name = "localClassesExtractionFromInlineFunctionsPhase",
|
name = "localClassesExtractionFromInlineFunctionsPhase",
|
||||||
description = "Move local classes from inline functions into nearest declaration container",
|
description = "Move local classes from inline functions into nearest declaration container",
|
||||||
prerequisite = setOf(localClassesInInlineFunctionsPhase)
|
prerequisite = setOf(localClassesInInlineFunctionsPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val syntheticAccessorLoweringPhase = makeBodyLoweringPhase(
|
private val syntheticAccessorLoweringPhase = makeIrModulePhase(
|
||||||
::SyntheticAccessorLowering,
|
::SyntheticAccessorLowering,
|
||||||
name = "syntheticAccessorLoweringPhase",
|
name = "syntheticAccessorLoweringPhase",
|
||||||
description = "Wrap top level inline function to access through them from inline functions"
|
description = "Wrap top level inline function to access through them from inline functions"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val wrapInlineDeclarationsWithReifiedTypeParametersLowering = makeBodyLoweringPhase(
|
private val wrapInlineDeclarationsWithReifiedTypeParametersLowering = makeIrModulePhase(
|
||||||
::WrapInlineDeclarationsWithReifiedTypeParametersLowering,
|
::WrapInlineDeclarationsWithReifiedTypeParametersLowering,
|
||||||
name = "WrapInlineDeclarationsWithReifiedTypeParametersLowering",
|
name = "WrapInlineDeclarationsWithReifiedTypeParametersLowering",
|
||||||
description = "Wrap inline declarations with reified type parameters"
|
description = "Wrap inline declarations with reified type parameters"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val saveInlineFunctionsBeforeInlining = makeDeclarationTransformerPhase(
|
private val saveInlineFunctionsBeforeInlining = makeIrModulePhase(
|
||||||
::SaveInlineFunctionsBeforeInlining,
|
::SaveInlineFunctionsBeforeInlining,
|
||||||
name = "SaveInlineFunctionsBeforeInlining",
|
name = "SaveInlineFunctionsBeforeInlining",
|
||||||
description = "Save inline function before inlining",
|
description = "Save inline function before inlining",
|
||||||
@@ -281,7 +196,7 @@ private val saveInlineFunctionsBeforeInlining = makeDeclarationTransformerPhase(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val functionInliningPhase = makeBodyLoweringPhase(
|
private val functionInliningPhase = makeIrModulePhase(
|
||||||
{
|
{
|
||||||
FunctionInlining(
|
FunctionInlining(
|
||||||
it,
|
it,
|
||||||
@@ -298,27 +213,27 @@ private val functionInliningPhase = makeBodyLoweringPhase(
|
|||||||
prerequisite = setOf(saveInlineFunctionsBeforeInlining)
|
prerequisite = setOf(saveInlineFunctionsBeforeInlining)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val copyInlineFunctionBodyLoweringPhase = makeDeclarationTransformerPhase(
|
private val copyInlineFunctionBodyLoweringPhase = makeIrModulePhase(
|
||||||
::CopyInlineFunctionBodyLowering,
|
::CopyInlineFunctionBodyLowering,
|
||||||
name = "CopyInlineFunctionBody",
|
name = "CopyInlineFunctionBody",
|
||||||
description = "Copy inline function body",
|
description = "Copy inline function body",
|
||||||
prerequisite = setOf(functionInliningPhase)
|
prerequisite = setOf(functionInliningPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val removeInlineDeclarationsWithReifiedTypeParametersLoweringPhase = makeDeclarationTransformerPhase(
|
private val removeInlineDeclarationsWithReifiedTypeParametersLoweringPhase = makeIrModulePhase(
|
||||||
{ RemoveInlineDeclarationsWithReifiedTypeParametersLowering() },
|
{ RemoveInlineDeclarationsWithReifiedTypeParametersLowering() },
|
||||||
name = "RemoveInlineFunctionsWithReifiedTypeParametersLowering",
|
name = "RemoveInlineFunctionsWithReifiedTypeParametersLowering",
|
||||||
description = "Remove Inline functions with reified parameters from context",
|
description = "Remove Inline functions with reified parameters from context",
|
||||||
prerequisite = setOf(functionInliningPhase)
|
prerequisite = setOf(functionInliningPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val captureStackTraceInThrowablesPhase = makeBodyLoweringPhase(
|
private val captureStackTraceInThrowablesPhase = makeIrModulePhase(
|
||||||
::CaptureStackTraceInThrowables,
|
::CaptureStackTraceInThrowables,
|
||||||
name = "CaptureStackTraceInThrowables",
|
name = "CaptureStackTraceInThrowables",
|
||||||
description = "Capture stack trace in Throwable constructors"
|
description = "Capture stack trace in Throwable constructors"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val throwableSuccessorsLoweringPhase = makeBodyLoweringPhase(
|
private val throwableSuccessorsLoweringPhase = makeIrModulePhase(
|
||||||
{ context ->
|
{ context ->
|
||||||
context.run {
|
context.run {
|
||||||
val extendThrowableSymbol =
|
val extendThrowableSymbol =
|
||||||
@@ -332,53 +247,53 @@ private val throwableSuccessorsLoweringPhase = makeBodyLoweringPhase(
|
|||||||
prerequisite = setOf(captureStackTraceInThrowablesPhase)
|
prerequisite = setOf(captureStackTraceInThrowablesPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val tailrecLoweringPhase = makeBodyLoweringPhase(
|
private val tailrecLoweringPhase = makeIrModulePhase(
|
||||||
::TailrecLowering,
|
::TailrecLowering,
|
||||||
name = "TailrecLowering",
|
name = "TailrecLowering",
|
||||||
description = "Replace `tailrec` callsites with equivalent loop"
|
description = "Replace `tailrec` callsites with equivalent loop"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val enumClassConstructorLoweringPhase = makeDeclarationTransformerPhase(
|
private val enumClassConstructorLoweringPhase = makeIrModulePhase(
|
||||||
::EnumClassConstructorLowering,
|
::EnumClassConstructorLowering,
|
||||||
name = "EnumClassConstructorLowering",
|
name = "EnumClassConstructorLowering",
|
||||||
description = "Transform Enum Class into regular Class"
|
description = "Transform Enum Class into regular Class"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val enumClassConstructorBodyLoweringPhase = makeBodyLoweringPhase(
|
private val enumClassConstructorBodyLoweringPhase = makeIrModulePhase(
|
||||||
::EnumClassConstructorBodyTransformer,
|
::EnumClassConstructorBodyTransformer,
|
||||||
name = "EnumClassConstructorBodyLowering",
|
name = "EnumClassConstructorBodyLowering",
|
||||||
description = "Transform Enum Class into regular Class"
|
description = "Transform Enum Class into regular Class"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val enumEntryInstancesLoweringPhase = makeDeclarationTransformerPhase(
|
private val enumEntryInstancesLoweringPhase = makeIrModulePhase(
|
||||||
::EnumEntryInstancesLowering,
|
::EnumEntryInstancesLowering,
|
||||||
name = "EnumEntryInstancesLowering",
|
name = "EnumEntryInstancesLowering",
|
||||||
description = "Create instance variable for each enum entry initialized with `null`",
|
description = "Create instance variable for each enum entry initialized with `null`",
|
||||||
prerequisite = setOf(enumClassConstructorLoweringPhase)
|
prerequisite = setOf(enumClassConstructorLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val enumEntryInstancesBodyLoweringPhase = makeBodyLoweringPhase(
|
private val enumEntryInstancesBodyLoweringPhase = makeIrModulePhase(
|
||||||
::EnumEntryInstancesBodyLowering,
|
::EnumEntryInstancesBodyLowering,
|
||||||
name = "EnumEntryInstancesBodyLowering",
|
name = "EnumEntryInstancesBodyLowering",
|
||||||
description = "Insert enum entry field initialization into correxposnding class constructors",
|
description = "Insert enum entry field initialization into correxposnding class constructors",
|
||||||
prerequisite = setOf(enumEntryInstancesLoweringPhase)
|
prerequisite = setOf(enumEntryInstancesLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val enumClassCreateInitializerLoweringPhase = makeDeclarationTransformerPhase(
|
private val enumClassCreateInitializerLoweringPhase = makeIrModulePhase(
|
||||||
::EnumClassCreateInitializerLowering,
|
::EnumClassCreateInitializerLowering,
|
||||||
name = "EnumClassCreateInitializerLowering",
|
name = "EnumClassCreateInitializerLowering",
|
||||||
description = "Create initializer for enum entries",
|
description = "Create initializer for enum entries",
|
||||||
prerequisite = setOf(enumClassConstructorLoweringPhase)
|
prerequisite = setOf(enumClassConstructorLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val enumEntryCreateGetInstancesFunsLoweringPhase = makeDeclarationTransformerPhase(
|
private val enumEntryCreateGetInstancesFunsLoweringPhase = makeIrModulePhase(
|
||||||
::EnumEntryCreateGetInstancesFunsLowering,
|
::EnumEntryCreateGetInstancesFunsLowering,
|
||||||
name = "EnumEntryCreateGetInstancesFunsLowering",
|
name = "EnumEntryCreateGetInstancesFunsLowering",
|
||||||
description = "Create enumEntry_getInstance functions",
|
description = "Create enumEntry_getInstance functions",
|
||||||
prerequisite = setOf(enumClassConstructorLoweringPhase)
|
prerequisite = setOf(enumClassConstructorLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val enumSyntheticFunsLoweringPhase = makeDeclarationTransformerPhase(
|
private val enumSyntheticFunsLoweringPhase = makeIrModulePhase(
|
||||||
::EnumSyntheticFunctionsAndPropertiesLowering,
|
::EnumSyntheticFunctionsAndPropertiesLowering,
|
||||||
name = "EnumSyntheticFunctionsAndPropertiesLowering",
|
name = "EnumSyntheticFunctionsAndPropertiesLowering",
|
||||||
description = "Implement `valueOf, `values` and `entries`",
|
description = "Implement `valueOf, `values` and `entries`",
|
||||||
@@ -389,148 +304,148 @@ private val enumSyntheticFunsLoweringPhase = makeDeclarationTransformerPhase(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val enumUsageLoweringPhase = makeBodyLoweringPhase(
|
private val enumUsageLoweringPhase = makeIrModulePhase(
|
||||||
::EnumUsageLowering,
|
::EnumUsageLowering,
|
||||||
name = "EnumUsageLowering",
|
name = "EnumUsageLowering",
|
||||||
description = "Replace enum access with invocation of corresponding function",
|
description = "Replace enum access with invocation of corresponding function",
|
||||||
prerequisite = setOf(enumEntryCreateGetInstancesFunsLoweringPhase)
|
prerequisite = setOf(enumEntryCreateGetInstancesFunsLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val externalEnumUsageLoweringPhase = makeBodyLoweringPhase(
|
private val externalEnumUsageLoweringPhase = makeIrModulePhase(
|
||||||
::ExternalEnumUsagesLowering,
|
::ExternalEnumUsagesLowering,
|
||||||
name = "ExternalEnumUsagesLowering",
|
name = "ExternalEnumUsagesLowering",
|
||||||
description = "Replace external enum entry accesses with field accesses"
|
description = "Replace external enum entry accesses with field accesses"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val enumEntryRemovalLoweringPhase = makeDeclarationTransformerPhase(
|
private val enumEntryRemovalLoweringPhase = makeIrModulePhase(
|
||||||
::EnumClassRemoveEntriesLowering,
|
::EnumClassRemoveEntriesLowering,
|
||||||
name = "EnumEntryRemovalLowering",
|
name = "EnumEntryRemovalLowering",
|
||||||
description = "Replace enum entry with corresponding class",
|
description = "Replace enum entry with corresponding class",
|
||||||
prerequisite = setOf(enumUsageLoweringPhase)
|
prerequisite = setOf(enumUsageLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val callableReferenceLowering = makeBodyLoweringPhase(
|
private val callableReferenceLowering = makeIrModulePhase(
|
||||||
::CallableReferenceLowering,
|
::CallableReferenceLowering,
|
||||||
name = "CallableReferenceLowering",
|
name = "CallableReferenceLowering",
|
||||||
description = "Build a lambda/callable reference class",
|
description = "Build a lambda/callable reference class",
|
||||||
prerequisite = setOf(functionInliningPhase, wrapInlineDeclarationsWithReifiedTypeParametersLowering)
|
prerequisite = setOf(functionInliningPhase, wrapInlineDeclarationsWithReifiedTypeParametersLowering)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val returnableBlockLoweringPhase = makeBodyLoweringPhase(
|
private val returnableBlockLoweringPhase = makeIrModulePhase(
|
||||||
::JsReturnableBlockLowering,
|
::JsReturnableBlockLowering,
|
||||||
name = "JsReturnableBlockLowering",
|
name = "JsReturnableBlockLowering",
|
||||||
description = "Introduce temporary variable for result and change returnable block's type to Unit",
|
description = "Introduce temporary variable for result and change returnable block's type to Unit",
|
||||||
prerequisite = setOf(functionInliningPhase)
|
prerequisite = setOf(functionInliningPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val rangeContainsLoweringPhase = makeBodyLoweringPhase(
|
private val rangeContainsLoweringPhase = makeIrModulePhase(
|
||||||
::RangeContainsLowering,
|
::RangeContainsLowering,
|
||||||
name = "RangeContainsLowering",
|
name = "RangeContainsLowering",
|
||||||
description = "[Optimization] Optimizes calls to contains() for ClosedRanges"
|
description = "[Optimization] Optimizes calls to contains() for ClosedRanges"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val forLoopsLoweringPhase = makeBodyLoweringPhase(
|
private val forLoopsLoweringPhase = makeIrModulePhase(
|
||||||
::ForLoopsLowering,
|
::ForLoopsLowering,
|
||||||
name = "ForLoopsLowering",
|
name = "ForLoopsLowering",
|
||||||
description = "[Optimization] For loops lowering"
|
description = "[Optimization] For loops lowering"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val enumWhenPhase = makeJsModulePhase(
|
private val enumWhenPhase = makeIrModulePhase(
|
||||||
::EnumWhenLowering,
|
::EnumWhenLowering,
|
||||||
name = "EnumWhenLowering",
|
name = "EnumWhenLowering",
|
||||||
description = "Replace `when` subjects of enum types with their ordinals"
|
description = "Replace `when` subjects of enum types with their ordinals"
|
||||||
).toModuleLowering()
|
)
|
||||||
|
|
||||||
private val propertyLazyInitLoweringPhase = makeBodyLoweringPhase(
|
private val propertyLazyInitLoweringPhase = makeIrModulePhase(
|
||||||
::PropertyLazyInitLowering,
|
::PropertyLazyInitLowering,
|
||||||
name = "PropertyLazyInitLowering",
|
name = "PropertyLazyInitLowering",
|
||||||
description = "Make property init as lazy"
|
description = "Make property init as lazy"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val removeInitializersForLazyProperties = makeDeclarationTransformerPhase(
|
private val removeInitializersForLazyProperties = makeIrModulePhase(
|
||||||
::RemoveInitializersForLazyProperties,
|
::RemoveInitializersForLazyProperties,
|
||||||
name = "RemoveInitializersForLazyProperties",
|
name = "RemoveInitializersForLazyProperties",
|
||||||
description = "Remove property initializers if they was initialized lazily"
|
description = "Remove property initializers if they was initialized lazily"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val propertyAccessorInlinerLoweringPhase = makeBodyLoweringPhase(
|
private val propertyAccessorInlinerLoweringPhase = makeIrModulePhase(
|
||||||
::JsPropertyAccessorInlineLowering,
|
::JsPropertyAccessorInlineLowering,
|
||||||
name = "PropertyAccessorInlineLowering",
|
name = "PropertyAccessorInlineLowering",
|
||||||
description = "[Optimization] Inline property accessors"
|
description = "[Optimization] Inline property accessors"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val copyPropertyAccessorBodiesLoweringPass = makeDeclarationTransformerPhase(
|
private val copyPropertyAccessorBodiesLoweringPass = makeIrModulePhase(
|
||||||
::CopyAccessorBodyLowerings,
|
::CopyAccessorBodyLowerings,
|
||||||
name = "CopyAccessorBodyLowering",
|
name = "CopyAccessorBodyLowering",
|
||||||
description = "Copy accessor bodies so that ist can be safely read in PropertyAccessorInlineLowering",
|
description = "Copy accessor bodies so that ist can be safely read in PropertyAccessorInlineLowering",
|
||||||
prerequisite = setOf(propertyAccessorInlinerLoweringPhase)
|
prerequisite = setOf(propertyAccessorInlinerLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val booleanPropertyInExternalLowering = makeBodyLoweringPhase(
|
private val booleanPropertyInExternalLowering = makeIrModulePhase(
|
||||||
::BooleanPropertyInExternalLowering,
|
::BooleanPropertyInExternalLowering,
|
||||||
name = "BooleanPropertyInExternalLowering",
|
name = "BooleanPropertyInExternalLowering",
|
||||||
description = "Lowering which wrap boolean in external declarations with Boolean() call and add diagnostic for such cases"
|
description = "Lowering which wrap boolean in external declarations with Boolean() call and add diagnostic for such cases"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val localDelegatedPropertiesLoweringPhase = makeBodyLoweringPhase(
|
private val localDelegatedPropertiesLoweringPhase = makeIrModulePhase<JsIrBackendContext>(
|
||||||
{ LocalDelegatedPropertiesLowering() },
|
{ LocalDelegatedPropertiesLowering() },
|
||||||
name = "LocalDelegatedPropertiesLowering",
|
name = "LocalDelegatedPropertiesLowering",
|
||||||
description = "Transform Local Delegated properties"
|
description = "Transform Local Delegated properties"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val localDeclarationsLoweringPhase = makeBodyLoweringPhase(
|
private val localDeclarationsLoweringPhase = makeIrModulePhase(
|
||||||
{ context -> LocalDeclarationsLowering(context, suggestUniqueNames = false) },
|
{ context -> LocalDeclarationsLowering(context, suggestUniqueNames = false) },
|
||||||
name = "LocalDeclarationsLowering",
|
name = "LocalDeclarationsLowering",
|
||||||
description = "Move local declarations into nearest declaration container",
|
description = "Move local declarations into nearest declaration container",
|
||||||
prerequisite = setOf(sharedVariablesLoweringPhase, localDelegatedPropertiesLoweringPhase)
|
prerequisite = setOf(sharedVariablesLoweringPhase, localDelegatedPropertiesLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val localClassExtractionPhase = makeBodyLoweringPhase(
|
private val localClassExtractionPhase = makeIrModulePhase(
|
||||||
{ context -> LocalClassPopupLowering(context) },
|
{ context -> LocalClassPopupLowering(context) },
|
||||||
name = "LocalClassExtractionPhase",
|
name = "LocalClassExtractionPhase",
|
||||||
description = "Move local declarations into nearest declaration container",
|
description = "Move local declarations into nearest declaration container",
|
||||||
prerequisite = setOf(localDeclarationsLoweringPhase)
|
prerequisite = setOf(localDeclarationsLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val innerClassesLoweringPhase = makeDeclarationTransformerPhase(
|
private val innerClassesLoweringPhase = makeIrModulePhase<JsIrBackendContext>(
|
||||||
{ context -> InnerClassesLowering(context, context.innerClassesSupport) },
|
{ context -> InnerClassesLowering(context, context.innerClassesSupport) },
|
||||||
name = "InnerClassesLowering",
|
name = "InnerClassesLowering",
|
||||||
description = "Capture outer this reference to inner class"
|
description = "Capture outer this reference to inner class"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val innerClassesMemberBodyLoweringPhase = makeBodyLoweringPhase(
|
private val innerClassesMemberBodyLoweringPhase = makeIrModulePhase(
|
||||||
{ context -> InnerClassesMemberBodyLowering(context, context.innerClassesSupport) },
|
{ context -> InnerClassesMemberBodyLowering(context, context.innerClassesSupport) },
|
||||||
name = "InnerClassesMemberBody",
|
name = "InnerClassesMemberBody",
|
||||||
description = "Replace `this` with 'outer this' field references",
|
description = "Replace `this` with 'outer this' field references",
|
||||||
prerequisite = setOf(innerClassesLoweringPhase)
|
prerequisite = setOf(innerClassesLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val innerClassConstructorCallsLoweringPhase = makeBodyLoweringPhase(
|
private val innerClassConstructorCallsLoweringPhase = makeIrModulePhase<JsIrBackendContext>(
|
||||||
{ context -> InnerClassConstructorCallsLowering(context, context.innerClassesSupport) },
|
{ context -> InnerClassConstructorCallsLowering(context, context.innerClassesSupport) },
|
||||||
name = "InnerClassConstructorCallsLowering",
|
name = "InnerClassConstructorCallsLowering",
|
||||||
description = "Replace inner class constructor invocation"
|
description = "Replace inner class constructor invocation"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val suspendFunctionsLoweringPhase = makeBodyLoweringPhase(
|
private val suspendFunctionsLoweringPhase = makeIrModulePhase(
|
||||||
::JsSuspendFunctionsLowering,
|
::JsSuspendFunctionsLowering,
|
||||||
name = "SuspendFunctionsLowering",
|
name = "SuspendFunctionsLowering",
|
||||||
description = "Transform suspend functions into CoroutineImpl instance and build state machine"
|
description = "Transform suspend functions into CoroutineImpl instance and build state machine"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val addContinuationToNonLocalSuspendFunctionsLoweringPhase = makeDeclarationTransformerPhase(
|
private val addContinuationToNonLocalSuspendFunctionsLoweringPhase = makeIrModulePhase(
|
||||||
::AddContinuationToNonLocalSuspendFunctionsLowering,
|
::AddContinuationToNonLocalSuspendFunctionsLowering,
|
||||||
name = "AddContinuationToNonLocalSuspendFunctionsLowering",
|
name = "AddContinuationToNonLocalSuspendFunctionsLowering",
|
||||||
description = "Add explicit continuation as last parameter of non-local suspend functions"
|
description = "Add explicit continuation as last parameter of non-local suspend functions"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val addContinuationToLocalSuspendFunctionsLoweringPhase = makeBodyLoweringPhase(
|
private val addContinuationToLocalSuspendFunctionsLoweringPhase = makeIrModulePhase(
|
||||||
::AddContinuationToLocalSuspendFunctionsLowering,
|
::AddContinuationToLocalSuspendFunctionsLowering,
|
||||||
name = "AddContinuationToLocalSuspendFunctionsLowering",
|
name = "AddContinuationToLocalSuspendFunctionsLowering",
|
||||||
description = "Add explicit continuation as last parameter of local suspend functions"
|
description = "Add explicit continuation as last parameter of local suspend functions"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
private val addContinuationToFunctionCallsLoweringPhase = makeBodyLoweringPhase(
|
private val addContinuationToFunctionCallsLoweringPhase = makeIrModulePhase(
|
||||||
::AddContinuationToFunctionCallsLowering,
|
::AddContinuationToFunctionCallsLowering,
|
||||||
name = "AddContinuationToFunctionCallsLowering",
|
name = "AddContinuationToFunctionCallsLowering",
|
||||||
description = "Replace suspend function calls with calls with continuation",
|
description = "Replace suspend function calls with calls with continuation",
|
||||||
@@ -540,25 +455,25 @@ private val addContinuationToFunctionCallsLoweringPhase = makeBodyLoweringPhase(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val privateMembersLoweringPhase = makeDeclarationTransformerPhase(
|
private val privateMembersLoweringPhase = makeIrModulePhase(
|
||||||
::PrivateMembersLowering,
|
::PrivateMembersLowering,
|
||||||
name = "PrivateMembersLowering",
|
name = "PrivateMembersLowering",
|
||||||
description = "Extract private members from classes"
|
description = "Extract private members from classes"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val privateMemberUsagesLoweringPhase = makeBodyLoweringPhase(
|
private val privateMemberUsagesLoweringPhase = makeIrModulePhase(
|
||||||
::PrivateMemberBodiesLowering,
|
::PrivateMemberBodiesLowering,
|
||||||
name = "PrivateMemberUsagesLowering",
|
name = "PrivateMemberUsagesLowering",
|
||||||
description = "Rewrite the private member usages"
|
description = "Rewrite the private member usages"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val propertyReferenceLoweringPhase = makeBodyLoweringPhase(
|
private val propertyReferenceLoweringPhase = makeIrModulePhase(
|
||||||
::PropertyReferenceLowering,
|
::PropertyReferenceLowering,
|
||||||
name = "PropertyReferenceLowering",
|
name = "PropertyReferenceLowering",
|
||||||
description = "Transform property references",
|
description = "Transform property references",
|
||||||
)
|
)
|
||||||
|
|
||||||
private val interopCallableReferenceLoweringPhase = makeBodyLoweringPhase(
|
private val interopCallableReferenceLoweringPhase = makeIrModulePhase(
|
||||||
::InteropCallableReferenceLowering,
|
::InteropCallableReferenceLowering,
|
||||||
name = "InteropCallableReferenceLowering",
|
name = "InteropCallableReferenceLowering",
|
||||||
description = "Interop layer for function references and lambdas",
|
description = "Interop layer for function references and lambdas",
|
||||||
@@ -570,66 +485,66 @@ private val interopCallableReferenceLoweringPhase = makeBodyLoweringPhase(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val defaultArgumentStubGeneratorPhase = makeDeclarationTransformerPhase(
|
private val defaultArgumentStubGeneratorPhase = makeIrModulePhase(
|
||||||
::JsDefaultArgumentStubGenerator,
|
::JsDefaultArgumentStubGenerator,
|
||||||
name = "DefaultArgumentStubGenerator",
|
name = "DefaultArgumentStubGenerator",
|
||||||
description = "Generate synthetic stubs for functions with default parameter values"
|
description = "Generate synthetic stubs for functions with default parameter values"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val defaultArgumentPatchOverridesPhase = makeDeclarationTransformerPhase(
|
private val defaultArgumentPatchOverridesPhase = makeIrModulePhase(
|
||||||
::DefaultParameterPatchOverridenSymbolsLowering,
|
::DefaultParameterPatchOverridenSymbolsLowering,
|
||||||
name = "DefaultArgumentsPatchOverrides",
|
name = "DefaultArgumentsPatchOverrides",
|
||||||
description = "Patch overrides for fake override dispatch functions",
|
description = "Patch overrides for fake override dispatch functions",
|
||||||
prerequisite = setOf(defaultArgumentStubGeneratorPhase)
|
prerequisite = setOf(defaultArgumentStubGeneratorPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val defaultParameterInjectorPhase = makeBodyLoweringPhase(
|
private val defaultParameterInjectorPhase = makeIrModulePhase(
|
||||||
::JsDefaultParameterInjector,
|
::JsDefaultParameterInjector,
|
||||||
name = "DefaultParameterInjector",
|
name = "DefaultParameterInjector",
|
||||||
description = "Replace callsite with default parameters with corresponding stub function",
|
description = "Replace callsite with default parameters with corresponding stub function",
|
||||||
prerequisite = setOf(interopCallableReferenceLoweringPhase, innerClassesLoweringPhase)
|
prerequisite = setOf(interopCallableReferenceLoweringPhase, innerClassesLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val defaultParameterCleanerPhase = makeDeclarationTransformerPhase(
|
private val defaultParameterCleanerPhase = makeIrModulePhase(
|
||||||
::DefaultParameterCleaner,
|
::DefaultParameterCleaner,
|
||||||
name = "DefaultParameterCleaner",
|
name = "DefaultParameterCleaner",
|
||||||
description = "Clean default parameters up"
|
description = "Clean default parameters up"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val varargLoweringPhase = makeBodyLoweringPhase(
|
private val varargLoweringPhase = makeIrModulePhase(
|
||||||
::VarargLowering,
|
::VarargLowering,
|
||||||
name = "VarargLowering",
|
name = "VarargLowering",
|
||||||
description = "Lower vararg arguments",
|
description = "Lower vararg arguments",
|
||||||
prerequisite = setOf(interopCallableReferenceLoweringPhase)
|
prerequisite = setOf(interopCallableReferenceLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val propertiesLoweringPhase = makeDeclarationTransformerPhase(
|
private val propertiesLoweringPhase = makeIrModulePhase<JsIrBackendContext>(
|
||||||
{ PropertiesLowering() },
|
{ PropertiesLowering() },
|
||||||
name = "PropertiesLowering",
|
name = "PropertiesLowering",
|
||||||
description = "Move fields and accessors out from its property"
|
description = "Move fields and accessors out from its property"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val primaryConstructorLoweringPhase = makeDeclarationTransformerPhase(
|
private val primaryConstructorLoweringPhase = makeIrModulePhase(
|
||||||
::PrimaryConstructorLowering,
|
::PrimaryConstructorLowering,
|
||||||
name = "PrimaryConstructorLowering",
|
name = "PrimaryConstructorLowering",
|
||||||
description = "Creates primary constructor if it doesn't exist",
|
description = "Creates primary constructor if it doesn't exist",
|
||||||
prerequisite = setOf(enumClassConstructorLoweringPhase)
|
prerequisite = setOf(enumClassConstructorLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val delegateToPrimaryConstructorLoweringPhase = makeBodyLoweringPhase(
|
private val delegateToPrimaryConstructorLoweringPhase = makeIrModulePhase(
|
||||||
::DelegateToSyntheticPrimaryConstructor,
|
::DelegateToSyntheticPrimaryConstructor,
|
||||||
name = "DelegateToSyntheticPrimaryConstructor",
|
name = "DelegateToSyntheticPrimaryConstructor",
|
||||||
description = "Delegates to synthetic primary constructor",
|
description = "Delegates to synthetic primary constructor",
|
||||||
prerequisite = setOf(primaryConstructorLoweringPhase)
|
prerequisite = setOf(primaryConstructorLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val annotationConstructorLowering = makeDeclarationTransformerPhase(
|
private val annotationConstructorLowering = makeIrModulePhase(
|
||||||
::AnnotationConstructorLowering,
|
::AnnotationConstructorLowering,
|
||||||
name = "AnnotationConstructorLowering",
|
name = "AnnotationConstructorLowering",
|
||||||
description = "Generate annotation constructor body"
|
description = "Generate annotation constructor body"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val initializersLoweringPhase = makeBodyLoweringPhase(
|
private val initializersLoweringPhase = makeIrModulePhase(
|
||||||
::InitializersLowering,
|
::InitializersLowering,
|
||||||
name = "InitializersLowering",
|
name = "InitializersLowering",
|
||||||
description = "Merge init block and field initializers into [primary] constructor",
|
description = "Merge init block and field initializers into [primary] constructor",
|
||||||
@@ -638,46 +553,46 @@ private val initializersLoweringPhase = makeBodyLoweringPhase(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val initializersCleanupLoweringPhase = makeDeclarationTransformerPhase(
|
private val initializersCleanupLoweringPhase = makeIrModulePhase(
|
||||||
::InitializersCleanupLowering,
|
::InitializersCleanupLowering,
|
||||||
name = "InitializersCleanupLowering",
|
name = "InitializersCleanupLowering",
|
||||||
description = "Remove non-static anonymous initializers and field init expressions",
|
description = "Remove non-static anonymous initializers and field init expressions",
|
||||||
prerequisite = setOf(initializersLoweringPhase)
|
prerequisite = setOf(initializersLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val multipleCatchesLoweringPhase = makeBodyLoweringPhase(
|
private val multipleCatchesLoweringPhase = makeIrModulePhase(
|
||||||
::MultipleCatchesLowering,
|
::MultipleCatchesLowering,
|
||||||
name = "MultipleCatchesLowering",
|
name = "MultipleCatchesLowering",
|
||||||
description = "Replace multiple catches with single one"
|
description = "Replace multiple catches with single one"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val errorExpressionLoweringPhase = makeBodyLoweringPhase(
|
private val errorExpressionLoweringPhase = makeIrModulePhase(
|
||||||
::JsErrorExpressionLowering,
|
::JsErrorExpressionLowering,
|
||||||
name = "errorExpressionLoweringPhase",
|
name = "errorExpressionLoweringPhase",
|
||||||
description = "Transform error expressions into simple ir code",
|
description = "Transform error expressions into simple ir code",
|
||||||
prerequisite = setOf(multipleCatchesLoweringPhase)
|
prerequisite = setOf(multipleCatchesLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val errorDeclarationLoweringPhase = makeDeclarationTransformerPhase(
|
private val errorDeclarationLoweringPhase = makeIrModulePhase(
|
||||||
::JsErrorDeclarationLowering,
|
::JsErrorDeclarationLowering,
|
||||||
name = "errorDeclarationLoweringPhase",
|
name = "errorDeclarationLoweringPhase",
|
||||||
description = "Transform error declarations into simple ir code"
|
description = "Transform error declarations into simple ir code"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val bridgesConstructionPhase = makeDeclarationTransformerPhase(
|
private val bridgesConstructionPhase = makeIrModulePhase(
|
||||||
::JsBridgesConstruction,
|
::JsBridgesConstruction,
|
||||||
name = "BridgesConstruction",
|
name = "BridgesConstruction",
|
||||||
description = "Generate bridges",
|
description = "Generate bridges",
|
||||||
prerequisite = setOf(suspendFunctionsLoweringPhase)
|
prerequisite = setOf(suspendFunctionsLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val singleAbstractMethodPhase = makeBodyLoweringPhase(
|
private val singleAbstractMethodPhase = makeIrModulePhase(
|
||||||
::JsSingleAbstractMethodLowering,
|
::JsSingleAbstractMethodLowering,
|
||||||
name = "SingleAbstractMethod",
|
name = "SingleAbstractMethod",
|
||||||
description = "Replace SAM conversions with instances of interface-implementing classes"
|
description = "Replace SAM conversions with instances of interface-implementing classes"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val typeOperatorLoweringPhase = makeBodyLoweringPhase(
|
private val typeOperatorLoweringPhase = makeIrModulePhase(
|
||||||
::TypeOperatorLowering,
|
::TypeOperatorLowering,
|
||||||
name = "TypeOperatorLowering",
|
name = "TypeOperatorLowering",
|
||||||
description = "Lower IrTypeOperator with corresponding logic",
|
description = "Lower IrTypeOperator with corresponding logic",
|
||||||
@@ -689,32 +604,32 @@ private val typeOperatorLoweringPhase = makeBodyLoweringPhase(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val secondaryConstructorLoweringPhase = makeDeclarationTransformerPhase(
|
private val secondaryConstructorLoweringPhase = makeIrModulePhase(
|
||||||
::SecondaryConstructorLowering,
|
::SecondaryConstructorLowering,
|
||||||
name = "SecondaryConstructorLoweringPhase",
|
name = "SecondaryConstructorLoweringPhase",
|
||||||
description = "Generate static functions for each secondary constructor",
|
description = "Generate static functions for each secondary constructor",
|
||||||
prerequisite = setOf(innerClassesLoweringPhase)
|
prerequisite = setOf(innerClassesLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val secondaryFactoryInjectorLoweringPhase = makeBodyLoweringPhase(
|
private val secondaryFactoryInjectorLoweringPhase = makeIrModulePhase(
|
||||||
::SecondaryFactoryInjectorLowering,
|
::SecondaryFactoryInjectorLowering,
|
||||||
name = "SecondaryFactoryInjectorLoweringPhase",
|
name = "SecondaryFactoryInjectorLoweringPhase",
|
||||||
description = "Replace usage of secondary constructor with corresponding static function",
|
description = "Replace usage of secondary constructor with corresponding static function",
|
||||||
prerequisite = setOf(innerClassesLoweringPhase)
|
prerequisite = setOf(innerClassesLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val constLoweringPhase = makeBodyLoweringPhase(
|
private val constLoweringPhase = makeIrModulePhase(
|
||||||
::ConstLowering,
|
::ConstLowering,
|
||||||
name = "ConstLowering",
|
name = "ConstLowering",
|
||||||
description = "Wrap Long and Char constants into constructor invocation"
|
description = "Wrap Long and Char constants into constructor invocation"
|
||||||
)
|
)
|
||||||
private val inlineClassDeclarationLoweringPhase = makeDeclarationTransformerPhase(
|
private val inlineClassDeclarationLoweringPhase = makeIrModulePhase<JsIrBackendContext>(
|
||||||
{ InlineClassLowering(it).inlineClassDeclarationLowering },
|
{ InlineClassLowering(it).inlineClassDeclarationLowering },
|
||||||
name = "InlineClassDeclarationLowering",
|
name = "InlineClassDeclarationLowering",
|
||||||
description = "Handle inline class declarations"
|
description = "Handle inline class declarations"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val inlineClassUsageLoweringPhase = makeBodyLoweringPhase(
|
private val inlineClassUsageLoweringPhase = makeIrModulePhase(
|
||||||
{ InlineClassLowering(it).inlineClassUsageLowering },
|
{ InlineClassLowering(it).inlineClassUsageLowering },
|
||||||
name = "InlineClassUsageLowering",
|
name = "InlineClassUsageLowering",
|
||||||
description = "Handle inline class usages",
|
description = "Handle inline class usages",
|
||||||
@@ -725,117 +640,117 @@ private val inlineClassUsageLoweringPhase = makeBodyLoweringPhase(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val autoboxingTransformerPhase = makeBodyLoweringPhase(
|
private val autoboxingTransformerPhase = makeIrModulePhase<JsIrBackendContext>(
|
||||||
::AutoboxingTransformer,
|
::AutoboxingTransformer,
|
||||||
name = "AutoboxingTransformer",
|
name = "AutoboxingTransformer",
|
||||||
description = "Insert box/unbox intrinsics"
|
description = "Insert box/unbox intrinsics"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val blockDecomposerLoweringPhase = makeBodyLoweringPhase(
|
private val blockDecomposerLoweringPhase = makeIrModulePhase(
|
||||||
::JsBlockDecomposerLowering,
|
::JsBlockDecomposerLowering,
|
||||||
name = "BlockDecomposerLowering",
|
name = "BlockDecomposerLowering",
|
||||||
description = "Transform statement-like-expression nodes into pure-statement to make it easily transform into JS",
|
description = "Transform statement-like-expression nodes into pure-statement to make it easily transform into JS",
|
||||||
prerequisite = setOf(typeOperatorLoweringPhase, suspendFunctionsLoweringPhase)
|
prerequisite = setOf(typeOperatorLoweringPhase, suspendFunctionsLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val jsClassUsageInReflectionPhase = makeBodyLoweringPhase(
|
private val jsClassUsageInReflectionPhase = makeIrModulePhase(
|
||||||
::JsClassUsageInReflectionLowering,
|
::JsClassUsageInReflectionLowering,
|
||||||
name = "JsClassUsageInReflectionLowering",
|
name = "JsClassUsageInReflectionLowering",
|
||||||
description = "[Optimization] Eliminate ClassReference and GetClassExpression usages in a simple case of usage raw js constructor",
|
description = "[Optimization] Eliminate ClassReference and GetClassExpression usages in a simple case of usage raw js constructor",
|
||||||
prerequisite = setOf(functionInliningPhase)
|
prerequisite = setOf(functionInliningPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val classReferenceLoweringPhase = makeBodyLoweringPhase(
|
private val classReferenceLoweringPhase = makeIrModulePhase(
|
||||||
::ClassReferenceLowering,
|
::ClassReferenceLowering,
|
||||||
name = "ClassReferenceLowering",
|
name = "ClassReferenceLowering",
|
||||||
description = "Handle class references",
|
description = "Handle class references",
|
||||||
prerequisite = setOf(jsClassUsageInReflectionPhase)
|
prerequisite = setOf(jsClassUsageInReflectionPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val primitiveCompanionLoweringPhase = makeBodyLoweringPhase(
|
private val primitiveCompanionLoweringPhase = makeIrModulePhase(
|
||||||
::PrimitiveCompanionLowering,
|
::PrimitiveCompanionLowering,
|
||||||
name = "PrimitiveCompanionLowering",
|
name = "PrimitiveCompanionLowering",
|
||||||
description = "Replace common companion object access with platform one"
|
description = "Replace common companion object access with platform one"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val callsLoweringPhase = makeBodyLoweringPhase(
|
private val callsLoweringPhase = makeIrModulePhase(
|
||||||
::CallsLowering,
|
::CallsLowering,
|
||||||
name = "CallsLowering",
|
name = "CallsLowering",
|
||||||
description = "Handle intrinsics"
|
description = "Handle intrinsics"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val staticMembersLoweringPhase = makeDeclarationTransformerPhase(
|
private val staticMembersLoweringPhase = makeIrModulePhase(
|
||||||
::StaticMembersLowering,
|
::StaticMembersLowering,
|
||||||
name = "StaticMembersLowering",
|
name = "StaticMembersLowering",
|
||||||
description = "Move static member declarations to top-level"
|
description = "Move static member declarations to top-level"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val objectDeclarationLoweringPhase = makeDeclarationTransformerPhase(
|
private val objectDeclarationLoweringPhase = makeIrModulePhase(
|
||||||
::ObjectDeclarationLowering,
|
::ObjectDeclarationLowering,
|
||||||
name = "ObjectDeclarationLowering",
|
name = "ObjectDeclarationLowering",
|
||||||
description = "Create lazy object instance generator functions",
|
description = "Create lazy object instance generator functions",
|
||||||
prerequisite = setOf(enumClassCreateInitializerLoweringPhase)
|
prerequisite = setOf(enumClassCreateInitializerLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val invokeStaticInitializersPhase = makeBodyLoweringPhase(
|
private val invokeStaticInitializersPhase = makeIrModulePhase(
|
||||||
::InvokeStaticInitializersLowering,
|
::InvokeStaticInitializersLowering,
|
||||||
name = "IntroduceStaticInitializersLowering",
|
name = "IntroduceStaticInitializersLowering",
|
||||||
description = "Invoke companion object's initializers from companion object in object constructor",
|
description = "Invoke companion object's initializers from companion object in object constructor",
|
||||||
prerequisite = setOf(objectDeclarationLoweringPhase)
|
prerequisite = setOf(objectDeclarationLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val es6AddBoxParameterToConstructorsLowering = makeDeclarationTransformerPhase(
|
private val es6AddBoxParameterToConstructorsLowering = makeIrModulePhase(
|
||||||
::ES6AddBoxParameterToConstructorsLowering,
|
::ES6AddBoxParameterToConstructorsLowering,
|
||||||
name = "ES6AddBoxParameterToConstructorsLowering",
|
name = "ES6AddBoxParameterToConstructorsLowering",
|
||||||
description = "Add box parameter to a constructor if needed",
|
description = "Add box parameter to a constructor if needed",
|
||||||
)
|
)
|
||||||
|
|
||||||
private val es6ConstructorLowering = makeDeclarationTransformerPhase(
|
private val es6ConstructorLowering = makeIrModulePhase(
|
||||||
::ES6ConstructorLowering,
|
::ES6ConstructorLowering,
|
||||||
name = "ES6ConstructorLowering",
|
name = "ES6ConstructorLowering",
|
||||||
description = "Lower constructors declarations to support ES classes",
|
description = "Lower constructors declarations to support ES classes",
|
||||||
prerequisite = setOf(es6AddBoxParameterToConstructorsLowering)
|
prerequisite = setOf(es6AddBoxParameterToConstructorsLowering)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val es6ConstructorUsageLowering = makeBodyLoweringPhase(
|
private val es6ConstructorUsageLowering = makeIrModulePhase(
|
||||||
::ES6ConstructorCallLowering,
|
::ES6ConstructorCallLowering,
|
||||||
name = "ES6ConstructorCallLowering",
|
name = "ES6ConstructorCallLowering",
|
||||||
description = "Lower constructor usages to support ES classes",
|
description = "Lower constructor usages to support ES classes",
|
||||||
prerequisite = setOf(es6ConstructorLowering)
|
prerequisite = setOf(es6ConstructorLowering)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val objectUsageLoweringPhase = makeBodyLoweringPhase(
|
private val objectUsageLoweringPhase = makeIrModulePhase(
|
||||||
::ObjectUsageLowering,
|
::ObjectUsageLowering,
|
||||||
name = "ObjectUsageLowering",
|
name = "ObjectUsageLowering",
|
||||||
description = "Transform IrGetObjectValue into instance generator call",
|
description = "Transform IrGetObjectValue into instance generator call",
|
||||||
prerequisite = setOf(primaryConstructorLoweringPhase)
|
prerequisite = setOf(primaryConstructorLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val escapedIdentifiersLowering = makeBodyLoweringPhase(
|
private val escapedIdentifiersLowering = makeIrModulePhase(
|
||||||
::EscapedIdentifiersLowering,
|
::EscapedIdentifiersLowering,
|
||||||
name = "EscapedIdentifiersLowering",
|
name = "EscapedIdentifiersLowering",
|
||||||
description = "Convert global variables with invalid names access to globalThis member expression"
|
description = "Convert global variables with invalid names access to globalThis member expression"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val implicitlyExportedDeclarationsMarkingLowering = makeDeclarationTransformerPhase(
|
private val implicitlyExportedDeclarationsMarkingLowering = makeIrModulePhase(
|
||||||
::ImplicitlyExportedDeclarationsMarkingLowering,
|
::ImplicitlyExportedDeclarationsMarkingLowering,
|
||||||
name = "ImplicitlyExportedDeclarationsMarkingLowering",
|
name = "ImplicitlyExportedDeclarationsMarkingLowering",
|
||||||
description = "Add @JsImplicitExport annotation to declarations which are not exported but are used inside other exported declarations as a type"
|
description = "Add @JsImplicitExport annotation to declarations which are not exported but are used inside other exported declarations as a type"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val cleanupLoweringPhase = makeBodyLoweringPhase(
|
private val cleanupLoweringPhase = makeIrModulePhase<JsIrBackendContext>(
|
||||||
{ CleanupLowering() },
|
{ CleanupLowering() },
|
||||||
name = "CleanupLowering",
|
name = "CleanupLowering",
|
||||||
description = "Clean up IR before codegen"
|
description = "Clean up IR before codegen"
|
||||||
)
|
)
|
||||||
|
|
||||||
private val jsSuspendArityStorePhase = makeDeclarationTransformerPhase(
|
private val jsSuspendArityStorePhase = makeIrModulePhase(
|
||||||
::JsSuspendArityStoreLowering,
|
::JsSuspendArityStoreLowering,
|
||||||
name = "JsSuspendArityStoreLowering",
|
name = "JsSuspendArityStoreLowering",
|
||||||
description = "Store arity for suspend functions to not remove it during DCE"
|
description = "Store arity for suspend functions to not remove it during DCE"
|
||||||
)
|
)
|
||||||
|
|
||||||
val constEvaluationPhase = makeJsModulePhase(
|
val constEvaluationPhase = makeIrModulePhase<JsIrBackendContext>(
|
||||||
{ context ->
|
{ context ->
|
||||||
val configuration = IrInterpreterConfiguration(
|
val configuration = IrInterpreterConfiguration(
|
||||||
printOnlyExceptionMessage = true,
|
printOnlyExceptionMessage = true,
|
||||||
@@ -845,15 +760,15 @@ val constEvaluationPhase = makeJsModulePhase(
|
|||||||
},
|
},
|
||||||
name = "ConstEvaluationLowering",
|
name = "ConstEvaluationLowering",
|
||||||
description = "Evaluate functions that are marked as `IntrinsicConstEvaluation`",
|
description = "Evaluate functions that are marked as `IntrinsicConstEvaluation`",
|
||||||
).toModuleLowering()
|
)
|
||||||
|
|
||||||
val mainFunctionCallWrapperLowering = makeJsModulePhase(
|
val mainFunctionCallWrapperLowering = makeIrModulePhase<JsIrBackendContext>(
|
||||||
::MainFunctionCallWrapperLowering,
|
::MainFunctionCallWrapperLowering,
|
||||||
name = "MainFunctionCallWrapperLowering",
|
name = "MainFunctionCallWrapperLowering",
|
||||||
description = "Generate main function call inside the wrapper-function"
|
description = "Generate main function call inside the wrapper-function"
|
||||||
).toModuleLowering()
|
)
|
||||||
|
|
||||||
val loweringList = listOf<Lowering>(
|
val loweringList = listOf<SimpleNamedCompilerPhase<JsIrBackendContext, IrModuleFragment, IrModuleFragment>>(
|
||||||
scriptRemoveReceiverLowering,
|
scriptRemoveReceiverLowering,
|
||||||
validateIrBeforeLowering,
|
validateIrBeforeLowering,
|
||||||
preventExportOfSyntheticDeclarationsLowering,
|
preventExportOfSyntheticDeclarationsLowering,
|
||||||
@@ -973,53 +888,53 @@ val jsPhases = SameTypeNamedCompilerPhase(
|
|||||||
nlevels = 1
|
nlevels = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
private val es6CollectConstructorsWhichNeedBoxParameterLowering = makeDeclarationTransformerPhase(
|
private val es6CollectConstructorsWhichNeedBoxParameterLowering = makeIrModulePhase(
|
||||||
::ES6CollectConstructorsWhichNeedBoxParameters,
|
::ES6CollectConstructorsWhichNeedBoxParameters,
|
||||||
name = "ES6CollectConstructorsWhichNeedBoxParameters",
|
name = "ES6CollectConstructorsWhichNeedBoxParameters",
|
||||||
description = "[Optimization] Collect all of the constructors which requires box parameter",
|
description = "[Optimization] Collect all of the constructors which requires box parameter",
|
||||||
)
|
)
|
||||||
|
|
||||||
private val es6BoxParameterOptimization = makeBodyLoweringPhase(
|
private val es6BoxParameterOptimization = makeIrModulePhase(
|
||||||
::ES6ConstructorBoxParameterOptimizationLowering,
|
::ES6ConstructorBoxParameterOptimizationLowering,
|
||||||
name = "ES6ConstructorBoxParameterOptimizationLowering",
|
name = "ES6ConstructorBoxParameterOptimizationLowering",
|
||||||
description = "[Optimization] Remove box parameter from the constructors which don't require box parameter",
|
description = "[Optimization] Remove box parameter from the constructors which don't require box parameter",
|
||||||
prerequisite = setOf(es6CollectConstructorsWhichNeedBoxParameterLowering)
|
prerequisite = setOf(es6CollectConstructorsWhichNeedBoxParameterLowering)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val es6CollectPrimaryConstructorsWhichCouldBeOptimizedLowering = makeDeclarationTransformerPhase(
|
private val es6CollectPrimaryConstructorsWhichCouldBeOptimizedLowering = makeIrModulePhase(
|
||||||
::ES6CollectPrimaryConstructorsWhichCouldBeOptimizedLowering,
|
::ES6CollectPrimaryConstructorsWhichCouldBeOptimizedLowering,
|
||||||
name = "ES6CollectPrimaryConstructorsWhichCouldBeOptimizedLowering",
|
name = "ES6CollectPrimaryConstructorsWhichCouldBeOptimizedLowering",
|
||||||
description = "[Optimization] Collect all of the constructors which could be translated into a regular constructor",
|
description = "[Optimization] Collect all of the constructors which could be translated into a regular constructor",
|
||||||
)
|
)
|
||||||
|
|
||||||
private val es6PrimaryConstructorOptimizationLowering = makeDeclarationTransformerPhase(
|
private val es6PrimaryConstructorOptimizationLowering = makeIrModulePhase(
|
||||||
::ES6PrimaryConstructorOptimizationLowering,
|
::ES6PrimaryConstructorOptimizationLowering,
|
||||||
name = "ES6PrimaryConstructorOptimizationLowering",
|
name = "ES6PrimaryConstructorOptimizationLowering",
|
||||||
description = "[Optimization] Replace synthetically generated static fabric method with a plain old ES6 constructors whenever it's possible",
|
description = "[Optimization] Replace synthetically generated static fabric method with a plain old ES6 constructors whenever it's possible",
|
||||||
prerequisite = setOf(es6CollectPrimaryConstructorsWhichCouldBeOptimizedLowering)
|
prerequisite = setOf(es6CollectPrimaryConstructorsWhichCouldBeOptimizedLowering)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val es6PrimaryConstructorUsageOptimizationLowering = makeBodyLoweringPhase(
|
private val es6PrimaryConstructorUsageOptimizationLowering = makeIrModulePhase(
|
||||||
::ES6PrimaryConstructorUsageOptimizationLowering,
|
::ES6PrimaryConstructorUsageOptimizationLowering,
|
||||||
name = "ES6PrimaryConstructorUsageOptimizationLowering",
|
name = "ES6PrimaryConstructorUsageOptimizationLowering",
|
||||||
description = "[Optimization] Replace usage of synthetically generated static fabric method with a plain old ES6 constructors whenever it's possible",
|
description = "[Optimization] Replace usage of synthetically generated static fabric method with a plain old ES6 constructors whenever it's possible",
|
||||||
prerequisite = setOf(es6BoxParameterOptimization, es6PrimaryConstructorOptimizationLowering)
|
prerequisite = setOf(es6BoxParameterOptimization, es6PrimaryConstructorOptimizationLowering)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val purifyObjectInstanceGetters = makeDeclarationTransformerPhase(
|
private val purifyObjectInstanceGetters = makeIrModulePhase(
|
||||||
::PurifyObjectInstanceGettersLowering,
|
::PurifyObjectInstanceGettersLowering,
|
||||||
name = "PurifyObjectInstanceGettersLowering",
|
name = "PurifyObjectInstanceGettersLowering",
|
||||||
description = "[Optimization] Make object instance getter functions pure whenever it's possible",
|
description = "[Optimization] Make object instance getter functions pure whenever it's possible",
|
||||||
)
|
)
|
||||||
|
|
||||||
private val inlineObjectsWithPureInitialization = makeBodyLoweringPhase(
|
private val inlineObjectsWithPureInitialization = makeIrModulePhase(
|
||||||
::InlineObjectsWithPureInitializationLowering,
|
::InlineObjectsWithPureInitializationLowering,
|
||||||
name = "InlineObjectsWithPureInitializationLowering",
|
name = "InlineObjectsWithPureInitializationLowering",
|
||||||
description = "[Optimization] Inline object instance fields getters whenever it's possible",
|
description = "[Optimization] Inline object instance fields getters whenever it's possible",
|
||||||
prerequisite = setOf(purifyObjectInstanceGetters)
|
prerequisite = setOf(purifyObjectInstanceGetters)
|
||||||
)
|
)
|
||||||
|
|
||||||
val optimizationLoweringList = listOf<Lowering>(
|
val optimizationLoweringList = listOf<SimpleNamedCompilerPhase<JsIrBackendContext, IrModuleFragment, IrModuleFragment>>(
|
||||||
es6CollectConstructorsWhichNeedBoxParameterLowering,
|
es6CollectConstructorsWhichNeedBoxParameterLowering,
|
||||||
es6CollectPrimaryConstructorsWhichCouldBeOptimizedLowering,
|
es6CollectPrimaryConstructorsWhichCouldBeOptimizedLowering,
|
||||||
es6BoxParameterOptimization,
|
es6BoxParameterOptimization,
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ fun compileIr(
|
|||||||
val phaserState = PhaserState<IrModuleFragment>()
|
val phaserState = PhaserState<IrModuleFragment>()
|
||||||
loweringList.forEachIndexed { _, lowering ->
|
loweringList.forEachIndexed { _, lowering ->
|
||||||
allModules.forEach { module ->
|
allModules.forEach { module ->
|
||||||
lowering.modulePhase.invoke(phaseConfig, phaserState, context, module)
|
lowering.invoke(phaseConfig, phaserState, context, module)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ fun lowerPreservingTags(
|
|||||||
loweringList.forEachIndexed { i, lowering ->
|
loweringList.forEachIndexed { i, lowering ->
|
||||||
controller.currentStage = i + 1
|
controller.currentStage = i + 1
|
||||||
modules.forEach { module ->
|
modules.forEach { module ->
|
||||||
lowering.modulePhase.invoke(phaseConfig, phaserState, context, module)
|
lowering.invoke(phaseConfig, phaserState, context, module)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ fun optimizeProgramByIr(
|
|||||||
val phaserState = PhaserState<IrModuleFragment>()
|
val phaserState = PhaserState<IrModuleFragment>()
|
||||||
optimizationLoweringList.forEachIndexed { _, lowering ->
|
optimizationLoweringList.forEachIndexed { _, lowering ->
|
||||||
modules.forEach { module ->
|
modules.forEach { module ->
|
||||||
lowering.modulePhase.invoke(phaseConfig, phaserState, context, module)
|
lowering.invoke(phaseConfig, phaserState, context, module)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user