Skip to content

Commit f5b04cc

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.
1 parent ee9563f commit f5b04cc

40 files changed

+1452
-1536
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
@@ -753,48 +753,35 @@ ERROR(sil_moveonlychecker_owned_value_consumed_and_used_at_same_time, none,
753753
ERROR(sil_moveonlychecker_value_used_after_consume, none,
754754
"'%0' used after consume", (StringRef))
755755
ERROR(sil_moveonlychecker_guaranteed_value_consumed, none,
756-
"'%0' has guaranteed ownership but was consumed", (StringRef))
756+
"'%0' is borrowed and cannot be consumed", (StringRef))
757+
758+
// FIXME: this diagnostic shouldn't ever be emitted now. rdar://109742587 (closures may still try to consume captures, e.g., borrowed parameters)
757759
ERROR(sil_moveonlychecker_guaranteed_value_captured_by_closure, none,
758-
"'%0' has guaranteed ownership but was consumed due to being captured by a closure", (StringRef))
759-
ERROR(sil_moveonlychecker_let_value_consumed_in_closure, none,
760-
"'%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))
760+
"'%0' is borrowed and cannot be consumed by closure capture", (StringRef))
761+
762+
ERROR(sil_moveonlychecker_capture_consumed_in_closure, none,
763+
"captured '%0' cannot be consumed within a closure", (StringRef))
761764
ERROR(sil_moveonlychecker_inout_not_reinitialized_before_end_of_function, none,
762-
"'%0' consumed but not reinitialized before end of function", (StringRef))
763-
ERROR(sil_moveonlychecker_inout_not_reinitialized_before_end_of_closure, none,
764-
"'%0' consumed in closure but not reinitialized before end of closure", (StringRef))
765+
"missing reinitialization of '%0' after consume", (StringRef))
765766
ERROR(sil_moveonlychecker_value_consumed_in_a_loop, none,
766767
"'%0' consumed by a use in a loop", (StringRef))
767-
ERROR(sil_moveonlychecker_exclusivity_violation, none,
768-
"'%0' has consuming use that cannot be eliminated due to a tight exclusivity scope", (StringRef))
769-
ERROR(sil_moveonlychecker_moveonly_field_consumed, none,
770-
"'%0' has a move only field that was consumed before later uses", (StringRef))
771768

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

