Skip to content

Commit fb80237

Browse files
committed
[GSB] Eliminate unnecessary "dependentType" parameters throughout.NFC
Now that ProtocolRequirement sources can compute their own stored types, stop propagating that information through the GSB.
1 parent 7900dec commit fb80237

File tree

2 files changed

+19
-49
lines changed

2 files changed

+19
-49
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ class GenericSignatureBuilder {
280280
bool addTypeRequirement(UnresolvedType subject,
281281
UnresolvedType constraint,
282282
FloatingRequirementSource source,
283-
Type dependentType,
284283
llvm::SmallPtrSetImpl<ProtocolDecl *> *visited
285284
= nullptr);
286285

@@ -314,25 +313,13 @@ class GenericSignatureBuilder {
314313
const RequirementSource *Source);
315314

316315
/// Add a new layout requirement to the subject.
317-
///
318-
/// FIXME: The "dependent type" is the subject type pre-substitution. We
319-
/// should be able to compute this!
320316
bool addLayoutRequirement(UnresolvedType subject,
321317
LayoutConstraint layout,
322-
FloatingRequirementSource source,
323-
Type dependentType);
318+
FloatingRequirementSource source);
324319

325320
/// Add the requirements placed on the given type parameter
326321
/// to the given potential archetype.
327-
///
328-
/// \param dependentType A dependent type thar describes \c pa relative to
329-
/// its protocol, for protocol requirements.
330-
///
331-
/// FIXME: \c dependentType will be derivable from \c parentSource and \c pa
332-
/// when we're no longer putting conformance requirements directly on the
333-
/// representative.
334322
bool addInheritedRequirements(TypeDecl *decl, PotentialArchetype *pa,
335-
Type dependentType,
336323
const RequirementSource *parentSource,
337324
llvm::SmallPtrSetImpl<ProtocolDecl *> &visited);
338325

