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:
Alexander Udalov
2020-07-01 02:38:41 +02:00
parent 4475325ffa
commit 15a969b3ba
2 changed files with 90 additions and 92 deletions
@@ -132,27 +132,24 @@ fun <Context : CommonBackendContext> namedOpUnitPhase(
fun <Context : CommonBackendContext> performByIrFile( fun <Context : CommonBackendContext> performByIrFile(
name: String = "PerformByIrFile", name: String = "PerformByIrFile",
description: String = "Perform phases by IrFile", description: String = "Perform phases by IrFile",
prerequisite: Set<NamedCompilerPhase<Context, *>> = emptySet(), lower: List<CompilerPhase<Context, IrFile, IrFile>>
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>
): NamedCompilerPhase<Context, IrModuleFragment> = ): NamedCompilerPhase<Context, IrModuleFragment> =
namedIrModulePhase( namedIrModulePhase(
name, description, prerequisite, PerformByIrFilePhase(lower), preconditions, postconditions, stickyPostconditions, actions, name, description, emptySet(), PerformByIrFilePhase(lower), emptySet(), emptySet(), emptySet(),
nlevels = 1, setOf(defaultDumper), nlevels = 1,
) )
private class PerformByIrFilePhase<Context : CommonBackendContext>( private class PerformByIrFilePhase<Context : CommonBackendContext>(
private val lower: CompilerPhase<Context, IrFile, IrFile> private val lower: List<CompilerPhase<Context, IrFile, IrFile>>
) : SameTypeCompilerPhase<Context, IrModuleFragment> { ) : SameTypeCompilerPhase<Context, IrModuleFragment> {
override fun invoke( override fun invoke(
phaseConfig: PhaseConfig, phaserState: PhaserState<IrModuleFragment>, context: Context, input: IrModuleFragment phaseConfig: PhaseConfig, phaserState: PhaserState<IrModuleFragment>, context: Context, input: IrModuleFragment
): IrModuleFragment { ): IrModuleFragment {
for (irFile in input.files) { for (irFile in input.files) {
try { try {
lower.invoke(phaseConfig, phaserState.changeType(), context, irFile) for (phase in lower) {
phase.invoke(phaseConfig, phaserState.changeType(), context, irFile)
}
} catch (e: Throwable) { } catch (e: Throwable) {
CodegenUtil.reportBackendException(e, "IR lowering", irFile.fileEntry.name) CodegenUtil.reportBackendException(e, "IR lowering", irFile.fileEntry.name)
} }
@@ -162,7 +159,8 @@ private class PerformByIrFilePhase<Context : CommonBackendContext>(
return input 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( 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'" description = "Throw proper exception for calls returning value of type 'kotlin.Nothing'"
) )
@Suppress("Reformat") private val jvmFilePhases = listOf(
private val jvmFilePhases = typeAliasAnnotationMethodsPhase,
typeAliasAnnotationMethodsPhase then stripTypeAliasDeclarationsPhase,
stripTypeAliasDeclarationsPhase then provisionalFunctionExpressionPhase,
provisionalFunctionExpressionPhase then
jvmOverloadsAnnotationPhase then jvmOverloadsAnnotationPhase,
mainMethodGenerationPhase then mainMethodGenerationPhase,
inventNamesForLocalClassesPhase then inventNamesForLocalClassesPhase,
kCallableNamePropertyPhase then kCallableNamePropertyPhase,
annotationPhase then annotationPhase,
polymorphicSignaturePhase then polymorphicSignaturePhase,
varargPhase then varargPhase,
arrayConstructorPhase then arrayConstructorPhase,
checkNotNullPhase then checkNotNullPhase,
lateinitNullableFieldsPhase then lateinitNullableFieldsPhase,
lateinitDeclarationLoweringPhase then lateinitDeclarationLoweringPhase,
lateinitUsageLoweringPhase then lateinitUsageLoweringPhase,
moveOrCopyCompanionObjectFieldsPhase then moveOrCopyCompanionObjectFieldsPhase,
inlineCallableReferenceToLambdaPhase then inlineCallableReferenceToLambdaPhase,
propertyReferencePhase then propertyReferencePhase,
constPhase then constPhase,
propertiesPhase then propertiesPhase,
remapObjectFieldAccesses then remapObjectFieldAccesses,
anonymousObjectSuperConstructorPhase then anonymousObjectSuperConstructorPhase,
tailrecPhase then tailrecPhase,
jvmStandardLibraryBuiltInsPhase then jvmStandardLibraryBuiltInsPhase,
forLoopsPhase then forLoopsPhase,
jvmInlineClassPhase then jvmInlineClassPhase,
sharedVariablesPhase then sharedVariablesPhase,
makePatchParentsPhase(1) then makePatchParentsPhase(1),
enumWhenPhase then enumWhenPhase,
singletonReferencesPhase then singletonReferencesPhase,
functionReferencePhase then functionReferencePhase,
singleAbstractMethodPhase then singleAbstractMethodPhase,
assertionPhase then assertionPhase,
returnableBlocksPhase then returnableBlocksPhase,
localDeclarationsPhase then localDeclarationsPhase,
jvmLocalClassExtractionPhase then jvmLocalClassExtractionPhase,
staticLambdaPhase then staticLambdaPhase,
jvmDefaultConstructorPhase then jvmDefaultConstructorPhase,
flattenStringConcatenationPhase then flattenStringConcatenationPhase,
foldConstantLoweringPhase then foldConstantLoweringPhase,
computeStringTrimPhase then computeStringTrimPhase,
jvmStringConcatenationLowering then jvmStringConcatenationLowering,
defaultArgumentStubPhase then defaultArgumentStubPhase,
defaultArgumentInjectorPhase then defaultArgumentInjectorPhase,
defaultArgumentCleanerPhase then defaultArgumentCleanerPhase,
interfacePhase then interfacePhase,
inheritedDefaultMethodsOnClassesPhase then inheritedDefaultMethodsOnClassesPhase,
interfaceSuperCallsPhase then interfaceSuperCallsPhase,
interfaceDefaultCallsPhase then interfaceDefaultCallsPhase,
interfaceObjectCallsPhase then interfaceObjectCallsPhase,
tailCallOptimizationPhase then tailCallOptimizationPhase,
addContinuationPhase then addContinuationPhase,
innerClassesPhase then innerClassesPhase,
innerClassesMemberBodyPhase then innerClassesMemberBodyPhase,
innerClassConstructorCallsPhase then innerClassConstructorCallsPhase,
makePatchParentsPhase(2) then makePatchParentsPhase(2),
enumClassPhase then enumClassPhase,
objectClassPhase then objectClassPhase,
staticInitializersPhase then staticInitializersPhase,
initializersPhase then initializersPhase,
initializersCleanupPhase then initializersCleanupPhase,
collectionStubMethodLowering then collectionStubMethodLowering,
functionNVarargBridgePhase then functionNVarargBridgePhase,
jvmStaticAnnotationPhase then jvmStaticAnnotationPhase,
staticDefaultFunctionPhase then staticDefaultFunctionPhase,
bridgePhase then bridgePhase,
syntheticAccessorPhase then syntheticAccessorPhase,
jvmArgumentNullabilityAssertions then jvmArgumentNullabilityAssertions,
toArrayPhase then toArrayPhase,
jvmOptimizationLoweringPhase then jvmOptimizationLoweringPhase,
ifNullExpressionsFusionPhase then ifNullExpressionsFusionPhase,
additionalClassAnnotationPhase then additionalClassAnnotationPhase,
typeOperatorLowering then typeOperatorLowering,
replaceKFunctionInvokeWithFunctionInvokePhase then replaceKFunctionInvokeWithFunctionInvokePhase,
kotlinNothingValueExceptionPhase then kotlinNothingValueExceptionPhase,
checkLocalNamesWithOldBackendPhase then checkLocalNamesWithOldBackendPhase,
renameFieldsPhase then renameFieldsPhase,
fakeInliningLocalVariablesLowering then fakeInliningLocalVariablesLowering,
makePatchParentsPhase(3) makePatchParentsPhase(3)
)
val jvmPhases = namedIrModulePhase( val jvmPhases = namedIrModulePhase(
name = "IrLowering", name = "IrLowering",