Skip to content

Commit 81f9603

Browse files
committed
polish noncopyable types diagnostic wordings
- replaces "move-only" terminology with "noncopyable" - replaces compiler jargon like "guaranteed parameters" and "lvalue" with corresponding language-level notions - simplifies diagnostics about closures. and probably more. rdar://109281444 (cherry picked from commit 31aa2f7)
1 parent 2a66c8a commit 81f9603

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1460
-1544
lines changed

docs/SIL.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2805,7 +2805,7 @@ canonical SIL that the value was never copied and thus is a "move only value"
28052805
even though the actual underlying wrapped type is copyable. As an example of
28062806
this, consider the following Swift::
28072807

2808-
func doSomething(@_noImplicitCopy _ x: Klass) -> () { // expected-error {{'x' has guaranteed ownership but was consumed}}
2808+
func doSomething(@_noImplicitCopy _ x: Klass) -> () { // expected-error {{'x' is borrowed and cannot be consumed}}
28092809
x.doSomething()
28102810
let x2 = x // expected-note {{consuming use}}
28112811
x2.doSomething()

include/swift/AST/DiagnosticsSIL.def

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -755,48 +755,35 @@ ERROR(sil_moveonlychecker_owned_value_consumed_and_used_at_same_time, none,
755755
ERROR(sil_moveonlychecker_value_used_after_consume, none,
756756
"'%0' used after consume", (StringRef))
757757
ERROR(sil_moveonlychecker_guaranteed_value_consumed, none,
758-
"'%0' has guaranteed ownership but was consumed", (StringRef))
758+
"'%0' is borrowed and cannot be consumed", (StringRef))
759+
760+
// FIXME: this diagnostic shouldn't ever be emitted now. rdar://109742587 (closures may still try to consume captures, e.g., borrowed parameters)
759761
ERROR(sil_moveonlychecker_guaranteed_value_captured_by_closure, none,
760-
"'%0' has guaranteed ownership but was consumed due to being captured by a closure", (StringRef))
761-
ERROR(sil_moveonlychecker_let_value_consumed_in_closure, none,
762-
"'%0' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations", (StringRef))
762+
"'%0' is borrowed and cannot be consumed by closure capture", (StringRef))
763+
764+
ERROR(sil_moveonlychecker_capture_consumed_in_closure, none,
765+
"captured '%0' cannot be consumed within a closure", (StringRef))
763766
ERROR(sil_moveonlychecker_inout_not_reinitialized_before_end_of_function, none,
764-
"'%0' consumed but not reinitialized before end of function", (StringRef))
765-
ERROR(sil_moveonlychecker_inout_not_reinitialized_before_end_of_closure, none,
766-
"'%0' consumed in closure but not reinitialized before end of closure", (StringRef))
767+
"missing reinitialization of '%0' after consume", (StringRef))
767768
ERROR(sil_moveonlychecker_value_consumed_in_a_loop, none,
768769
"'%0' consumed by a use in a loop", (StringRef))
769-
ERROR(sil_moveonlychecker_exclusivity_violation, none,
770-
"'%0' has consuming use that cannot be eliminated due to a tight exclusivity scope", (StringRef))
771-
ERROR(sil_moveonlychecker_moveonly_field_consumed, none,
772-
"'%0' has a move only field that was consumed before later uses", (StringRef))
773770