@@ -1077,8 +1064,7 @@ class GenericSignatureBuilder::FloatingRequirementSource {
10771064

10781065
/// Retrieve the complete requirement source rooted at the given potential
10791066
/// archetype.
1080-
const RequirementSource *getSource(PotentialArchetype *pa,
1081-
Type dependentType) const;
1067+
const RequirementSource *getSource(PotentialArchetype *pa) const;
10821068

10831069
/// Retrieve the source location for this requirement.
10841070
SourceLoc getLoc() const;

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -795,8 +795,7 @@ static Type formProtocolRelativeType(ProtocolDecl *proto,
795795
}
796796

797797
const RequirementSource *FloatingRequirementSource::getSource(
798-
PotentialArchetype *pa,
799-
Type dependentType) const {
798+
PotentialArchetype *pa) const {
800799
switch (kind) {
801800
case Resolved:
802801
return storage.get<const RequirementSource *>();
@@ -818,11 +817,11 @@ const RequirementSource *FloatingRequirementSource::getSource(
818817
auto baseSourcePA =
819818
baseSource->getAffectedPotentialArchetype(*pa->getBuilder());
820819

821-
auto newDependentType =
820+
auto dependentType =
822821
formProtocolRelativeType(protocolReq.protocol, baseSourcePA, pa);
823822

824823
return storage.get<const RequirementSource *>()
825-
->viaProtocolRequirement(*pa->getBuilder(), newDependentType,
824+
->viaProtocolRequirement(*pa->getBuilder(), dependentType,
826825
protocolReq.protocol, protocolReq.written);
827826
}
828827
}
@@ -2135,9 +2134,7 @@ bool GenericSignatureBuilder::addGenericParameterRequirements(
21352134

21362135
// Add the requirements from the declaration.
21372136
llvm::SmallPtrSet<ProtocolDecl *, 8> visited;
2138-
return addInheritedRequirements(GenericParam, PA,
2139-
GenericParam->getDeclaredInterfaceType(),
2140-
nullptr, visited);
2137+
return addInheritedRequirements(GenericParam, PA, nullptr, visited);
21412138
}
21422139

21432140
void GenericSignatureBuilder::addGenericParameter(GenericTypeParamType *GenericParam) {
@@ -2248,8 +2245,7 @@ bool GenericSignatureBuilder::addConformanceRequirement(PotentialArchetype *PAT,
22482245
if (auto resolver = getLazyResolver())
22492246
resolver->resolveInheritedProtocols(Proto);
22502247

2251-
if (addInheritedRequirements(Proto, PAT, Proto->getSelfInterfaceType(),
2252-
Source, Visited))
2248+
if (addInheritedRequirements(Proto, PAT, Source, Visited))
22532249
return true;
22542250

22552251
// Add any requirements in the where clause on the protocol.
@@ -2268,9 +2264,7 @@ bool GenericSignatureBuilder::addConformanceRequirement(PotentialArchetype *PAT,
22682264
auto AssocPA = T->getNestedType(AssocType, *this);
22692265

22702266
if (AssocPA != T) {
2271-
if (addInheritedRequirements(AssocType, AssocPA,
2272-
AssocType->getDeclaredInterfaceType(),
2273-
Source, Visited))
2267+
if (addInheritedRequirements(AssocType, AssocPA, Source, Visited))
22742268
return true;
22752269
}
22762270
if (auto WhereClause = AssocType->getTrailingWhereClause()) {
@@ -2320,8 +2314,7 @@ bool GenericSignatureBuilder::addLayoutRequirementDirect(
23202314
bool GenericSignatureBuilder::addLayoutRequirement(
23212315
UnresolvedType subject,
23222316
LayoutConstraint layout,
2323-
FloatingRequirementSource source,
2324-
Type dependentType) {
2317+
FloatingRequirementSource source) {
23252318
// Resolve the subject.
23262319
auto resolvedSubject = resolve(subject, source);
23272320
if (!resolvedSubject) {
@@ -2347,8 +2340,7 @@ bool GenericSignatureBuilder::addLayoutRequirement(
23472340
}
23482341

23492342
auto pa = resolvedSubject->getPotentialArchetype();
2350-
return addLayoutRequirementDirect(pa, layout,
2351-
source.getSource(pa, dependentType));
2343+
return addLayoutRequirementDirect(pa, layout, source.getSource(pa));
23522344
}
23532345

23542346
bool GenericSignatureBuilder::updateSuperclass(
@@ -2446,7 +2438,6 @@ bool GenericSignatureBuilder::addTypeRequirement(
24462438
UnresolvedType subject,
24472439
UnresolvedType constraint,
24482440
FloatingRequirementSource source,
2449-
Type dependentType,
24502441
llvm::SmallPtrSetImpl<ProtocolDecl *> *visited) {
24512442
// Make sure we always have a "visited" set to pass down.
24522443
SmallPtrSet<ProtocolDecl *, 4> visitedSet;
@@ -2525,7 +2516,7 @@ bool GenericSignatureBuilder::addTypeRequirement(
25252516
auto subjectPA = resolvedSubject->getPotentialArchetype();
25262517
assert(subjectPA && "No potential archetype?");
25272518

2528-
auto resolvedSource = source.getSource(subjectPA, dependentType);
2519+
auto resolvedSource = source.getSource(subjectPA);
25292520

25302521
// Protocol requirements.
25312522
if (constraintType->isExistentialType()) {
@@ -2835,15 +2826,12 @@ bool GenericSignatureBuilder::addSameTypeRequirementDirect(
28352826
// If both sides of the requirement are type parameters, equate them.
28362827
if (pa1 && pa2) {
28372828
return addSameTypeRequirementBetweenArchetypes(pa1, pa2,
2838-
source.getSource(pa1,
2839-
Type()));
2829+
source.getSource(pa1));
28402830
// If just one side is a type parameter, map it to a concrete type.
28412831
} else if (pa1) {
2842-
return addSameTypeRequirementToConcrete(pa1, t2,
2843-
source.getSource(pa1, Type()));
2832+
return addSameTypeRequirementToConcrete(pa1, t2, source.getSource(pa1));
28442833
} else if (pa2) {
2845-
return addSameTypeRequirementToConcrete(pa2, t1,
2846-
source.getSource(pa2, Type()));
2834+
return addSameTypeRequirementToConcrete(pa2, t1, source.getSource(pa2));
28472835
} else {
28482836
return addSameTypeRequirementBetweenConcrete(t1, t2, source,
28492837
diagnoseMismatch);
@@ -2875,7 +2863,6 @@ void GenericSignatureBuilder::markPotentialArchetypeRecursive(
28752863
bool GenericSignatureBuilder::addInheritedRequirements(
28762864
TypeDecl *decl,
28772865
PotentialArchetype *pa,
2878-
Type dependentType,
28792866
const RequirementSource *parentSource,
28802867
llvm::SmallPtrSetImpl<ProtocolDecl *> &visited) {
28812868
if (isa<AssociatedTypeDecl>(decl) &&
@@ -2913,8 +2900,7 @@ bool GenericSignatureBuilder::addInheritedRequirements(
29132900
};
29142901

29152902
// Protocol requirement.
2916-
return addTypeRequirement(pa, inheritedType, getFloatingSource(),
2917-
dependentType, &visited);
2903+
return addTypeRequirement(pa, inheritedType, getFloatingSource(), &visited);
29182904
});
29192905
}
29202906

@@ -2938,12 +2924,12 @@ bool GenericSignatureBuilder::addRequirement(const RequirementRepr *Req,
29382924
case RequirementReprKind::LayoutConstraint:
29392925
return addLayoutRequirement(subst(Req->getSubject()),
29402926
Req->getLayoutConstraint(),
2941-
source, Req->getSubject());
2927+
source);
29422928

29432929
case RequirementReprKind::TypeConstraint:
29442930
return addTypeRequirement(subst(Req->getSubject()),
29452931
subst(Req->getConstraint()),
2946-
source, Req->getSubject());
2932+
source);
29472933

29482934
case RequirementReprKind::SameType:
29492935
// Require that at least one side of the requirement contain a type
@@ -2995,14 +2981,12 @@ bool GenericSignatureBuilder::addRequirement(
29952981
case RequirementKind::Conformance:
29962982
return addTypeRequirement(subst(req.getFirstType()),
29972983
subst(req.getSecondType()),
2998-
source, req.getFirstType(),
2999-
&Visited);
2984+
source, &Visited);
30002985

30012986
case RequirementKind::Layout:
30022987
return addLayoutRequirement(subst(req.getFirstType()),
30032988
req.getLayoutConstraint(),
3004-
source,
3005-
req.getFirstType());
2989+
source);
30062990

30072991
case RequirementKind::SameType:
30082992
return addSameTypeRequirement(

0 commit comments

Comments
 (0)