Skip to content

Commit ed1e683

Browse files
committed
Address review feedback on AbstractConformance in ProtocolConformanceRef
1 parent ffc62bb commit ed1e683

37 files changed

+83
-81
lines changed

include/swift/AST/ASTBridgingImpl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ BridgedASTType BridgedConformance::getType() const {
602602
}
603603

604604
BridgedDeclObj BridgedConformance::getRequirement() const {
605-
return {unbridged().getRequirement()};
605+
return {unbridged().getProtocol()};
606606
}
607607

608608
BridgedConformance BridgedConformance::getGenericConformance() const {

include/swift/AST/ProtocolConformanceRef.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ class ProtocolConformanceRef {
179179
}
180180

181181
/// Retrieve the conforming type.
182-
Type getConformingType() const;
182+
Type getType() const;
183183

184184
/// Return the protocol requirement.
185-
ProtocolDecl *getRequirement() const;
185+
ProtocolDecl *getProtocol() const;
186186

187187
/// Apply a substitution to the conforming type.
188188
ProtocolConformanceRef subst(Type origType, SubstitutionMap subMap,

lib/APIDigester/ModuleAnalyzerNodes.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, ImportDecl *ID):
14981498
}
14991499

15001500
SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, ProtocolConformanceRef Conform):
1501-
SDKNodeInitInfo(Ctx, Conform.getRequirement()) {
1501+
SDKNodeInitInfo(Ctx, Conform.getProtocol()) {
15021502
// The conformance can be conditional. The generic signature keeps track of
15031503
// the requirements.
15041504
if (Conform.isConcrete()) {

lib/AST/ASTContext.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5108,7 +5108,7 @@ void SILFunctionType::Profile(
51085108
invocationSubs.profile(id);
51095109
id.AddBoolean((bool)conformance);
51105110
if (conformance)
5111-
id.AddPointer(conformance.getRequirement());
5111+
id.AddPointer(conformance.getProtocol());
51125112
}
51135113

51145114
SILFunctionType::SILFunctionType(

lib/AST/ASTDumper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5512,7 +5512,7 @@ class PrintConformance : public PrintBase {
55125512
assert(conformance.isAbstract());
55135513

55145514
printHead("abstract_conformance", ASTNodeColor, label);
5515-
printReferencedDeclField(conformance.getRequirement(),
5515+
printReferencedDeclField(conformance.getProtocol(),
55165516
Label::always("protocol"));
55175517
printFoot();
55185518
}

lib/AST/ASTMangler.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -2158,7 +2158,7 @@ void ASTMangler::appendRetroactiveConformances(SubstitutionMap subMap,
21582158
if (conformance.isInvalid())
21592159
continue;
21602160

2161-
if (conformance.getRequirement()->isMarkerProtocol())
2161+
if (conformance.getProtocol()->isMarkerProtocol())
21622162
continue;
21632163

21642164
SWIFT_DEFER {
@@ -4516,7 +4516,7 @@ void ASTMangler::appendAnyProtocolConformance(
45164516
// If we have a conformance to a marker protocol but we aren't allowed to
45174517
// emit marker protocols, skip it.
45184518
if (!AllowMarkerProtocols &&
4519-
conformance.getRequirement()->isMarkerProtocol())
4519+
conformance.getProtocol()->isMarkerProtocol())
45204520
return;
45214521

45224522
// While all invertible protocols are marker protocols, do not mangle them
@@ -4525,15 +4525,17 @@ void ASTMangler::appendAnyProtocolConformance(
45254525
// but we *might* have let that slip by for the other cases below, so the
45264526
// early-exits are highly conservative.
45274527
const bool forInvertible =
4528-
conformance.getRequirement()->getInvertibleProtocolKind().has_value();
4528+
conformance.getProtocol()->getInvertibleProtocolKind().has_value();
45294529

45304530
if (conformingType->isTypeParameter()) {
45314531
assert(genericSig && "Need a generic signature to resolve conformance");
45324532
if (forInvertible)
45334533
return;
45344534

4535+
// FIXME: conformingType parameter should no longer be needed, because
4536+
// its in conformance.
45354537
auto path = genericSig->getConformancePath(conformingType,
4536-
conformance.getRequirement());
4538+
conformance.getProtocol());
45374539
appendDependentProtocolConformance(path, genericSig);
45384540
} else if (auto opaqueType = conformingType->getAs<OpaqueTypeArchetypeType>()) {
45394541
if (forInvertible)
@@ -4544,7 +4546,7 @@ void ASTMangler::appendAnyProtocolConformance(
45444546
ConformancePath conformancePath =
45454547
opaqueSignature->getConformancePath(
45464548
opaqueType->getInterfaceType(),
4547-
conformance.getRequirement());
4549+
conformance.getProtocol());
45484550

45494551
// Append the conformance path with the signature of the opaque type.
45504552
appendDependentProtocolConformance(conformancePath, opaqueSignature);

lib/AST/ASTPrinter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6634,7 +6634,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
66346634
case SILFunctionType::Representation::WitnessMethod:
66356635
Printer << "witness_method: ";
66366636
printTypeDeclName(
6637-
witnessMethodConformance.getRequirement()->getDeclaredType()
6637+
witnessMethodConformance.getProtocol()->getDeclaredType()
66386638
->castTo<ProtocolType>());
66396639
break;
66406640
case SILFunctionType::Representation::Closure:

lib/AST/ASTVerifier.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1785,7 +1785,7 @@ class Verifier : public ASTWalker {
17851785
for (auto proto : erasedLayout.getProtocols()) {
17861786
if (std::find_if(conformances.begin(), conformances.end(),
17871787
[&](ProtocolConformanceRef ref) -> bool {
1788-
return ref.getRequirement() == proto->getDecl();
1788+
return ref.getProtocol() == proto->getDecl();
17891789
})
17901790
== conformances.end()) {
17911791
Out << "ErasureExpr is missing conformance for required protocol\n";
@@ -1819,7 +1819,7 @@ class Verifier : public ASTWalker {
18191819
anyHashableDecl->getDeclaredInterfaceType(),
18201820
"AnyHashableErasureExpr and the standard AnyHashable type");
18211821

1822-
if (E->getConformance().getRequirement() != hashableDecl) {
1822+
if (E->getConformance().getProtocol() != hashableDecl) {
18231823
Out << "conformance on AnyHashableErasureExpr was not for Hashable\n";
18241824
E->getConformance().dump(Out);
18251825
abort();
@@ -2811,7 +2811,7 @@ class Verifier : public ASTWalker {
28112811
if (!type->is<ArchetypeType>() && !type->isAnyExistentialType()) {
28122812
Out << "type " << type
28132813
<< " should not have an abstract conformance to "
2814-
<< conformance.getRequirement()->getName();
2814+
<< conformance.getProtocol()->getName();
28152815
abort();
28162816
}
28172817

lib/AST/AbstractConformance.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ class AbstractConformance final : public llvm::FoldingSetNode {
2929
AbstractConformance(Type conformingType, ProtocolDecl *requirement)
3030
: conformingType(conformingType), requirement(requirement) { }
3131

32-
Type getConformingType() const { return conformingType; }
33-
ProtocolDecl *getRequirement() const { return requirement; }
32+
Type getType() const { return conformingType; }
33+
ProtocolDecl *getProtocol() const { return requirement; }
3434

3535
void Profile(llvm::FoldingSetNodeID &id) const {
36-
Profile(id, getConformingType(), getRequirement());
36+
Profile(id, getType(), getProtocol());
3737
}
3838

3939
/// Profile the substitution map storage, for use with LLVM's FoldingSet.

lib/AST/Effects.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void swift::simple_display(llvm::raw_ostream &out,
136136

137137
bool ProtocolConformanceRef::hasEffect(EffectKind kind) const {
138138
if (!isConcrete()) { return kind != EffectKind::Unsafe; }
139-
return evaluateOrDefault(getRequirement()->getASTContext().evaluator,
139+
return evaluateOrDefault(getProtocol()->getASTContext().evaluator,
140140
ConformanceHasEffectRequest{kind, getConcrete()},
141141
true);
142142
}

lib/AST/ProtocolConformanceRef.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ bool ProtocolConformanceRef::isInvalid() const {
4343
return false;
4444
}
4545

46-
Type ProtocolConformanceRef::getConformingType() const {
46+
Type ProtocolConformanceRef::getType() const {
4747
if (isInvalid())
4848
return Type();
4949

@@ -53,16 +53,16 @@ Type ProtocolConformanceRef::getConformingType() const {
5353
if (isPack())
5454
return Type(getPack()->getType());
5555

56-
return getAbstract()->getConformingType();
56+
return getAbstract()->getType();
5757
}
5858

59-
ProtocolDecl *ProtocolConformanceRef::getRequirement() const {
59+
ProtocolDecl *ProtocolConformanceRef::getProtocol() const {
6060
if (isConcrete()) {
6161
return getConcrete()->getProtocol();
6262
} else if (isPack()) {
6363
return getPack()->getProtocol();
6464
} else {
65-
return getAbstract()->getRequirement();
65+
return getAbstract()->getProtocol();
6666
}
6767
}
6868

@@ -107,7 +107,7 @@ ProtocolConformanceRef::subst(Type origType, InFlightSubstitution &IFS) const {
107107
// Otherwise, compute the substituted type.
108108
auto substType = origType.subst(IFS);
109109

110-
auto *proto = getRequirement();
110+
auto *proto = getProtocol();
111111

112112
// If the type is an existential, it must be self-conforming.
113113
if (substType->isExistentialType()) {
@@ -156,7 +156,7 @@ ProtocolConformanceRef::getTypeWitnessByName(Type type, Identifier name) const {
156156
assert(!isInvalid());
157157

158158
// Find the named requirement.
159-
ProtocolDecl *proto = getRequirement();
159+
ProtocolDecl *proto = getProtocol();
160160
auto *assocType = proto->getAssociatedType(name);
161161

162162
// FIXME: Shouldn't this be a hard error?
@@ -169,7 +169,7 @@ ProtocolConformanceRef::getTypeWitnessByName(Type type, Identifier name) const {
169169
ConcreteDeclRef
170170
ProtocolConformanceRef::getWitnessByName(Type type, DeclName name) const {
171171
// Find the named requirement.
172-
auto *proto = getRequirement();
172+
auto *proto = getProtocol();
173173
auto *requirement = proto->getSingleRequirement(name);
174174
if (requirement == nullptr)
175175
return ConcreteDeclRef();
@@ -210,7 +210,7 @@ Type ProtocolConformanceRef::getTypeWitness(Type conformingType,
210210
if (isInvalid())
211211
return failed();
212212

213-
auto proto = getRequirement();
213+
auto proto = getProtocol();
214214
ASSERT(assocType->getProtocol() == proto);
215215

216216
if (isConcrete()) {
@@ -239,7 +239,7 @@ Type ProtocolConformanceRef::getAssociatedType(Type conformingType,
239239
if (isInvalid())
240240
return ErrorType::get(assocType->getASTContext());
241241

242-
auto proto = getRequirement();
242+
auto proto = getProtocol();
243243

244244
auto substMap =
245245
SubstitutionMap::getProtocolSubstitutions(proto, conformingType, *this);
@@ -313,7 +313,7 @@ bool ProtocolConformanceRef::isCanonical() const {
313313
return getPack()->isCanonical();
314314

315315
if (isAbstract()) {
316-
Type conformingType = getConformingType();
316+
Type conformingType = getType();
317317
return !conformingType || conformingType->isCanonical();
318318
}
319319

@@ -329,10 +329,10 @@ ProtocolConformanceRef::getCanonicalConformanceRef() const {
329329
return ProtocolConformanceRef(getPack()->getCanonicalConformance());
330330

331331
if (isAbstract()) {
332-
Type conformingType = getConformingType();
332+
Type conformingType = getType();
333333
if (conformingType)
334334
conformingType = conformingType->getCanonicalType();
335-
return forAbstract(conformingType, getRequirement());
335+
return forAbstract(conformingType, getProtocol());
336336
}
337337

338338
return ProtocolConformanceRef(getConcrete()->getCanonicalConformance());
@@ -445,7 +445,7 @@ bool ProtocolConformanceRef::forEachIsolatedConformance(
445445

446446
void swift::simple_display(llvm::raw_ostream &out, ProtocolConformanceRef conformanceRef) {
447447
if (conformanceRef.isAbstract()) {
448-
simple_display(out, conformanceRef.getRequirement());
448+
simple_display(out, conformanceRef.getProtocol());
449449
} else if (conformanceRef.isConcrete()) {
450450
simple_display(out, conformanceRef.getConcrete());
451451
} else if (conformanceRef.isPack()) {
@@ -455,7 +455,7 @@ void swift::simple_display(llvm::raw_ostream &out, ProtocolConformanceRef confor
455455

456456
SourceLoc swift::extractNearestSourceLoc(const ProtocolConformanceRef conformanceRef) {
457457
if (conformanceRef.isAbstract()) {
458-
return extractNearestSourceLoc(conformanceRef.getRequirement());
458+
return extractNearestSourceLoc(conformanceRef.getProtocol());
459459
} else if (conformanceRef.isConcrete()) {
460460
return extractNearestSourceLoc(conformanceRef.getConcrete());
461461
}

lib/IRGen/GenExistential.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,7 @@ static void forEachProtocolWitnessTable(
18021802
"mismatched protocol conformances");
18031803

18041804
for (unsigned i = 0, e = protocols.size(); i < e; ++i) {
1805-
assert(protocols[i] == witnessConformances[i].getRequirement());
1805+
assert(protocols[i] == witnessConformances[i].getProtocol());
18061806
auto table = emitWitnessTableRef(IGF, srcType, srcMetadataCache,
18071807
witnessConformances[i]);
18081808
body(i, table);
@@ -1877,7 +1877,7 @@ OwnedAddress irgen::emitBoxedExistentialContainerAllocation(IRGenFunction &IGF,
18771877
assert(conformances.size() == 1 && destTI.getStoredProtocols().size() == 1);
18781878
const ProtocolDecl *proto = destTI.getStoredProtocols()[0];
18791879
(void) proto;
1880-
assert(proto == conformances[0].getRequirement());
1880+
assert(proto == conformances[0].getProtocol());
18811881
auto witness = emitWitnessTableRef(IGF, formalSrcType, &srcMetadata,
18821882
conformances[0]);
18831883

@@ -1965,7 +1965,7 @@ void irgen::emitClassExistentialContainer(IRGenFunction &IGF,
19651965
static size_t numProtocolsWithWitnessTables(
19661966
ArrayRef<ProtocolConformanceRef> conformances) {
19671967
return llvm::count_if(conformances, [](ProtocolConformanceRef conformance) {
1968-
auto proto = conformance.getRequirement();
1968+
auto proto = conformance.getProtocol();
19691969
return Lowering::TypeConverter::protocolRequiresWitnessTable(proto);
19701970
});
19711971
}

lib/IRGen/GenMeta.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ namespace {
11871187

11881188
auto assocConf = entry.getAssociatedConformanceWitness();
11891189
if (assocConf.Requirement != association ||
1190-
assocConf.Witness.getRequirement() != requirement)
1190+
assocConf.Witness.getProtocol() != requirement)
11911191
continue;
11921192

11931193
AssociatedConformance conformance(Proto, association, requirement);

lib/IRGen/GenPack.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ static llvm::Value *emitPackExpansionElementWitnessTable(
575575
auto instantiatedPatternTy =
576576
context.environment->mapContextualPackTypeIntoElementContext(patternTy);
577577
auto instantiatedConformance =
578-
lookupConformance(instantiatedPatternTy, conformance.getRequirement());
578+
lookupConformance(instantiatedPatternTy, conformance.getProtocol());
579579

580580
// Emit the element witness table.
581581
auto *wtable = emitWitnessTableRef(IGF, instantiatedPatternTy,
@@ -1124,7 +1124,7 @@ void irgen::bindOpenedElementArchetypesAtIndex(IRGenFunction &IGF,
11241124
assert(conformances.size() == wtables.size());
11251125
for (unsigned i : indices(wtables)) {
11261126
auto reqt = GenericRequirement::forWitnessTable(
1127-
archetype, conformances[i].getRequirement());
1127+
archetype, conformances[i].getProtocol());
11281128
bindGenericRequirement(IGF, reqt, wtables[i], MetadataState::Complete,
11291129
SubstitutionMap());
11301130
}

0 commit comments

Comments
 (0)