diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-01-16 16:27:05 -0800 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-01-17 12:45:18 -0800 |
commit | f5397818aa6c9822ce6593e3eec02edfffdc4f2e (patch) | |
tree | 42e4d6503e947ae62c2de0864110586da9ff89c9 /test/files/pos/t6942/t6942.scala | |
parent | 1a63cf8b9b48c98fa754a1eb6dcfe35220016c74 (diff) | |
download | scala-f5397818aa6c9822ce6593e3eec02edfffdc4f2e.tar.gz scala-f5397818aa6c9822ce6593e3eec02edfffdc4f2e.tar.bz2 scala-f5397818aa6c9822ce6593e3eec02edfffdc4f2e.zip |
SI-6942 more efficient unreachability analysis
Avoid blowing the stack/the analysis budget by more eagerly translating
the propositions that model matches to CNF.
First building a large proposition that represents the match,
and then converting to CNF tends to blow the stack.
Luckily, it's easy to convert to CNF as we go.
The optimization relies on `CNF(P1 /\ ... /\ PN) == CNF(P1) ++ CNF(...) ++ CNF(PN)`:
Normalizing a conjunction of propositions
yields the same formula as
concatenating the normalized conjuncts.
CNF conversion is expensive for large propositions,
so we push it down into the conjunction and
then concatenate the resulting arrays of clauses (which is cheap).
(CNF converts a free-form proposition into an `Array[Set[Lit]]`, where:
- the Array's elements are /\'ed together;
- and the Set's elements are \/'ed;
- a Lit is a possibly negated variable.)
NOTE:
- removeVarEq may throw an AnalysisBudget.Exception
- also reworked the interface used to build formula,
so that we can more easily plug in SAT4J when the time comes
Diffstat (limited to 'test/files/pos/t6942/t6942.scala')
-rw-r--r-- | test/files/pos/t6942/t6942.scala | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/test/files/pos/t6942/t6942.scala b/test/files/pos/t6942/t6942.scala new file mode 100644 index 0000000000..77963d2634 --- /dev/null +++ b/test/files/pos/t6942/t6942.scala @@ -0,0 +1,64 @@ +// not a peep out of the pattern matcher's unreachability analysis +// its budget should suffice for these simple matches (they do have a large search space) +class Test { + import foo.Bar // a large enum + def exhaustUnreachabilitysStack_ENUM_STYLE = (null: Bar) match { + case Bar.BULGARIA => + case _ => + } + + // lots of strings + def exhaustUnreachabilitysStack_StringStyle = "foo" match { + case "a" => + case "b" => + case "c" => + case "d" => + case "e" => + case "f" => + case "aa" => + case "ba" => + case "ca" => + case "da" => + case "ea" => + case "f1a" => + case "a1a" => + case "b1a" => + case "c1a" => + case "d1a" => + case "e1a" => + case "f1a2" => + case "f1a0" => + case "a1a2" => + case "b1a2" => + case "c1a2" => + case "d1a2" => + case "e1a2" => + case "f1a3" => + case "_a" => + case "_b" => + case "_c" => + case "_d" => + case "_e" => + case "_f" => + case "_aa" => + case "_ba" => + case "_ca" => + case "_da" => + case "_ea" => + case "_f1a" => + case "_a1a" => + case "_b1a" => + case "_c1a" => + case "_d1a" => + case "_e1a" => + case "_f1a0" => + case "_f1a2" => + case "_a1a2" => + case "_b1a2" => + case "_c1a2" => + case "_d1a2" => + case "_e1a2" => + case "_f1a3" => + case _ => + } +} |