Skip to content

Commit da39d9b

Browse files
committed
[GenericSig Builder] Rework RequirementSource to describe requirement path.
Reimplement the RequirementSource class, which captures how a particular requirement is satisfied by a generic signature. The primary goal of this rework is to keep the complete path one follows in a generic signature to get from some explicit requirement in the generic signature to some derived requirement or type, e.g., 1) Start at an explicit requirement "C: Collection" 2) Go to the inherited protocol Sequence, 3) Get the "Iterator" associated type 4) Get its conformance to "IteratorProtocol" 5) Get the "Element" associated type We don't currently capture all of the information we want in the path, but the basic structure is there, and should also allow us to capture more source-location information, find the "optimal" path, etc. There are are a number of potential uses: * IRGen could eventually use this to dig out the witness tables and type metadata it needs, instead of using its own fulfillment strategy * SubstitutionMap could use this to lookup conformances, rather than it's egregious hacks * The canonical generic signature builder could use this to lookup conformances as needed, e.g., for the recursive-conformances case. ... and probably more simplifications, once we get this right.
1 parent 5fb6bb2 commit da39d9b

File tree

11 files changed

+937
-372
lines changed

11 files changed

+937
-372
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 343 additions & 65 deletions
Large diffs are not rendered by default.

lib/AST/Decl.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3020,12 +3020,12 @@ void ProtocolDecl::computeRequirementSignature() {
30203020
auto selfType = genericSig->getGenericParams()[0];
30213021
auto requirement = genericSig->getRequirements()[0];
30223022

3023-
RequirementSource source(RequirementSource::ProtocolRequirementSignatureSelf,
3024-
getLoc());
3025-
3026-
GenericSignatureBuilder builder(getASTContext(), LookUpConformanceInModule(module));
3023+
GenericSignatureBuilder builder(getASTContext(),
3024+
LookUpConformanceInModule(module));
30273025
builder.addGenericParameter(selfType);
3028-
builder.addRequirement(requirement, source);
3026+
builder.addRequirement(requirement,
3027+
RequirementSource::forRequirementSignature(builder,
3028+
this));
30293029
builder.finalize(SourceLoc(), { selfType });
30303030

30313031
RequirementSignature = builder.getGenericSignature();

0 commit comments

Comments
 (0)