774-
ERROR(sil_moveonlychecker_notconsumable_but_assignable_was_consumed_classfield_let, none,
775-
"'%0' was consumed but it is illegal to consume a noncopyable class let field. One can only read from it",
776-
(StringRef))
777-
ERROR(sil_moveonlychecker_notconsumable_but_assignable_was_consumed_classfield_var, none,
778-
"'%0' was consumed but it is illegal to consume a noncopyable class var field. One can only read from it or assign to it",
779-
(StringRef))
780-
ERROR(sil_moveonlychecker_notconsumable_but_assignable_was_consumed_global_var, none,
781-
"'%0' was consumed but it is illegal to consume a noncopyable global var. One can only read from it or assign to it",
782-
(StringRef))
783-
ERROR(sil_moveonlychecker_notconsumable_but_assignable_was_consumed_global_let, none,
784-
"'%0' was consumed but it is illegal to consume a noncopyable global let. One can only read from it",
785-
(StringRef))
786-
ERROR(sil_moveonlychecker_notconsumable_but_assignable_was_consumed_escaping_var, none,
787-
"'%0' was consumed but it is illegal to consume a noncopyable mutable capture of an escaping closure. One can only read from it or assign over it",
788-
(StringRef))
789-
ERROR(sil_moveonlychecker_let_capture_consumed, none,
790-
"'%0' was consumed but it is illegal to consume a noncopyable immutable capture of an escaping closure. One can only read from it", (StringRef))
771+
ERROR(sil_moveonlychecker_use_after_partial_consume, none,
772+
"cannot use '%0' after partial consume", (StringRef))
773+
774+
ERROR(sil_moveonlychecker_notconsumable_but_assignable_was_consumed, none,
775+
"cannot consume noncopyable stored property '%0' %select{of a class|that is global}1",
776+
(StringRef, bool))
777+
791778
ERROR(sil_moveonlychecker_cannot_destructure_deinit_nominal_type_self, none,
792779
"Cannot partially consume '%0' since it has a user defined deinit",
793780
(StringRef))
794781
ERROR(sil_moveonlychecker_cannot_destructure_deinit_nominal_type_field, none,
795782
"Cannot partially consume '%0' since it contains field '%1.%2' whose type %3 has a user defined deinit",
796783
(StringRef, StringRef, StringRef, DeclBaseName))
797784

