@@ -1465,61 +1465,6 @@ AvailabilityRange TypeChecker::overApproximateAvailabilityAtLocation(
1465
1465
return availabilityAtLocation (loc, DC, MostRefined).getPlatformRange ();
1466
1466
}
1467
1467
1468
- static bool isDeclarationUnavailable (
1469
- const Decl *D, const DeclContext *referenceDC,
1470
- llvm::function_ref<AvailabilityRange()> getAvailabilityRange) {
1471
- ASTContext &Context = referenceDC->getASTContext ();
1472
- if (Context.LangOpts .DisableAvailabilityChecking ) {
1473
- return false ;
1474
- }
1475
-
1476
- if (!referenceDC->getParentSourceFile ()) {
1477
- // We only check availability if this reference is in a source file; we do
1478
- // not check in other kinds of FileUnits.
1479
- return false ;
1480
- }
1481
-
1482
- AvailabilityRange safeRangeUnderApprox{
1483
- AvailabilityInference::availableRange (D)};
1484
-
1485
- if (safeRangeUnderApprox.isAlwaysAvailable ())
1486
- return false ;
1487
-
1488
- AvailabilityRange runningOSOverApprox = getAvailabilityRange ();
1489
-
1490
- // The reference is safe if an over-approximation of the running OS
1491
- // versions is fully contained within an under-approximation
1492
- // of the versions on which the declaration is available. If this
1493
- // containment cannot be guaranteed, we say the reference is
1494
- // not available.
1495
- return !runningOSOverApprox.isContainedIn (safeRangeUnderApprox);
1496
- }
1497
-
1498
- static std::optional<AvailabilityRange>
1499
- checkDeclarationAvailability (const Decl *D, const ExportContext &Where) {
1500
- // Skip computing potential unavailability if the declaration is explicitly
1501
- // unavailable and the context is also unavailable.
1502
- if (const AvailableAttr *Attr = AvailableAttr::isUnavailable (D))
1503
- if (isInsideCompatibleUnavailableDeclaration (D, Where.getAvailability (),
1504
- Attr))
1505
- return std::nullopt;
1506
-
1507
- if (isDeclarationUnavailable (D, Where.getDeclContext (), [&Where] {
1508
- return Where.getAvailabilityRange ();
1509
- })) {
1510
- return AvailabilityInference::availableRange (D);
1511
- }
1512
-
1513
- return std::nullopt;
1514
- }
1515
-
1516
- std::optional<AvailabilityRange>
1517
- TypeChecker::checkConformanceAvailability (const RootProtocolConformance *conf,
1518
- const ExtensionDecl *ext,
1519
- const ExportContext &where) {
1520
- return checkDeclarationAvailability (ext, where);
1521
- }
1522
-
1523
1468
// / A class that walks the AST to find the innermost (i.e., deepest) node that
1524
1469
// / contains a target SourceRange and matches a particular criterion.
1525
1470
// / This class finds the innermost nodes of interest by walking
@@ -4625,6 +4570,7 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
4625
4570
// Diagnose "missing" conformances where we needed a conformance but
4626
4571
// didn't have one.
4627
4572
auto *DC = where.getDeclContext ();
4573
+ auto &ctx = DC->getASTContext ();
4628
4574
if (auto builtinConformance = dyn_cast<BuiltinProtocolConformance>(rootConf)){
4629
4575
if (builtinConformance->isMissing ()) {
4630
4576
diagnoseMissingConformance (loc, builtinConformance->getType (),
@@ -4638,7 +4584,6 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
4638
4584
4639
4585
Type selfTy = rootConf->getProtocol ()->getSelfInterfaceType ();
4640
4586
if (!depTy->isEqual (selfTy)) {
4641
- auto &ctx = DC->getASTContext ();
4642
4587
ctx.Diags .diagnose (
4643
4588
loc,
4644
4589
diag::assoc_conformance_from_implementation_only_module,
@@ -4653,20 +4598,24 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
4653
4598
return true ;
4654
4599
}
4655
4600
4656
- if (diagnoseExplicitUnavailability (loc, rootConf, ext, where,
4657
- warnIfConformanceUnavailablePreSwift6)) {
4658
- maybeEmitAssociatedTypeNote ();
4659
- return true ;
4660
- }
4601
+ auto unmetRequirement = getUnmetDeclAvailabilityRequirement (
4602
+ ext, where.getDeclContext (), where.getAvailability ());
4603
+ if (unmetRequirement) {
4604
+ // FIXME: diagnoseExplicitUnavailability() should take unmet requirement
4605
+ if (diagnoseExplicitUnavailability (
4606
+ loc, rootConf, ext, where,
4607
+ warnIfConformanceUnavailablePreSwift6)) {
4608
+ maybeEmitAssociatedTypeNote ();
4609
+ return true ;
4610
+ }
4661
4611
4662
- // Diagnose (and possibly signal) for potential unavailability
4663
- auto maybeUnavail = TypeChecker::checkConformanceAvailability (
4664
- rootConf, ext, where);
4665
- if (maybeUnavail.has_value ()) {
4666
- diagnosePotentialUnavailability (rootConf, ext, loc, DC,
4667
- maybeUnavail.value ());
4668
- maybeEmitAssociatedTypeNote ();
4669
- return true ;
4612
+ // Diagnose (and possibly signal) for potential unavailability
4613
+ if (auto requiredRange =
4614
+ unmetRequirement->getRequiredNewerAvailabilityRange (ctx)) {
4615
+ diagnosePotentialUnavailability (rootConf, ext, loc, DC, *requiredRange);
4616
+ maybeEmitAssociatedTypeNote ();
4617
+ return true ;
4618
+ }
4670
4619
}
4671
4620
4672
4621
// Diagnose for deprecation
0 commit comments