@@ -261,7 +261,7 @@ struct SynthesizedExtensionAnalyzer::Implementation {
261261 bool IncludeUnconditional;
262262 PrintOptions Options;
263263 MergeGroupVector AllGroups;
264- std::unique_ptr< ExtensionInfoMap> InfoMap;
264+ ExtensionInfoMap InfoMap;
265265
266266 Implementation (NominalTypeDecl *Target,
267267 bool IncludeUnconditional,
@@ -416,9 +416,9 @@ struct SynthesizedExtensionAnalyzer::Implementation {
416416 }
417417 }
418418
419- std::unique_ptr< ExtensionInfoMap>
419+ ExtensionInfoMap
420420 collectSynthesizedExtensionInfoForProtocol (MergeGroupVector &AllGroups) {
421- std::unique_ptr< ExtensionInfoMap> InfoMap ( new ExtensionInfoMap ()) ;
421+ ExtensionInfoMap InfoMap;
422422 ExtensionMergeInfoMap MergeInfoMap;
423423 for (auto *E : Target->getExtensions ()) {
424424 if (!Options.shouldPrint (E))
@@ -427,12 +427,12 @@ struct SynthesizedExtensionAnalyzer::Implementation {
427427 /* EnablingExt*/ nullptr ,
428428 /* Conf*/ nullptr );
429429 if (Pair.first ) {
430- InfoMap-> insert ({E, Pair.first });
430+ InfoMap. insert ({E, Pair.first });
431431 MergeInfoMap.insert ({E, Pair.second });
432432 }
433433 }
434- populateMergeGroup (* InfoMap, MergeInfoMap, AllGroups,
435- /* AllowMergeWithDefBody*/ false );
434+ populateMergeGroup (InfoMap, MergeInfoMap, AllGroups,
435+ /* AllowMergeWithDefBody= */ false );
436436 std::sort (AllGroups.begin (), AllGroups.end ());
437437 for (auto &Group : AllGroups) {
438438 Group.sortMembers ();
@@ -448,12 +448,13 @@ struct SynthesizedExtensionAnalyzer::Implementation {
448448 return false ;
449449 }
450450
451- std::unique_ptr< ExtensionInfoMap>
451+ ExtensionInfoMap
452452 collectSynthesizedExtensionInfo (MergeGroupVector &AllGroups) {
453453 if (isa<ProtocolDecl>(Target)) {
454454 return collectSynthesizedExtensionInfoForProtocol (AllGroups);
455455 }
456- std::unique_ptr<ExtensionInfoMap> InfoMap (new ExtensionInfoMap ());
456+
457+ ExtensionInfoMap InfoMap;
457458 ExtensionMergeInfoMap MergeInfoMap;
458459 std::vector<NominalTypeDecl*> Unhandled;
459460
@@ -470,7 +471,7 @@ struct SynthesizedExtensionAnalyzer::Implementation {
470471 if (AdjustedOpts.shouldPrint (E)) {
471472 auto Pair = isApplicable (E, Synthesized, EnablingE, Conf);
472473 if (Pair.first ) {
473- InfoMap-> insert ({E, Pair.first });
474+ InfoMap. insert ({E, Pair.first });
474475 MergeInfoMap.insert ({E, Pair.second });
475476 }
476477 }
@@ -515,8 +516,8 @@ struct SynthesizedExtensionAnalyzer::Implementation {
515516 }
516517 }
517518
518- populateMergeGroup (* InfoMap, MergeInfoMap, AllGroups,
519- /* AllowMergeWithDefBody*/ true );
519+ populateMergeGroup (InfoMap, MergeInfoMap, AllGroups,
520+ /* AllowMergeWithDefBody= */ true );
520521
521522 std::sort (AllGroups.begin (), AllGroups.end ());
522523 for (auto &Group : AllGroups) {
@@ -531,20 +532,22 @@ struct SynthesizedExtensionAnalyzer::Implementation {
531532 }
532533};
533534
534- SynthesizedExtensionAnalyzer::
535- SynthesizedExtensionAnalyzer (NominalTypeDecl *Target,
536- PrintOptions Options,
537- bool IncludeUnconditional):
538- Impl(*(new Implementation(Target, IncludeUnconditional, Options))) {}
535+ SynthesizedExtensionAnalyzer::SynthesizedExtensionAnalyzer (
536+ NominalTypeDecl *Target, PrintOptions Options, bool IncludeUnconditional)
537+ : Impl(*(new Implementation(Target, IncludeUnconditional, Options))) {}
539538
540539SynthesizedExtensionAnalyzer::~SynthesizedExtensionAnalyzer () {delete &Impl;}
541540
542- bool SynthesizedExtensionAnalyzer::
543- isInSynthesizedExtension ( const ValueDecl *VD) {
541+ bool SynthesizedExtensionAnalyzer::isInSynthesizedExtension (
542+ const ValueDecl *VD) {
544543 if (auto Ext = dyn_cast_or_null<ExtensionDecl>(VD->getDeclContext ()->
545544 getInnermostTypeContext ())) {
546- return Impl.InfoMap ->count (Ext) != 0 &&
547- Impl.InfoMap ->find (Ext)->second .IsSynthesized ;
545+ auto It = Impl.InfoMap .find (Ext);
546+ if (It != Impl.InfoMap .end () && It->second .IsSynthesized ) {
547+ // A synthesized extension will only be created if the underlying type
548+ // is in the same module
549+ return VD->getModuleContext () == Impl.Target ->getModuleContext ();
550+ }
548551 }
549552 return false ;
550553}
@@ -565,8 +568,7 @@ forEachExtensionMergeGroup(MergeGroupKind Kind, ExtensionGroupOperation Fn) {
565568 }
566569}
567570
568- bool SynthesizedExtensionAnalyzer::
569- hasMergeGroup (MergeGroupKind Kind) {
571+ bool SynthesizedExtensionAnalyzer::hasMergeGroup (MergeGroupKind Kind) {
570572 for (auto &Group : Impl.AllGroups ) {
571573 if (Kind == MergeGroupKind::All)
572574 return true ;
0 commit comments