Skip to content

Commit b37d436

Browse files
authored
Merge pull request swiftlang#71244 from hborla/swift-6-diagnostics
[Concurrency] Audit diagnostics for Swift 6.
2 parents 464a14b + 11cb94f commit b37d436

14 files changed

+220
-149
lines changed

include/swift/AST/DiagnosticEngine.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,25 @@ namespace swift {
575575
return limitBehavior(limit);
576576
}
577577

578+
/// Conditionally limit the diagnostic behavior if the given \c limit
579+
/// is not \c None.
580+
InFlightDiagnostic &limitBehaviorIf(
581+
llvm::Optional<DiagnosticBehavior> limit) {
582+
if (!limit) {
583+
return *this;
584+
}
585+
586+
return limitBehavior(*limit);
587+
}
588+
589+
/// Limit the diagnostic behavior to \c limit until the specified
590+
/// version.
591+
///
592+
/// This helps stage in fixes for stricter diagnostics as warnings
593+
/// until the next major language version.
594+
InFlightDiagnostic &limitBehaviorUntilSwiftVersion(
595+
DiagnosticBehavior limit, unsigned majorVersion);
596+
578597
/// Limit the diagnostic behavior to warning until the specified version.
579598
///
580599
/// This helps stage in fixes for stricter diagnostics as warnings

