Skip to content

Commit 32c3395

Browse files
committed
Handle If in BCodeBodyBuilder.genCond().
This is more for completeness of `genCond()`. It can now push down the jumps inside all the control structures for which it makes sense to do so. It typically applies when the condition of an `if` or `while` is an `if..else` expression. It is however not always a win. If the result of the nested `if`s must be converted to a boolean anyway, doing this will result in duplication of the conversion to boolean. A jardiff on the bootstrapped `scala3-compiler.jar` shows 191 additions and 287 deletions, suggesting that, on average, this is good to have.
1 parent d260adf commit 32c3395

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,6 +1570,15 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
15701570
emitLocalVarScopes()
15711571
varsInScope = savedScope
15721572

1573+
case If(condp, thenp, elsep) =>
1574+
val innerSuccess = new asm.Label
1575+
val innerFailure = new asm.Label
1576+
genCond(condp, innerSuccess, innerFailure, targetIfNoJump = innerSuccess)
1577+
markProgramPoint(innerSuccess)
1578+
genCond(thenp, success, failure, targetIfNoJump = innerFailure)
1579+
markProgramPoint(innerFailure)
1580+
genCond(elsep, success, failure, targetIfNoJump)
1581+
15731582
case _ => loadAndTestBoolean()
15741583
}
15751584

0 commit comments

Comments
 (0)