Fix #9268: Scala.js: Add support for switch-Matches. #9411
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This implementation has been ported from the scalac backend, but is much simpler because it does not have to deal with hacks around scalac's LabelDefs.
As preliminary work: For switch-Matches in PatMap, convert scrutinee and alternatives to Int.
In JVM bytecode as well in Scala.js IR, switches only work with primitive ints. Therefore, it makes more sense to convert the scrutinee and alternatives of switch-Matches to Ints early.
This is also what scalac does. See
RegularSwitchMaker
inpatmat/MatchOptimization.scala
.The JVM back-end tolerates non-ints due its aggressive and blind adaptations everywhere (not because of a deliberate action to support non-Ints). However, the Scala.js back-end does not like receiving non-Ints in
Match
es, because it is much more conservative in where it inserts adaptations (i.e., almost nowhere).