@@ -467,10 +467,12 @@ namespace {
467
467
// / AST walker that infers requirements from type representations.
468
468
struct InferRequirementsWalker : public TypeWalker {
469
469
ModuleDecl *module ;
470
+ DeclContext *dc;
470
471
SmallVector<Requirement, 2 > reqs;
471
472
SmallVector<RequirementError, 2 > errors;
472
473
473
- explicit InferRequirementsWalker (ModuleDecl *module ) : module(module ) {}
474
+ explicit InferRequirementsWalker (ModuleDecl *module , DeclContext *dc)
475
+ : module(module ), dc(dc) {}
474
476
475
477
Action walkToTypePre (Type ty) override {
476
478
// Unbound generic types are the result of recovered-but-invalid code, and
@@ -484,10 +486,17 @@ struct InferRequirementsWalker : public TypeWalker {
484
486
Action walkToTypePost (Type ty) override {
485
487
// Skip `Sendable` conformance requirements that are inferred from
486
488
// `@preconcurrency` declarations.
487
- auto skipRequirement = [](Requirement req, Decl *fromDecl) {
489
+ auto skipRequirement = [& ](Requirement req, Decl *fromDecl) {
488
490
if (!fromDecl->preconcurrency ())
489
491
return false ;
490
492
493
+ // If this decl is `@preconcurrency`, include concurrency
494
+ // requirements. The explicit annotation directly on the decl
495
+ // will still exclude `Sendable` requirements from ABI.
496
+ auto *decl = dc->getAsDecl ();
497
+ if (!decl || decl->preconcurrency ())
498
+ return false ;
499
+
491
500
return (req.getKind () == RequirementKind::Conformance &&
492
501
req.getSecondType ()->castTo <ProtocolType>()->getDecl ()
493
502
->isSpecificProtocol (KnownProtocolKind::Sendable));
@@ -602,12 +611,13 @@ struct InferRequirementsWalker : public TypeWalker {
602
611
// / We automatically infer 'T : Hashable' from the fact that 'struct Set'
603
612
// / declares a Hashable requirement on its generic parameter.
604
613
void swift::rewriting::inferRequirements (
605
- Type type, SourceLoc loc, ModuleDecl *module ,
614
+ Type type, SourceLoc loc,
615
+ ModuleDecl *module , DeclContext *dc,
606
616
SmallVectorImpl<StructuralRequirement> &result) {
607
617
if (!type)
608
618
return ;
609
619
610
- InferRequirementsWalker walker (module );
620
+ InferRequirementsWalker walker (module , dc );
611
621
type.walk (walker);
612
622
613
623
for (const auto &req : walker.reqs )
@@ -636,11 +646,11 @@ void swift::rewriting::realizeRequirement(
636
646
if (shouldInferRequirements) {
637
647
auto firstLoc = (reqRepr ? reqRepr->getSubjectRepr ()->getStartLoc ()
638
648
: SourceLoc ());
639
- inferRequirements (firstType, firstLoc, moduleForInference, result);
649
+ inferRequirements (firstType, firstLoc, moduleForInference, dc, result);
640
650
641
651
auto secondLoc = (reqRepr ? reqRepr->getConstraintRepr ()->getStartLoc ()
642
652
: SourceLoc ());
643
- inferRequirements (secondType, secondLoc, moduleForInference, result);
653
+ inferRequirements (secondType, secondLoc, moduleForInference, dc, result);
644
654
}
645
655
646
656
realizeTypeRequirement (dc, firstType, secondType, loc, result, errors);
@@ -651,7 +661,7 @@ void swift::rewriting::realizeRequirement(
651
661
if (shouldInferRequirements) {
652
662
auto firstLoc = (reqRepr ? reqRepr->getSubjectRepr ()->getStartLoc ()
653
663
: SourceLoc ());
654
- inferRequirements (firstType, firstLoc, moduleForInference, result);
664
+ inferRequirements (firstType, firstLoc, moduleForInference, dc, result);
655
665
}
656
666
657
667
SmallVector<Requirement, 2 > reqs;
@@ -669,11 +679,11 @@ void swift::rewriting::realizeRequirement(
669
679
if (shouldInferRequirements) {
670
680
auto firstLoc = (reqRepr ? reqRepr->getFirstTypeRepr ()->getStartLoc ()
671
681
: SourceLoc ());
672
- inferRequirements (firstType, firstLoc, moduleForInference, result);
682
+ inferRequirements (firstType, firstLoc, moduleForInference, dc, result);
673
683
674
684
auto secondLoc = (reqRepr ? reqRepr->getSecondTypeRepr ()->getStartLoc ()
675
685
: SourceLoc ());
676
- inferRequirements (secondType, secondLoc, moduleForInference, result);
686
+ inferRequirements (secondType, secondLoc, moduleForInference, dc, result);
677
687
}
678
688
679
689
SmallVector<Requirement, 2 > reqs;
@@ -717,7 +727,8 @@ void swift::rewriting::realizeInheritedRequirements(
717
727
auto *typeRepr = inheritedTypes[index].getTypeRepr ();
718
728
SourceLoc loc = (typeRepr ? typeRepr->getStartLoc () : SourceLoc ());
719
729
if (shouldInferRequirements) {
720
- inferRequirements (inheritedType, loc, moduleForInference, result);
730
+ inferRequirements (inheritedType, loc, moduleForInference,
731
+ decl->getInnermostDeclContext (), result);
721
732
}
722
733
723
734
realizeTypeRequirement (dc, type, inheritedType, loc, result, errors);
0 commit comments