Skip to content

Commit f1a7738

Browse files
committed
Rename @_predatesConcurrency to @preconcurrency.
Introduce the `@preconcurrency` attribute name for `@_predatesConcurrency`, which has been the favored name in the pitch thread so far. Retain the old name for now to help smooth migration.
1 parent 73746e0 commit f1a7738

31 files changed

+120
-105
lines changed

include/swift/AST/ASTMangler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class ASTMangler : public Mangler {
7070
/// Whether the mangling predates concurrency, and therefore shouldn't
7171
/// include concurrency features such as global actors or @Sendable
7272
/// function types.
73-
bool PredatesConcurrency = false;
73+
bool Preconcurrency = false;
7474

7575
public:
7676
using SymbolicReferent = llvm::PointerUnion<const NominalTypeDecl *,

include/swift/AST/Attr.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,9 +688,9 @@ SIMPLE_DECL_ATTR(_noAllocation, NoAllocation,
688688
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
689689
124)
690690

691-
SIMPLE_DECL_ATTR(_predatesConcurrency, PredatesConcurrency,
691+
SIMPLE_DECL_ATTR(preconcurrency, Preconcurrency,
692692
OnFunc | OnConstructor | OnProtocol | OnGenericType | OnVar | OnSubscript |
693-
OnEnumElement | OnImport | UserInaccessible |
693+
OnEnumElement | OnImport |
694694
ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove,
695695
125)
696696

include/swift/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
896896
void setHoisted(bool hoisted = true) { Bits.Decl.Hoisted = hoisted; }
897897

898898
/// Whether this declaration predates the introduction of concurrency.
899-
bool predatesConcurrency() const;
899+
bool preconcurrency() const;
900900

901901
public:
902902
bool escapedFromIfConfig() const {

include/swift/AST/DiagnosticsParse.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,7 @@ ERROR(sil_inst_autodiff_invalid_witness_generic_signature,PointsToFirstBadToken,
17321732
(StringRef, StringRef))
17331733

17341734
WARNING(warn_attr_unsafe_removed,none,
1735-
"'%0' attribute has been removed in favor of @_predatesConcurrency",
1735+
"'%0' attribute has been removed in favor of @preconcurrency",
17361736
(StringRef))
17371737

17381738
//------------------------------------------------------------------------------

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,11 +1953,11 @@ NOTE(add_nominal_sendable_conformance,none,
19531953
"consider making %0 %1 conform to the 'Sendable' protocol",
19541954
(DescriptiveDeclKind, DeclName))
19551955
REMARK(add_predates_concurrency_import,none,
1956-
"add '@_predatesConcurrency' to %select{suppress|treat}0 "
1956+
"add '@preconcurrency' to %select{suppress|treat}0 "
19571957
"'Sendable'-related %select{warnings|errors}0 from module %1"
19581958
"%select{| as warnings}0", (bool, Identifier))
19591959
REMARK(remove_predates_concurrency_import,none,
1960-
"'@_predatesConcurrency' attribute on module %0 is unused", (Identifier))
1960+
"'@preconcurrency' attribute on module %0 is unused", (Identifier))
19611961
WARNING(public_decl_needs_sendable,none,
19621962
"public %0 %1 does not specify whether it is 'Sendable' or not",
19631963
(DescriptiveDeclKind, DeclName))

include/swift/AST/Import.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ enum class ImportFlags {
8282

8383
/// The module is imported assuming that the module itself predates
8484
/// concurrency.
85-
PredatesConcurrency = 0x20,
85+
Preconcurrency = 0x20,
8686

8787
/// Used for DenseMap.
8888
Reserved = 0x80
@@ -550,17 +550,17 @@ struct AttributedImport {
550550
/// Names of explicitly imported SPI groups.
551551
ArrayRef<Identifier> spiGroups;
552552

553-
/// When the import declaration has a `@_predatesConcurrency` annotation, this
553+
/// When the import declaration has a `@preconcurrency` annotation, this
554554
/// is the source range covering the annotation.
555-
SourceRange predatesConcurrencyRange;
555+
SourceRange preconcurrencyRange;
556556

557557
AttributedImport(ModuleInfo module, SourceLoc importLoc = SourceLoc(),
558558
ImportOptions options = ImportOptions(),
559559
StringRef filename = {}, ArrayRef<Identifier> spiGroups = {},
560-
SourceRange predatesConcurrencyRange = {})
560+
SourceRange preconcurrencyRange = {})
561561
: module(module), importLoc(importLoc), options(options),
562562
sourceFileArg(filename), spiGroups(spiGroups),
563-
predatesConcurrencyRange(predatesConcurrencyRange) {
563+
preconcurrencyRange(preconcurrencyRange) {
564564
assert(!(options.contains(ImportFlags::Exported) &&
565565
options.contains(ImportFlags::ImplementationOnly)) ||
566566
options.contains(ImportFlags::Reserved));
@@ -570,7 +570,7 @@ struct AttributedImport {
570570
AttributedImport(ModuleInfo module, AttributedImport<OtherModuleInfo> other)
571571
: AttributedImport(module, other.importLoc, other.options,
572572
other.sourceFileArg, other.spiGroups,
573-
other.predatesConcurrencyRange) { }
573+
other.preconcurrencyRange) { }
574574

575575
friend bool operator==(const AttributedImport<ModuleInfo> &lhs,
576576
const AttributedImport<ModuleInfo> &rhs) {

include/swift/AST/SourceFile.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ class SourceFile final : public FileUnit {
8484
/// This is \c None until it is filled in by the import resolution phase.
8585
Optional<ArrayRef<AttributedImport<ImportedModule>>> Imports;
8686

87-
/// Which imports have made use of @_predatesConcurrency.
87+
/// Which imports have made use of @preconcurrency.
8888
llvm::SmallDenseSet<AttributedImport<ImportedModule>>
89-
PredatesConcurrencyImportsUsed;
89+
PreconcurrencyImportsUsed;
9090

9191
/// A unique identifier representing this file; used to mark private decls
9292
/// within the file to keep them from conflicting with other files in the
@@ -297,12 +297,12 @@ class SourceFile final : public FileUnit {
297297
/// resolution.
298298
void setImports(ArrayRef<AttributedImport<ImportedModule>> imports);
299299

300-
/// Whether the given import has used @_predatesConcurrency.
301-
bool hasImportUsedPredatesConcurrency(
300+
/// Whether the given import has used @preconcurrency.
301+
bool hasImportUsedPreconcurrency(
302302
AttributedImport<ImportedModule> import) const;
303303

304-
/// Note that the given import has used @_predatesConcurrency/
305-
void setImportUsedPredatesConcurrency(
304+
/// Note that the given import has used @preconcurrency/
305+
void setImportUsedPreconcurrency(
306306
AttributedImport<ImportedModule> import);
307307

308308
enum ImportQueryKind {

lib/AST/ASTMangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2982,7 +2982,7 @@ CanType ASTMangler::getDeclTypeForMangling(
29822982
// If this declaration predates concurrency, adjust its type to not
29832983
// contain type features that were not available pre-concurrency. This
29842984
// cannot alter the ABI in any way.
2985-
if (decl->predatesConcurrency()) {
2985+
if (decl->preconcurrency()) {
29862986
ty = ty->stripConcurrency(/*recurse=*/true, /*dropGlobalActor=*/true);
29872987
}
29882988

lib/AST/Decl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,8 +725,8 @@ Optional<CustomAttrNominalPair> Decl::getGlobalActorAttr() const {
725725
None);
726726
}
727727

728-
bool Decl::predatesConcurrency() const {
729-
if (getAttrs().hasAttribute<PredatesConcurrencyAttr>())
728+
bool Decl::preconcurrency() const {
729+
if (getAttrs().hasAttribute<PreconcurrencyAttr>())
730730
return true;
731731

732732
// Imported C declarations always predate concurrency.

lib/AST/Module.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,14 +2245,14 @@ SourceFile::setImports(ArrayRef<AttributedImport<ImportedModule>> imports) {
22452245
Imports = getASTContext().AllocateCopy(imports);
22462246
}
22472247

2248-
bool SourceFile::hasImportUsedPredatesConcurrency(
2248+
bool SourceFile::hasImportUsedPreconcurrency(
22492249
AttributedImport<ImportedModule> import) const {
2250-
return PredatesConcurrencyImportsUsed.count(import) != 0;
2250+
return PreconcurrencyImportsUsed.count(import) != 0;
22512251
}
22522252

2253-
void SourceFile::setImportUsedPredatesConcurrency(
2253+
void SourceFile::setImportUsedPreconcurrency(
22542254
AttributedImport<ImportedModule> import) {
2255-
PredatesConcurrencyImportsUsed.insert(import);
2255+
PreconcurrencyImportsUsed.insert(import);
22562256
}
22572257

22582258
bool HasImplementationOnlyImportsRequest::evaluate(Evaluator &evaluator,

lib/Parse/ParseDecl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3096,6 +3096,11 @@ ParserStatus Parser::parseDeclAttribute(
30963096
AtLoc = SourceLoc();
30973097
}
30983098

3099+
// Temporary name for @preconcurrency
3100+
checkInvalidAttrName(
3101+
"_predatesConcurrency", "preconcurrency", DAK_Preconcurrency,
3102+
diag::attr_renamed_warning);
3103+
30993104
if (DK == DAK_Count && Tok.getText() == "warn_unused_result") {
31003105
// The behavior created by @warn_unused_result is now the default. Emit a
31013106
// Fix-It to remove.

lib/Sema/ImportResolution.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,9 @@ UnboundImport::UnboundImport(ImportDecl *ID)
550550
}
551551
import.spiGroups = ID->getASTContext().AllocateCopy(spiGroups);
552552

553-
if (auto attr = ID->getAttrs().getAttribute<PredatesConcurrencyAttr>()) {
554-
import.options |= ImportFlags::PredatesConcurrency;
555-
import.predatesConcurrencyRange = attr->getRangeWithAt();
553+
if (auto attr = ID->getAttrs().getAttribute<PreconcurrencyAttr>()) {
554+
import.options |= ImportFlags::Preconcurrency;
555+
import.preconcurrencyRange = attr->getRangeWithAt();
556556
}
557557
}
558558

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
117117
IGNORED_ATTR(ImplicitSelfCapture)
118118
IGNORED_ATTR(InheritActorContext)
119119
IGNORED_ATTR(Isolated)
120-
IGNORED_ATTR(PredatesConcurrency)
120+
IGNORED_ATTR(Preconcurrency)
121121
#undef IGNORED_ATTR
122122

123123
void visitAlignmentAttr(AlignmentAttr *attr) {

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -717,15 +717,15 @@ DiagnosticBehavior SendableCheckContext::diagnosticBehavior(
717717
isExplicitSendableConformance() ||
718718
hasExplicitSendableConformance(nominal);
719719

720-
// Determine whether this nominal type is visible via a @_predatesConcurrency
720+
// Determine whether this nominal type is visible via a @preconcurrency
721721
// import.
722722
auto import = findImportFor(nominal, fromDC);
723723

724724
// When the type is explicitly non-Sendable...
725725
if (isExplicitlyNonSendable) {
726-
// @_predatesConcurrency imports downgrade the diagnostic to a warning.
727-
if (import && import->options.contains(ImportFlags::PredatesConcurrency)) {
728-
// FIXME: Note that this @_predatesConcurrency import was "used".
726+
// @preconcurrency imports downgrade the diagnostic to a warning.
727+
if (import && import->options.contains(ImportFlags::Preconcurrency)) {
728+
// FIXME: Note that this @preconcurrency import was "used".
729729
return DiagnosticBehavior::Warning;
730730
}
731731

@@ -734,10 +734,10 @@ DiagnosticBehavior SendableCheckContext::diagnosticBehavior(
734734

735735
// When the type is implicitly non-Sendable...
736736

737-
// @_predatesConcurrency suppresses the diagnostic in Swift 5.x, and
737+
// @preconcurrency suppresses the diagnostic in Swift 5.x, and
738738
// downgrades it to a warning in Swift 6 and later.
739-
if (import && import->options.contains(ImportFlags::PredatesConcurrency)) {
740-
// FIXME: Note that this @_predatesConcurrency import was "used".
739+
if (import && import->options.contains(ImportFlags::Preconcurrency)) {
740+
// FIXME: Note that this @preconcurrency import was "used".
741741
return nominalModule->getASTContext().LangOpts.isSwiftVersionAtLeast(6)
742742
? DiagnosticBehavior::Warning
743743
: DiagnosticBehavior::Ignore;
@@ -797,29 +797,29 @@ static bool diagnoseSingleNonSendableType(
797797
nominal->getName());
798798

799799
// If we found the import that makes this nominal type visible, remark
800-
// that it can be @_predatesConcurrency import.
800+
// that it can be @preconcurrency import.
801801
// Only emit this remark once per source file, because it can happen a
802802
// lot.
803-
if (import && !import->options.contains(ImportFlags::PredatesConcurrency) &&
803+
if (import && !import->options.contains(ImportFlags::Preconcurrency) &&
804804
import->importLoc.isValid() && sourceFile &&
805-
!sourceFile->hasImportUsedPredatesConcurrency(*import)) {
805+
!sourceFile->hasImportUsedPreconcurrency(*import)) {
806806
SourceLoc importLoc = import->importLoc;
807807
ctx.Diags.diagnose(
808808
importLoc, diag::add_predates_concurrency_import,
809809
ctx.LangOpts.isSwiftVersionAtLeast(6),
810810
nominal->getParentModule()->getName())
811-
.fixItInsert(importLoc, "@_predatesConcurrency ");
811+
.fixItInsert(importLoc, "@preconcurrency ");
812812

813-
sourceFile->setImportUsedPredatesConcurrency(*import);
813+
sourceFile->setImportUsedPreconcurrency(*import);
814814
}
815815
}
816816

817817
// If we found an import that makes this nominal type visible, and that
818-
// was a @_predatesConcurrency import, note that we have made use of the
818+
// was a @preconcurrency import, note that we have made use of the
819819
// attribute.
820-
if (import && import->options.contains(ImportFlags::PredatesConcurrency) &&
820+
if (import && import->options.contains(ImportFlags::Preconcurrency) &&
821821
sourceFile) {
822-
sourceFile->setImportUsedPredatesConcurrency(*import);
822+
sourceFile->setImportUsedPreconcurrency(*import);
823823
}
824824

825825
return behavior == DiagnosticBehavior::Unspecified && !wasSuppressed;
@@ -2967,7 +2967,7 @@ static Optional<ActorIsolation> getIsolationFromAttributes(
29672967
}
29682968

29692969
// If the declaration predates concurrency, it has unsafe actor isolation.
2970-
if (decl->predatesConcurrency())
2970+
if (decl->preconcurrency())
29712971
isUnsafe = true;
29722972

29732973
return ActorIsolation::forGlobalActor(
@@ -4211,7 +4211,7 @@ static bool hasKnownUnsafeSendableFunctionParams(AbstractFunctionDecl *func) {
42114211
Type swift::adjustVarTypeForConcurrency(
42124212
Type type, VarDecl *var, DeclContext *dc,
42134213
llvm::function_ref<Type(const AbstractClosureExpr *)> getType) {
4214-
if (!var->predatesConcurrency())
4214+
if (!var->preconcurrency())
42154215
return type;
42164216

42174217
if (contextRequiresStrictConcurrencyChecking(dc, getType))
@@ -4232,7 +4232,7 @@ Type swift::adjustVarTypeForConcurrency(
42324232
}
42334233

42344234
/// Adjust a function type for @_unsafeSendable, @_unsafeMainActor, and
4235-
/// @_predatesConcurrency.
4235+
/// @preconcurrency.
42364236
static AnyFunctionType *applyUnsafeConcurrencyToFunctionType(
42374237
AnyFunctionType *fnType, ValueDecl *decl,
42384238
bool inConcurrencyContext, unsigned numApplies, bool isMainDispatchQueue) {
@@ -4258,7 +4258,7 @@ static AnyFunctionType *applyUnsafeConcurrencyToFunctionType(
42584258
assert(typeParams.size() == paramDecls->size());
42594259
bool knownUnsafeParams = func && hasKnownUnsafeSendableFunctionParams(func);
42604260
bool stripConcurrency =
4261-
decl->predatesConcurrency() && !inConcurrencyContext;
4261+
decl->preconcurrency() && !inConcurrencyContext;
42624262
for (unsigned index : indices(typeParams)) {
42634263
auto param = typeParams[index];
42644264

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,7 @@ namespace {
15051505
UNINTERESTING_ATTR(DynamicReplacement)
15061506
UNINTERESTING_ATTR(PrivateImport)
15071507
UNINTERESTING_ATTR(MainType)
1508-
UNINTERESTING_ATTR(PredatesConcurrency)
1508+
UNINTERESTING_ATTR(Preconcurrency)
15091509

15101510
// Differentiation-related attributes.
15111511
UNINTERESTING_ATTR(Differentiable)

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6039,7 +6039,7 @@ static bool isImpliedByConformancePredatingConcurrency(
60396039
return false;
60406040

60416041
auto impliedProto = implied->getProtocol();
6042-
if (impliedProto->predatesConcurrency() ||
6042+
if (impliedProto->preconcurrency() ||
60436043
impliedProto->isSpecificProtocol(KnownProtocolKind::Error) ||
60446044
impliedProto->isSpecificProtocol(KnownProtocolKind::CodingKey))
60456045
return true;
@@ -6073,7 +6073,7 @@ void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {
60736073

60746074
ProtocolConformance *SendableConformance = nullptr;
60756075
bool sendableConformanceIsUnchecked = false;
6076-
bool sendableConformancePredatesConcurrency = false;
6076+
bool sendableConformancePreconcurrency = false;
60776077
bool anyInvalid = false;
60786078
for (auto conformance : conformances) {
60796079
// Check and record normal conformances.
@@ -6107,7 +6107,7 @@ void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {
61076107
if (normal->isUnchecked())
61086108
sendableConformanceIsUnchecked = true;
61096109
else if (isImpliedByConformancePredatingConcurrency(normal))
6110-
sendableConformancePredatesConcurrency = true;
6110+
sendableConformancePreconcurrency = true;
61116111
else if (isa<InheritedProtocolConformance>(conformance))
61126112
sendableConformanceIsUnchecked = true;
61136113
}
@@ -6145,7 +6145,7 @@ void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {
61456145
// Check constraints of Sendable.
61466146
if (SendableConformance && !sendableConformanceIsUnchecked) {
61476147
SendableCheck check = SendableCheck::Explicit;
6148-
if (sendableConformancePredatesConcurrency)
6148+
if (sendableConformancePreconcurrency)
61496149
check = SendableCheck::ImpliedByStandardProtocol;
61506150
else if (SendableConformance->getSourceKind() ==
61516151
ConformanceEntryKind::Synthesized)

lib/Sema/TypeChecker.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,19 +264,19 @@ void swift::performTypeChecking(SourceFile &SF) {
264264
TypeCheckSourceFileRequest{&SF}, {});
265265
}
266266

267-
/// If any of the imports in this source file was @_predatesConcurrency but
267+
/// If any of the imports in this source file was @preconcurrency but
268268
/// there were no diagnostics downgraded or suppressed due to that
269-
/// @_predatesConcurrency, suggest that the attribute be removed.
270-
static void diagnoseUnnecessaryPredatesConcurrencyImports(SourceFile &sf) {
269+
/// @preconcurrency, suggest that the attribute be removed.
270+
static void diagnoseUnnecessaryPreconcurrencyImports(SourceFile &sf) {
271271
ASTContext &ctx = sf.getASTContext();
272272
for (const auto &import : sf.getImports()) {
273-
if (import.options.contains(ImportFlags::PredatesConcurrency) &&
273+
if (import.options.contains(ImportFlags::Preconcurrency) &&
274274
import.importLoc.isValid() &&
275-
!sf.hasImportUsedPredatesConcurrency(import)) {
275+
!sf.hasImportUsedPreconcurrency(import)) {
276276
ctx.Diags.diagnose(
277277
import.importLoc, diag::remove_predates_concurrency_import,
278278
import.module.importedModule->getName())
279-
.fixItRemove(import.predatesConcurrencyRange);
279+
.fixItRemove(import.preconcurrencyRange);
280280
}
281281
}
282282
}
@@ -322,7 +322,7 @@ TypeCheckSourceFileRequest::evaluate(Evaluator &eval, SourceFile *SF) const {
322322
typeCheckDelayedFunctions(*SF);
323323
}
324324

325-
diagnoseUnnecessaryPredatesConcurrencyImports(*SF);
325+
diagnoseUnnecessaryPreconcurrencyImports(*SF);
326326

327327
// Check to see if there's any inconsistent @_implementationOnly imports.
328328
evaluateOrDefault(

0 commit comments

Comments
 (0)