@@ -53,7 +53,8 @@ concreteSyntaxDeclForAvailableAttribute(const Decl *AbstractSyntaxDecl);
53
53
static bool diagnoseExplicitUnavailability (
54
54
SourceLoc loc, const RootProtocolConformance *rootConf,
55
55
const ExtensionDecl *ext, const ExportContext &where,
56
- bool warnIfConformanceUnavailablePreSwift6 = false );
56
+ bool warnIfConformanceUnavailablePreSwift6 = false ,
57
+ bool preconcurrency = false );
57
58
58
59
// / Emit a diagnostic for references to declarations that have been
59
60
// / marked as unavailable, either through "unavailable" or "obsoleted:".
@@ -66,7 +67,8 @@ static bool diagnoseSubstitutionMapAvailability(
66
67
SourceLoc loc, SubstitutionMap subs, const ExportContext &where,
67
68
Type depTy = Type(), Type replacementTy = Type(),
68
69
bool warnIfConformanceUnavailablePreSwift6 = false,
69
- bool suppressParameterizationCheckForOptional = false);
70
+ bool suppressParameterizationCheckForOptional = false,
71
+ bool preconcurrency = false);
70
72
71
73
// / Diagnose uses of unavailable declarations in types.
72
74
static bool
@@ -2985,7 +2987,8 @@ getExplicitUnavailabilityDiagnosticInfo(const Decl *decl,
2985
2987
bool diagnoseExplicitUnavailability (
2986
2988
SourceLoc loc, const RootProtocolConformance *rootConf,
2987
2989
const ExtensionDecl *ext, const ExportContext &where,
2988
- bool warnIfConformanceUnavailablePreSwift6) {
2990
+ bool warnIfConformanceUnavailablePreSwift6,
2991
+ bool preconcurrency) {
2989
2992
// Invertible protocols are never unavailable.
2990
2993
if (rootConf->getProtocol ()->getInvertibleProtocolKind ())
2991
2994
return false ;
@@ -3011,7 +3014,7 @@ bool diagnoseExplicitUnavailability(
3011
3014
diags
3012
3015
.diagnose (loc, diag::conformance_availability_unavailable, type, proto,
3013
3016
platform.empty (), platform, EncodedMessage.Message )
3014
- .limitBehaviorUntilSwiftVersion (behavior, 6 )
3017
+ .limitBehaviorWithPreconcurrency (behavior, preconcurrency )
3015
3018
.warnUntilSwiftVersionIf (warnIfConformanceUnavailablePreSwift6, 6 );
3016
3019
3017
3020
switch (diagnosticInfo->getStatus ()) {
@@ -3523,6 +3526,7 @@ class ExprAvailabilityWalker : public ASTWalker {
3523
3526
ASTContext &Context;
3524
3527
MemberAccessContext AccessContext = MemberAccessContext::Default;
3525
3528
SmallVector<const Expr *, 16 > ExprStack;
3529
+ SmallVector<bool , 4 > PreconcurrencyCalleeStack;
3526
3530
const ExportContext &Where;
3527
3531
3528
3532
public:
@@ -3546,6 +3550,15 @@ class ExprAvailabilityWalker : public ASTWalker {
3546
3550
3547
3551
ExprStack.push_back (E);
3548
3552
3553
+ if (auto *apply = dyn_cast<ApplyExpr>(E)) {
3554
+ bool preconcurrency = false ;
3555
+ auto declRef = apply->getFn ()->getReferencedDecl ();
3556
+ if (auto *decl = declRef.getDecl ()) {
3557
+ preconcurrency = decl->preconcurrency ();
3558
+ }
3559
+ PreconcurrencyCalleeStack.push_back (preconcurrency);
3560
+ }
3561
+
3549
3562
if (auto DR = dyn_cast<DeclRefExpr>(E)) {
3550
3563
diagnoseDeclRefAvailability (DR->getDeclRef (), DR->getSourceRange (),
3551
3564
getEnclosingApplyExpr (), std::nullopt);
@@ -3668,9 +3681,15 @@ class ExprAvailabilityWalker : public ASTWalker {
3668
3681
EE->getLoc (),
3669
3682
Where.getDeclContext ());
3670
3683
3684
+ bool preconcurrency = false ;
3685
+ if (!PreconcurrencyCalleeStack.empty ()) {
3686
+ preconcurrency = PreconcurrencyCalleeStack.back ();
3687
+ }
3688
+
3671
3689
for (ProtocolConformanceRef C : EE->getConformances ()) {
3672
3690
diagnoseConformanceAvailability (E->getLoc (), C, Where, Type (), Type (),
3673
- /* useConformanceAvailabilityErrorsOpt=*/ true );
3691
+ /* useConformanceAvailabilityErrorsOpt=*/ true ,
3692
+ /* preconcurrency=*/ preconcurrency);
3674
3693
}
3675
3694
}
3676
3695
@@ -3696,6 +3715,10 @@ class ExprAvailabilityWalker : public ASTWalker {
3696
3715
assert (ExprStack.back () == E);
3697
3716
ExprStack.pop_back ();
3698
3717
3718
+ if (auto *apply = dyn_cast<ApplyExpr>(E)) {
3719
+ PreconcurrencyCalleeStack.pop_back ();
3720
+ }
3721
+
3699
3722
return Action::Continue (E);
3700
3723
}
3701
3724
@@ -3990,8 +4013,12 @@ bool ExprAvailabilityWalker::diagnoseDeclRefAvailability(
3990
4013
}
3991
4014
3992
4015
if (R.isValid ()) {
3993
- if (diagnoseSubstitutionMapAvailability (R.Start , declRef.getSubstitutions (),
3994
- Where)) {
4016
+ if (diagnoseSubstitutionMapAvailability (
4017
+ R.Start , declRef.getSubstitutions (), Where,
4018
+ Type (), Type (),
4019
+ /* warnIfConformanceUnavailablePreSwift6*/ false ,
4020
+ /* suppressParameterizationCheckForOptional*/ false ,
4021
+ /* preconcurrency*/ D->preconcurrency ())) {
3995
4022
return true ;
3996
4023
}
3997
4024
}
@@ -4489,7 +4516,8 @@ class ProblematicTypeFinder : public TypeDeclFinder {
4489
4516
/* depTy=*/ Type (),
4490
4517
/* replacementTy=*/ Type (),
4491
4518
/* warnIfConformanceUnavailablePreSwift6=*/ false ,
4492
- /* suppressParameterizationCheckForOptional=*/ ty->isOptional ());
4519
+ /* suppressParameterizationCheckForOptional=*/ ty->isOptional (),
4520
+ /* preconcurrency*/ ty->getAnyNominal ()->preconcurrency ());
4493
4521
return Action::Continue;
4494
4522
}
4495
4523
@@ -4539,17 +4567,19 @@ void swift::diagnoseTypeAvailability(const TypeRepr *TR, Type T, SourceLoc loc,
4539
4567
}
4540
4568
4541
4569
static void diagnoseMissingConformance (
4542
- SourceLoc loc, Type type, ProtocolDecl *proto, const DeclContext *fromDC) {
4570
+ SourceLoc loc, Type type, ProtocolDecl *proto, const DeclContext *fromDC,
4571
+ bool preconcurrency) {
4543
4572
assert (proto->isSpecificProtocol (KnownProtocolKind::Sendable));
4544
- diagnoseMissingSendableConformance (loc, type, fromDC);
4573
+ diagnoseMissingSendableConformance (loc, type, fromDC, preconcurrency );
4545
4574
}
4546
4575
4547
4576
bool
4548
4577
swift::diagnoseConformanceAvailability (SourceLoc loc,
4549
4578
ProtocolConformanceRef conformance,
4550
4579
const ExportContext &where,
4551
4580
Type depTy, Type replacementTy,
4552
- bool warnIfConformanceUnavailablePreSwift6) {
4581
+ bool warnIfConformanceUnavailablePreSwift6,
4582
+ bool preconcurrency) {
4553
4583
assert (!where.isImplicit ());
4554
4584
4555
4585
if (conformance.isInvalid () || conformance.isAbstract ())
@@ -4561,7 +4591,8 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
4561
4591
for (auto patternConf : pack->getPatternConformances ()) {
4562
4592
diagnosed |= diagnoseConformanceAvailability (
4563
4593
loc, patternConf, where, depTy, replacementTy,
4564
- warnIfConformanceUnavailablePreSwift6);
4594
+ warnIfConformanceUnavailablePreSwift6,
4595
+ preconcurrency);
4565
4596
}
4566
4597
return diagnosed;
4567
4598
}
@@ -4581,7 +4612,8 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
4581
4612
if (auto builtinConformance = dyn_cast<BuiltinProtocolConformance>(rootConf)){
4582
4613
if (builtinConformance->isMissing ()) {
4583
4614
diagnoseMissingConformance (loc, builtinConformance->getType (),
4584
- builtinConformance->getProtocol (), DC);
4615
+ builtinConformance->getProtocol (), DC,
4616
+ preconcurrency);
4585
4617
}
4586
4618
}
4587
4619
@@ -4611,7 +4643,8 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
4611
4643
// FIXME: diagnoseExplicitUnavailability() should take unmet requirement
4612
4644
if (diagnoseExplicitUnavailability (
4613
4645
loc, rootConf, ext, where,
4614
- warnIfConformanceUnavailablePreSwift6)) {
4646
+ warnIfConformanceUnavailablePreSwift6,
4647
+ preconcurrency)) {
4615
4648
maybeEmitAssociatedTypeNote ();
4616
4649
return true ;
4617
4650
}
@@ -4640,7 +4673,8 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
4640
4673
SubstitutionMap subConformanceSubs = concreteConf->getSubstitutionMap ();
4641
4674
if (diagnoseSubstitutionMapAvailability (loc, subConformanceSubs, where,
4642
4675
depTy, replacementTy,
4643
- warnIfConformanceUnavailablePreSwift6))
4676
+ warnIfConformanceUnavailablePreSwift6,
4677
+ preconcurrency))
4644
4678
return true ;
4645
4679
4646
4680
return false ;
@@ -4649,12 +4683,14 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
4649
4683
bool diagnoseSubstitutionMapAvailability (
4650
4684
SourceLoc loc, SubstitutionMap subs, const ExportContext &where, Type depTy,
4651
4685
Type replacementTy, bool warnIfConformanceUnavailablePreSwift6,
4652
- bool suppressParameterizationCheckForOptional) {
4686
+ bool suppressParameterizationCheckForOptional,
4687
+ bool preconcurrency) {
4653
4688
bool hadAnyIssues = false ;
4654
4689
for (ProtocolConformanceRef conformance : subs.getConformances ()) {
4655
4690
if (diagnoseConformanceAvailability (loc, conformance, where,
4656
4691
depTy, replacementTy,
4657
- warnIfConformanceUnavailablePreSwift6))
4692
+ warnIfConformanceUnavailablePreSwift6,
4693
+ preconcurrency))
4658
4694
hadAnyIssues = true ;
4659
4695
}
4660
4696
0 commit comments