Skip to content

Commit 77565ff

Browse files
committed
IDE: Remove bogus use of getCanonicalTypeInContext()
The GenericSig might come from a protocol extension. The original types in the Requirement come from this generic signature. However, the Requirement can then be substituted with the base type's concrete substitutions, and if the base type is a conforming nominal type, we now have a Requirement whose types are written in terms of the conforming nominal type's generic signature. Therefore, the call to getCanonicalTypeInContext() might not produce correct results, since there's no guarantee the protocol extension's GenericSignature has the same requirements as the conforming type's. This used to just silently produce incorrect results, but now asserts when the RequirementMachine is enabled. To fix this I replaced these calls with plain old getCanonicalType() that does not take a GenericSignature. If we find a case that is now broken as a result of this change, we'll need to re-introduce some bookkeeping here to keep track of *which* GenericSignature generates the types in the substituted Requirement.
1 parent 74fbc8b commit 77565ff

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

lib/IDE/IDETypeChecking.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ struct SynthesizedExtensionAnalyzer::Implementation {
170170
bool Unmergable;
171171
unsigned InheritsCount;
172172
std::set<Requirement> Requirements;
173-
void addRequirement(GenericSignature GenericSig, swift::Requirement Req) {
173+
void addRequirement(swift::Requirement Req) {
174174
auto First = Req.getFirstType();
175-
auto CanFirst = GenericSig->getCanonicalTypeInContext(First);
175+
auto CanFirst = First->getCanonicalType();
176176
auto Second = Req.getSecondType();
177-
auto CanSecond = GenericSig->getCanonicalTypeInContext(Second);
177+
auto CanSecond = Second->getCanonicalType();
178178

179179
Requirements.insert({First, Second, Req.getKind(), CanFirst, CanSecond});
180180
}
@@ -284,7 +284,6 @@ struct SynthesizedExtensionAnalyzer::Implementation {
284284
}
285285

286286
auto handleRequirements = [&](SubstitutionMap subMap,
287-
GenericSignature GenericSig,
288287
ExtensionDecl *OwningExt,
289288
ArrayRef<Requirement> Reqs) {
290289
ProtocolDecl *BaseProto = OwningExt->getInnermostDeclContext()
@@ -336,7 +335,7 @@ struct SynthesizedExtensionAnalyzer::Implementation {
336335
if (!SubstReq->canBeSatisfied())
337336
return true;
338337

339-
MergeInfo.addRequirement(GenericSig, Req);
338+
MergeInfo.addRequirement(Req);
340339
}
341340
}
342341
return false;
@@ -355,7 +354,7 @@ struct SynthesizedExtensionAnalyzer::Implementation {
355354

356355
assert(Ext->getGenericSignature() && "No generic signature.");
357356
auto GenericSig = Ext->getGenericSignature();
358-
if (handleRequirements(subMap, GenericSig, Ext, GenericSig->getRequirements()))
357+
if (handleRequirements(subMap, Ext, GenericSig->getRequirements()))
359358
return {Result, MergeInfo};
360359
}
361360

@@ -366,7 +365,6 @@ struct SynthesizedExtensionAnalyzer::Implementation {
366365
subMap = BaseType->getContextSubstitutionMap(M, NTD);
367366
}
368367
if (handleRequirements(subMap,
369-
Conf->getGenericSignature(),
370368
EnablingExt,
371369
Conf->getConditionalRequirements()))
372370
return {Result, MergeInfo};

0 commit comments

Comments
 (0)