Skip to content

Commit 02c30d1

Browse files
committed
AST: Fix confusion when builtin conformance passed to registerProtocolConformance()
1 parent a144c69 commit 02c30d1

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

include/swift/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4219,7 +4219,7 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
42194219
///
42204220
/// This is used by deserialization of module files to report
42214221
/// conformances.
4222-
void registerProtocolConformance(ProtocolConformance *conformance,
4222+
void registerProtocolConformance(NormalProtocolConformance *conformance,
42234223
bool synthesized = false);
42244224

42254225
void setConformanceLoader(LazyMemberLoader *resolver, uint64_t contextData);

lib/AST/ConformanceLookupTable.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void ConformanceLookupTable::forEachInStage(ConformanceStage stage,
174174
if (loader.first) {
175175
SmallVector<ProtocolConformance *, 2> conformances;
176176
loader.first->loadAllConformances(nominal, loader.second, conformances);
177-
loadAllConformances(nominal, conformances);
177+
registerProtocolConformances(nominal, conformances);
178178
}
179179

180180
nominalFunc(nominal);
@@ -202,7 +202,7 @@ void ConformanceLookupTable::forEachInStage(ConformanceStage stage,
202202
if (loader.first) {
203203
SmallVector<ProtocolConformance *, 2> conformances;
204204
loader.first->loadAllConformances(next, loader.second, conformances);
205-
loadAllConformances(next, conformances);
205+
registerProtocolConformances(next, conformances);
206206
for (auto conf : conformances) {
207207
protocols.push_back(
208208
{conf->getProtocol(), SourceLoc(), SourceLoc(), SourceLoc()});
@@ -433,19 +433,17 @@ void ConformanceLookupTable::updateLookupTable(NominalTypeDecl *nominal,
433433
}
434434
}
435435

436-
void ConformanceLookupTable::loadAllConformances(
436+
void ConformanceLookupTable::registerProtocolConformances(
437437
DeclContext *dc,
438438
ArrayRef<ProtocolConformance*> conformances) {
439439
// If this declaration context came from source, there's nothing to
440440
// do here.
441-
if (dc->getParentSourceFile() ||
442-
dc->getParentModule()->isBuiltinModule()) {
443-
return;
444-
}
441+
assert(!dc->getParentSourceFile() &&
442+
!dc->getParentModule()->isBuiltinModule());
445443

446444
// Add entries for each loaded conformance.
447445
for (auto conformance : conformances) {
448-
registerProtocolConformance(conformance);
446+
registerProtocolConformance(dc, conformance);
449447
}
450448
}
451449

@@ -1019,10 +1017,9 @@ void ConformanceLookupTable::addSynthesizedConformance(
10191017
}
10201018

10211019
void ConformanceLookupTable::registerProtocolConformance(
1022-
ProtocolConformance *conformance,
1020+
DeclContext *dc, ProtocolConformance *conformance,
10231021
bool synthesized) {
10241022
auto protocol = conformance->getProtocol();
1025-
auto dc = conformance->getDeclContext();
10261023
auto nominal = dc->getSelfNominalTypeDecl();
10271024

10281025
// If there is an entry to update, do so.

lib/AST/ConformanceLookupTable.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,10 @@ class ConformanceLookupTable : public ASTAllocated<ConformanceLookupTable> {
459459
/// Update a lookup table with conformances from newly-added extensions.
460460
void updateLookupTable(NominalTypeDecl *nominal, ConformanceStage stage);
461461

462-
/// Load all of the protocol conformances for the given (serialized)
462+
/// Register deserialized protocol conformances for the given (serialized)
463463
/// declaration context.
464-
void loadAllConformances(DeclContext *dc,
465-
ArrayRef<ProtocolConformance *> conformances);
464+
void registerProtocolConformances(DeclContext *dc,
465+
ArrayRef<ProtocolConformance *> conformances);
466466

467467
public:
468468
/// Create a new conformance lookup table.
@@ -477,7 +477,8 @@ class ConformanceLookupTable : public ASTAllocated<ConformanceLookupTable> {
477477
DeclContext *conformanceDC);
478478

479479
/// Register an externally-supplied protocol conformance.
480-
void registerProtocolConformance(ProtocolConformance *conformance,
480+
void registerProtocolConformance(DeclContext *dc,
481+
ProtocolConformance *conformance,
481482
bool synthesized = false);
482483

483484
/// Look for conformances to the given protocol.

lib/AST/ProtocolConformance.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,9 +1195,10 @@ void NominalTypeDecl::getImplicitProtocols(
11951195
}
11961196

11971197
void NominalTypeDecl::registerProtocolConformance(
1198-
ProtocolConformance *conformance, bool synthesized) {
1198+
NormalProtocolConformance *conformance, bool synthesized) {
11991199
prepareConformanceTable();
1200-
ConformanceTable->registerProtocolConformance(conformance, synthesized);
1200+
auto *dc = conformance->getDeclContext();
1201+
ConformanceTable->registerProtocolConformance(dc, conformance, synthesized);
12011202
}
12021203

12031204
ArrayRef<ValueDecl *>

0 commit comments

Comments
 (0)