include/swift/AST/DiagnosticsSema.def

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5270,7 +5270,10 @@ NOTE(note_add_async_and_throws_to_decl,none,
52705270
NOTE(note_add_distributed_to_decl,none,
52715271
"add 'distributed' to %0 to make this %kindonly0 satisfy the protocol requirement",
52725272
(const ValueDecl *))
5273-
ERROR(add_globalactor_to_function,none,
5273+
ERROR(invalid_isolated_calls_in_body,none,
5274+
"calls to '@%0'-isolated' code in %kind1",
5275+
(StringRef, const ValueDecl *))
5276+
NOTE(add_globalactor_to_function,none,
52745277
"add '@%0' to make %kind1 part of global actor %2",
52755278
(StringRef, const ValueDecl *, Type))
52765279
FIXIT(insert_globalactor_attr, "@%0 ", (Type))
@@ -5565,43 +5568,43 @@ ERROR(isolation_macro_experimental,none,
55655568
NOTE(in_derived_conformance, none,
55665569
"in derived conformance to %0",
55675570
(Type))
5568-
WARNING(non_sendable_param_type,none,
5569-
"non-sendable type %0 %select{passed in call to %3 %kind2|"
5570-
"exiting %3 context in call to non-isolated %kind2|"
5571-
"passed in implicitly asynchronous call to %3 %kind2|"
5572-
"in parameter of the protocol requirement satisfied by %3 %kind2|"
5573-
"in parameter of superclass method overridden by %3 %kind2|"
5574-
"in parameter of %3 '@objc' %kind2}1 cannot cross actor boundary",
5575-
(Type, unsigned, const ValueDecl *, ActorIsolation))
5576-
WARNING(non_sendable_call_argument,none,
5577-
"passing argument of non-sendable type %0 %select{into %2 context|"
5578-
"outside of %2 context}1 may introduce data races",
5579-
(Type, bool, ActorIsolation))
5580-
WARNING(non_sendable_result_type,none,
5581-
"non-sendable type %0 returned by %select{call to %3 %kind2|"
5582-
"call from %4 context to non-isolated %kind2|"
5583-
"implicitly asynchronous call to %3 %kind2|"
5584-
"%3 %kind2 satisfying protocol requirement|"
5585-
"%3 overriding %kind2|"
5586-
"%3 '@objc' %kind2}1 cannot cross actor boundary",
5587-
(Type, unsigned, const ValueDecl *, ActorIsolation))
5588-
WARNING(non_sendable_call_result_type,none,
5589-
"non-sendable type %0 returned by %select{implicitly asynchronous |}1"
5590-
"call to %2 function cannot cross actor boundary",
5591-
(Type, bool, ActorIsolation))
5592-
WARNING(non_sendable_property_type,none,
5593-
"non-sendable type %0 in %select{"
5594-
"%select{asynchronous access to %4 %kind1|"
5595-
"asynchronous access from %4 context to non-isolated %kind1|"
5596-
"implicitly asynchronous access to %4 %kind1|"
5597-
"conformance of %4 %kind1 to protocol requirement|"
5598-
"%4 overriding %kind1|"
5599-
"%4 '@objc' %kind1}3|captured local %1}2 cannot "
5600-
"cross %select{actor|task}2 boundary",
5601-
(Type, const ValueDecl *, bool, unsigned, ActorIsolation))
5602-
WARNING(non_sendable_keypath_capture,none,
5603-
"cannot form key path that captures non-sendable type %0",
5604-
(Type))
5571+
ERROR(non_sendable_param_type,none,
5572+
"non-sendable type %0 %select{passed in call to %3 %kind2|"
5573+
"exiting %3 context in call to non-isolated %kind2|"
5574+
"passed in implicitly asynchronous call to %3 %kind2|"
5575+
"in parameter of the protocol requirement satisfied by %3 %kind2|"
5576+
"in parameter of superclass method overridden by %3 %kind2|"
5577+
"in parameter of %3 '@objc' %kind2}1 cannot cross actor boundary",
5578+
(Type, unsigned, const ValueDecl *, ActorIsolation))
5579+
ERROR(non_sendable_call_argument,none,
5580+
"passing argument of non-sendable type %0 %select{into %2 context|"
5581+
"outside of %2 context}1 may introduce data races",
5582+
(Type, bool, ActorIsolation))
5583+
ERROR(non_sendable_result_type,none,
5584+
"non-sendable type %0 returned by %select{call to %3 %kind2|"
5585+
"call from %4 context to non-isolated %kind2|"
5586+
"implicitly asynchronous call to %3 %kind2|"
5587+
"%3 %kind2 satisfying protocol requirement|"
5588+
"%3 overriding %kind2|"
5589+
"%3 '@objc' %kind2}1 cannot cross actor boundary",
5590+
(Type, unsigned, const ValueDecl *, ActorIsolation))
5591+
ERROR(non_sendable_call_result_type,none,
5592+
"non-sendable type %0 returned by %select{implicitly asynchronous |}1"
5593+
"call to %2 function cannot cross actor boundary",
5594+
(Type, bool, ActorIsolation))
5595+
ERROR(non_sendable_property_type,none,
5596+
"non-sendable type %0 in %select{"
5597+
"%select{asynchronous access to %4 %kind1|"
5598+
"asynchronous access from %4 context to non-isolated %kind1|"
5599+
"implicitly asynchronous access to %4 %kind1|"
5600+
"conformance of %4 %kind1 to protocol requirement|"
5601+
"%4 overriding %kind1|"
5602+
"%4 '@objc' %kind1}3|captured local %1}2 cannot "
5603+
"cross %select{actor|task}2 boundary",
5604+
(Type, const ValueDecl *, bool, unsigned, ActorIsolation))
5605+
ERROR(non_sendable_keypath_capture,none,
5606+
"cannot form key path that captures non-sendable type %0",
5607+
(Type))
56055608
ERROR(non_concurrent_type_member,none,
56065609
"%select{stored property %2|associated value %2}1 of "
56075610
"'Sendable'-conforming %kind3 has non-sendable type %0",

lib/AST/DiagnosticEngine.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,17 @@ InFlightDiagnostic::limitBehavior(DiagnosticBehavior limit) {
328328
}
329329

330330
InFlightDiagnostic &
331-
InFlightDiagnostic::warnUntilSwiftVersion(unsigned majorVersion) {
331+
InFlightDiagnostic::limitBehaviorUntilSwiftVersion(
332+
DiagnosticBehavior limit, unsigned majorVersion) {
332333
if (!Engine->languageVersion.isVersionAtLeast(majorVersion)) {
333-
limitBehavior(DiagnosticBehavior::Warning)
334-
.wrapIn(diag::error_in_future_swift_version, majorVersion);
334+
// If the behavior limit is a warning or less, wrap the diagnostic
335+
// in a message that this will become an error in a later Swift
336+
// version. We do this before limiting the behavior, because
337+
// wrapIn will result in the behavior of the wrapping diagnostic.
338+
if (limit >= DiagnosticBehavior::Warning)
339+
wrapIn(diag::error_in_future_swift_version, majorVersion);
340+
341+
limitBehavior(limit);
335342
}
336343

337344
if (majorVersion == 6) {
@@ -343,6 +350,12 @@ InFlightDiagnostic::warnUntilSwiftVersion(unsigned majorVersion) {
343350
return *this;
344351
}
345352

353+
InFlightDiagnostic &
354+
InFlightDiagnostic::warnUntilSwiftVersion(unsigned majorVersion) {
355+
return limitBehaviorUntilSwiftVersion(DiagnosticBehavior::Warning,
356+
majorVersion);
357+
}
358+
346359
InFlightDiagnostic &
347360
InFlightDiagnostic::warnInSwiftInterface(const DeclContext *context) {
348361
auto sourceFile = context->getParentSourceFile();

0 commit comments

Comments
 (0)