Skip to content

Commit d4f2e2b

Browse files
committed
[IDE] Use getProtocolSubstitutions in SynthesizedExtensionAnalyzer
Get the substitution map from the conformance rather than building it from the base type.
1 parent da0525a commit d4f2e2b

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

lib/IDE/IDETypeChecking.cpp

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -277,22 +277,17 @@ struct SynthesizedExtensionAnalyzer::Implementation {
277277
using MergeGroupVector = std::vector<ExtensionMergeGroup>;
278278

279279
NominalTypeDecl *Target;
280-
Type BaseType;
281280
DeclContext *DC;
282281
bool IncludeUnconditional;
283282
PrintOptions Options;
284283
MergeGroupVector AllGroups;
285284
ExtensionInfoMap InfoMap;
286285

287-
Implementation(NominalTypeDecl *Target,
288-
bool IncludeUnconditional,
289-
PrintOptions &&Options):
290-
Target(Target),
291-
BaseType(Target->getDeclaredInterfaceType()),
292-
DC(Target),
293-
IncludeUnconditional(IncludeUnconditional),
294-
Options(std::move(Options)), AllGroups(MergeGroupVector()),
295-
InfoMap(collectSynthesizedExtensionInfo(AllGroups)) {}
286+
Implementation(NominalTypeDecl *Target, bool IncludeUnconditional,
287+
PrintOptions &&Options)
288+
: Target(Target), DC(Target), IncludeUnconditional(IncludeUnconditional),
289+
Options(std::move(Options)), AllGroups(MergeGroupVector()),
290+
InfoMap(collectSynthesizedExtensionInfo(AllGroups)) {}
296291

297292
unsigned countInherits(ExtensionDecl *ED) {
298293
SmallVector<InheritedEntry, 4> Results;
@@ -316,9 +311,9 @@ struct SynthesizedExtensionAnalyzer::Implementation {
316311
// extension SomeType: SomeProtocol where T: SomeProtocol {}. The former is
317312
// Ext and the latter is EnablingExt/Conf. Either of these can be
318313
// conditional in ways that need to be considered when merging.
319-
auto conformanceIsConditional =
320-
Conf && !Conf->getConditionalRequirements().empty();
321-
if (!Ext->isConstrainedExtension() && !conformanceIsConditional) {
314+
auto isConditionalEnablingExt =
315+
Conf && EnablingExt && !Conf->getConditionalRequirements().empty();
316+
if (!Ext->isConstrainedExtension() && !isConditionalEnablingExt) {
322317
if (IncludeUnconditional)
323318
Result.Ext = Ext;
324319
return {Result, MergeInfo};
@@ -330,9 +325,9 @@ struct SynthesizedExtensionAnalyzer::Implementation {
330325
// Substitute the base conforming type into a protocol's generic signature
331326
// if needed.
332327
SubstitutionMap subMap;
333-
if (!BaseType->is<ProtocolType>() && BaseProto) {
334-
subMap = SubstitutionMap::get(BaseProto->getGenericSignature(),
335-
{BaseType}, LookUpConformanceInModule());
328+
if (Conf && BaseProto) {
329+
subMap = SubstitutionMap::getProtocolSubstitutions(
330+
ProtocolConformanceRef(Conf));
336331
}
337332
for (auto Req : Reqs) {
338333
// Skip protocol's Self : <Protocol> requirement.
@@ -407,7 +402,7 @@ struct SynthesizedExtensionAnalyzer::Implementation {
407402
return {Result, MergeInfo};
408403
}
409404

410-
if (Conf) {
405+
if (isConditionalEnablingExt) {
411406
if (handleRequirements(EnablingExt, Conf->getConditionalRequirements()))
412407
return {Result, MergeInfo};
413408
}
@@ -509,7 +504,7 @@ struct SynthesizedExtensionAnalyzer::Implementation {
509504
continue;
510505

511506
for (auto *E : Conf->getProtocol()->getExtensions())
512-
handleExtension(E, true, nullptr, nullptr);
507+
handleExtension(E, true, nullptr, Conf);
513508
}
514509

515510
// Merge with actual extensions.

0 commit comments

Comments
 (0)