@@ -3809,6 +3809,28 @@ static void lookupReplacedDecl(DeclNameRef replacedDeclName,
3809
3809
results);
3810
3810
}
3811
3811
3812
+ static void
3813
+ diagnoseCandidatesEliminatedByModuleSelector (DeclNameRefWithLoc replacedDeclName,
3814
+ DeclAttribute *attr,
3815
+ const ValueDecl *replacement,
3816
+ DiagnosticEngine &Diags) {
3817
+ if (replacedDeclName.Name .getModuleSelector ().empty ())
3818
+ return ;
3819
+
3820
+ // Look up without the module selector
3821
+ SmallVector<ValueDecl *, 4 > results;
3822
+ lookupReplacedDecl (DeclNameRef (replacedDeclName.Name .getFullName ()),
3823
+ attr, replacement, results);
3824
+
3825
+ auto selectorLoc = replacedDeclName.Loc .getModuleSelectorLoc ();
3826
+
3827
+ for (auto candidate : results)
3828
+ Diags.diagnose (selectorLoc, diag::note_change_module_selector,
3829
+ candidate->getModuleContext ()->getBaseIdentifier ())
3830
+ .fixItReplace (selectorLoc,
3831
+ candidate->getModuleContext ()->getBaseIdentifier ().str ());
3832
+ }
3833
+
3812
3834
// / Remove any argument labels from the interface type of the given value that
3813
3835
// / are extraneous from the type system's point of view, producing the
3814
3836
// / type to compare against for the purposes of dynamic replacement.
@@ -3828,14 +3850,14 @@ static Type getDynamicComparisonType(ValueDecl *value) {
3828
3850
return interfaceType->removeArgumentLabels (numArgumentLabels);
3829
3851
}
3830
3852
3831
- static FuncDecl *findSimilarAccessor (DeclNameRef replacedVarName,
3853
+ static FuncDecl *findSimilarAccessor (DeclNameRefWithLoc replacedVarName,
3832
3854
const AccessorDecl *replacement,
3833
3855
DeclAttribute *attr, ASTContext &ctx,
3834
3856
bool forDynamicReplacement) {
3835
3857
3836
3858
// Retrieve the replaced abstract storage decl.
3837
3859
SmallVector<ValueDecl *, 4 > results;
3838
- lookupReplacedDecl (replacedVarName, attr, replacement, results);
3860
+ lookupReplacedDecl (replacedVarName. Name , attr, replacement, results);
3839
3861
3840
3862
// Filter out any accessors that won't work.
3841
3863
if (!results.empty ()) {
@@ -3868,15 +3890,19 @@ static FuncDecl *findSimilarAccessor(DeclNameRef replacedVarName,
3868
3890
if (results.empty ()) {
3869
3891
Diags.diagnose (attr->getLocation (),
3870
3892
diag::dynamic_replacement_accessor_not_found,
3871
- replacedVarName);
3893
+ replacedVarName. Name );
3872
3894
attr->setInvalid ();
3895
+
3896
+ diagnoseCandidatesEliminatedByModuleSelector (replacedVarName, attr,
3897
+ replacement, Diags);
3898
+
3873
3899
return nullptr ;
3874
3900
}
3875
3901
3876
3902
if (results.size () > 1 ) {
3877
3903
Diags.diagnose (attr->getLocation (),
3878
3904
diag::dynamic_replacement_accessor_ambiguous,
3879
- replacedVarName);
3905
+ replacedVarName. Name );
3880
3906
for (auto result : results) {
3881
3907
Diags.diagnose (result,
3882
3908
diag::dynamic_replacement_accessor_ambiguous_candidate,
@@ -3918,15 +3944,15 @@ static FuncDecl *findSimilarAccessor(DeclNameRef replacedVarName,
3918
3944
return origAccessor;
3919
3945
}
3920
3946
3921
- static FuncDecl *findReplacedAccessor (DeclNameRef replacedVarName,
3947
+ static FuncDecl *findReplacedAccessor (DeclNameRefWithLoc replacedVarName,
3922
3948
const AccessorDecl *replacement,
3923
3949
DeclAttribute *attr,
3924
3950
ASTContext &ctx) {
3925
3951
return findSimilarAccessor (replacedVarName, replacement, attr, ctx,
3926
3952
/* forDynamicReplacement*/ true );
3927
3953
}
3928
3954
3929
- static FuncDecl *findTargetAccessor (DeclNameRef replacedVarName,
3955
+ static FuncDecl *findTargetAccessor (DeclNameRefWithLoc replacedVarName,
3930
3956
const AccessorDecl *replacement,
3931
3957
DeclAttribute *attr,
3932
3958
ASTContext &ctx) {
@@ -3935,15 +3961,15 @@ static FuncDecl *findTargetAccessor(DeclNameRef replacedVarName,
3935
3961
}
3936
3962
3937
3963
static AbstractFunctionDecl *
3938
- findSimilarFunction (DeclNameRef replacedFunctionName,
3964
+ findSimilarFunction (DeclNameRefWithLoc replacedFunctionName,
3939
3965
const AbstractFunctionDecl *base, DeclAttribute *attr,
3940
3966
DiagnosticEngine *Diags, bool forDynamicReplacement) {
3941
3967
3942
3968
// Note: we might pass a constant attribute when typechecker is nullptr.
3943
3969
// Any modification to attr must be guarded by a null check on TC.
3944
3970
//
3945
3971
SmallVector<ValueDecl *, 4 > lookupResults;
3946
- lookupReplacedDecl (replacedFunctionName, attr, base, lookupResults);
3972
+ lookupReplacedDecl (replacedFunctionName. Name , attr, base, lookupResults);
3947
3973
3948
3974
SmallVector<AbstractFunctionDecl *, 4 > candidates;
3949
3975
for (auto *result : lookupResults) {
@@ -3964,7 +3990,9 @@ findSimilarFunction(DeclNameRef replacedFunctionName,
3964
3990
forDynamicReplacement
3965
3991
? diag::dynamic_replacement_function_not_found
3966
3992
: diag::specialize_target_function_not_found,
3967
- replacedFunctionName);
3993
+ replacedFunctionName.Name );
3994
+ diagnoseCandidatesEliminatedByModuleSelector (replacedFunctionName, attr,
3995
+ base, *Diags);
3968
3996
}
3969
3997
3970
3998
attr->setInvalid ();
@@ -4030,7 +4058,7 @@ findSimilarFunction(DeclNameRef replacedFunctionName,
4030
4058
forDynamicReplacement
4031
4059
? diag::dynamic_replacement_function_of_type_not_found
4032
4060
: diag::specialize_target_function_of_type_not_found,
4033
- replacedFunctionName,
4061
+ replacedFunctionName. Name ,
4034
4062
base->getInterfaceType ()->getCanonicalType ());
4035
4063
4036
4064
for (auto *result : matches) {
@@ -4046,15 +4074,15 @@ findSimilarFunction(DeclNameRef replacedFunctionName,
4046
4074
}
4047
4075
4048
4076
static AbstractFunctionDecl *
4049
- findReplacedFunction (DeclNameRef replacedFunctionName,
4077
+ findReplacedFunction (DeclNameRefWithLoc replacedFunctionName,
4050
4078
const AbstractFunctionDecl *replacement,
4051
4079
DynamicReplacementAttr *attr, DiagnosticEngine *Diags) {
4052
4080
return findSimilarFunction (replacedFunctionName, replacement, attr, Diags,
4053
4081
true /* forDynamicReplacement*/ );
4054
4082
}
4055
4083
4056
4084
static AbstractFunctionDecl *
4057
- findTargetFunction (DeclNameRef targetFunctionName,
4085
+ findTargetFunction (DeclNameRefWithLoc targetFunctionName,
4058
4086
const AbstractFunctionDecl *base,
4059
4087
AbstractSpecializeAttr * attr, DiagnosticEngine *diags) {
4060
4088
return findSimilarFunction (targetFunctionName, base, attr, diags,
@@ -5707,13 +5735,15 @@ DynamicallyReplacedDeclRequest::evaluate(Evaluator &evaluator,
5707
5735
}
5708
5736
5709
5737
auto &Ctx = VD->getASTContext ();
5738
+ DeclNameRefWithLoc nameWithLoc{attr->getReplacedFunctionName (),
5739
+ attr->getReplacedFunctionNameLoc (),
5740
+ std::nullopt};
5710
5741
if (auto *AD = dyn_cast<AccessorDecl>(VD)) {
5711
- return findReplacedAccessor (attr-> getReplacedFunctionName () , AD, attr, Ctx);
5742
+ return findReplacedAccessor (nameWithLoc , AD, attr, Ctx);
5712
5743
}
5713
5744
5714
5745
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(VD)) {
5715
- return findReplacedFunction (attr->getReplacedFunctionName (), AFD,
5716
- attr, &Ctx.Diags );
5746
+ return findReplacedFunction (nameWithLoc, AFD, attr, &Ctx.Diags );
5717
5747
}
5718
5748
5719
5749
if (auto *SD = dyn_cast<AbstractStorageDecl>(VD)) {
@@ -5736,8 +5766,10 @@ SpecializeAttrTargetDeclRequest::evaluate(Evaluator &evaluator,
5736
5766
5737
5767
auto &ctx = vd->getASTContext ();
5738
5768
5739
- auto targetFunctionName = attr->getTargetFunctionName ();
5740
- if (!targetFunctionName)
5769
+ DeclNameRefWithLoc targetFunctionName{attr->getTargetFunctionName (),
5770
+ attr->getTargetFunctionNameLoc (),
5771
+ std::nullopt};
5772
+ if (!targetFunctionName.Name )
5741
5773
return nullptr ;
5742
5774
5743
5775
if (auto *ad = dyn_cast<AccessorDecl>(vd)) {
0 commit comments