Skip to content

Commit 7149702

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 c7a5049 commit 7149702

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
@@ -898,7 +898,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
898898
void setHoisted(bool hoisted = true) { Bits.Decl.Hoisted = hoisted; }
899899

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

903903
public:
904904
bool escapedFromIfConfig() const {

include/swift/AST/DiagnosticsParse.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,7 @@ ERROR(sil_inst_autodiff_invalid_witness_generic_signature,PointsToFirstBadToken,
17421742
(StringRef, StringRef))
17431743

17441744
WARNING(warn_attr_unsafe_removed,none,
1745-
"'%0' attribute has been removed in favor of @_predatesConcurrency",
1745+
"'%0' attribute has been removed in favor of @preconcurrency",
17461746
(StringRef))
17471747

17481748
//------------------------------------------------------------------------------

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,11 +1958,11 @@ NOTE(add_nominal_sendable_conformance,none,
19581958
"consider making %0 %1 conform to the 'Sendable' protocol",
19591959
(DescriptiveDeclKind, DeclName))
19601960
REMARK(add_predates_concurrency_import,none,
1961-
"add '@_predatesConcurrency' to %select{suppress|treat}0 "
1961+
"add '@preconcurrency' to %select{suppress|treat}0 "
19621962
"'Sendable'-related %select{warnings|errors}0 from module %1"
19631963
"%select{| as warnings}0", (bool, Identifier))
19641964
REMARK(remove_predates_concurrency_import,none,
1965-
"'@_predatesConcurrency' attribute on module %0 is unused", (Identifier))
1965+
"'@preconcurrency' attribute on module %0 is unused", (Identifier))
19661966
WARNING(public_decl_needs_sendable,none,
19671967
"public %0 %1 does not specify whether it is 'Sendable' or not",
19681968
(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
@@ -566,17 +566,17 @@ struct AttributedImport {
566566
/// Names of explicitly imported SPI groups.
567567
ArrayRef<Identifier> spiGroups;
568568

569-
/// When the import declaration has a `@_predatesConcurrency` annotation, this
569+
/// When the import declaration has a `@preconcurrency` annotation, this
570570
/// is the source range covering the annotation.
571-
SourceRange predatesConcurrencyRange;
571+
SourceRange preconcurrencyRange;
572572

573573
AttributedImport(ModuleInfo module, SourceLoc importLoc = SourceLoc(),
574574
ImportOptions options = ImportOptions(),
575575
StringRef filename = {}, ArrayRef<Identifier> spiGroups = {},
576-
SourceRange predatesConcurrencyRange = {})
576+
SourceRange preconcurrencyRange = {})
577577
: module(module), importLoc(importLoc), options(options),
578578
sourceFileArg(filename), spiGroups(spiGroups),
579-
predatesConcurrencyRange(predatesConcurrencyRange) {
579+
preconcurrencyRange(preconcurrencyRange) {
580580
assert(!(options.contains(ImportFlags::Exported) &&
581581
options.contains(ImportFlags::ImplementationOnly)) ||
582582
options.contains(ImportFlags::Reserved));
@@ -586,7 +586,7 @@ struct AttributedImport {
586586
AttributedImport(ModuleInfo module, AttributedImport<OtherModuleInfo> other)
587587
: AttributedImport(module, other.importLoc, other.options,
588588
other.sourceFileArg, other.spiGroups,
589-
other.predatesConcurrencyRange) { }
589+
other.preconcurrencyRange) { }
590590

591591
friend bool operator==(const AttributedImport<ModuleInfo> &lhs,
592592
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
@@ -301,12 +301,12 @@ class SourceFile final : public FileUnit {
301301
/// resolution.
302302
void setImports(ArrayRef<AttributedImport<ImportedModule>> imports);
303303

304-
/// Whether the given import has used @_predatesConcurrency.
305-
bool hasImportUsedPredatesConcurrency(
304+
/// Whether the given import has used @preconcurrency.
305+
bool hasImportUsedPreconcurrency(
306306
AttributedImport<ImportedModule> import) const;
307307

308-
/// Note that the given import has used @_predatesConcurrency/
309-
void setImportUsedPredatesConcurrency(
308+
/// Note that the given import has used @preconcurrency/
309+
void setImportUsedPreconcurrency(
310310
AttributedImport<ImportedModule> import);
311311

312312
enum ImportQueryKind {

lib/AST/ASTMangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3011,7 +3011,7 @@ CanType ASTMangler::getDeclTypeForMangling(
30113011
// If this declaration predates concurrency, adjust its type to not
30123012
// contain type features that were not available pre-concurrency. This
30133013
// cannot alter the ABI in any way.
3014-
if (decl->predatesConcurrency()) {
3014+
if (decl->preconcurrency()) {
30153015
ty = ty->stripConcurrency(/*recurse=*/true, /*dropGlobalActor=*/true);
30163016
}
30173017

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
@@ -2302,14 +2302,14 @@ SourceFile::setImports(ArrayRef<AttributedImport<ImportedModule>> imports) {
23022302
Imports = getASTContext().AllocateCopy(imports);
23032303
}
23042304

2305-
bool SourceFile::hasImportUsedPredatesConcurrency(
2305+
bool SourceFile::hasImportUsedPreconcurrency(
23062306
AttributedImport<ImportedModule> import) const {
2307-
return PredatesConcurrencyImportsUsed.count(import) != 0;
2307+
return PreconcurrencyImportsUsed.count(import) != 0;
23082308
}
23092309

2310-
void SourceFile::setImportUsedPredatesConcurrency(
2310+
void SourceFile::setImportUsedPreconcurrency(
23112311
AttributedImport<ImportedModule> import) {
2312-
PredatesConcurrencyImportsUsed.insert(import);
2312+
PreconcurrencyImportsUsed.insert(import);
23132313
}
23142314

23152315
bool HasImplementationOnlyImportsRequest::evaluate(Evaluator &evaluator,

lib/Parse/ParseDecl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3150,6 +3150,11 @@ ParserStatus Parser::parseDeclAttribute(
31503150
AtLoc = SourceLoc();
31513151
}
31523152

3153+
// Temporary name for @preconcurrency
3154+
checkInvalidAttrName(
3155+
"_predatesConcurrency", "preconcurrency", DAK_Preconcurrency,
3156+
diag::attr_renamed_warning);
3157+
31533158
if (DK == DAK_Count && Tok.getText() == "warn_unused_result") {
31543159
// The behavior created by @warn_unused_result is now the default. Emit a
31553160
// 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(
@@ -4217,7 +4217,7 @@ static bool hasKnownUnsafeSendableFunctionParams(AbstractFunctionDecl *func) {
42174217
Type swift::adjustVarTypeForConcurrency(
42184218
Type type, VarDecl *var, DeclContext *dc,
42194219
llvm::function_ref<Type(const AbstractClosureExpr *)> getType) {
4220-
if (!var->predatesConcurrency())
4220+
if (!var->preconcurrency())
42214221
return type;
42224222

42234223
if (contextRequiresStrictConcurrencyChecking(dc, getType))
@@ -4238,7 +4238,7 @@ Type swift::adjustVarTypeForConcurrency(
42384238
}
42394239

42404240
/// Adjust a function type for @_unsafeSendable, @_unsafeMainActor, and
4241-
/// @_predatesConcurrency.
4241+
/// @preconcurrency.
42424242
static AnyFunctionType *applyUnsafeConcurrencyToFunctionType(
42434243
AnyFunctionType *fnType, ValueDecl *decl,
42444244
bool inConcurrencyContext, unsigned numApplies, bool isMainDispatchQueue) {
@@ -4264,7 +4264,7 @@ static AnyFunctionType *applyUnsafeConcurrencyToFunctionType(
42644264
assert(typeParams.size() == paramDecls->size());
42654265
bool knownUnsafeParams = func && hasKnownUnsafeSendableFunctionParams(func);
42664266
bool stripConcurrency =
4267-
decl->predatesConcurrency() && !inConcurrencyContext;
4267+
decl->preconcurrency() && !inConcurrencyContext;
42684268
for (unsigned index : indices(typeParams)) {
42694269
auto param = typeParams[index];
42704270

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,7 @@ namespace {
15061506
UNINTERESTING_ATTR(DynamicReplacement)
15071507
UNINTERESTING_ATTR(PrivateImport)
15081508
UNINTERESTING_ATTR(MainType)
1509-
UNINTERESTING_ATTR(PredatesConcurrency)
1509+
UNINTERESTING_ATTR(Preconcurrency)
15101510

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

lib/Sema/TypeCheckProtocol.cpp

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

61136113
auto impliedProto = implied->getProtocol();
6114-
if (impliedProto->predatesConcurrency() ||
6114+
if (impliedProto->preconcurrency() ||
61156115
impliedProto->isSpecificProtocol(KnownProtocolKind::Error) ||
61166116
impliedProto->isSpecificProtocol(KnownProtocolKind::CodingKey))
61176117
return true;
@@ -6145,7 +6145,7 @@ void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {
61456145

61466146
ProtocolConformance *SendableConformance = nullptr;
61476147
bool sendableConformanceIsUnchecked = false;
6148-
bool sendableConformancePredatesConcurrency = false;
6148+
bool sendableConformancePreconcurrency = false;
61496149
bool anyInvalid = false;
61506150
for (auto conformance : conformances) {
61516151
// Check and record normal conformances.
@@ -6179,7 +6179,7 @@ void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {
61796179
if (normal->isUnchecked())
61806180
sendableConformanceIsUnchecked = true;
61816181
else if (isImpliedByConformancePredatingConcurrency(normal))
6182-
sendableConformancePredatesConcurrency = true;
6182+
sendableConformancePreconcurrency = true;
61836183
else if (isa<InheritedProtocolConformance>(conformance))
61846184
sendableConformanceIsUnchecked = true;
61856185
}
@@ -6217,7 +6217,7 @@ void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {
62176217
// Check constraints of Sendable.
62186218
if (SendableConformance && !sendableConformanceIsUnchecked) {
62196219
SendableCheck check = SendableCheck::Explicit;
6220-
if (sendableConformancePredatesConcurrency)
6220+
if (sendableConformancePreconcurrency)
62216221
check = SendableCheck::ImpliedByStandardProtocol;
62226222
else if (SendableConformance->getSourceKind() ==
62236223
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)