@@ -44,7 +44,7 @@ namespace {
44
44
Type = 1 << 1 ,
45
45
Constructor = 1 << 2 ,
46
46
Disjunct = 1 << 3 ,
47
- BooleanConstant = 1 << 5 ,
47
+ BooleanConstant = 1 << 4 ,
48
48
};
49
49
50
50
// / A data structure for conveniently pattern-matching on the kinds of
@@ -75,27 +75,26 @@ namespace {
75
75
class Space final {
76
76
private:
77
77
SpaceKind Kind;
78
- Type Ty ;
78
+ llvm::PointerIntPair< Type, 1 , bool > TypeAndVal ;
79
79
Identifier Head;
80
80
std::forward_list<Space> Spaces;
81
- bool Val;
82
81
83
82
public:
84
83
explicit Space (Type T)
85
- : Kind (SpaceKind::Type), Ty (T ), Head (Identifier ()),
86
- Spaces ({}), Val ( false ) {}
84
+ : Kind (SpaceKind::Type), TypeAndVal (T, false ), Head (Identifier ()),
85
+ Spaces ({}){}
87
86
explicit Space (Type T, Identifier H, SmallVectorImpl<Space> &SP)
88
- : Kind (SpaceKind::Constructor), Ty (T ), Head (H),
89
- Spaces (SP.begin (), SP.end ()), Val ( false ) {}
87
+ : Kind (SpaceKind::Constructor), TypeAndVal (T, false ), Head (H),
88
+ Spaces (SP.begin (), SP.end ()) {}
90
89
explicit Space (SmallVectorImpl<Space> &SP)
91
- : Kind (SpaceKind::Disjunct), Ty (Type ()), Head ( Identifier () ),
92
- Spaces (SP.begin (), SP.end ()), Val ( false ) {}
90
+ : Kind (SpaceKind::Disjunct), TypeAndVal (Type (), false ),
91
+ Head ( Identifier ()), Spaces (SP.begin (), SP.end ()) {}
93
92
explicit Space ()
94
- : Kind (SpaceKind::Empty), Ty (Type ()), Head (Identifier ()),
95
- Spaces ({}), Val ( false ) {}
93
+ : Kind (SpaceKind::Empty), TypeAndVal (Type (), false ), Head (Identifier ()),
94
+ Spaces ({}) {}
96
95
explicit Space (bool C)
97
- : Kind (SpaceKind::BooleanConstant), Ty (Type ()), Head ( Identifier () ),
98
- Spaces ({}), Val (C ) {}
96
+ : Kind (SpaceKind::BooleanConstant), TypeAndVal (Type (), C ),
97
+ Head ( Identifier ()), Spaces ({} ) {}
99
98
100
99
SpaceKind getKind () const { return Kind; }
101
100
@@ -107,7 +106,7 @@ namespace {
107
106
assert ((getKind () == SpaceKind::Type
108
107
|| getKind () == SpaceKind::Constructor)
109
108
&& " Wrong kind of space tried to access space type" );
110
- return Ty ;
109
+ return TypeAndVal. getPointer () ;
111
110
}
112
111
113
112
Identifier getHead () const {
@@ -126,7 +125,7 @@ namespace {
126
125
bool getBoolValue () const {
127
126
assert (getKind () == SpaceKind::BooleanConstant
128
127
&& " Wrong kind of space tried to access bool value" );
129
- return Val ;
128
+ return TypeAndVal. getInt () ;
130
129
}
131
130
132
131
// An optimization that computes if the difference of this space and
@@ -237,11 +236,8 @@ namespace {
237
236
return true ;
238
237
}
239
238
PAIRCASE (SpaceKind::Constructor, SpaceKind::Disjunct):
240
- // / H(p1, ..., pn) <= (S1 | ... | Sn) iff (this - other) == [EMPTY]
241
- return this ->minus (other).simplify ().isEmpty ();
242
-
243
239
PAIRCASE (SpaceKind::BooleanConstant, SpaceKind::Disjunct): {
244
- // Bool <= (S1 | ... | Sn) iff Bool <= S1 || ... || Bool <= Sn
240
+ // S <= (S1 | ... | Sn) <= S iff (S <= S1) || ... || (S <= Sn)
245
241
for (auto ¶m : other.getSpaces ()) {
246
242
if (this ->isSubspace (param)) {
247
243
return true ;
@@ -617,7 +613,7 @@ namespace {
617
613
}
618
614
break ;
619
615
case SpaceKind::BooleanConstant:
620
- buffer << ((Val ) ? " true" : " false" );
616
+ buffer << ((getBoolValue () ) ? " true" : " false" );
621
617
break ;
622
618
case SpaceKind::Constructor: {
623
619
if (!Head.empty ()) {
@@ -649,7 +645,7 @@ namespace {
649
645
break ;
650
646
case SpaceKind::Type:
651
647
if (!normalize) {
652
- Ty ->print (buffer);
648
+ getType () ->print (buffer);
653
649
}
654
650
buffer << " _" ;
655
651
break ;
@@ -680,13 +676,13 @@ namespace {
680
676
return Space ();
681
677
}
682
678
}
683
- return Space (Ty , Head, simplifiedSpaces);
679
+ return Space (getType () , Head, simplifiedSpaces);
684
680
}
685
681
case SpaceKind::Type: {
686
682
// If the decomposition of a space is empty, the space is empty.
687
- if (canDecompose (Ty )) {
683
+ if (canDecompose (this -> getType () )) {
688
684
SmallVector<Space, 4 > ss;
689
- decompose (Ty , ss);
685
+ decompose (this -> getType () , ss);
690
686
if (ss.empty ()) {
691
687
return Space ();
692
688
}
@@ -811,11 +807,11 @@ namespace {
811
807
continue ;
812
808
813
809
auto projection = projectPattern (Ctx, caseItem.getPattern ());
814
- spaces.push_back (projection);
815
810
816
811
// Space is trivially covered with a default clause.
817
812
if (caseItem.isDefault ())
818
813
return ;
814
+ spaces.push_back (projection);
819
815
}
820
816
}
821
817
@@ -1027,12 +1023,14 @@ namespace {
1027
1023
}
1028
1024
case PatternKind::Paren: {
1029
1025
auto *PP = dyn_cast<ParenPattern>(SP);
1030
- auto *SP = PP->getSubPattern ();
1026
+ auto *SP = PP->getSemanticsProvidingPattern ();
1027
+
1031
1028
// Special Case: A constructor pattern may have all of its payload
1032
1029
// matched by a single var pattern. Project it like the tuple it
1033
1030
// really is.
1034
- if (SP->getKind () == PatternKind::Var
1035
- || SP->getKind () == PatternKind::Any) {
1031
+ if (SP->getKind () == PatternKind::Named
1032
+ || SP->getKind () == PatternKind::Any
1033
+ || SP->getKind () == PatternKind::Tuple) {
1036
1034
if (auto *TTy = SP->getType ()->getAs <TupleType>()) {
1037
1035
for (auto ty : TTy->getElements ()) {
1038
1036
conArgSpace.push_back (Space (ty.getType ()));
0 commit comments