Skip to content

Commit cb0721f

Browse files
authored
Merge pull request #60470 from slavapestov/rename-conformance-path
AST: Rename ConformanceAccessPath to ConformancePath
2 parents 7701ddc + 4a041c5 commit cb0721f

12 files changed

+68
-81
lines changed

docs/Lexicon.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ thunk helpers" sometimes seen in Swift backtraces come from.)
4949

5050
Broadly, an "access path" is a list of "accesses" which must be chained together
5151
to compute some output from an input. For instance, the generics system has a
52-
type called a `ConformanceAccessPath` which explains how to, for example,
52+
type called a `ConformancePath` which explains how to, for example,
5353
walk from `T: Collection` to `T: Sequence` to `T.Iterator: IteratorProtocol`.
5454
There are several different kinds of "access path" in different parts of the compiler,
5555
but they all follow this basic theme.

include/swift/AST/ASTMangler.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class NamedDecl;
2525
namespace swift {
2626

2727
class AbstractClosureExpr;
28-
class ConformanceAccessPath;
28+
class ConformancePath;
2929
class RootProtocolConformance;
3030

3131
namespace Mangle {
@@ -560,7 +560,7 @@ class ASTMangler : public Mangler {
560560
void appendConcreteProtocolConformance(
561561
const ProtocolConformance *conformance,
562562
GenericSignature sig);
563-
void appendDependentProtocolConformance(const ConformanceAccessPath &path,
563+
void appendDependentProtocolConformance(const ConformancePath &path,
564564
GenericSignature sig);
565565
void appendOpParamForLayoutConstraint(LayoutConstraint Layout);
566566

include/swift/AST/GenericSignature.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ namespace rewriting {
7070
/// \c Sequence conformance of \c C (because \c Collection inherits
7171
/// \c Sequence). Finally, it extracts the conformance of the associated type
7272
/// \c Iterator to \c IteratorProtocol from the \c Sequence protocol.
73-
class ConformanceAccessPath {
73+
class ConformancePath {
7474
public:
7575
/// An entry in the conformance access path, which is described by the
7676
/// dependent type on which the conformance is stated as the protocol to
@@ -80,7 +80,7 @@ class ConformanceAccessPath {
8080
private:
8181
ArrayRef<Entry> path;
8282

83-
ConformanceAccessPath(ArrayRef<Entry> path) : path(path) {}
83+
ConformancePath(ArrayRef<Entry> path) : path(path) {}
8484

8585
friend class GenericSignatureImpl;
8686
friend class rewriting::RequirementMachine;
@@ -398,20 +398,20 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
398398
/// signature.
399399
bool isValidTypeParameter(Type type) const;
400400

401-
/// Retrieve the conformance access path used to extract the conformance of
401+
/// Retrieve the conformance path used to extract the conformance of
402402
/// interface \c type to the given \c protocol.
403403
///
404-
/// \param type The interface type whose conformance access path is to be
404+
/// \param type The type parameter whose conformance path is to be
405405
/// queried.
406406
/// \param protocol A protocol to which \c type conforms.
407407
///
408-
/// \returns the conformance access path that starts at a requirement of
408+
/// \returns the conformance path that starts at a requirement of
409409
/// this generic signature and ends at the conformance that makes \c type
410410
/// conform to \c protocol.
411411
///
412-
/// \seealso ConformanceAccessPath
413-
ConformanceAccessPath getConformanceAccessPath(Type type,
414-
ProtocolDecl *protocol) const;
412+
/// \seealso ConformancePath
413+
ConformancePath getConformancePath(Type type,
414+
ProtocolDecl *protocol) const;
415415

416416
/// Lookup a nested type with the given name within this type parameter.
417417
TypeDecl *lookupNestedType(Type type, Identifier name) const;

include/swift/Basic/Statistics.def

+2-10
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,8 @@ FRONTEND_STATISTIC(Sema, NumRequirementMachineCompletionSteps)
230230
/// Number of new rules added by concrete term unification.
231231
FRONTEND_STATISTIC(Sema, NumRequirementMachineUnifiedConcreteTerms)
232232

233-
/// Number of generic signature builders constructed. Rough proxy for
234-
/// amount of work the GSB does analyzing type signatures.
235-
FRONTEND_STATISTIC(Sema, NumGenericSignatureBuilders)
236-
237-
/// Number of steps in the GSB's redundant requirements algorithm, which is in
238-
/// the worst-case exponential.
239-
FRONTEND_STATISTIC(Sema, NumRedundantRequirementSteps)
240-
241-
/// Number of conformance access paths we had to compute.
242-
FRONTEND_STATISTIC(Sema, NumConformanceAccessPathsRecorded)
233+
/// Number of conformance paths we had to compute.
234+
FRONTEND_STATISTIC(Sema, NumConformancePathsRecorded)
243235

244236
/// Number of lazy requirement signatures registered.
245237
FRONTEND_STATISTIC(Sema, NumLazyRequirementSignatures)

lib/AST/ASTMangler.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -3357,9 +3357,9 @@ void ASTMangler::appendProtocolConformanceRef(
33573357
}
33583358

33593359
/// Retrieve the index of the conformance requirement indicated by the
3360-
/// conformance access path entry within the given set of requirements.
3360+
/// conformance path entry within the given set of requirements.
33613361
static unsigned conformanceRequirementIndex(
3362-
const ConformanceAccessPath::Entry &entry,
3362+
const ConformancePath::Entry &entry,
33633363
ArrayRef<Requirement> requirements) {
33643364
unsigned result = 0;
33653365
for (const auto &req : requirements) {
@@ -3377,7 +3377,7 @@ static unsigned conformanceRequirementIndex(
33773377
}
33783378

33793379
void ASTMangler::appendDependentProtocolConformance(
3380-
const ConformanceAccessPath &path,
3380+
const ConformancePath &path,
33813381
GenericSignature sig) {
33823382
ProtocolDecl *currentProtocol = nullptr;
33833383
for (const auto &entry : path) {
@@ -3441,19 +3441,19 @@ void ASTMangler::appendAnyProtocolConformance(
34413441

34423442
if (conformingType->isTypeParameter()) {
34433443
assert(genericSig && "Need a generic signature to resolve conformance");
3444-
auto path = genericSig->getConformanceAccessPath(conformingType,
3445-
conformance.getAbstract());
3444+
auto path = genericSig->getConformancePath(conformingType,
3445+
conformance.getAbstract());
34463446
appendDependentProtocolConformance(path, genericSig);
34473447
} else if (auto opaqueType = conformingType->getAs<OpaqueTypeArchetypeType>()) {
34483448
GenericSignature opaqueSignature =
34493449
opaqueType->getDecl()->getOpaqueInterfaceGenericSignature();
3450-
ConformanceAccessPath conformanceAccessPath =
3451-
opaqueSignature->getConformanceAccessPath(
3450+
ConformancePath conformancePath =
3451+
opaqueSignature->getConformancePath(
34523452
opaqueType->getInterfaceType(),
34533453
conformance.getAbstract());
34543454

3455-
// Append the conformance access path with the signature of the opaque type.
3456-
appendDependentProtocolConformance(conformanceAccessPath, opaqueSignature);
3455+
// Append the conformance path with the signature of the opaque type.
3456+
appendDependentProtocolConformance(conformancePath, opaqueSignature);
34573457
appendType(conformingType, genericSig);
34583458
appendOperator("HO");
34593459
} else {

lib/AST/GenericSignature.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
using namespace swift;
3131

32-
void ConformanceAccessPath::print(raw_ostream &out) const {
32+
void ConformancePath::print(raw_ostream &out) const {
3333
llvm::interleave(
3434
begin(), end(),
3535
[&](const Entry &entry) {
@@ -39,7 +39,7 @@ void ConformanceAccessPath::print(raw_ostream &out) const {
3939
[&] { out << " -> "; });
4040
}
4141

42-
void ConformanceAccessPath::dump() const {
42+
void ConformancePath::dump() const {
4343
print(llvm::errs());
4444
llvm::errs() << "\n";
4545
}
@@ -475,10 +475,10 @@ CanGenericSignature::getGenericParams() const {
475475
return {base, params.size()};
476476
}
477477

478-
ConformanceAccessPath
479-
GenericSignatureImpl::getConformanceAccessPath(Type type,
480-
ProtocolDecl *protocol) const {
481-
return getRequirementMachine()->getConformanceAccessPath(type, protocol);
478+
ConformancePath
479+
GenericSignatureImpl::getConformancePath(Type type,
480+
ProtocolDecl *protocol) const {
481+
return getRequirementMachine()->getConformancePath(type, protocol);
482482
}
483483

484484
TypeDecl *

lib/AST/RequirementMachine/GenericSignatureQueries.cpp

+27-27
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
// arbitrary type, not just a type parameter, and recursively transfozms the
2929
// type parameters it contains, if any.
3030
//
31-
// Also, getConformanceAccessPath() is another one-off operation.
31+
// Also, getConformancePath() is another one-off operation.
3232
//
3333
//===----------------------------------------------------------------------===//
3434

@@ -469,7 +469,7 @@ bool RequirementMachine::isValidTypeParameter(Type type) const {
469469
return (prefix == term);
470470
}
471471

472-
/// Retrieve the conformance access path used to extract the conformance of
472+
/// Retrieve the conformance path used to extract the conformance of
473473
/// interface \c type to the given \c protocol.
474474
///
475475
/// \param type The interface type whose conformance access path is to be
@@ -480,10 +480,10 @@ bool RequirementMachine::isValidTypeParameter(Type type) const {
480480
/// this generic signature and ends at the conformance that makes \c type
481481
/// conform to \c protocol.
482482
///
483-
/// \seealso ConformanceAccessPath
484-
ConformanceAccessPath
485-
RequirementMachine::getConformanceAccessPath(Type type,
486-
ProtocolDecl *protocol) {
483+
/// \seealso ConformancePath
484+
ConformancePath
485+
RequirementMachine::getConformancePath(Type type,
486+
ProtocolDecl *protocol) {
487487
assert(type->isTypeParameter());
488488

489489
auto mutTerm = Context.getMutableTermForType(type->getCanonicalType(),
@@ -505,9 +505,9 @@ RequirementMachine::getConformanceAccessPath(Type type,
505505
auto term = Term::get(mutTerm, Context);
506506

507507
// Check if we've already cached the result before doing anything else.
508-
auto found = ConformanceAccessPaths.find(
508+
auto found = ConformancePaths.find(
509509
std::make_pair(term, protocol));
510-
if (found != ConformanceAccessPaths.end()) {
510+
if (found != ConformancePaths.end()) {
511511
return found->second;
512512
}
513513

@@ -516,25 +516,25 @@ RequirementMachine::getConformanceAccessPath(Type type,
516516
FrontendStatsTracer tracer(Stats, "get-conformance-access-path");
517517

518518
auto recordPath = [&](Term term, ProtocolDecl *proto,
519-
ConformanceAccessPath path) {
519+
ConformancePath path) {
520520
// Add the path to the buffer.
521-
CurrentConformanceAccessPaths.emplace_back(term, path);
521+
CurrentConformancePaths.emplace_back(term, path);
522522

523523
// Add the path to the map.
524524
auto key = std::make_pair(term, proto);
525-
auto inserted = ConformanceAccessPaths.insert(
525+
auto inserted = ConformancePaths.insert(
526526
std::make_pair(key, path));
527527
assert(inserted.second);
528528
(void) inserted;
529529

530530
if (Stats)
531-
++Stats->getFrontendCounters().NumConformanceAccessPathsRecorded;
531+
++Stats->getFrontendCounters().NumConformancePathsRecorded;
532532
};
533533

534534
// If this is the first time we're asked to look up a conformance access path,
535535
// visit all of the root conformance requirements in our generic signature and
536536
// add them to the buffer.
537-
if (ConformanceAccessPaths.empty()) {
537+
if (ConformancePaths.empty()) {
538538
for (const auto &req : Sig.getRequirements()) {
539539
// We only care about conformance requirements.
540540
if (req.getKind() != RequirementKind::Conformance)
@@ -543,9 +543,9 @@ RequirementMachine::getConformanceAccessPath(Type type,
543543
auto rootType = CanType(req.getFirstType());
544544
auto *rootProto = req.getProtocolDecl();
545545

546-
ConformanceAccessPath::Entry root(rootType, rootProto);
547-
ArrayRef<ConformanceAccessPath::Entry> path(root);
548-
ConformanceAccessPath result(ctx.AllocateCopy(path));
546+
ConformancePath::Entry root(rootType, rootProto);
547+
ArrayRef<ConformancePath::Entry> path(root);
548+
ConformancePath result(ctx.AllocateCopy(path));
549549

550550
auto mutTerm = Context.getMutableTermForType(rootType, nullptr);
551551
System.simplify(mutTerm);
@@ -555,17 +555,17 @@ RequirementMachine::getConformanceAccessPath(Type type,
555555
}
556556
}
557557

558-
// We enumerate conformance access paths in shortlex order until we find the
558+
// We enumerate conformance paths in shortlex order until we find the
559559
// path whose corresponding type reduces to the one we are looking for.
560560
while (true) {
561-
auto found = ConformanceAccessPaths.find(
561+
auto found = ConformancePaths.find(
562562
std::make_pair(term, protocol));
563-
if (found != ConformanceAccessPaths.end()) {
563+
if (found != ConformancePaths.end()) {
564564
return found->second;
565565
}
566566

567-
if (CurrentConformanceAccessPaths.empty()) {
568-
llvm::errs() << "Failed to find conformance access path for ";
567+
if (CurrentConformancePaths.empty()) {
568+
llvm::errs() << "Failed to find conformance path for ";
569569
llvm::errs() << type << " (" << term << ")" << " : ";
570570
llvm::errs() << protocol->getName() << ":\n";
571571
type.dump(llvm::errs());
@@ -574,18 +574,18 @@ RequirementMachine::getConformanceAccessPath(Type type,
574574
abort();
575575
}
576576

577-
// The buffer consists of all conformance access paths of length N.
577+
// The buffer consists of all conformance paths of length N.
578578
// Swap it out with an empty buffer, and fill it with all paths of
579579
// length N+1.
580-
std::vector<std::pair<Term, ConformanceAccessPath>> oldPaths;
581-
std::swap(CurrentConformanceAccessPaths, oldPaths);
580+
std::vector<std::pair<Term, ConformancePath>> oldPaths;
581+
std::swap(CurrentConformancePaths, oldPaths);
582582

583583
for (const auto &pair : oldPaths) {
584584
const auto &lastElt = pair.second.back();
585585
auto *lastProto = lastElt.second;
586586

587587
// A copy of the current path, populated as needed.
588-
SmallVector<ConformanceAccessPath::Entry, 4> entries;
588+
SmallVector<ConformancePath::Entry, 4> entries;
589589

590590
auto reqs = lastProto->getRequirementSignature().getRequirements();
591591
for (const auto &req : reqs) {
@@ -607,7 +607,7 @@ RequirementMachine::getConformanceAccessPath(Type type,
607607
// don't add it to the buffer. Note that because we iterate over
608608
// conformance access paths in shortlex order, the existing
609609
// conformance access path is shorter than the one we found just now.
610-
if (ConformanceAccessPaths.count(
610+
if (ConformancePaths.count(
611611
std::make_pair(nextTerm, nextProto)))
612612
continue;
613613

@@ -620,7 +620,7 @@ RequirementMachine::getConformanceAccessPath(Type type,
620620

621621
// Add the next entry.
622622
entries.emplace_back(nextSubjectType, nextProto);
623-
ConformanceAccessPath result = ctx.AllocateCopy(entries);
623+
ConformancePath result = ctx.AllocateCopy(entries);
624624
entries.pop_back();
625625

626626
recordPath(nextTerm, nextProto, result);

lib/AST/RequirementMachine/RequirementMachine.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,8 @@ void RequirementMachine::dump(llvm::raw_ostream &out) const {
565565
System.dump(out);
566566
Map.dump(out);
567567

568-
out << "Conformance access paths: {\n";
569-
for (auto pair : ConformanceAccessPaths) {
568+
out << "Conformance paths: {\n";
569+
for (auto pair : ConformancePaths) {
570570
out << "- " << pair.first.first << " : ";
571571
out << pair.first.second->getName() << " => ";
572572
pair.second.print(out);

lib/AST/RequirementMachine/RequirementMachine.h

+6-8
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,15 @@ class RequirementMachine final {
7171

7272
UnifiedStatsReporter *Stats;
7373

74-
/// All conformance access paths computed so far.
74+
/// All conformance paths computed so far.
7575
llvm::DenseMap<std::pair<Term, ProtocolDecl *>,
76-
ConformanceAccessPath> ConformanceAccessPaths;
76+
ConformancePath> ConformancePaths;
7777

7878
/// Conformance access paths computed during the last round. All elements
7979
/// have the same length. If a conformance access path of greater length
80-
/// is requested, we refill CurrentConformanceAccessPaths with all paths of
81-
/// length N+1, and add them to the ConformanceAccessPaths map.
82-
std::vector<std::pair<Term, ConformanceAccessPath>>
83-
CurrentConformanceAccessPaths;
80+
/// is requested, we refill CurrentConformancePaths with all paths of
81+
/// length N+1, and add them to the ConformancePaths map.
82+
std::vector<std::pair<Term, ConformancePath>> CurrentConformancePaths;
8483

8584
explicit RequirementMachine(RewriteContext &rewriteCtx);
8685

@@ -158,8 +157,7 @@ class RequirementMachine final {
158157
Type getReducedType(Type type,
159158
TypeArrayView<GenericTypeParamType> genericParams) const;
160159
bool isValidTypeParameter(Type type) const;
161-
ConformanceAccessPath getConformanceAccessPath(Type type,
162-
ProtocolDecl *protocol);
160+
ConformancePath getConformancePath(Type type, ProtocolDecl *protocol);
163161
TypeDecl *lookupNestedType(Type depType, Identifier name) const;
164162

165163
llvm::DenseMap<const ProtocolDecl *, RequirementSignature>

lib/AST/RequirementMachine/RequirementMachineRequests.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ RequirementMachine::computeMinimalGenericSignature(
482482
auto sig = GenericSignature::get(getGenericParams(), reqs);
483483

484484
// Remember the signature for generic signature queries. In particular,
485-
// getConformanceAccessPath() needs the current requirement machine's
485+
// getConformancePath() needs the current requirement machine's
486486
// generic signature.
487487
Sig = sig.getCanonicalSignature();
488488

lib/AST/SubstitutionMap.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,10 @@ SubstitutionMap::lookupConformance(CanType type, ProtocolDecl *proto) const {
367367
return ProtocolConformanceRef::forMissingOrInvalid(substType, proto);
368368
}
369369

370-
auto accessPath =
371-
genericSig->getConformanceAccessPath(type, proto);
370+
auto path = genericSig->getConformancePath(type, proto);
372371

373372
ProtocolConformanceRef conformance;
374-
for (const auto &step : accessPath) {
373+
for (const auto &step : path) {
375374
// For the first step, grab the initial conformance.
376375
if (conformance.isInvalid()) {
377376
if (auto initialConformance = getSignatureConformance(

0 commit comments

Comments
 (0)