798-
NOTE(sil_moveonlychecker_moveonly_field_consumed_here, none,
799-
"move only field consumed here", ())
785+
NOTE(sil_moveonlychecker_partial_consume_here, none,
786+
"partial consume here", ())
800787
NOTE(sil_moveonlychecker_boundary_use, none,
801788
"boundary use here", ())
802789
NOTE(sil_moveonlychecker_consuming_use_here, none,
@@ -816,15 +803,6 @@ NOTE(sil_movekillscopyablevalue_value_cyclic_consumed_in_loop_here, none,
816803
NOTE(sil_moveonlychecker_deinit_here, none,
817804
"deinit declared here", ())
818805

819-
ERROR(sil_moveonlychecker_not_understand_consumable_and_assignable, none,
820-
"Usage of @noImplicitCopy that the move checker does not know how to "
821-
"check!", ())
822-
ERROR(sil_moveonlychecker_not_understand_moveonly, none,
823-
"Usage of a move only type that the move checker does not know how to "
824-
"check!", ())
825-
ERROR(sil_moveonlychecker_missed_copy, none,
826-
"copy of noncopyable typed value. This is a compiler bug. Please file a bug with a small example of the bug", ())
827-
828806
// move kills copyable values checker diagnostics
829807
ERROR(sil_movekillscopyablevalue_value_consumed_more_than_once, none,
830808
"'%0' used after being consumed", (StringRef))
@@ -834,10 +812,22 @@ NOTE(sil_movekillscopyablevalue_use_here, none,
834812
"use here", ())
835813
NOTE(sil_movekillscopyablevalue_value_consumed_in_loop, none,
836814
"consume here would occur multiple times in loop", ())
815+
816+
// errors involving noncopyables that are considered to be bugs in the compiler
817+
ERROR(sil_moveonlychecker_not_understand_consumable_and_assignable, none,
818+
"usage of no-implicit-copy value that the compiler can't verify. This is a compiler bug. Please file a bug with a small example of the bug", ())
819+
ERROR(sil_moveonlychecker_not_understand_moveonly, none,
820+
"usage of a noncopyable type that compiler can't verify. This is a compiler bug. Please file a bug with a small example of the bug"
821+
"check!", ())
822+
ERROR(sil_moveonlychecker_bug_missed_copy, none,
823+
"copy of noncopyable typed value. This is a compiler bug. Please file a bug with a small example of the bug", ())
824+
ERROR(sil_moveonlychecker_bug_exclusivity_violation, none,
825+
"'%0' has an unexpected exclusivity violation. This is a compiler bug. Please file a bug with a small example of the bug", (StringRef))
837826
ERROR(sil_movekillscopyablevalue_move_applied_to_unsupported_move, none,
838-
"'consume' applied to value that the compiler does not support checking",
827+
"'consume' applied to value that the compiler does not support. This is a compiler bug. Please file a bug with a small example of the bug",
839828
())
840829

830+
841831
// Implicit inout-to-UnsafeRawPointer conversions
842832
WARNING(nontrivial_to_rawpointer_conversion,none,
843833
"forming %1 to a variable of type %0; this is likely incorrect because %2 may contain "

include/swift/AST/DiagnosticsSema.def

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6907,30 +6907,6 @@ ERROR(wrap_invalid_attr_added_by_access_note, none,
69076907

69086908
#undef WHICH_ACCESS_NOTE
69096909

6910-
// Move Only diagnostics
6911-
6912-
ERROR(experimental_moveonly_feature_can_only_be_used_when_enabled,
6913-
none, "Can not use feature when experimental move only is disabled! Pass"
6914-
" the frontend flag -enable-experimental-move-only to swift to enable "
6915-
"the usage of this language feature", ())
6916-
ERROR(noimplicitcopy_attr_valid_only_on_local_let_params,
6917-
none, "'@_noImplicitCopy' attribute can only be applied to local lets and params", ())
6918-
ERROR(noimplicitcopy_attr_invalid_in_generic_context,
6919-
none, "'@_noImplicitCopy' attribute cannot be applied to entities in generic contexts", ())
6920-
ERROR(moveonly_generics, none, "move-only type %0 cannot be used with generics yet", (Type))
6921-
ERROR(moveonly_effectful_getter,none,
6922-
"%0 of move-only type cannot be 'async' or 'throws'", (DescriptiveDeclKind))
6923-
ERROR(noimplicitcopy_attr_not_allowed_on_moveonlytype,none,
6924-
"'@_noImplicitCopy' has no effect when applied to a move only type", ())
6925-
ERROR(moveonly_enums_do_not_support_indirect,none,
6926-
"move-only enum %0 cannot be marked indirect or have indirect cases yet", (Identifier))
6927-
ERROR(moveonly_cast,none,
6928-
"move-only types cannot be conditionally cast", ())
6929-
ERROR(moveonly_failable_init,none,
6930-
"move-only types cannot have failable initializers yet", ())
6931-
ERROR(moveonly_objc_enum_banned, none,
6932-
"@objc enums cannot be marked as move-only", ())
6933-
69346910
//------------------------------------------------------------------------------
69356911
// MARK: Type inference from default expressions
69366912
//------------------------------------------------------------------------------
@@ -6988,21 +6964,6 @@ ERROR(concurrency_task_to_thread_model_global_actor_annotation,none,
69886964
"annotating a type with a global actor %0 is not permitted within %1",
69896965
(TypeRepr*, StringRef))
69906966

6991-
ERROR(moveOnly_not_allowed_here,none,
6992-
"'moveOnly' only applies to structs or enums", ())
6993-
ERROR(consume_expression_not_passed_lvalue,none,
6994-
"'consume' can only be applied to lvalues", ())
6995-
ERROR(borrow_expression_not_passed_lvalue,none,
6996-
"'borrow' can only be applied to lvalues", ())
6997-
ERROR(copy_expression_not_passed_lvalue,none,
6998-
"'copy' can only be applied to lvalues", ())
6999-
ERROR(copy_expression_cannot_be_used_with_noncopyable_types,none,
7000-
"'copy' cannot be applied to noncopyable types", ())
7001-
7002-
ERROR(moveOnly_requires_lexical_lifetimes,none,
7003-
"noncopyable types require lexical borrow scopes "
7004-
"(add -enable-lexical-borrow-scopes=true)", ())
7005-
70066967
//------------------------------------------------------------------------------
70076968
// MARK: #_hasSymbol
70086969
//------------------------------------------------------------------------------
@@ -7135,31 +7096,68 @@ NOTE(macro_expand_circular_reference_unnamed_through, none,
71357096
"circular reference expanding %0 macros", (StringRef))
71367097

71377098
//------------------------------------------------------------------------------
7138-
// MARK: Move Only Errors
7099+
// MARK: Noncopyable Types Diagnostics
71397100
//------------------------------------------------------------------------------
71407101

7141-
ERROR(moveonly_copyable_type_that_contains_moveonly_type, none,
7142-
"%0 %1 cannot contain a move-only type without also being move-only",
7102+
ERROR(noncopyable_within_copyable, none,
7103+
"%0 %1 cannot contain a noncopyable type without also being noncopyable",
71437104
(DescriptiveDeclKind, DeclName))
7144-
NOTE(moveonly_copyable_type_that_contains_moveonly_type_location, none,
7145-
"contained move-only %0 '%1.%2'",
7105+
NOTE(noncopyable_within_copyable_location, none,
7106+
"contained noncopyable %0 '%1.%2'",
71467107
(DescriptiveDeclKind, StringRef, StringRef))
7147-
ERROR(moveonly_cannot_conform_to_type, none,
7148-
"move-only %0 %1 cannot conform to %2",
7108+
ERROR(noncopyable_cannot_conform_to_type, none,
7109+
"noncopyable %0 %1 cannot conform to %2",
71497110
(DescriptiveDeclKind, DeclName, Type))
7150-
ERROR(moveonly_parameter_missing_ownership, none,
7111+
ERROR(noncopyable_parameter_requires_ownership, none,
71517112
"noncopyable parameter must specify its ownership", ())
7152-
ERROR(moveonly_parameter_subscript_unsupported, none,
7113+
ERROR(noncopyable_parameter_subscript_unsupported, none,
71537114
"subscripts cannot have noncopyable parameters yet", ())
7154-
NOTE(moveonly_parameter_ownership_suggestion, none,
7115+
NOTE(noncopyable_parameter_ownership_suggestion, none,
71557116
"add '%0' %1", (StringRef, StringRef))
71567117
ERROR(ownership_specifier_copyable,none,
7157-
"Copyable types cannot be 'consuming' or 'borrowing' yet", ())
7118+
"copyable types cannot be 'consuming' or 'borrowing' yet", ())
71587119
ERROR(self_ownership_specifier_copyable,none,
7159-
"%0 is not yet valid on %1s in a Copyable type",
7120+
"%0 is not yet valid on %1s of a copyable type",
71607121
(SelfAccessKind, DescriptiveDeclKind))
71617122
ERROR(ownership_specifier_nonescaping_closure,none,
71627123
"'%0' cannot be applied to nonescaping closure", (StringRef))
7124+
ERROR(noncopyable_generics, none, "noncopyable type %0 cannot be used with generics yet", (Type))
7125+
ERROR(noncopyable_effectful_getter,none,
7126+
"%0 of noncopyable type cannot be 'async' or 'throws'", (DescriptiveDeclKind))
7127+
ERROR(noncopyable_enums_do_not_support_indirect,none,
7128+
"noncopyable enum %0 cannot be marked indirect or have indirect cases yet", (Identifier))
7129+
ERROR(noncopyable_cast,none,
7130+
"noncopyable types cannot be conditionally cast", ())
7131+
ERROR(noncopyable_failable_init,none,
7132+
"noncopyable types cannot have failable initializers yet", ())
7133+
ERROR(noncopyable_objc_enum, none,
7134+
"noncopyable enums cannot be marked '@objc'", ())
7135+
ERROR(moveOnly_not_allowed_here,none,
7136+
"'@_moveOnly' attribute is only valid on structs or enums", ())
7137+
ERROR(consume_expression_not_passed_lvalue,none,
7138+
"'consume' can only be applied to a local binding ('let', 'var', or parameter)", ())
7139+
ERROR(borrow_expression_not_passed_lvalue,none,
7140+
"'borrow' can only be applied to a local binding ('let', 'var', or parameter)", ())
7141+
ERROR(copy_expression_not_passed_lvalue,none,
7142+
"'copy' can only be applied to a local binding ('let', 'var', or parameter)", ())
7143+
ERROR(copy_expression_cannot_be_used_with_noncopyable_types,none,
7144+
"'copy' cannot be applied to noncopyable types", ())
7145+
7146+
ERROR(moveOnly_requires_lexical_lifetimes,none,
7147+
"noncopyable types require lexical borrow scopes "
7148+
"(add -enable-lexical-borrow-scopes=true)", ())
7149+
7150+
// Experimental noncopyable feature diagnostics:
7151+
ERROR(experimental_moveonly_feature_can_only_be_used_when_enabled,
7152+
none, "Can not use feature when experimental move only is disabled! Pass"
7153+
" the frontend flag -enable-experimental-move-only to swift to enable "
7154+
"the usage of this language feature", ())
7155+
ERROR(noimplicitcopy_attr_valid_only_on_local_let_params,
7156+
none, "'@_noImplicitCopy' attribute can only be applied to local lets and params", ())
7157+
ERROR(noimplicitcopy_attr_invalid_in_generic_context,
7158+
none, "'@_noImplicitCopy' attribute cannot be applied to entities in generic contexts", ())
7159+
ERROR(noimplicitcopy_attr_not_allowed_on_moveonlytype,none,
7160+
"'@_noImplicitCopy' has no effect when applied to a noncopyable type", ())
71637161

71647162
//------------------------------------------------------------------------------
71657163
// MARK: Runtime discoverable attributes (@runtimeMetadata)

0 commit comments

Comments
 (0)