diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-07-02 10:55:40 +0200 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-07-03 15:43:00 +0200 |
commit | 64acb46ab796a01bb5186385b7f8568748a857be (patch) | |
tree | 085582b323bceb452731ad84f23a2e3d7c228ea9 /docs | |
parent | bc2e6fe8bf20b2aa985ea78a2c610ac33497da38 (diff) | |
download | scala-64acb46ab796a01bb5186385b7f8568748a857be.tar.gz scala-64acb46ab796a01bb5186385b7f8568748a857be.tar.bz2 scala-64acb46ab796a01bb5186385b7f8568748a857be.zip |
SI-5830 switches: support guards, unreachability
turn switches with guards into guard-free switches by collecting all cases
that are (possibly) guarded by different guards but that switch on the same constant,
and pushing the implied if-then-else into the collapsed case body
```
case C if G1 => B1
case C if Gi => Bi
case C if GN => BN
```
becomes
```
case C => if (G1) B1
else if (Gi) Bi
else if (GN) BN
else default() // not necessary if GN == EmptyTree
```
default() is a jump to the default case; to enable this, we wrap a default() { } labeldef
around the last case's body (the user-defined default or the synthetic case that throws the matcherror)
so we can jump to the default case after the last guard is checked
(assuming unreachability is checked, once we ended up in a non-default case,
one of the guards either matches or we go to the default case)
the unreachability analysis is minimal -- we simply check (after rewriting to guard-free form)
that:
- there are no duplicate cases
- the default case comes last
misc notes:
- can't jump in exception handlers (TODO: a more fine-grained analysis on when we need to jump)
- work around SI-6015 (test file run/t5830.scala crashed the inliner)
- propagate type of case body to label def of default case
(needed for existentials, see e.g., t2683)
- the default(){} LabelDef breaks SelectiveANFTransform -- workaround: don't write guarded switches in CPS code
(do the above transformation manually)
Diffstat (limited to 'docs')
0 files changed, 0 insertions, 0 deletions