File tree 1 file changed +38
-0
lines changed
compiler/src/dotty/tools/dotc/transform/patmat
1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ package dotty .tools .dotc .transform .patmat
2
+ package `new logic`
3
+
4
+ import dotty .tools .dotc .core .Contexts .Context
5
+
6
+ /** Checks satisfiability of constraints in an extremely naive way */
7
+ object NaiveConstraintChecker {
8
+ def hasUnsatisfiableConstraints (s : ConstrainedSpace )(implicit ctx : Context ): Boolean =
9
+ ! termsPotentiallySatisfiable(s.termConstraints) ||
10
+ ! typesPotentiallySatisfiable(s.typeConstraints)
11
+
12
+ def termsPotentiallySatisfiable (constraints : List [TermConstraint ]): Boolean =
13
+ constraints.forall {
14
+ case Dummy | Neg (Dummy ) => true
15
+ case AlwaysSatisfied => true
16
+ case Neg (AlwaysSatisfied ) => false
17
+ }
18
+
19
+ @ annotation.tailrec
20
+ def typesPotentiallySatisfiable (constraints : List [TypeConstraint ])(implicit ctx : Context ): Boolean = {
21
+ def comparePair (tpeq1 : TypeEquality , tpeq2 : TypeEquality ) =
22
+ if (tpeq1.tp1 =:= tpeq2.tp1) tpeq1.tp2 =:= tpeq2.tp2 else true
23
+
24
+ @ annotation.tailrec
25
+ def compareOneVsList (tpeq : TypeEquality , constraints : List [TypeConstraint ]): Boolean =
26
+ constraints match {
27
+ case Nil => true
28
+ case (tpeq2 : TypeEquality ) :: rest =>
29
+ comparePair(tpeq, tpeq2) && compareOneVsList(tpeq, rest)
30
+ }
31
+
32
+ constraints match {
33
+ case Nil => true
34
+ case (tpeq : TypeEquality ) :: tail =>
35
+ compareOneVsList(tpeq, tail) && typesPotentiallySatisfiable(tail)
36
+ }
37
+ }
38
+ }
You can’t perform that action at this time.
0 commit comments