@@ -2848,7 +2848,8 @@ bool swift::diagnoseExplicitUnavailability(SourceLoc loc,
2848
2848
const RootProtocolConformance *rootConf,
2849
2849
const ExtensionDecl *ext,
2850
2850
const ExportContext &where,
2851
- bool warnIfConformanceUnavailablePreSwift6) {
2851
+ bool warnIfConformanceUnavailablePreSwift6,
2852
+ bool preconcurrency) {
2852
2853
auto *attr = AvailableAttr::isUnavailable (ext);
2853
2854
if (!attr)
2854
2855
return false ;
@@ -2909,7 +2910,7 @@ bool swift::diagnoseExplicitUnavailability(SourceLoc loc,
2909
2910
diags.diagnose (loc, diag::conformance_availability_unavailable,
2910
2911
type, proto,
2911
2912
platform.empty (), platform, EncodedMessage.Message )
2912
- .limitBehaviorUntilSwiftVersion (behavior, 6 )
2913
+ .limitBehaviorWithPreconcurrency (behavior, preconcurrency )
2913
2914
.warnUntilSwiftVersionIf (warnIfConformanceUnavailablePreSwift6, 6 );
2914
2915
2915
2916
switch (attr->getVersionAvailability (ctx)) {
@@ -3442,6 +3443,7 @@ class ExprAvailabilityWalker : public ASTWalker {
3442
3443
ASTContext &Context;
3443
3444
MemberAccessContext AccessContext = MemberAccessContext::Default;
3444
3445
SmallVector<const Expr *, 16 > ExprStack;
3446
+ SmallVector<bool , 4 > PreconcurrencyCalleeStack;
3445
3447
const ExportContext &Where;
3446
3448
3447
3449
public:
@@ -3469,6 +3471,19 @@ class ExprAvailabilityWalker : public ASTWalker {
3469
3471
3470
3472
ExprStack.push_back (E);
3471
3473
3474
+ if (auto *apply = dyn_cast<ApplyExpr>(E)) {
3475
+ bool preconcurrency = false ;
3476
+ auto *fn = apply->getFn ();
3477
+ if (auto *selfApply = dyn_cast<SelfApplyExpr>(fn)) {
3478
+ fn = selfApply->getFn ();
3479
+ }
3480
+ auto declRef = fn->getReferencedDecl ();
3481
+ if (auto *decl = declRef.getDecl ()) {
3482
+ preconcurrency = decl->preconcurrency ();
3483
+ }
3484
+ PreconcurrencyCalleeStack.push_back (preconcurrency);
3485
+ }
3486
+
3472
3487
if (auto DR = dyn_cast<DeclRefExpr>(E)) {
3473
3488
diagnoseDeclRefAvailability (DR->getDeclRef (), DR->getSourceRange (),
3474
3489
getEnclosingApplyExpr (), std::nullopt);
@@ -3573,9 +3588,15 @@ class ExprAvailabilityWalker : public ASTWalker {
3573
3588
EE->getLoc (),
3574
3589
Where.getDeclContext ());
3575
3590
3591
+ bool preconcurrency = false ;
3592
+ if (!PreconcurrencyCalleeStack.empty ()) {
3593
+ preconcurrency = PreconcurrencyCalleeStack.back ();
3594
+ }
3595
+
3576
3596
for (ProtocolConformanceRef C : EE->getConformances ()) {
3577
3597
diagnoseConformanceAvailability (E->getLoc (), C, Where, Type (), Type (),
3578
- /* useConformanceAvailabilityErrorsOpt=*/ true );
3598
+ /* useConformanceAvailabilityErrorsOpt=*/ true ,
3599
+ /* preconcurrency=*/ preconcurrency);
3579
3600
}
3580
3601
}
3581
3602
@@ -3601,6 +3622,10 @@ class ExprAvailabilityWalker : public ASTWalker {
3601
3622
assert (ExprStack.back () == E);
3602
3623
ExprStack.pop_back ();
3603
3624
3625
+ if (auto *apply = dyn_cast<ApplyExpr>(E)) {
3626
+ PreconcurrencyCalleeStack.pop_back ();
3627
+ }
3628
+
3604
3629
return Action::Continue (E);
3605
3630
}
3606
3631
@@ -3875,8 +3900,12 @@ bool ExprAvailabilityWalker::diagnoseDeclRefAvailability(
3875
3900
return true ;
3876
3901
3877
3902
if (R.isValid ()) {
3878
- if (diagnoseSubstitutionMapAvailability (R.Start , declRef.getSubstitutions (),
3879
- Where)) {
3903
+ if (diagnoseSubstitutionMapAvailability (
3904
+ R.Start , declRef.getSubstitutions (), Where,
3905
+ Type (), Type (),
3906
+ /* warnIfConformanceUnavailablePreSwift6*/ false ,
3907
+ /* suppressParameterizationCheckForOptional*/ false ,
3908
+ /* preconcurrency*/ D->preconcurrency ())) {
3880
3909
return true ;
3881
3910
}
3882
3911
}
@@ -4348,7 +4377,8 @@ class ProblematicTypeFinder : public TypeDeclFinder {
4348
4377
/* depTy=*/ Type (),
4349
4378
/* replacementTy=*/ Type (),
4350
4379
/* warnIfConformanceUnavailablePreSwift6=*/ false ,
4351
- /* suppressParameterizationCheckForOptional=*/ ty->isOptional ());
4380
+ /* suppressParameterizationCheckForOptional=*/ ty->isOptional (),
4381
+ /* preconcurrency*/ ty->getAnyNominal ()->preconcurrency ());
4352
4382
return Action::Continue;
4353
4383
}
4354
4384
@@ -4403,17 +4433,19 @@ void swift::diagnoseTypeAvailability(const TypeRepr *TR, Type T, SourceLoc loc,
4403
4433
}
4404
4434
4405
4435
static void diagnoseMissingConformance (
4406
- SourceLoc loc, Type type, ProtocolDecl *proto, const DeclContext *fromDC) {
4436
+ SourceLoc loc, Type type, ProtocolDecl *proto, const DeclContext *fromDC,
4437
+ bool preconcurrency) {
4407
4438
assert (proto->isSpecificProtocol (KnownProtocolKind::Sendable));
4408
- diagnoseMissingSendableConformance (loc, type, fromDC);
4439
+ diagnoseMissingSendableConformance (loc, type, fromDC, preconcurrency );
4409
4440
}
4410
4441
4411
4442
bool
4412
4443
swift::diagnoseConformanceAvailability (SourceLoc loc,
4413
4444
ProtocolConformanceRef conformance,
4414
4445
const ExportContext &where,
4415
4446
Type depTy, Type replacementTy,
4416
- bool warnIfConformanceUnavailablePreSwift6) {
4447
+ bool warnIfConformanceUnavailablePreSwift6,
4448
+ bool preconcurrency) {
4417
4449
assert (!where.isImplicit ());
4418
4450
4419
4451
if (conformance.isInvalid () || conformance.isAbstract ())
@@ -4425,7 +4457,8 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
4425
4457
for (auto patternConf : pack->getPatternConformances ()) {
4426
4458
diagnosed |= diagnoseConformanceAvailability (
4427
4459
loc, patternConf, where, depTy, replacementTy,
4428
- warnIfConformanceUnavailablePreSwift6);
4460
+ warnIfConformanceUnavailablePreSwift6,
4461
+ preconcurrency);
4429
4462
}
4430
4463
return diagnosed;
4431
4464
}
@@ -4444,7 +4477,8 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
4444
4477
if (auto builtinConformance = dyn_cast<BuiltinProtocolConformance>(rootConf)){
4445
4478
if (builtinConformance->isMissing ()) {
4446
4479
diagnoseMissingConformance (loc, builtinConformance->getType (),
4447
- builtinConformance->getProtocol (), DC);
4480
+ builtinConformance->getProtocol (), DC,
4481
+ preconcurrency);
4448
4482
}
4449
4483
}
4450
4484
@@ -4470,7 +4504,8 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
4470
4504
}
4471
4505
4472
4506
if (diagnoseExplicitUnavailability (loc, rootConf, ext, where,
4473
- warnIfConformanceUnavailablePreSwift6)) {
4507
+ warnIfConformanceUnavailablePreSwift6,
4508
+ preconcurrency)) {
4474
4509
maybeEmitAssociatedTypeNote ();
4475
4510
return true ;
4476
4511
}
@@ -4498,7 +4533,8 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
4498
4533
SubstitutionMap subConformanceSubs = concreteConf->getSubstitutionMap ();
4499
4534
if (diagnoseSubstitutionMapAvailability (loc, subConformanceSubs, where,
4500
4535
depTy, replacementTy,
4501
- warnIfConformanceUnavailablePreSwift6))
4536
+ warnIfConformanceUnavailablePreSwift6,
4537
+ preconcurrency))
4502
4538
return true ;
4503
4539
4504
4540
return false ;
@@ -4510,12 +4546,14 @@ swift::diagnoseSubstitutionMapAvailability(SourceLoc loc,
4510
4546
const ExportContext &where,
4511
4547
Type depTy, Type replacementTy,
4512
4548
bool warnIfConformanceUnavailablePreSwift6,
4513
- bool suppressParameterizationCheckForOptional) {
4549
+ bool suppressParameterizationCheckForOptional,
4550
+ bool preconcurrency) {
4514
4551
bool hadAnyIssues = false ;
4515
4552
for (ProtocolConformanceRef conformance : subs.getConformances ()) {
4516
4553
if (diagnoseConformanceAvailability (loc, conformance, where,
4517
4554
depTy, replacementTy,
4518
- warnIfConformanceUnavailablePreSwift6))
4555
+ warnIfConformanceUnavailablePreSwift6,
4556
+ preconcurrency))
4519
4557
hadAnyIssues = true ;
4520
4558
}
4521
4559
0 commit comments