[JS_IR] More subtle local classes copying in inliner
This commit is contained in:
@@ -8,6 +8,9 @@ package org.jetbrains.kotlin.ir.backend.js
|
|||||||
import org.jetbrains.kotlin.backend.common.*
|
import org.jetbrains.kotlin.backend.common.*
|
||||||
import org.jetbrains.kotlin.backend.common.lower.*
|
import org.jetbrains.kotlin.backend.common.lower.*
|
||||||
import org.jetbrains.kotlin.backend.common.lower.inline.FunctionInlining
|
import org.jetbrains.kotlin.backend.common.lower.inline.FunctionInlining
|
||||||
|
import org.jetbrains.kotlin.backend.common.lower.inline.LocalClassesExtractionFromInlineFunctionsLowering
|
||||||
|
import org.jetbrains.kotlin.backend.common.lower.inline.LocalClassesInInlineFunctionsLowering
|
||||||
|
import org.jetbrains.kotlin.backend.common.lower.inline.LocalClassesInInlineLambdasLowering
|
||||||
import org.jetbrains.kotlin.backend.common.lower.loops.ForLoopsLowering
|
import org.jetbrains.kotlin.backend.common.lower.loops.ForLoopsLowering
|
||||||
import org.jetbrains.kotlin.backend.common.lower.optimizations.FoldConstantLowering
|
import org.jetbrains.kotlin.backend.common.lower.optimizations.FoldConstantLowering
|
||||||
import org.jetbrains.kotlin.backend.common.lower.optimizations.PropertyAccessorInlineLowering
|
import org.jetbrains.kotlin.backend.common.lower.optimizations.PropertyAccessorInlineLowering
|
||||||
@@ -168,11 +171,40 @@ private val arrayConstructorPhase = makeBodyLoweringPhase(
|
|||||||
description = "Transform `Array(size) { index -> value }` into a loop"
|
description = "Transform `Array(size) { index -> value }` into a loop"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private val sharedVariablesLoweringPhase = makeBodyLoweringPhase(
|
||||||
|
::SharedVariablesLowering,
|
||||||
|
name = "SharedVariablesLowering",
|
||||||
|
description = "Box captured mutable variables",
|
||||||
|
prerequisite = setOf(lateinitDeclarationLoweringPhase, lateinitUsageLoweringPhase)
|
||||||
|
)
|
||||||
|
|
||||||
|
private val localClassesInInlineLambdasPhase = makeBodyLoweringPhase(
|
||||||
|
::LocalClassesInInlineLambdasLowering,
|
||||||
|
name = "LocalClassesInInlineLambdasPhase",
|
||||||
|
description = "Extract local classes from inline lambdas"
|
||||||
|
)
|
||||||
|
|
||||||
|
private val localClassesInInlineFunctionsPhase = makeBodyLoweringPhase(
|
||||||
|
::LocalClassesInInlineFunctionsLowering,
|
||||||
|
name = "LocalClassesInInlineFunctionsPhase",
|
||||||
|
description = "Extract local classes from inline functions"
|
||||||
|
)
|
||||||
|
|
||||||
|
private val localClassesExtractionFromInlineFunctionsPhase = makeBodyLoweringPhase(
|
||||||
|
::LocalClassesExtractionFromInlineFunctionsLowering,
|
||||||
|
name = "localClassesExtractionFromInlineFunctionsPhase",
|
||||||
|
description = "Move local classes from inline functions into nearest declaration container",
|
||||||
|
prerequisite = setOf(localClassesInInlineFunctionsPhase)
|
||||||
|
)
|
||||||
|
|
||||||
private val functionInliningPhase = makeBodyLoweringPhase(
|
private val functionInliningPhase = makeBodyLoweringPhase(
|
||||||
::FunctionInlining,
|
::FunctionInlining,
|
||||||
name = "FunctionInliningPhase",
|
name = "FunctionInliningPhase",
|
||||||
description = "Perform function inlining",
|
description = "Perform function inlining",
|
||||||
prerequisite = setOf(expectDeclarationsRemovingPhase)
|
prerequisite = setOf(
|
||||||
|
expectDeclarationsRemovingPhase, sharedVariablesLoweringPhase,
|
||||||
|
localClassesInInlineLambdasPhase, localClassesExtractionFromInlineFunctionsPhase
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val copyInlineFunctionBodyLoweringPhase = makeDeclarationTransformerPhase(
|
private val copyInlineFunctionBodyLoweringPhase = makeDeclarationTransformerPhase(
|
||||||
@@ -263,12 +295,6 @@ private val enumEntryRemovalLoweringPhase = makeDeclarationTransformerPhase(
|
|||||||
prerequisite = setOf(enumUsageLoweringPhase)
|
prerequisite = setOf(enumUsageLoweringPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val sharedVariablesLoweringPhase = makeBodyLoweringPhase(
|
|
||||||
::SharedVariablesLowering,
|
|
||||||
name = "SharedVariablesLowering",
|
|
||||||
description = "Box captured mutable variables"
|
|
||||||
)
|
|
||||||
|
|
||||||
private val callableReferenceLowering = makeBodyLoweringPhase(
|
private val callableReferenceLowering = makeBodyLoweringPhase(
|
||||||
::CallableReferenceLowering,
|
::CallableReferenceLowering,
|
||||||
name = "CallableReferenceLowering",
|
name = "CallableReferenceLowering",
|
||||||
@@ -585,18 +611,21 @@ val loweringList = listOf<Lowering>(
|
|||||||
expectDeclarationsRemovingPhase,
|
expectDeclarationsRemovingPhase,
|
||||||
stripTypeAliasDeclarationsPhase,
|
stripTypeAliasDeclarationsPhase,
|
||||||
arrayConstructorPhase,
|
arrayConstructorPhase,
|
||||||
|
lateinitNullableFieldsPhase,
|
||||||
|
lateinitDeclarationLoweringPhase,
|
||||||
|
lateinitUsageLoweringPhase,
|
||||||
|
sharedVariablesLoweringPhase,
|
||||||
|
localClassesInInlineLambdasPhase,
|
||||||
|
localClassesInInlineFunctionsPhase,
|
||||||
|
localClassesExtractionFromInlineFunctionsPhase,
|
||||||
functionInliningPhase,
|
functionInliningPhase,
|
||||||
copyInlineFunctionBodyLoweringPhase,
|
copyInlineFunctionBodyLoweringPhase,
|
||||||
createScriptFunctionsPhase,
|
createScriptFunctionsPhase,
|
||||||
callableReferenceLowering,
|
callableReferenceLowering,
|
||||||
singleAbstractMethodPhase,
|
singleAbstractMethodPhase,
|
||||||
lateinitNullableFieldsPhase,
|
|
||||||
lateinitDeclarationLoweringPhase,
|
|
||||||
lateinitUsageLoweringPhase,
|
|
||||||
tailrecLoweringPhase,
|
tailrecLoweringPhase,
|
||||||
enumClassConstructorLoweringPhase,
|
enumClassConstructorLoweringPhase,
|
||||||
enumClassConstructorBodyLoweringPhase,
|
enumClassConstructorBodyLoweringPhase,
|
||||||
sharedVariablesLoweringPhase,
|
|
||||||
localDelegatedPropertiesLoweringPhase,
|
localDelegatedPropertiesLoweringPhase,
|
||||||
localDeclarationsLoweringPhase,
|
localDeclarationsLoweringPhase,
|
||||||
localClassExtractionPhase,
|
localClassExtractionPhase,
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
// TODO: inliner doesn't fix usesite of local object (likely for any local inlined class)
|
|
||||||
// IGNORE_BACKEND: JS_IR
|
|
||||||
// NO_CHECK_LAMBDA_INLINING
|
// NO_CHECK_LAMBDA_INLINING
|
||||||
// FILE: 1.kt
|
// FILE: 1.kt
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user