From b5695188f9002f10bbd0987c63f64f270df2c2a0 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 12 Oct 2020 14:33:03 +0200 Subject: [PATCH] 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). --- .../jetbrains/kotlin/backend/common/Lower.kt | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/Lower.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/Lower.kt index 8b895aee268..9a0ffa1c699 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/Lower.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/Lower.kt @@ -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?