IR: remove FunctionLoweringPass, refactor usages to FileLoweringPass

FunctionLoweringPass didn't add much value over FileLoweringPass, but
had a hidden footgun (like ClassLoweringPass) in that if your lowering
pass invoked a visitor/transformer on the function body and you forgot
to override visitFunction to stop visiting nested functions,
runOnFilePostfix would work with the complexity of the squared number of
nesting levels. It looks like this was happening with K/N's
DataClassOperatorsLowering (I haven't measured though).
This commit is contained in:
Alexander Udalov
2020-10-12 14:33:03 +02:00
parent c110031935
commit b5695188f9
@@ -53,12 +53,6 @@ interface DeclarationContainerLoweringPass : FileLoweringPass {
override fun lower(irFile: IrFile) = runOnFilePostfix(irFile)
}
interface FunctionLoweringPass : FileLoweringPass {
fun lower(irFunction: IrFunction)
override fun lower(irFile: IrFile) = runOnFilePostfix(irFile)
}
interface BodyLoweringPass : FileLoweringPass {
fun lower(irBody: IrBody, container: IrDeclaration)
@@ -178,19 +172,6 @@ private class BodyLoweringVisitor(
}
}
fun FunctionLoweringPass.runOnFilePostfix(irFile: IrFile) {
irFile.acceptVoid(object : IrElementVisitorVoid {
override fun visitElement(element: IrElement) {
element.acceptChildrenVoid(this)
}
override fun visitFunction(declaration: IrFunction) {
declaration.acceptChildrenVoid(this)
lower(declaration)
}
})
}
interface DeclarationTransformer : FileLoweringPass {
fun transformFlat(declaration: IrDeclaration): List<IrDeclaration>?