796-
NOTE(sil_moveonlychecker_moveonly_field_consumed_here, none,
797-
"move only field consumed here", ())
783+
NOTE(sil_moveonlychecker_partial_consume_here, none,
784+
"partial consume here", ())
798785
NOTE(sil_moveonlychecker_boundary_use, none,
799786
"boundary use here", ())
800787
NOTE(sil_moveonlychecker_consuming_use_here, none,
@@ -814,15 +801,6 @@ NOTE(sil_movekillscopyablevalue_value_cyclic_consumed_in_loop_here, none,
814801
NOTE(sil_moveonlychecker_deinit_here, none,
815802
"deinit declared here", ())
816803

817-
ERROR(sil_moveonlychecker_not_understand_consumable_and_assignable, none,
818-
"Usage of @noImplicitCopy that the move checker does not know how to "
819-
"check!", ())
820-
ERROR(sil_moveonlychecker_not_understand_moveonly, none,
821-
"Usage of a move only type that the move checker does not know how to "
822-
"check!", ())
823-
ERROR(sil_moveonlychecker_missed_copy, none,
824-
"copy of noncopyable typed value. This is a compiler bug. Please file a bug with a small example of the bug", ())
825-
826804
// move kills copyable values checker diagnostics
827805
ERROR(sil_movekillscopyablevalue_value_consumed_more_than_once, none,
828806
"'%0' used after being consumed", (StringRef))
@@ -832,10 +810,22 @@ NOTE(sil_movekillscopyablevalue_use_here, none,
832810
"use here", ())
833811
NOTE(sil_movekillscopyablevalue_value_consumed_in_loop, none,
834812
"consume here would occur multiple times in loop", ())
813+
814+
// errors involving noncopyables that are considered to be bugs in the compiler
815+
ERROR(sil_moveonlychecker_not_understand_consumable_and_assignable, none,
816+
"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", ())
817+
ERROR(sil_moveonlychecker_not_understand_moveonly, none,
818+
"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"
819+
"check!", ())
820+
ERROR(sil_moveonlychecker_bug_missed_copy, none,
821+
"copy of noncopyable typed value. This is a compiler bug. Please file a bug with a small example of the bug", ())
822+
ERROR(sil_moveonlychecker_bug_exclusivity_violation, none,
823+
"'%0' has an unexpected exclusivity violation. This is a compiler bug. Please file a bug with a small example of the bug", (StringRef))
835824
ERROR(sil_movekillscopyablevalue_move_applied_to_unsupported_move, none,
836-
"'consume' applied to value that the compiler does not support checking",
825+
"'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",
837826
())
838827

828+
839829
// Implicit inout-to-UnsafeRawPointer conversions
840830
WARNING(nontrivial_to_rawpointer_conversion,none,
841831
"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
@@ -6930,30 +6930,6 @@ ERROR(wrap_invalid_attr_added_by_access_note, none,
69306930

69316931
#undef WHICH_ACCESS_NOTE
69326932

6933-
// Move Only diagnostics
6934-
6935-
ERROR(experimental_moveonly_feature_can_only_be_used_when_enabled,
6936-
none, "Can not use feature when experimental move only is disabled! Pass"
6937-
" the frontend flag -enable-experimental-move-only to swift to enable "
6938-
"the usage of this language feature", ())
6939-
ERROR(noimplicitcopy_attr_valid_only_on_local_let_params,
6940-
none, "'@_noImplicitCopy' attribute can only be applied to local lets and params", ())
6941-
ERROR(noimplicitcopy_attr_invalid_in_generic_context,
6942-
none, "'@_noImplicitCopy' attribute cannot be applied to entities in generic contexts", ())
6943-
ERROR(moveonly_generics, none, "move-only type %0 cannot be used with generics yet", (Type))
6944-
ERROR(moveonly_effectful_getter,none,
6945-
"%0 of move-only type cannot be 'async' or 'throws'", (DescriptiveDeclKind))
6946-
ERROR(noimplicitcopy_attr_not_allowed_on_moveonlytype,none,
6947-
"'@_noImplicitCopy' has no effect when applied to a move only type", ())
6948-
ERROR(moveonly_enums_do_not_support_indirect,none,
6949-
"move-only enum %0 cannot be marked indirect or have indirect cases yet", (Identifier))
6950-
ERROR(moveonly_cast,none,
6951-
"move-only types cannot be conditionally cast", ())
6952-
ERROR(moveonly_failable_init,none,
6953-
"move-only types cannot have failable initializers yet", ())
6954-
ERROR(moveonly_objc_enum_banned, none,
6955-
"@objc enums cannot be marked as move-only", ())
6956-
69576933
//------------------------------------------------------------------------------
69586934
// MARK: Type inference from default expressions
69596935
//------------------------------------------------------------------------------
@@ -7011,21 +6987,6 @@ ERROR(concurrency_task_to_thread_model_global_actor_annotation,none,
70116987
"annotating a type with a global actor %0 is not permitted within %1",
70126988
(TypeRepr*, StringRef))
70136989

7014-
ERROR(moveOnly_not_allowed_here,none,
7015-
"'moveOnly' only applies to structs or enums", ())
7016-
ERROR(consume_expression_not_passed_lvalue,none,
7017-
"'consume' can only be applied to lvalues", ())
7018-
ERROR(borrow_expression_not_passed_lvalue,none,
7019-
"'borrow' can only be applied to lvalues", ())
7020-
ERROR(copy_expression_not_passed_lvalue,none,
7021-
"'copy' can only be applied to lvalues", ())
7022-
ERROR(copy_expression_cannot_be_used_with_noncopyable_types,none,
7023-
"'copy' cannot be applied to noncopyable types", ())
7024-
7025-
ERROR(moveOnly_requires_lexical_lifetimes,none,
7026-
"noncopyable types require lexical borrow scopes "
7027-
"(add -enable-lexical-borrow-scopes=true)", ())
7028-
70296990
//------------------------------------------------------------------------------
70306991
// MARK: #_hasSymbol
70316992
//------------------------------------------------------------------------------
@@ -7158,31 +7119,68 @@ NOTE(macro_expand_circular_reference_unnamed_through, none,
71587119
"circular reference expanding %0 macros", (StringRef))
71597120

71607121
//------------------------------------------------------------------------------
7161-
// MARK: Move Only Errors
7122+
// MARK: Noncopyable Types Diagnostics
71627123
//------------------------------------------------------------------------------
71637124

7164-
ERROR(moveonly_copyable_type_that_contains_moveonly_type, none,
7165-
"%0 %1 cannot contain a move-only type without also being move-only",
7125+
ERROR(noncopyable_within_copyable, none,
7126+
"%0 %1 cannot contain a noncopyable type without also being noncopyable",
71667127
(DescriptiveDeclKind, DeclName))
7167-
NOTE(moveonly_copyable_type_that_contains_moveonly_type_location, none,
7168-
"contained move-only %0 '%1.%2'",
7128+
NOTE(noncopyable_within_copyable_location, none,
7129+
"contained noncopyable %0 '%1.%2'",
71697130
(DescriptiveDeclKind, StringRef, StringRef))
7170-
ERROR(moveonly_cannot_conform_to_type, none,
7171-
"move-only %0 %1 cannot conform to %2",
7131+
ERROR(noncopyable_cannot_conform_to_type, none,
7132+
"noncopyable %0 %1 cannot conform to %2",
71727133
(DescriptiveDeclKind, DeclName, Type))
7173-
ERROR(moveonly_parameter_missing_ownership, none,
7134+
ERROR(noncopyable_parameter_requires_ownership, none,
71747135
"noncopyable parameter must specify its ownership", ())
7175-
ERROR(moveonly_parameter_subscript_unsupported, none,
7136+
ERROR(noncopyable_parameter_subscript_unsupported, none,
71767137
"subscripts cannot have noncopyable parameters yet", ())
7177-
NOTE(moveonly_parameter_ownership_suggestion, none,
7138+
NOTE(noncopyable_parameter_ownership_suggestion, none,
71787139
"add '%0' %1", (StringRef, StringRef))
71797140
ERROR(ownership_specifier_copyable,none,
7180-
"Copyable types cannot be 'consuming' or 'borrowing' yet", ())
7141+
"copyable types cannot be 'consuming' or 'borrowing' yet", ())
71817142
ERROR(self_ownership_specifier_copyable,none,
7182-
"%0 is not yet valid on %1s in a Copyable type",
7143+
"%0 is not yet valid on %1s of a copyable type",
71837144
(SelfAccessKind, DescriptiveDeclKind))
71847145
ERROR(ownership_specifier_nonescaping_closure,none,
71857146
"'%0' cannot be applied to nonescaping closure", (StringRef))
7147+
ERROR(noncopyable_generics, none, "noncopyable type %0 cannot be used with generics yet", (Type))
7148+
ERROR(noncopyable_effectful_getter,none,
7149+
"%0 of noncopyable type cannot be 'async' or 'throws'", (DescriptiveDeclKind))
7150+
ERROR(noncopyable_enums_do_not_support_indirect,none,
7151+
"noncopyable enum %0 cannot be marked indirect or have indirect cases yet", (Identifier))
7152+
ERROR(noncopyable_cast,none,
7153+
"noncopyable types cannot be conditionally cast", ())
7154+
ERROR(noncopyable_failable_init,none,
7155+
"noncopyable types cannot have failable initializers yet", ())
7156+
ERROR(noncopyable_objc_enum, none,
7157+
"noncopyable enums cannot be marked '@objc'", ())
7158+
ERROR(moveOnly_not_allowed_here,none,
7159+
"'@_moveOnly' attribute is only valid on structs or enums", ())
7160+
ERROR(consume_expression_not_passed_lvalue,none,
7161+
"'consume' can only be applied to a local binding ('let', 'var', or parameter)", ())
7162+
ERROR(borrow_expression_not_passed_lvalue,none,
7163+
"'borrow' can only be applied to a local binding ('let', 'var', or parameter)", ())
7164+
ERROR(copy_expression_not_passed_lvalue,none,
7165+
"'copy' can only be applied to a local binding ('let', 'var', or parameter)", ())
7166+
ERROR(copy_expression_cannot_be_used_with_noncopyable_types,none,
7167+
"'copy' cannot be applied to noncopyable types", ())
7168+
7169+
ERROR(moveOnly_requires_lexical_lifetimes,none,
7170+
"noncopyable types require lexical borrow scopes "
7171+
"(add -enable-lexical-borrow-scopes=true)", ())
7172+
7173+
// Experimental noncopyable feature diagnostics:
7174+
ERROR(experimental_moveonly_feature_can_only_be_used_when_enabled,
7175+
none, "Can not use feature when experimental move only is disabled! Pass"
7176+
" the frontend flag -enable-experimental-move-only to swift to enable "
7177+
"the usage of this language feature", ())
7178+
ERROR(noimplicitcopy_attr_valid_only_on_local_let_params,
7179+
none, "'@_noImplicitCopy' attribute can only be applied to local lets and params", ())
7180+
ERROR(noimplicitcopy_attr_invalid_in_generic_context,
7181+
none, "'@_noImplicitCopy' attribute cannot be applied to entities in generic contexts", ())
7182+
ERROR(noimplicitcopy_attr_not_allowed_on_moveonlytype,none,
7183+
"'@_noImplicitCopy' has no effect when applied to a noncopyable type", ())
71867184

71877185
//------------------------------------------------------------------------------
71887186
// MARK: Runtime discoverable attributes (@runtimeMetadata)

0 commit comments

Comments
 (0)