@@ -3684,6 +3684,28 @@ static void lookupReplacedDecl(DeclNameRef replacedDeclName,
3684
3684
results);
3685
3685
}
3686
3686
3687
+ static void
3688
+ diagnoseCandidatesEliminatedByModuleSelector (DeclNameRefWithLoc replacedDeclName,
3689
+ DeclAttribute *attr,
3690
+ const ValueDecl *replacement,
3691
+ DiagnosticEngine &Diags) {
3692
+ if (replacedDeclName.Name .getModuleSelector ().empty ())
3693
+ return ;
3694
+
3695
+ // Look up without the module selector
3696
+ SmallVector<ValueDecl *, 4 > results;
3697
+ lookupReplacedDecl (DeclNameRef (replacedDeclName.Name .getFullName ()),
3698
+ attr, replacement, results);
3699
+
3700
+ auto selectorLoc = replacedDeclName.Loc .getModuleSelectorLoc ();
3701
+
3702
+ for (auto candidate : results)
3703
+ Diags.diagnose (selectorLoc, diag::note_change_module_selector,
3704
+ candidate->getModuleContext ()->getBaseIdentifier ())
3705
+ .fixItReplace (selectorLoc,
3706
+ candidate->getModuleContext ()->getBaseIdentifier ().str ());
3707
+ }
3708
+
3687
3709
// / Remove any argument labels from the interface type of the given value that
3688
3710
// / are extraneous from the type system's point of view, producing the
3689
3711
// / type to compare against for the purposes of dynamic replacement.
@@ -3703,14 +3725,14 @@ static Type getDynamicComparisonType(ValueDecl *value) {
3703
3725
return interfaceType->removeArgumentLabels (numArgumentLabels);
3704
3726
}
3705
3727
3706
- static FuncDecl *findSimilarAccessor (DeclNameRef replacedVarName,
3728
+ static FuncDecl *findSimilarAccessor (DeclNameRefWithLoc replacedVarName,
3707
3729
const AccessorDecl *replacement,
3708
3730
DeclAttribute *attr, ASTContext &ctx,
3709
3731
bool forDynamicReplacement) {
3710
3732
3711
3733
// Retrieve the replaced abstract storage decl.
3712
3734
SmallVector<ValueDecl *, 4 > results;
3713
- lookupReplacedDecl (replacedVarName, attr, replacement, results);
3735
+ lookupReplacedDecl (replacedVarName. Name , attr, replacement, results);
3714
3736
3715
3737
// Filter out any accessors that won't work.
3716
3738
if (!results.empty ()) {
@@ -3743,15 +3765,19 @@ static FuncDecl *findSimilarAccessor(DeclNameRef replacedVarName,
3743
3765
if (results.empty ()) {
3744
3766
Diags.diagnose (attr->getLocation (),
3745
3767
diag::dynamic_replacement_accessor_not_found,
3746
- replacedVarName);
3768
+ replacedVarName. Name );
3747
3769
attr->setInvalid ();
3770
+
3771
+ diagnoseCandidatesEliminatedByModuleSelector (replacedVarName, attr,
3772
+ replacement, Diags);
3773
+
3748
3774
return nullptr ;
3749
3775
}
3750
3776
3751
3777
if (results.size () > 1 ) {
3752
3778
Diags.diagnose (attr->getLocation (),
3753
3779
diag::dynamic_replacement_accessor_ambiguous,
3754
- replacedVarName);
3780
+ replacedVarName. Name );
3755
3781
for (auto result : results) {
3756
3782
Diags.diagnose (result,
3757
3783
diag::dynamic_replacement_accessor_ambiguous_candidate,
@@ -3793,15 +3819,15 @@ static FuncDecl *findSimilarAccessor(DeclNameRef replacedVarName,
3793
3819
return origAccessor;
3794
3820
}
3795
3821
3796
- static FuncDecl *findReplacedAccessor (DeclNameRef replacedVarName,
3822
+ static FuncDecl *findReplacedAccessor (DeclNameRefWithLoc replacedVarName,
3797
3823
const AccessorDecl *replacement,
3798
3824
DeclAttribute *attr,
3799
3825
ASTContext &ctx) {
3800
3826
return findSimilarAccessor (replacedVarName, replacement, attr, ctx,
3801
3827
/* forDynamicReplacement*/ true );
3802
3828
}
3803
3829
3804
- static FuncDecl *findTargetAccessor (DeclNameRef replacedVarName,
3830
+ static FuncDecl *findTargetAccessor (DeclNameRefWithLoc replacedVarName,
3805
3831
const AccessorDecl *replacement,
3806
3832
DeclAttribute *attr,
3807
3833
ASTContext &ctx) {
@@ -3810,15 +3836,15 @@ static FuncDecl *findTargetAccessor(DeclNameRef replacedVarName,
3810
3836
}
3811
3837
3812
3838
static AbstractFunctionDecl *
3813
- findSimilarFunction (DeclNameRef replacedFunctionName,
3839
+ findSimilarFunction (DeclNameRefWithLoc replacedFunctionName,
3814
3840
const AbstractFunctionDecl *base, DeclAttribute *attr,
3815
3841
DiagnosticEngine *Diags, bool forDynamicReplacement) {
3816
3842
3817
3843
// Note: we might pass a constant attribute when typechecker is nullptr.
3818
3844
// Any modification to attr must be guarded by a null check on TC.
3819
3845
//
3820
3846
SmallVector<ValueDecl *, 4 > lookupResults;
3821
- lookupReplacedDecl (replacedFunctionName, attr, base, lookupResults);
3847
+ lookupReplacedDecl (replacedFunctionName. Name , attr, base, lookupResults);
3822
3848
3823
3849
SmallVector<AbstractFunctionDecl *, 4 > candidates;
3824
3850
for (auto *result : lookupResults) {
@@ -3839,7 +3865,9 @@ findSimilarFunction(DeclNameRef replacedFunctionName,
3839
3865
forDynamicReplacement
3840
3866
? diag::dynamic_replacement_function_not_found
3841
3867
: diag::specialize_target_function_not_found,
3842
- replacedFunctionName);
3868
+ replacedFunctionName.Name );
3869
+ diagnoseCandidatesEliminatedByModuleSelector (replacedFunctionName, attr,
3870
+ base, *Diags);
3843
3871
}
3844
3872
3845
3873
attr->setInvalid ();
@@ -3905,7 +3933,7 @@ findSimilarFunction(DeclNameRef replacedFunctionName,
3905
3933
forDynamicReplacement
3906
3934
? diag::dynamic_replacement_function_of_type_not_found
3907
3935
: diag::specialize_target_function_of_type_not_found,
3908
- replacedFunctionName,
3936
+ replacedFunctionName. Name ,
3909
3937
base->getInterfaceType ()->getCanonicalType ());
3910
3938
3911
3939
for (auto *result : matches) {
@@ -3921,15 +3949,15 @@ findSimilarFunction(DeclNameRef replacedFunctionName,
3921
3949
}
3922
3950
3923
3951
static AbstractFunctionDecl *
3924
- findReplacedFunction (DeclNameRef replacedFunctionName,
3952
+ findReplacedFunction (DeclNameRefWithLoc replacedFunctionName,
3925
3953
const AbstractFunctionDecl *replacement,
3926
3954
DynamicReplacementAttr *attr, DiagnosticEngine *Diags) {
3927
3955
return findSimilarFunction (replacedFunctionName, replacement, attr, Diags,
3928
3956
true /* forDynamicReplacement*/ );
3929
3957
}
3930
3958
3931
3959
static AbstractFunctionDecl *
3932
- findTargetFunction (DeclNameRef targetFunctionName,
3960
+ findTargetFunction (DeclNameRefWithLoc targetFunctionName,
3933
3961
const AbstractFunctionDecl *base,
3934
3962
SpecializeAttr * attr, DiagnosticEngine *diags) {
3935
3963
return findSimilarFunction (targetFunctionName, base, attr, diags,
@@ -5587,13 +5615,15 @@ DynamicallyReplacedDeclRequest::evaluate(Evaluator &evaluator,
5587
5615
}
5588
5616
5589
5617
auto &Ctx = VD->getASTContext ();
5618
+ DeclNameRefWithLoc nameWithLoc{attr->getReplacedFunctionName (),
5619
+ attr->getReplacedFunctionNameLoc (),
5620
+ std::nullopt};
5590
5621
if (auto *AD = dyn_cast<AccessorDecl>(VD)) {
5591
- return findReplacedAccessor (attr-> getReplacedFunctionName () , AD, attr, Ctx);
5622
+ return findReplacedAccessor (nameWithLoc , AD, attr, Ctx);
5592
5623
}
5593
5624
5594
5625
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(VD)) {
5595
- return findReplacedFunction (attr->getReplacedFunctionName (), AFD,
5596
- attr, &Ctx.Diags );
5626
+ return findReplacedFunction (nameWithLoc, AFD, attr, &Ctx.Diags );
5597
5627
}
5598
5628
5599
5629
if (auto *SD = dyn_cast<AbstractStorageDecl>(VD)) {
@@ -5616,8 +5646,10 @@ SpecializeAttrTargetDeclRequest::evaluate(Evaluator &evaluator,
5616
5646
5617
5647
auto &ctx = vd->getASTContext ();
5618
5648
5619
- auto targetFunctionName = attr->getTargetFunctionName ();
5620
- if (!targetFunctionName)
5649
+ DeclNameRefWithLoc targetFunctionName{attr->getTargetFunctionName (),
5650
+ attr->getTargetFunctionNameLoc (),
5651
+ std::nullopt};
5652
+ if (!targetFunctionName.Name )
5621
5653
return nullptr ;
5622
5654
5623
5655
if (auto *ad = dyn_cast<AccessorDecl>(vd)) {
0 commit comments