@@ -2405,6 +2405,28 @@ static void lookupReplacedDecl(DeclNameRef replacedDeclName,
2405
2405
results);
2406
2406
}
2407
2407
2408
+ static void
2409
+ diagnoseCandidatesEliminatedByModuleSelector (DeclNameRefWithLoc replacedDeclName,
2410
+ DeclAttribute *attr,
2411
+ const ValueDecl *replacement,
2412
+ DiagnosticEngine &Diags) {
2413
+ if (replacedDeclName.Name .getModuleSelector ().empty ())
2414
+ return ;
2415
+
2416
+ // Look up without the module selector
2417
+ SmallVector<ValueDecl *, 4 > results;
2418
+ lookupReplacedDecl (DeclNameRef (replacedDeclName.Name .getFullName ()),
2419
+ attr, replacement, results);
2420
+
2421
+ auto selectorLoc = replacedDeclName.Loc .getModuleSelectorLoc ();
2422
+
2423
+ for (auto candidate : results)
2424
+ Diags.diagnose (selectorLoc, diag::note_change_module_selector,
2425
+ candidate->getModuleContext ()->getBaseIdentifier ())
2426
+ .fixItReplace (selectorLoc,
2427
+ candidate->getModuleContext ()->getBaseIdentifier ().str ());
2428
+ }
2429
+
2408
2430
// / Remove any argument labels from the interface type of the given value that
2409
2431
// / are extraneous from the type system's point of view, producing the
2410
2432
// / type to compare against for the purposes of dynamic replacement.
@@ -2424,14 +2446,14 @@ static Type getDynamicComparisonType(ValueDecl *value) {
2424
2446
return interfaceType->removeArgumentLabels (numArgumentLabels);
2425
2447
}
2426
2448
2427
- static FuncDecl *findSimilarAccessor (DeclNameRef replacedVarName,
2449
+ static FuncDecl *findSimilarAccessor (DeclNameRefWithLoc replacedVarName,
2428
2450
const AccessorDecl *replacement,
2429
2451
DeclAttribute *attr, ASTContext &ctx,
2430
2452
bool forDynamicReplacement) {
2431
2453
2432
2454
// Retrieve the replaced abstract storage decl.
2433
2455
SmallVector<ValueDecl *, 4 > results;
2434
- lookupReplacedDecl (replacedVarName, attr, replacement, results);
2456
+ lookupReplacedDecl (replacedVarName. Name , attr, replacement, results);
2435
2457
2436
2458
// Filter out any accessors that won't work.
2437
2459
if (!results.empty ()) {
@@ -2464,15 +2486,19 @@ static FuncDecl *findSimilarAccessor(DeclNameRef replacedVarName,
2464
2486
if (results.empty ()) {
2465
2487
Diags.diagnose (attr->getLocation (),
2466
2488
diag::dynamic_replacement_accessor_not_found,
2467
- replacedVarName);
2489
+ replacedVarName. Name );
2468
2490
attr->setInvalid ();
2491
+
2492
+ diagnoseCandidatesEliminatedByModuleSelector (replacedVarName, attr,
2493
+ replacement, Diags);
2494
+
2469
2495
return nullptr ;
2470
2496
}
2471
2497
2472
2498
if (results.size () > 1 ) {
2473
2499
Diags.diagnose (attr->getLocation (),
2474
2500
diag::dynamic_replacement_accessor_ambiguous,
2475
- replacedVarName);
2501
+ replacedVarName. Name );
2476
2502
for (auto result : results) {
2477
2503
Diags.diagnose (result,
2478
2504
diag::dynamic_replacement_accessor_ambiguous_candidate,
@@ -2513,15 +2539,15 @@ static FuncDecl *findSimilarAccessor(DeclNameRef replacedVarName,
2513
2539
return origAccessor;
2514
2540
}
2515
2541
2516
- static FuncDecl *findReplacedAccessor (DeclNameRef replacedVarName,
2542
+ static FuncDecl *findReplacedAccessor (DeclNameRefWithLoc replacedVarName,
2517
2543
const AccessorDecl *replacement,
2518
2544
DeclAttribute *attr,
2519
2545
ASTContext &ctx) {
2520
2546
return findSimilarAccessor (replacedVarName, replacement, attr, ctx,
2521
2547
/* forDynamicReplacement*/ true );
2522
2548
}
2523
2549
2524
- static FuncDecl *findTargetAccessor (DeclNameRef replacedVarName,
2550
+ static FuncDecl *findTargetAccessor (DeclNameRefWithLoc replacedVarName,
2525
2551
const AccessorDecl *replacement,
2526
2552
DeclAttribute *attr,
2527
2553
ASTContext &ctx) {
@@ -2530,15 +2556,15 @@ static FuncDecl *findTargetAccessor(DeclNameRef replacedVarName,
2530
2556
}
2531
2557
2532
2558
static AbstractFunctionDecl *
2533
- findSimilarFunction (DeclNameRef replacedFunctionName,
2559
+ findSimilarFunction (DeclNameRefWithLoc replacedFunctionName,
2534
2560
const AbstractFunctionDecl *base, DeclAttribute *attr,
2535
2561
DiagnosticEngine *Diags, bool forDynamicReplacement) {
2536
2562
2537
2563
// Note: we might pass a constant attribute when typechecker is nullptr.
2538
2564
// Any modification to attr must be guarded by a null check on TC.
2539
2565
//
2540
2566
SmallVector<ValueDecl *, 4 > results;
2541
- lookupReplacedDecl (replacedFunctionName, attr, base, results);
2567
+ lookupReplacedDecl (replacedFunctionName. Name , attr, base, results);
2542
2568
2543
2569
for (auto *result : results) {
2544
2570
// Protocol requirements are not replaceable.
@@ -2574,13 +2600,16 @@ findSimilarFunction(DeclNameRef replacedFunctionName,
2574
2600
forDynamicReplacement
2575
2601
? diag::dynamic_replacement_function_not_found
2576
2602
: diag::specialize_target_function_not_found,
2577
- replacedFunctionName);
2603
+ replacedFunctionName.Name );
2604
+
2605
+ diagnoseCandidatesEliminatedByModuleSelector (replacedFunctionName, attr,
2606
+ base, *Diags);
2578
2607
} else {
2579
2608
Diags->diagnose (attr->getLocation (),
2580
2609
forDynamicReplacement
2581
2610
? diag::dynamic_replacement_function_of_type_not_found
2582
2611
: diag::specialize_target_function_of_type_not_found,
2583
- replacedFunctionName,
2612
+ replacedFunctionName. Name ,
2584
2613
base->getInterfaceType ()->getCanonicalType ());
2585
2614
2586
2615
for (auto *result : results) {
@@ -2597,15 +2626,15 @@ findSimilarFunction(DeclNameRef replacedFunctionName,
2597
2626
}
2598
2627
2599
2628
static AbstractFunctionDecl *
2600
- findReplacedFunction (DeclNameRef replacedFunctionName,
2629
+ findReplacedFunction (DeclNameRefWithLoc replacedFunctionName,
2601
2630
const AbstractFunctionDecl *replacement,
2602
2631
DynamicReplacementAttr *attr, DiagnosticEngine *Diags) {
2603
2632
return findSimilarFunction (replacedFunctionName, replacement, attr, Diags,
2604
2633
true /* forDynamicReplacement*/ );
2605
2634
}
2606
2635
2607
2636
static AbstractFunctionDecl *
2608
- findTargetFunction (DeclNameRef targetFunctionName,
2637
+ findTargetFunction (DeclNameRefWithLoc targetFunctionName,
2609
2638
const AbstractFunctionDecl *base,
2610
2639
SpecializeAttr * attr, DiagnosticEngine *diags) {
2611
2640
return findSimilarFunction (targetFunctionName, base, attr, diags,
@@ -3507,13 +3536,14 @@ DynamicallyReplacedDeclRequest::evaluate(Evaluator &evaluator,
3507
3536
}
3508
3537
3509
3538
auto &Ctx = VD->getASTContext ();
3539
+ DeclNameRefWithLoc nameWithLoc{attr->getReplacedFunctionName (),
3540
+ attr->getReplacedFunctionNameLoc (), None};
3510
3541
if (auto *AD = dyn_cast<AccessorDecl>(VD)) {
3511
- return findReplacedAccessor (attr-> getReplacedFunctionName () , AD, attr, Ctx);
3542
+ return findReplacedAccessor (nameWithLoc , AD, attr, Ctx);
3512
3543
}
3513
3544
3514
3545
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(VD)) {
3515
- return findReplacedFunction (attr->getReplacedFunctionName (), AFD,
3516
- attr, &Ctx.Diags );
3546
+ return findReplacedFunction (nameWithLoc, AFD, attr, &Ctx.Diags );
3517
3547
}
3518
3548
3519
3549
if (auto *SD = dyn_cast<AbstractStorageDecl>(VD)) {
@@ -3536,8 +3566,9 @@ SpecializeAttrTargetDeclRequest::evaluate(Evaluator &evaluator,
3536
3566
3537
3567
auto &ctx = vd->getASTContext ();
3538
3568
3539
- auto targetFunctionName = attr->getTargetFunctionName ();
3540
- if (!targetFunctionName)
3569
+ DeclNameRefWithLoc targetFunctionName{attr->getTargetFunctionName (),
3570
+ attr->getTargetFunctionNameLoc (), None};
3571
+ if (!targetFunctionName.Name )
3541
3572
return nullptr ;
3542
3573
3543
3574
if (auto *ad = dyn_cast<AccessorDecl>(vd)) {
0 commit comments