From 64acb46ab796a01bb5186385b7f8568748a857be Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Mon, 2 Jul 2012 10:55:40 +0200 Subject: 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) --- test/files/neg/t5830.flags | 1 + 1 file changed, 1 insertion(+) create mode 100644 test/files/neg/t5830.flags (limited to 'test/files/neg/t5830.flags') diff --git a/test/files/neg/t5830.flags b/test/files/neg/t5830.flags new file mode 100644 index 0000000000..e8fb65d50c --- /dev/null +++ b/test/files/neg/t5830.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file -- cgit v1.2.3