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