New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix for SI-5672 #596
fix for SI-5672 #596
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1646,7 +1646,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL | |
// TODO: if patterns allow switch but the type of the scrutinee doesn't, cast (type-test) the scrutinee to the corresponding switchable type and switch on the result | ||
if (regularSwitchMaker.switchableTpe(scrutSym.tpe)) { | ||
val caseDefsWithDefault = regularSwitchMaker(cases map {c => (scrutSym, c)}, pt) | ||
if (caseDefsWithDefault.length <= 2) None // not worth emitting a switch... also, the optimizer has trouble digesting tiny switches, apparently, so let's be nice and not generate them | ||
if (caseDefsWithDefault isEmpty) None // not worth emitting a switch. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So is the optimizer now happy with one-branch switches? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the changes above result in that one-branch-switch becoming straight-line code, a comment in SI-5672 shows the javap output for it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great! |
||
else { | ||
// match on scrutSym -- converted to an int if necessary -- not on scrut directly (to avoid duplicating scrut) | ||
val scrutToInt: Tree = | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assertion should probably go inside the constructor of
Instruction
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's the right thing to do but we aren't there yet. I've created a ticket for that: https://issues.scala-lang.org/browse/SI-5819