Skip to content

Commit cfb1595

Browse files
committed
RequirementMachine: Rename Atom => Symbol
1 parent d52dca5 commit cfb1595

9 files changed

+440
-440
lines changed

lib/AST/RequirementMachine/EquivalenceClassMap.cpp

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
//
2121
// T.[p] => T
2222
//
23-
// Where [p] is a "property atom": [layout: L], [superclass: Foo],
23+
// Where [p] is a "property symbol": [layout: L], [superclass: Foo],
2424
// [concrete: Bar].
2525
//
2626
// Given an arbitrary type T and a property [p], we can check if T satisfies the
@@ -200,7 +200,7 @@ Type EquivalenceClass::getConcreteType(
200200
/// If the nth entry in the array is S, this will produce S.X.Y.Z.
201201
///
202202
/// There is a special behavior if the substitution is a term consisting of a
203-
/// single protocol atom [P]. If the innermost associated type in
203+
/// single protocol symbol [P]. If the innermost associated type in
204204
/// \p typeWitness is [Q:Foo], the result will be [P:Foo], not [P].[Q:Foo] or
205205
/// [Q:Foo].
206206
static MutableTerm getRelativeTermForType(CanType typeWitness,
@@ -212,43 +212,43 @@ static MutableTerm getRelativeTermForType(CanType typeWitness,
212212
unsigned index = getGenericParamIndex(typeWitness->getRootGenericParam());
213213
result = MutableTerm(substitutions[index]);
214214

215-
// If the substitution is a term consisting of a single protocol atom
215+
// If the substitution is a term consisting of a single protocol symbol
216216
// [P], save P for later.
217217
const ProtocolDecl *proto = nullptr;
218218
if (result.size() == 1 &&
219-
result[0].getKind() == Atom::Kind::Protocol) {
219+
result[0].getKind() == Symbol::Kind::Protocol) {
220220
proto = result[0].getProtocol();
221221
}
222222

223223
// Collect zero or more member type names in reverse order.
224-
SmallVector<Atom, 3> atoms;
224+
SmallVector<Symbol, 3> symbols;
225225
while (auto memberType = dyn_cast<DependentMemberType>(typeWitness)) {
226226
typeWitness = memberType.getBase();
227227

228228
auto *assocType = memberType->getAssocType();
229229
assert(assocType != nullptr &&
230230
"Conformance checking should not produce unresolved member types");
231231

232-
// If the substitution is a term consisting of a single protocol atom [P],
232+
// If the substitution is a term consisting of a single protocol symbol [P],
233233
// produce [P:Foo] instead of [P].[Q:Foo] or [Q:Foo].
234234
const auto *thisProto = assocType->getProtocol();
235235
if (proto && isa<GenericTypeParamType>(typeWitness)) {
236236
thisProto = proto;
237237

238238
assert(result.size() == 1);
239-
assert(result[0].getKind() == Atom::Kind::Protocol);
239+
assert(result[0].getKind() == Symbol::Kind::Protocol);
240240
assert(result[0].getProtocol() == proto);
241241
result = MutableTerm();
242242
}
243243

244-
atoms.push_back(Atom::forAssociatedType(thisProto,
245-
assocType->getName(), ctx));
244+
symbols.push_back(Symbol::forAssociatedType(thisProto,
245+
assocType->getName(), ctx));
246246
}
247247

248248
// Add the member type names.
249-
std::reverse(atoms.begin(), atoms.end());
250-
for (auto atom : atoms)
251-
result.add(atom);
249+
std::reverse(symbols.begin(), symbols.end());
250+
for (auto symbol : symbols)
251+
result.add(symbol);
252252

253253
return result;
254254
}
@@ -311,7 +311,7 @@ remapConcreteSubstitutionSchema(CanType concreteType,
311311
/// T.[concrete: Foo<τ_0_0, τ_0_1, String> with {X.Y, Z}]
312312
/// T.[concrete: Foo<Int, τ_0_0, τ_0_1> with {A.B, W}]
313313
///
314-
/// The two concrete type atoms will be added to the equivalence class of 'T',
314+
/// The two concrete type symbols will be added to the equivalence class of 'T',
315315
/// and we will eventually end up in this method, where we will generate three
316316
/// induced rules:
317317
///
@@ -324,7 +324,7 @@ remapConcreteSubstitutionSchema(CanType concreteType,
324324
///
325325
/// Returns true if a conflict was detected.
326326
static bool unifyConcreteTypes(
327-
Atom lhs, Atom rhs, RewriteContext &ctx,
327+
Symbol lhs, Symbol rhs, RewriteContext &ctx,
328328
SmallVectorImpl<std::pair<MutableTerm, MutableTerm>> &inducedRules,
329329
bool debug) {
330330
auto lhsType = lhs.getConcreteType();
@@ -385,7 +385,7 @@ static bool unifyConcreteTypes(
385385
ctx, result);
386386

387387
MutableTerm constraintTerm(subjectTerm);
388-
constraintTerm.add(Atom::forConcreteType(concreteType, result, ctx));
388+
constraintTerm.add(Symbol::forConcreteType(concreteType, result, ctx));
389389

390390
if (debug) {
391391
llvm::dbgs() << "%% Induced rule " << subjectTerm
@@ -408,7 +408,7 @@ static bool unifyConcreteTypes(
408408
ctx, result);
409409

410410
MutableTerm constraintTerm(subjectTerm);
411-
constraintTerm.add(Atom::forConcreteType(concreteType, result, ctx));
411+
constraintTerm.add(Symbol::forConcreteType(concreteType, result, ctx));
412412

413413
if (debug) {
414414
llvm::dbgs() << "%% Induced rule " << subjectTerm
@@ -439,24 +439,24 @@ static bool unifyConcreteTypes(
439439
}
440440

441441
void EquivalenceClass::addProperty(
442-
Atom property, RewriteContext &ctx,
442+
Symbol property, RewriteContext &ctx,
443443
SmallVectorImpl<std::pair<MutableTerm, MutableTerm>> &inducedRules,
444444
bool debug) {
445445

446446
switch (property.getKind()) {
447-
case Atom::Kind::Protocol:
447+
case Symbol::Kind::Protocol:
448448
ConformsTo.push_back(property.getProtocol());
449449
return;
450450

451-
case Atom::Kind::Layout:
451+
case Symbol::Kind::Layout:
452452
if (!Layout)
453453
Layout = property.getLayoutConstraint();
454454
else
455455
Layout = Layout.merge(property.getLayoutConstraint());
456456

457457
return;
458458

459-
case Atom::Kind::Superclass: {
459+
case Symbol::Kind::Superclass: {
460460
auto superclass = property.getSuperclass();
461461

462462
// A superclass requirement implies a layout requirement.
@@ -466,15 +466,15 @@ void EquivalenceClass::addProperty(
466466
? LayoutConstraintKind::Class
467467
: LayoutConstraintKind::NativeClass,
468468
ctx.getASTContext());
469-
addProperty(Atom::forLayout(layout, ctx), ctx, inducedRules, debug);
469+
addProperty(Symbol::forLayout(layout, ctx), ctx, inducedRules, debug);
470470

471471
// FIXME: This needs to find the most derived subclass and also call
472472
// unifyConcreteTypes()
473473
Superclass = property;
474474
return;
475475
}
476476

477-
case Atom::Kind::ConcreteType: {
477+
case Symbol::Kind::ConcreteType: {
478478
if (ConcreteType) {
479479
(void) unifyConcreteTypes(*ConcreteType, property,
480480
ctx, inducedRules, debug);
@@ -485,13 +485,13 @@ void EquivalenceClass::addProperty(
485485
return;
486486
}
487487

488-
case Atom::Kind::Name:
489-
case Atom::Kind::GenericParam:
490-
case Atom::Kind::AssociatedType:
488+
case Symbol::Kind::Name:
489+
case Symbol::Kind::GenericParam:
490+
case Symbol::Kind::AssociatedType:
491491
break;
492492
}
493493

494-
llvm_unreachable("Bad atom kind");
494+
llvm_unreachable("Bad symbol kind");
495495
}
496496

497497
void EquivalenceClass::copyPropertiesFrom(const EquivalenceClass *next,
@@ -620,7 +620,7 @@ void EquivalenceClassMap::clear() {
620620
/// Record a protocol conformance, layout or superclass constraint on the given
621621
/// key. Must be called in monotonically non-decreasing key order.
622622
void EquivalenceClassMap::addProperty(
623-
const MutableTerm &key, Atom property,
623+
const MutableTerm &key, Symbol property,
624624
SmallVectorImpl<std::pair<MutableTerm, MutableTerm>> &inducedRules) {
625625
assert(property.isProperty());
626626
auto *equivClass = getOrCreateEquivalenceClass(key);
@@ -803,8 +803,8 @@ void EquivalenceClassMap::concretizeNestedTypesFromConcreteParent(
803803
}
804804

805805
MutableTerm subjectType = key;
806-
subjectType.add(Atom::forAssociatedType(proto, assocType->getName(),
807-
Context));
806+
subjectType.add(Symbol::forAssociatedType(proto, assocType->getName(),
807+
Context));
808808

809809
MutableTerm constraintType;
810810

@@ -896,7 +896,7 @@ MutableTerm EquivalenceClassMap::computeConstraintTermForTypeWitness(
896896

897897
// Add a rule T.[P:A].[concrete: Foo.A] => T.[P:A].
898898
constraintType.add(
899-
Atom::forConcreteType(
899+
Symbol::forConcreteType(
900900
typeWitnessSchema, result, Context));
901901

902902
return constraintType;
@@ -913,7 +913,7 @@ void EquivalenceClassMap::dump(llvm::raw_ostream &out) const {
913913
}
914914

915915
/// Build the equivalence class map from all rules of the form T.[p] => T, where
916-
/// [p] is a property atom.
916+
/// [p] is a property symbol.
917917
///
918918
/// Returns a pair consisting of a status and number of iterations executed.
919919
///
@@ -930,7 +930,7 @@ RewriteSystem::buildEquivalenceClassMap(EquivalenceClassMap &map,
930930
unsigned maxDepth) {
931931
map.clear();
932932

933-
std::vector<std::pair<MutableTerm, Atom>> properties;
933+
std::vector<std::pair<MutableTerm, Symbol>> properties;
934934

935935
for (const auto &rule : Rules) {
936936
if (rule.isDeleted())
@@ -959,8 +959,8 @@ RewriteSystem::buildEquivalenceClassMap(EquivalenceClassMap &map,
959959
// before longer rules, so that it can perform lookups on suffixes and call
960960
// EquivalenceClass::copyPropertiesFrom().
961961
std::sort(properties.begin(), properties.end(),
962-
[&](const std::pair<MutableTerm, Atom> &lhs,
963-
const std::pair<MutableTerm, Atom> &rhs) -> bool {
962+
[&](const std::pair<MutableTerm, Symbol> &lhs,
963+
const std::pair<MutableTerm, Symbol> &rhs) -> bool {
964964
return lhs.first.compare(rhs.first, Protos) < 0;
965965
});
966966

lib/AST/RequirementMachine/EquivalenceClassMap.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class MutableTerm;
4545
class RewriteContext;
4646
class Term;
4747

48-
/// Stores all rewrite rules of the form T.[p] => T, where [p] is a property atom,
48+
/// Stores all rewrite rules of the form T.[p] => T, where [p] is a property symbol,
4949
/// for a single term 'T'.
5050
class EquivalenceClass {
5151
friend class EquivalenceClassMap;
@@ -61,22 +61,22 @@ class EquivalenceClass {
6161
LayoutConstraint Layout;
6262

6363
/// The most specific superclass constraint this type satisfies.
64-
Optional<Atom> Superclass;
64+
Optional<Symbol> Superclass;
6565

6666
/// All concrete conformances of Superclass to the protocols in the
6767
/// ConformsTo list.
6868
llvm::TinyPtrVector<ProtocolConformance *> SuperclassConformances;
6969

7070
/// The most specific concrete type constraint this type satisfies.
71-
Optional<Atom> ConcreteType;
71+
Optional<Symbol> ConcreteType;
7272

7373
/// All concrete conformances of ConcreteType to the protocols in the
7474
/// ConformsTo list.
7575
llvm::TinyPtrVector<ProtocolConformance *> ConcreteConformances;
7676

7777
explicit EquivalenceClass(const MutableTerm &key) : Key(key) {}
7878

79-
void addProperty(Atom property,
79+
void addProperty(Symbol property,
8080
RewriteContext &ctx,
8181
SmallVectorImpl<std::pair<MutableTerm, MutableTerm>> &inducedRules,
8282
bool debug);
@@ -131,7 +131,7 @@ class EquivalenceClass {
131131
};
132132

133133
/// Stores all rewrite rules of the form T.[p] => T, where [p] is a property
134-
/// atom, for all terms 'T'.
134+
/// symbol, for all terms 'T'.
135135
///
136136
/// Out-of-line methods are documented in EquivalenceClassMap.cpp.
137137
class EquivalenceClassMap {
@@ -166,7 +166,7 @@ class EquivalenceClassMap {
166166
void dump(llvm::raw_ostream &out) const;
167167

168168
void clear();
169-
void addProperty(const MutableTerm &key, Atom property,
169+
void addProperty(const MutableTerm &key, Symbol property,
170170
SmallVectorImpl<std::pair<MutableTerm, MutableTerm>> &inducedRules);
171171

172172
void computeConcreteTypeInDomainMap();

lib/AST/RequirementMachine/GenericSignatureQueries.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -212,32 +212,32 @@ MutableTerm
212212
RequirementMachine::Implementation::getLongestValidPrefix(const MutableTerm &term) {
213213
MutableTerm prefix;
214214

215-
for (auto atom : term) {
216-
switch (atom.getKind()) {
217-
case Atom::Kind::Name:
215+
for (auto symbol : term) {
216+
switch (symbol.getKind()) {
217+
case Symbol::Kind::Name:
218218
return prefix;
219219

220-
case Atom::Kind::Protocol:
220+
case Symbol::Kind::Protocol:
221221
assert(prefix.empty() &&
222-
"Protocol atom can only appear at the start of a type term");
223-
if (!System.getProtocols().isKnownProtocol(atom.getProtocol()))
222+
"Protocol symbol can only appear at the start of a type term");
223+
if (!System.getProtocols().isKnownProtocol(symbol.getProtocol()))
224224
return prefix;
225225

226226
break;
227227

228-
case Atom::Kind::GenericParam:
228+
case Symbol::Kind::GenericParam:
229229
assert(prefix.empty() &&
230-
"Generic parameter atom can only appear at the start of a type term");
230+
"Generic parameter symbol can only appear at the start of a type term");
231231
break;
232232

233-
case Atom::Kind::AssociatedType: {
233+
case Symbol::Kind::AssociatedType: {
234234
const auto *equivClass = Map.lookUpEquivalenceClass(prefix);
235235
if (!equivClass)
236236
return prefix;
237237

238238
auto conformsTo = equivClass->getConformsTo();
239239

240-
for (const auto *proto : atom.getProtocols()) {
240+
for (const auto *proto : symbol.getProtocols()) {
241241
if (!System.getProtocols().isKnownProtocol(proto))
242242
return prefix;
243243

@@ -250,14 +250,14 @@ RequirementMachine::Implementation::getLongestValidPrefix(const MutableTerm &ter
250250
break;
251251
}
252252

253-
case Atom::Kind::Layout:
254-
case Atom::Kind::Superclass:
255-
case Atom::Kind::ConcreteType:
256-
llvm_unreachable("Property atom cannot appear in a type term");
253+
case Symbol::Kind::Layout:
254+
case Symbol::Kind::Superclass:
255+
case Symbol::Kind::ConcreteType:
256+
llvm_unreachable("Property symbol cannot appear in a type term");
257257
}
258258

259-
// This atom is valid, add it to the longest prefix.
260-
prefix.add(atom);
259+
// This symbol is valid, add it to the longest prefix.
260+
prefix.add(symbol);
261261
}
262262

263263
return prefix;

0 commit comments

Comments
 (0)