IR: refactor performByIrFile a little
Take a list of phases instead of the CompositePhase, to make stacktraces nicer and avoid quadratic time of phase construction.
This commit is contained in:
+9
-11
@@ -132,27 +132,24 @@ fun <Context : CommonBackendContext> namedOpUnitPhase(
|
||||
fun <Context : CommonBackendContext> performByIrFile(
|
||||
name: String = "PerformByIrFile",
|
||||
description: String = "Perform phases by IrFile",
|
||||
prerequisite: Set<NamedCompilerPhase<Context, *>> = emptySet(),
|
||||
preconditions: Set<Checker<IrModuleFragment>> = emptySet(),
|
||||
postconditions: Set<Checker<IrModuleFragment>> = emptySet(),
|
||||
stickyPostconditions: Set<Checker<IrModuleFragment>> = emptySet(),
|
||||
actions: Set<Action<IrModuleFragment, Context>> = setOf(defaultDumper),
|
||||
lower: CompilerPhase<Context, IrFile, IrFile>
|
||||
lower: List<CompilerPhase<Context, IrFile, IrFile>>
|
||||
): NamedCompilerPhase<Context, IrModuleFragment> =
|
||||
namedIrModulePhase(
|
||||
name, description, prerequisite, PerformByIrFilePhase(lower), preconditions, postconditions, stickyPostconditions, actions,
|
||||
nlevels = 1,
|
||||
name, description, emptySet(), PerformByIrFilePhase(lower), emptySet(), emptySet(), emptySet(),
|
||||
setOf(defaultDumper), nlevels = 1,
|
||||
)
|
||||
|
||||
private class PerformByIrFilePhase<Context : CommonBackendContext>(
|
||||
private val lower: CompilerPhase<Context, IrFile, IrFile>
|
||||
private val lower: List<CompilerPhase<Context, IrFile, IrFile>>
|
||||
) : SameTypeCompilerPhase<Context, IrModuleFragment> {
|
||||
override fun invoke(
|
||||
phaseConfig: PhaseConfig, phaserState: PhaserState<IrModuleFragment>, context: Context, input: IrModuleFragment
|
||||
): IrModuleFragment {
|
||||
for (irFile in input.files) {
|
||||
try {
|
||||
lower.invoke(phaseConfig, phaserState.changeType(), context, irFile)
|
||||
for (phase in lower) {
|
||||
phase.invoke(phaseConfig, phaserState.changeType(), context, irFile)
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
CodegenUtil.reportBackendException(e, "IR lowering", irFile.fileEntry.name)
|
||||
}
|
||||
@@ -162,7 +159,8 @@ private class PerformByIrFilePhase<Context : CommonBackendContext>(
|
||||
return input
|
||||
}
|
||||
|
||||
override fun getNamedSubphases(startDepth: Int) = lower.getNamedSubphases(startDepth)
|
||||
override fun getNamedSubphases(startDepth: Int): List<Pair<Int, NamedCompilerPhase<Context, *>>> =
|
||||
lower.flatMap { it.getNamedSubphases(startDepth) }
|
||||
}
|
||||
|
||||
fun <Context : CommonBackendContext> makeIrFilePhase(
|
||||
|
||||
@@ -270,109 +270,109 @@ private val kotlinNothingValueExceptionPhase = makeIrFilePhase<CommonBackendCont
|
||||
description = "Throw proper exception for calls returning value of type 'kotlin.Nothing'"
|
||||
)
|
||||
|
||||
@Suppress("Reformat")
|
||||
private val jvmFilePhases =
|
||||
typeAliasAnnotationMethodsPhase then
|
||||
stripTypeAliasDeclarationsPhase then
|
||||
provisionalFunctionExpressionPhase then
|
||||
private val jvmFilePhases = listOf(
|
||||
typeAliasAnnotationMethodsPhase,
|
||||
stripTypeAliasDeclarationsPhase,
|
||||
provisionalFunctionExpressionPhase,
|
||||
|
||||
jvmOverloadsAnnotationPhase then
|
||||
mainMethodGenerationPhase then
|
||||
jvmOverloadsAnnotationPhase,
|
||||
mainMethodGenerationPhase,
|
||||
|
||||
inventNamesForLocalClassesPhase then
|
||||
kCallableNamePropertyPhase then
|
||||
annotationPhase then
|
||||
polymorphicSignaturePhase then
|
||||
varargPhase then
|
||||
arrayConstructorPhase then
|
||||
checkNotNullPhase then
|
||||
inventNamesForLocalClassesPhase,
|
||||
kCallableNamePropertyPhase,
|
||||
annotationPhase,
|
||||
polymorphicSignaturePhase,
|
||||
varargPhase,
|
||||
arrayConstructorPhase,
|
||||
checkNotNullPhase,
|
||||
|
||||
lateinitNullableFieldsPhase then
|
||||
lateinitDeclarationLoweringPhase then
|
||||
lateinitUsageLoweringPhase then
|
||||
lateinitNullableFieldsPhase,
|
||||
lateinitDeclarationLoweringPhase,
|
||||
lateinitUsageLoweringPhase,
|
||||
|
||||
moveOrCopyCompanionObjectFieldsPhase then
|
||||
inlineCallableReferenceToLambdaPhase then
|
||||
propertyReferencePhase then
|
||||
constPhase then
|
||||
propertiesPhase then
|
||||
remapObjectFieldAccesses then
|
||||
anonymousObjectSuperConstructorPhase then
|
||||
tailrecPhase then
|
||||
moveOrCopyCompanionObjectFieldsPhase,
|
||||
inlineCallableReferenceToLambdaPhase,
|
||||
propertyReferencePhase,
|
||||
constPhase,
|
||||
propertiesPhase,
|
||||
remapObjectFieldAccesses,
|
||||
anonymousObjectSuperConstructorPhase,
|
||||
tailrecPhase,
|
||||
|
||||
jvmStandardLibraryBuiltInsPhase then
|
||||
jvmStandardLibraryBuiltInsPhase,
|
||||
|
||||
forLoopsPhase then
|
||||
jvmInlineClassPhase then
|
||||
forLoopsPhase,
|
||||
jvmInlineClassPhase,
|
||||
|
||||
sharedVariablesPhase then
|
||||
sharedVariablesPhase,
|
||||
|
||||
makePatchParentsPhase(1) then
|
||||
makePatchParentsPhase(1),
|
||||
|
||||
enumWhenPhase then
|
||||
singletonReferencesPhase then
|
||||
enumWhenPhase,
|
||||
singletonReferencesPhase,
|
||||
|
||||
functionReferencePhase then
|
||||
singleAbstractMethodPhase then
|
||||
assertionPhase then
|
||||
returnableBlocksPhase then
|
||||
localDeclarationsPhase then
|
||||
jvmLocalClassExtractionPhase then
|
||||
staticLambdaPhase then
|
||||
functionReferencePhase,
|
||||
singleAbstractMethodPhase,
|
||||
assertionPhase,
|
||||
returnableBlocksPhase,
|
||||
localDeclarationsPhase,
|
||||
jvmLocalClassExtractionPhase,
|
||||
staticLambdaPhase,
|
||||
|
||||
jvmDefaultConstructorPhase then
|
||||
jvmDefaultConstructorPhase,
|
||||
|
||||
flattenStringConcatenationPhase then
|
||||
foldConstantLoweringPhase then
|
||||
computeStringTrimPhase then
|
||||
jvmStringConcatenationLowering then
|
||||
flattenStringConcatenationPhase,
|
||||
foldConstantLoweringPhase,
|
||||
computeStringTrimPhase,
|
||||
jvmStringConcatenationLowering,
|
||||
|
||||
defaultArgumentStubPhase then
|
||||
defaultArgumentInjectorPhase then
|
||||
defaultArgumentCleanerPhase then
|
||||
defaultArgumentStubPhase,
|
||||
defaultArgumentInjectorPhase,
|
||||
defaultArgumentCleanerPhase,
|
||||
|
||||
interfacePhase then
|
||||
inheritedDefaultMethodsOnClassesPhase then
|
||||
interfaceSuperCallsPhase then
|
||||
interfaceDefaultCallsPhase then
|
||||
interfaceObjectCallsPhase then
|
||||
interfacePhase,
|
||||
inheritedDefaultMethodsOnClassesPhase,
|
||||
interfaceSuperCallsPhase,
|
||||
interfaceDefaultCallsPhase,
|
||||
interfaceObjectCallsPhase,
|
||||
|
||||
tailCallOptimizationPhase then
|
||||
addContinuationPhase then
|
||||
tailCallOptimizationPhase,
|
||||
addContinuationPhase,
|
||||
|
||||
innerClassesPhase then
|
||||
innerClassesMemberBodyPhase then
|
||||
innerClassConstructorCallsPhase then
|
||||
innerClassesPhase,
|
||||
innerClassesMemberBodyPhase,
|
||||
innerClassConstructorCallsPhase,
|
||||
|
||||
makePatchParentsPhase(2) then
|
||||
makePatchParentsPhase(2),
|
||||
|
||||
enumClassPhase then
|
||||
objectClassPhase then
|
||||
staticInitializersPhase then
|
||||
initializersPhase then
|
||||
initializersCleanupPhase then
|
||||
collectionStubMethodLowering then
|
||||
functionNVarargBridgePhase then
|
||||
jvmStaticAnnotationPhase then
|
||||
staticDefaultFunctionPhase then
|
||||
bridgePhase then
|
||||
syntheticAccessorPhase then
|
||||
enumClassPhase,
|
||||
objectClassPhase,
|
||||
staticInitializersPhase,
|
||||
initializersPhase,
|
||||
initializersCleanupPhase,
|
||||
collectionStubMethodLowering,
|
||||
functionNVarargBridgePhase,
|
||||
jvmStaticAnnotationPhase,
|
||||
staticDefaultFunctionPhase,
|
||||
bridgePhase,
|
||||
syntheticAccessorPhase,
|
||||
|
||||
jvmArgumentNullabilityAssertions then
|
||||
toArrayPhase then
|
||||
jvmOptimizationLoweringPhase then
|
||||
ifNullExpressionsFusionPhase then
|
||||
additionalClassAnnotationPhase then
|
||||
typeOperatorLowering then
|
||||
replaceKFunctionInvokeWithFunctionInvokePhase then
|
||||
kotlinNothingValueExceptionPhase then
|
||||
jvmArgumentNullabilityAssertions,
|
||||
toArrayPhase,
|
||||
jvmOptimizationLoweringPhase,
|
||||
ifNullExpressionsFusionPhase,
|
||||
additionalClassAnnotationPhase,
|
||||
typeOperatorLowering,
|
||||
replaceKFunctionInvokeWithFunctionInvokePhase,
|
||||
kotlinNothingValueExceptionPhase,
|
||||
|
||||
checkLocalNamesWithOldBackendPhase then
|
||||
checkLocalNamesWithOldBackendPhase,
|
||||
|
||||
renameFieldsPhase then
|
||||
fakeInliningLocalVariablesLowering then
|
||||
renameFieldsPhase,
|
||||
fakeInliningLocalVariablesLowering,
|
||||
|
||||
makePatchParentsPhase(3)
|
||||
makePatchParentsPhase(3)
|
||||
)
|
||||
|
||||
val jvmPhases = namedIrModulePhase(
|
||||
name = "IrLowering",
|
||||
|
||||
Reference in New Issue
Block a user