Skip to content

Commit 0f13eda

Browse files
committed
[RequirementMachine] Add a new symbol kind for the shape of a parameter
pack.
1 parent ae5ebba commit 0f13eda

File tree

8 files changed

+49
-22
lines changed

8 files changed

+49
-22
lines changed

lib/AST/RequirementMachine/GenericSignatureQueries.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ RequirementMachine::getLongestValidPrefix(const MutableTerm &term) const {
267267
case Symbol::Kind::Superclass:
268268
case Symbol::Kind::ConcreteType:
269269
case Symbol::Kind::ConcreteConformance:
270+
case Symbol::Kind::Shape:
270271
llvm::errs() <<"Invalid symbol in a type term: " << term << "\n";
271272
abort();
272273
}
@@ -735,6 +736,7 @@ void RequirementMachine::verify(const MutableTerm &term) const {
735736
case Symbol::Kind::Superclass:
736737
case Symbol::Kind::ConcreteType:
737738
case Symbol::Kind::ConcreteConformance:
739+
case Symbol::Kind::Shape:
738740
llvm::errs() << "Bad initial symbol in " << term << "\n";
739741
abort();
740742
break;
@@ -757,6 +759,7 @@ void RequirementMachine::verify(const MutableTerm &term) const {
757759
case Symbol::Kind::Superclass:
758760
case Symbol::Kind::ConcreteType:
759761
case Symbol::Kind::ConcreteConformance:
762+
case Symbol::Kind::Shape:
760763
llvm::errs() << "Bad interior symbol " << symbol << " in " << term << "\n";
761764
abort();
762765
break;

lib/AST/RequirementMachine/InterfaceType.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ getTypeForSymbolRange(const Symbol *begin, const Symbol *end,
303303
case Symbol::Kind::Superclass:
304304
case Symbol::Kind::ConcreteType:
305305
case Symbol::Kind::ConcreteConformance:
306+
case Symbol::Kind::Shape:
306307
llvm::errs() << "Invalid root symbol: " << MutableTerm(begin, end) << "\n";
307308
abort();
308309
}

lib/AST/RequirementMachine/MinimalConformances.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ static const ProtocolDecl *getParentConformanceForTerm(Term lhs) {
285285
case Symbol::Kind::Superclass:
286286
case Symbol::Kind::ConcreteType:
287287
case Symbol::Kind::ConcreteConformance:
288+
case Symbol::Kind::Shape:
288289
break;
289290
}
290291

lib/AST/RequirementMachine/PropertyUnification.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ void PropertyMap::addProperty(
647647
case Symbol::Kind::Name:
648648
case Symbol::Kind::GenericParam:
649649
case Symbol::Kind::AssociatedType:
650+
case Symbol::Kind::Shape:
650651
break;
651652
}
652653

lib/AST/RequirementMachine/RequirementBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ void RequirementBuilder::addRequirementRules(ArrayRef<unsigned> rules) {
243243
case Symbol::Kind::Name:
244244
case Symbol::Kind::AssociatedType:
245245
case Symbol::Kind::GenericParam:
246+
case Symbol::Kind::Shape:
246247
break;
247248
}
248249

lib/AST/RequirementMachine/Rule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const ProtocolDecl *Rule::isAnyConformanceRule() const {
7272
case Symbol::Kind::Name:
7373
case Symbol::Kind::AssociatedType:
7474
case Symbol::Kind::GenericParam:
75+
case Symbol::Kind::Shape:
7576
break;
7677
}
7778

lib/AST/RequirementMachine/Symbol.cpp

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ struct Symbol::Storage final
4242
public llvm::TrailingObjects<Storage, unsigned, Term> {
4343
friend class Symbol;
4444

45-
llvm::PointerIntPair<const ProtocolDecl *, 3> ProtoAndKind;
45+
Symbol::Kind Kind;
46+
const ProtocolDecl *Proto = nullptr;
4647

4748
union {
4849
Identifier Name;
@@ -52,26 +53,28 @@ struct Symbol::Storage final
5253
};
5354

5455
explicit Storage(Identifier name) {
55-
ProtoAndKind.setInt(unsigned(Symbol::Kind::Name));
56+
Kind = Symbol::Kind::Name;
5657
Name = name;
5758
}
5859

5960
explicit Storage(LayoutConstraint layout) {
60-
ProtoAndKind.setInt(unsigned(Symbol::Kind::Layout));
61+
Kind = Symbol::Kind::Layout;
6162
Layout = layout;
6263
}
6364

6465
explicit Storage(const ProtocolDecl *proto) {
65-
ProtoAndKind.setPointerAndInt(proto, unsigned(Symbol::Kind::Protocol));
66+
Kind = Symbol::Kind::Protocol;
67+
Proto = proto;
6668
}
6769

6870
explicit Storage(GenericTypeParamType *param) {
69-
ProtoAndKind.setInt(unsigned(Symbol::Kind::GenericParam));
71+
Kind = Symbol::Kind::GenericParam;
7072
GenericParam = param;
7173
}
7274

7375
Storage(const ProtocolDecl *proto, Identifier name) {
74-
ProtoAndKind.setPointerAndInt(proto, unsigned(Symbol::Kind::AssociatedType));
76+
Kind = Symbol::Kind::AssociatedType;
77+
Proto = proto;
7578
Name = name;
7679
}
7780

@@ -82,7 +85,7 @@ struct Symbol::Storage final
8285
assert(!type->hasTypeVariable());
8386
assert(type->hasTypeParameter() != substitutions.empty());
8487

85-
ProtoAndKind.setInt(unsigned(kind));
88+
Kind = kind;
8689
ConcreteType = type;
8790

8891
*getTrailingObjects<unsigned>() = substitutions.size();
@@ -95,7 +98,8 @@ struct Symbol::Storage final
9598
assert(!type->hasTypeVariable());
9699
assert(type->hasTypeParameter() != substitutions.empty());
97100

98-
ProtoAndKind.setPointerAndInt(proto, unsigned(Symbol::Kind::ConcreteConformance));
101+
Kind = Symbol::Kind::ConcreteConformance;
102+
Proto = proto;
99103

100104
*getTrailingObjects<unsigned>() = substitutions.size();
101105
ConcreteType = type;
@@ -105,10 +109,9 @@ struct Symbol::Storage final
105109
}
106110

107111
size_t numTrailingObjects(OverloadToken<unsigned>) const {
108-
auto kind = Symbol::Kind(ProtoAndKind.getInt());
109-
return (kind == Symbol::Kind::Superclass ||
110-
kind == Symbol::Kind::ConcreteType ||
111-
kind == Symbol::Kind::ConcreteConformance);
112+
return (Kind == Symbol::Kind::Superclass ||
113+
Kind == Symbol::Kind::ConcreteType ||
114+
Kind == Symbol::Kind::ConcreteConformance);
112115
}
113116

114117
size_t numTrailingObjects(OverloadToken<Term>) const {
@@ -132,7 +135,7 @@ struct Symbol::Storage final
132135
};
133136

134137
Symbol::Kind Symbol::getKind() const {
135-
return Kind(Ptr->ProtoAndKind.getInt());
138+
return Ptr->Kind;
136139
}
137140

138141
/// Get the identifier associated with an unbound name symbol or an
@@ -149,7 +152,7 @@ const ProtocolDecl *Symbol::getProtocol() const {
149152
assert(getKind() == Kind::Protocol ||
150153
getKind() == Kind::AssociatedType ||
151154
getKind() == Kind::ConcreteConformance);
152-
return Ptr->ProtoAndKind.getPointer();
155+
return Ptr->Proto;
153156
}
154157

155158
/// Get the generic parameter associated with a generic parameter symbol.
@@ -441,6 +444,7 @@ const ProtocolDecl *Symbol::getRootProtocol() const {
441444
case Symbol::Kind::Superclass:
442445
case Symbol::Kind::ConcreteType:
443446
case Symbol::Kind::ConcreteConformance:
447+
case Symbol::Kind::Shape:
444448
break;
445449
}
446450

@@ -512,6 +516,7 @@ Optional<int> Symbol::compare(Symbol other, RewriteContext &ctx) const {
512516
break;
513517
}
514518

519+
case Kind::Shape:
515520
case Kind::GenericParam: {
516521
auto *param = getGenericParam();
517522
auto *otherParam = other.getGenericParam();
@@ -593,6 +598,7 @@ Symbol Symbol::withConcreteSubstitutions(
593598
case Kind::Name:
594599
case Kind::Protocol:
595600
case Kind::AssociatedType:
601+
case Kind::Shape:
596602
case Kind::Layout:
597603
break;
598604
}
@@ -710,15 +716,20 @@ void Symbol::dump(llvm::raw_ostream &out) const {
710716
out << getProtocol()->getName();
711717
out << "]";
712718
return;
719+
720+
case Kind::Shape: {
721+
out << "[shape]";
722+
return;
723+
}
713724
}
714725

715726
llvm_unreachable("Bad symbol kind");
716727
}
717728

718729
void Symbol::Storage::Profile(llvm::FoldingSetNodeID &id) const {
719-
id.AddInteger(ProtoAndKind.getInt());
730+
id.AddInteger(unsigned(Kind));
720731

721-
switch (Symbol::Kind(ProtoAndKind.getInt())) {
732+
switch (Kind) {
722733
case Symbol::Kind::Name:
723734
id.AddPointer(Name.get());
724735
return;
@@ -728,15 +739,19 @@ void Symbol::Storage::Profile(llvm::FoldingSetNodeID &id) const {
728739
return;
729740

730741
case Symbol::Kind::Protocol:
731-
id.AddPointer(ProtoAndKind.getPointer());
742+
id.AddPointer(Proto);
732743
return;
733744

734745
case Symbol::Kind::GenericParam:
735746
id.AddPointer(GenericParam);
736747
return;
737748

749+
case Symbol::Kind::Shape:
750+
// Nothing more to add.
751+
return;
752+
738753
case Symbol::Kind::AssociatedType: {
739-
id.AddPointer(ProtoAndKind.getPointer());
754+
id.AddPointer(Proto);
740755
id.AddPointer(Name.get());
741756
return;
742757
}
@@ -752,7 +767,7 @@ void Symbol::Storage::Profile(llvm::FoldingSetNodeID &id) const {
752767
}
753768

754769
case Symbol::Kind::ConcreteConformance: {
755-
id.AddPointer(ProtoAndKind.getPointer());
770+
id.AddPointer(Proto);
756771
id.AddPointer(ConcreteType.getPointer());
757772

758773
id.AddInteger(getNumSubstitutions());
@@ -764,4 +779,4 @@ void Symbol::Storage::Profile(llvm::FoldingSetNodeID &id) const {
764779
}
765780

766781
llvm_unreachable("Bad symbol kind");
767-
}
782+
}

lib/AST/RequirementMachine/Symbol.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ class Symbol final {
113113
/// An unbound identifier name.
114114
Name,
115115

116+
/// A shape term 'T.[shape]'. The parent term must be a
117+
/// generic parameter.
118+
Shape,
119+
116120
//////
117121
////// "Property-like" symbol kinds:
118122
//////
@@ -130,7 +134,7 @@ class Symbol final {
130134
ConcreteType,
131135
};
132136

133-
static const unsigned NumKinds = 8;
137+
static const unsigned NumKinds = 9;
134138

135139
static const StringRef Kinds[];
136140

@@ -284,4 +288,4 @@ namespace llvm {
284288
};
285289
} // end namespace llvm
286290

287-
#endif
291+
#endif

0 commit comments

Comments
 (0)