Skip to content

Rename @_predatesConcurrency to @preconcurrency. #41022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/AST/ASTMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ASTMangler : public Mangler {
/// Whether the mangling predates concurrency, and therefore shouldn't
/// include concurrency features such as global actors or @Sendable
/// function types.
bool PredatesConcurrency = false;
bool Preconcurrency = false;

public:
using SymbolicReferent = llvm::PointerUnion<const NominalTypeDecl *,
Expand Down
4 changes: 2 additions & 2 deletions include/swift/AST/Attr.def
Original file line number Diff line number Diff line change
Expand Up @@ -688,9 +688,9 @@ SIMPLE_DECL_ATTR(_noAllocation, NoAllocation,
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
124)

SIMPLE_DECL_ATTR(_predatesConcurrency, PredatesConcurrency,
SIMPLE_DECL_ATTR(preconcurrency, Preconcurrency,
OnFunc | OnConstructor | OnProtocol | OnGenericType | OnVar | OnSubscript |
OnEnumElement | OnImport | UserInaccessible |
OnEnumElement | OnImport |
ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove,
125)

Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
void setHoisted(bool hoisted = true) { Bits.Decl.Hoisted = hoisted; }

/// Whether this declaration predates the introduction of concurrency.
bool predatesConcurrency() const;
bool preconcurrency() const;

public:
bool escapedFromIfConfig() const {
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/DiagnosticsParse.def
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,7 @@ ERROR(sil_inst_autodiff_invalid_witness_generic_signature,PointsToFirstBadToken,
(StringRef, StringRef))

WARNING(warn_attr_unsafe_removed,none,
"'%0' attribute has been removed in favor of @_predatesConcurrency",
"'%0' attribute has been removed in favor of @preconcurrency",
(StringRef))

//------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -1953,11 +1953,11 @@ NOTE(add_nominal_sendable_conformance,none,
"consider making %0 %1 conform to the 'Sendable' protocol",
(DescriptiveDeclKind, DeclName))
REMARK(add_predates_concurrency_import,none,
"add '@_predatesConcurrency' to %select{suppress|treat}0 "
"add '@preconcurrency' to %select{suppress|treat}0 "
"'Sendable'-related %select{warnings|errors}0 from module %1"
"%select{| as warnings}0", (bool, Identifier))
REMARK(remove_predates_concurrency_import,none,
"'@_predatesConcurrency' attribute on module %0 is unused", (Identifier))
"'@preconcurrency' attribute on module %0 is unused", (Identifier))
WARNING(public_decl_needs_sendable,none,
"public %0 %1 does not specify whether it is 'Sendable' or not",
(DescriptiveDeclKind, DeclName))
Expand Down
12 changes: 6 additions & 6 deletions include/swift/AST/Import.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ enum class ImportFlags {

/// The module is imported assuming that the module itself predates
/// concurrency.
PredatesConcurrency = 0x20,
Preconcurrency = 0x20,

/// Used for DenseMap.
Reserved = 0x80
Expand Down Expand Up @@ -550,17 +550,17 @@ struct AttributedImport {
/// Names of explicitly imported SPI groups.
ArrayRef<Identifier> spiGroups;

/// When the import declaration has a `@_predatesConcurrency` annotation, this
/// When the import declaration has a `@preconcurrency` annotation, this
/// is the source range covering the annotation.
SourceRange predatesConcurrencyRange;
SourceRange preconcurrencyRange;

AttributedImport(ModuleInfo module, SourceLoc importLoc = SourceLoc(),
ImportOptions options = ImportOptions(),
StringRef filename = {}, ArrayRef<Identifier> spiGroups = {},
SourceRange predatesConcurrencyRange = {})
SourceRange preconcurrencyRange = {})
: module(module), importLoc(importLoc), options(options),
sourceFileArg(filename), spiGroups(spiGroups),
predatesConcurrencyRange(predatesConcurrencyRange) {
preconcurrencyRange(preconcurrencyRange) {
assert(!(options.contains(ImportFlags::Exported) &&
options.contains(ImportFlags::ImplementationOnly)) ||
options.contains(ImportFlags::Reserved));
Expand All @@ -570,7 +570,7 @@ struct AttributedImport {
AttributedImport(ModuleInfo module, AttributedImport<OtherModuleInfo> other)
: AttributedImport(module, other.importLoc, other.options,
other.sourceFileArg, other.spiGroups,
other.predatesConcurrencyRange) { }
other.preconcurrencyRange) { }

friend bool operator==(const AttributedImport<ModuleInfo> &lhs,
const AttributedImport<ModuleInfo> &rhs) {
Expand Down
12 changes: 6 additions & 6 deletions include/swift/AST/SourceFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ class SourceFile final : public FileUnit {
/// This is \c None until it is filled in by the import resolution phase.
Optional<ArrayRef<AttributedImport<ImportedModule>>> Imports;

/// Which imports have made use of @_predatesConcurrency.
/// Which imports have made use of @preconcurrency.
llvm::SmallDenseSet<AttributedImport<ImportedModule>>
PredatesConcurrencyImportsUsed;
PreconcurrencyImportsUsed;

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

/// Whether the given import has used @_predatesConcurrency.
bool hasImportUsedPredatesConcurrency(
/// Whether the given import has used @preconcurrency.
bool hasImportUsedPreconcurrency(
AttributedImport<ImportedModule> import) const;

/// Note that the given import has used @_predatesConcurrency/
void setImportUsedPredatesConcurrency(
/// Note that the given import has used @preconcurrency/
void setImportUsedPreconcurrency(
AttributedImport<ImportedModule> import);

enum ImportQueryKind {
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2982,7 +2982,7 @@ CanType ASTMangler::getDeclTypeForMangling(
// If this declaration predates concurrency, adjust its type to not
// contain type features that were not available pre-concurrency. This
// cannot alter the ABI in any way.
if (decl->predatesConcurrency()) {
if (decl->preconcurrency()) {
ty = ty->stripConcurrency(/*recurse=*/true, /*dropGlobalActor=*/true);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,8 @@ Optional<CustomAttrNominalPair> Decl::getGlobalActorAttr() const {
None);
}

bool Decl::predatesConcurrency() const {
if (getAttrs().hasAttribute<PredatesConcurrencyAttr>())
bool Decl::preconcurrency() const {
if (getAttrs().hasAttribute<PreconcurrencyAttr>())
return true;

// Imported C declarations always predate concurrency.
Expand Down
8 changes: 4 additions & 4 deletions lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2245,14 +2245,14 @@ SourceFile::setImports(ArrayRef<AttributedImport<ImportedModule>> imports) {
Imports = getASTContext().AllocateCopy(imports);
}

bool SourceFile::hasImportUsedPredatesConcurrency(
bool SourceFile::hasImportUsedPreconcurrency(
AttributedImport<ImportedModule> import) const {
return PredatesConcurrencyImportsUsed.count(import) != 0;
return PreconcurrencyImportsUsed.count(import) != 0;
}

void SourceFile::setImportUsedPredatesConcurrency(
void SourceFile::setImportUsedPreconcurrency(
AttributedImport<ImportedModule> import) {
PredatesConcurrencyImportsUsed.insert(import);
PreconcurrencyImportsUsed.insert(import);
}

bool HasImplementationOnlyImportsRequest::evaluate(Evaluator &evaluator,
Expand Down
5 changes: 5 additions & 0 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3096,6 +3096,11 @@ ParserStatus Parser::parseDeclAttribute(
AtLoc = SourceLoc();
}

// Temporary name for @preconcurrency
checkInvalidAttrName(
"_predatesConcurrency", "preconcurrency", DAK_Preconcurrency,
diag::attr_renamed_warning);

if (DK == DAK_Count && Tok.getText() == "warn_unused_result") {
// The behavior created by @warn_unused_result is now the default. Emit a
// Fix-It to remove.
Expand Down
6 changes: 3 additions & 3 deletions lib/Sema/ImportResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,9 @@ UnboundImport::UnboundImport(ImportDecl *ID)
}
import.spiGroups = ID->getASTContext().AllocateCopy(spiGroups);

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

Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
IGNORED_ATTR(ImplicitSelfCapture)
IGNORED_ATTR(InheritActorContext)
IGNORED_ATTR(Isolated)
IGNORED_ATTR(PredatesConcurrency)
IGNORED_ATTR(Preconcurrency)
#undef IGNORED_ATTR

void visitAlignmentAttr(AlignmentAttr *attr) {
Expand Down
38 changes: 19 additions & 19 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,15 +717,15 @@ DiagnosticBehavior SendableCheckContext::diagnosticBehavior(
isExplicitSendableConformance() ||
hasExplicitSendableConformance(nominal);

// Determine whether this nominal type is visible via a @_predatesConcurrency
// Determine whether this nominal type is visible via a @preconcurrency
// import.
auto import = findImportFor(nominal, fromDC);

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

Expand All @@ -734,10 +734,10 @@ DiagnosticBehavior SendableCheckContext::diagnosticBehavior(

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

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

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

sourceFile->setImportUsedPredatesConcurrency(*import);
sourceFile->setImportUsedPreconcurrency(*import);
}
}

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

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

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

return ActorIsolation::forGlobalActor(
Expand Down Expand Up @@ -4211,7 +4211,7 @@ static bool hasKnownUnsafeSendableFunctionParams(AbstractFunctionDecl *func) {
Type swift::adjustVarTypeForConcurrency(
Type type, VarDecl *var, DeclContext *dc,
llvm::function_ref<Type(const AbstractClosureExpr *)> getType) {
if (!var->predatesConcurrency())
if (!var->preconcurrency())
return type;

if (contextRequiresStrictConcurrencyChecking(dc, getType))
Expand All @@ -4232,7 +4232,7 @@ Type swift::adjustVarTypeForConcurrency(
}

/// Adjust a function type for @_unsafeSendable, @_unsafeMainActor, and
/// @_predatesConcurrency.
/// @preconcurrency.
static AnyFunctionType *applyUnsafeConcurrencyToFunctionType(
AnyFunctionType *fnType, ValueDecl *decl,
bool inConcurrencyContext, unsigned numApplies, bool isMainDispatchQueue) {
Expand All @@ -4258,7 +4258,7 @@ static AnyFunctionType *applyUnsafeConcurrencyToFunctionType(
assert(typeParams.size() == paramDecls->size());
bool knownUnsafeParams = func && hasKnownUnsafeSendableFunctionParams(func);
bool stripConcurrency =
decl->predatesConcurrency() && !inConcurrencyContext;
decl->preconcurrency() && !inConcurrencyContext;
for (unsigned index : indices(typeParams)) {
auto param = typeParams[index];

Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckDeclOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ namespace {
UNINTERESTING_ATTR(DynamicReplacement)
UNINTERESTING_ATTR(PrivateImport)
UNINTERESTING_ATTR(MainType)
UNINTERESTING_ATTR(PredatesConcurrency)
UNINTERESTING_ATTR(Preconcurrency)

// Differentiation-related attributes.
UNINTERESTING_ATTR(Differentiable)
Expand Down
8 changes: 4 additions & 4 deletions lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6039,7 +6039,7 @@ static bool isImpliedByConformancePredatingConcurrency(
return false;

auto impliedProto = implied->getProtocol();
if (impliedProto->predatesConcurrency() ||
if (impliedProto->preconcurrency() ||
impliedProto->isSpecificProtocol(KnownProtocolKind::Error) ||
impliedProto->isSpecificProtocol(KnownProtocolKind::CodingKey))
return true;
Expand Down Expand Up @@ -6073,7 +6073,7 @@ void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {

ProtocolConformance *SendableConformance = nullptr;
bool sendableConformanceIsUnchecked = false;
bool sendableConformancePredatesConcurrency = false;
bool sendableConformancePreconcurrency = false;
bool anyInvalid = false;
for (auto conformance : conformances) {
// Check and record normal conformances.
Expand Down Expand Up @@ -6107,7 +6107,7 @@ void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {
if (normal->isUnchecked())
sendableConformanceIsUnchecked = true;
else if (isImpliedByConformancePredatingConcurrency(normal))
sendableConformancePredatesConcurrency = true;
sendableConformancePreconcurrency = true;
else if (isa<InheritedProtocolConformance>(conformance))
sendableConformanceIsUnchecked = true;
}
Expand Down Expand Up @@ -6145,7 +6145,7 @@ void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {
// Check constraints of Sendable.
if (SendableConformance && !sendableConformanceIsUnchecked) {
SendableCheck check = SendableCheck::Explicit;
if (sendableConformancePredatesConcurrency)
if (sendableConformancePreconcurrency)
check = SendableCheck::ImpliedByStandardProtocol;
else if (SendableConformance->getSourceKind() ==
ConformanceEntryKind::Synthesized)
Expand Down
14 changes: 7 additions & 7 deletions lib/Sema/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,19 +264,19 @@ void swift::performTypeChecking(SourceFile &SF) {
TypeCheckSourceFileRequest{&SF}, {});
}

/// If any of the imports in this source file was @_predatesConcurrency but
/// If any of the imports in this source file was @preconcurrency but
/// there were no diagnostics downgraded or suppressed due to that
/// @_predatesConcurrency, suggest that the attribute be removed.
static void diagnoseUnnecessaryPredatesConcurrencyImports(SourceFile &sf) {
/// @preconcurrency, suggest that the attribute be removed.
static void diagnoseUnnecessaryPreconcurrencyImports(SourceFile &sf) {
ASTContext &ctx = sf.getASTContext();
for (const auto &import : sf.getImports()) {
if (import.options.contains(ImportFlags::PredatesConcurrency) &&
if (import.options.contains(ImportFlags::Preconcurrency) &&
import.importLoc.isValid() &&
!sf.hasImportUsedPredatesConcurrency(import)) {
!sf.hasImportUsedPreconcurrency(import)) {
ctx.Diags.diagnose(
import.importLoc, diag::remove_predates_concurrency_import,
import.module.importedModule->getName())
.fixItRemove(import.predatesConcurrencyRange);
.fixItRemove(import.preconcurrencyRange);
}
}
}
Expand Down Expand Up @@ -322,7 +322,7 @@ TypeCheckSourceFileRequest::evaluate(Evaluator &eval, SourceFile *SF) const {
typeCheckDelayedFunctions(*SF);
}

diagnoseUnnecessaryPredatesConcurrencyImports(*SF);
diagnoseUnnecessaryPreconcurrencyImports(*SF);

// Check to see if there's any inconsistent @_implementationOnly imports.
evaluateOrDefault(
Expand Down
Loading