Skip to content

Commit b60d635

Browse files
committed
[interop] make interop diagnostics more consistent with the rest of Swift diagnostics
1 parent c28031c commit b60d635

14 files changed

+74
-76
lines changed

include/swift/AST/DiagnosticsClangImporter.def

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ NOTE(unresolvable_clang_decl_is_a_framework_bug,none,
8383
(StringRef))
8484

8585
WARNING(clang_swift_attr_unhandled,none,
86-
"Ignoring unknown Swift attribute or modifier '%0'", (StringRef))
86+
"ignoring unknown Swift attribute or modifier '%0'", (StringRef))
8787

8888
WARNING(clang_error_code_must_be_sendable,none,
8989
"cannot make error code type '%0' non-sendable because Swift errors "
@@ -160,77 +160,75 @@ NOTE(incomplete_interface, none, "interface %0 is incomplete", (const clang::Nam
160160
NOTE(incomplete_protocol, none, "protocol %0 is incomplete", (const clang::NamedDecl*))
161161
NOTE(incomplete_record, none, "record '%0' is not defined (incomplete)", (StringRef))
162162
NOTE(record_over_aligned, none, "record '%0' is over aligned", (StringRef))
163-
NOTE(record_non_trivial_copy_destroy, none, "record '%0' is not trivial to copy/destroy", (StringRef))
163+
NOTE(record_non_trivial_copy_destroy, none, "record '%0' is not trivial to copy or destroy", (StringRef))
164164
NOTE(record_is_dependent, none, "record '%0' is dependent", (StringRef))
165165
NOTE(record_parent_unimportable, none, "record %0's parent is not importable", (StringRef))
166166
NOTE(reference_passed_by_value, none, "function uses foreign reference type "
167167
"'%0' as a value in %1 types which breaks "
168-
"'swift_shared_reference' contract (outlined in "
169-
"C++ Interop User Manual).",
168+
"'swift_shared_reference' contract",
170169
(StringRef, StringRef))
171170
NOTE(record_not_automatically_importable, none, "record '%0' is not "
172-
"automatically available: %1. "
173-
"Does this type have reference "
171+
"automatically available: %1; "
172+
"does this type have reference "
174173
"semantics?",
175174
(StringRef, StringRef))
176175

177176
NOTE(projection_value_not_imported, none, "C++ method '%0' that returns a value "
178-
"of type '%1' is unavailable. ",
177+
"of type '%1' is unavailable",
179178
(StringRef, StringRef))
180179
NOTE(projection_ptr_not_imported, none, "C++ method '%0' that returns a pointer "
181-
"of type '%1' is unavailable. ",
180+
"of type '%1' is unavailable",
182181
(StringRef, StringRef))
183182
NOTE(projection_reference_not_imported, none, "C++ method '%0' that returns a reference "
184-
"of type '%1' is unavailable. ",
183+
"of type '%1' is unavailable",
185184
(StringRef, StringRef))
186185
NOTE(projection_may_return_interior_ptr, none, "C++ method '%0' may return an "
187-
"interior pointer. ",
186+
"interior pointer",
188187
(StringRef))
189-
NOTE(mark_self_contained, none, "Mark type '%0' as 'SWIFT_SELF_CONTAINED' in C++ to "
190-
"make methods that use it available in Swift. ",
188+
NOTE(mark_self_contained, none, "annotate type '%0' with 'SWIFT_SELF_CONTAINED' in C++ to "
189+
"make methods that return it available in Swift",
191190
(StringRef))
192191
NOTE(mark_safe_to_import, none, "annotate method '%0' with 'SWIFT_RETURNS_INDEPENDENT_VALUE' in C++ to "
193192
"make it available in Swift",
194193
(StringRef))
195194

196-
NOTE(at_to_subscript, none, "Do you want to replace it with a call "
195+
NOTE(at_to_subscript, none, "do you want to replace it with a call "
197196
"to the subscript operator?",
198197
())
199-
NOTE(get_swift_iterator, none, "Do you want to make a Swift iterator instead?",
198+
NOTE(get_swift_iterator, none, "do you want to make a Swift iterator instead?",
200199
())
201-
NOTE(replace_with_nil, none, "Do you want to compare against 'nil' instead?'",
200+
NOTE(replace_with_nil, none, "do you want to compare against 'nil' instead?",
202201
())
203-
NOTE(get_first_element, none, "Do you want to get the first element instead?",
202+
NOTE(get_first_element, none, "do you want to get the first element instead?",
204203
())
205-
NOTE(get_last_element, none, "Do you want to get the last element instead?",
204+
NOTE(get_last_element, none, "do you want to get the last element instead?",
206205
())
207206

208207
NOTE(iterator_method_unavailable, none, "C++ method '%0' that returns an "
209208
"iterator is unavailable",
210209
(StringRef))
211210
NOTE(iterator_potentially_unsafe, none, "C++ methods that return iterators "
212-
"are potentially unsafe. Try re-writing "
213-
"to use Swift iterator APIs.", ())
211+
"are potentially unsafe; try using Swift collection APIs instead", ())
214212

215213
ERROR(reference_type_must_have_retain_attr,none,
216-
"reference type '%0' must have 'retain:' swift attribute.", (StringRef))
214+
"reference type '%0' must have 'retain:' swift attribute", (StringRef))
217215
ERROR(reference_type_must_have_release_attr,none,
218-
"reference type '%0' must have 'release:' swift attribute.", (StringRef))
216+
"reference type '%0' must have 'release:' swift attribute", (StringRef))
219217
ERROR(foreign_reference_types_cannot_find_retain,none,
220-
"cannot find retain function '%0' for reference type '%1'.", (StringRef, StringRef))
218+
"cannot find retain function '%0' for reference type '%1'", (StringRef, StringRef))
221219
ERROR(foreign_reference_types_cannot_find_release,none,
222-
"cannot find release function '%0' for reference type '%1'.", (StringRef, StringRef))
220+
"cannot find release function '%0' for reference type '%1'", (StringRef, StringRef))
223221
ERROR(too_many_reference_type_retain_operations,none,
224-
"too many functions with name '%0'. There must be exactly one retain "
225-
"function for reference type '%1'.", (StringRef, StringRef))
222+
"multiple functions '%0' found; there must be exactly one retain "
223+
"function for reference type '%1'", (StringRef, StringRef))
226224
ERROR(too_many_reference_type_release_operations,none,
227-
"too many functions with name '%0'. There must be exactly one release "
228-
"function for reference type '%1'.", (StringRef, StringRef))
225+
"multiple functions '%0' found; there must be exactly one release "
226+
"function for reference type '%1'", (StringRef, StringRef))
229227
ERROR(foreign_reference_types_invalid_retain,none,
230-
"specified retain function '%0' is invalid. Retain must have exactly one "
228+
"specified retain function '%0' is invalid; retain function must have exactly one "
231229
"argument of type '%1'", (StringRef, StringRef))
232230
ERROR(foreign_reference_types_invalid_release,none,
233-
"specified release function '%0' is invalid. Release must have exactly "
231+
"specified release function '%0' is invalid; release function must have exactly "
234232
"one argument of type '%1'", (StringRef, StringRef))
235233

236234

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -522,18 +522,18 @@ WARNING(compiler_plugin_not_loaded,none,
522522
"compiler plugin not loaded: %0; loader error: %1", (StringRef, StringRef))
523523

524524
ERROR(dont_enable_interop_and_compat,none,
525-
"do not pass both -enable-experimental-cxx-interop and "
526-
"-cxx-interoperability-mode. Remove -enable-experimental-cxx-interop.", ())
525+
"do not pass both '-enable-experimental-cxx-interop' and "
526+
"'-cxx-interoperability-mode'; remove '-enable-experimental-cxx-interop'", ())
527527

528528
NOTE(valid_cxx_interop_modes,none,
529529
"valid arguments to '-cxx-interoperability-mode=' are %0", (StringRef))
530530
NOTE(swift_will_maintain_compat,none,
531531
"Swift will maintain source compatibility for imported APIs based on the "
532532
"selected compatibility mode, so updating the Swift compiler will not "
533-
"change how APIs are imported.", ())
533+
"change how APIs are imported", ())
534534
WARNING(enable_interop_flag_deprecated,none,
535-
"the -enable-experimental-cxx-interop flag is deprecated. Please pass "
536-
"'-cxx-interoperability-mode=' instead.", ())
535+
"the '-enable-experimental-cxx-interop' flag is deprecated; please pass "
536+
"'-cxx-interoperability-mode=' instead", ())
537537

538538
ERROR(layout_string_instantiation_without_layout_strings,none,
539539
"-enable-layout-string-value-witnesses-instantiation can not be enabled "

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,9 +2002,9 @@ ERROR(where_nongeneric_toplevel,none,
20022002
"'where' clause cannot be applied to a non-generic top-level "
20032003
"declaration", ())
20042004
ERROR(unable_to_convert_generic_swift_types,none,
2005-
"could not generate C++ types from the generic Swift types provided. "
2006-
"The following Swift type(s) provided to '%0' could not be "
2007-
"converted: %1.",
2005+
"could not generate C++ types from the generic Swift types provided; "
2006+
"the following Swift type(s) provided to '%0' could not be "
2007+
"converted: %1",
20082008
(StringRef, StringRef))
20092009

20102010
// Type aliases

test/Inputs/clang-importer-sdk/usr/include/objc_structs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ struct StructOfBlocks {
88
void (^__unsafe_unretained _Nonnull block)(void);
99
};
1010

11-
struct StrongsInAStruct { // expected-note {{record 'StrongsInAStruct' is not trivial to copy/destroy}}
11+
struct StrongsInAStruct { // expected-note {{record 'StrongsInAStruct' is not trivial to copy or destroy}}
1212
__strong NSString *nsstr;
1313
};
1414

15-
struct WeaksInAStruct { // expected-note {{record 'WeaksInAStruct' is not trivial to copy/destroy}}
15+
struct WeaksInAStruct { // expected-note {{record 'WeaksInAStruct' is not trivial to copy or destroy}}
1616
__weak NSString *nsstr;
1717
};

test/Interop/Cxx/class/fixit-add-safe-to-import-self-contained.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public func test(x: X) {
3333
// CHECK: ^
3434
// CHECK: SWIFT_RETURNS_INDEPENDENT_VALUE
3535

36-
// CHECK: note: Mark type 'Ptr' as 'SWIFT_SELF_CONTAINED' in C++ to make methods that use it available in Swift.
36+
// CHECK: note: annotate type 'Ptr' with 'SWIFT_SELF_CONTAINED' in C++ to make methods that return it available in Swift
3737
// CHECK: struct Ptr {
3838
// CHECK: ^
3939
// CHECK: SWIFT_SELF_CONTAINED

test/Interop/Cxx/class/fixits-for-std-vector.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,27 @@ import CxxStdlib
2222

2323
public func test(v: V) {
2424
// CHECK: note: C++ method 'begin' that returns an iterator is unavailable
25-
// CHECK: note: Do you want to make a Swift iterator instead?
25+
// CHECK: note: do you want to make a Swift iterator instead?
2626
// CHECK: ^~~~~
2727
// CHECK: makeIterator
2828
_ = v.begin()
2929

3030
// CHECK: note: C++ method 'end' that returns an iterator is unavailable
31-
// CHECK: note: Do you want to compare against 'nil' instead?'
31+
// CHECK: note: do you want to compare against 'nil' instead?
3232
// CHECK: ^~~~
3333
// CHECK: nil
3434
_ = v.end()
3535

36-
// CHECK: note: C++ method 'front' that returns a reference of type 'UnsafePointer' is unavailable.
37-
// CHECK: note: C++ method 'front' may return an interior pointer.
38-
// CHECK: note: Do you want to get the first element instead?
36+
// CHECK: note: C++ method 'front' that returns a reference of type 'UnsafePointer' is unavailable
37+
// CHECK: note: C++ method 'front' may return an interior pointer
38+
// CHECK: note: do you want to get the first element instead?
3939
// CHECK: ^~~~~~~
4040
// CHECK: first
4141
_ = v.front()
4242

43-
// CHECK: note: C++ method 'back' that returns a reference of type 'UnsafePointer' is unavailable.
44-
// CHECK: note: C++ method 'back' may return an interior pointer.
45-
// CHECK: note: Do you want to get the last element instead?
43+
// CHECK: note: C++ method 'back' that returns a reference of type 'UnsafePointer' is unavailable
44+
// CHECK: note: C++ method 'back' may return an interior pointer
45+
// CHECK: note: do you want to get the last element instead?
4646
// CHECK: ^~~~~~
4747
// CHECK: last
4848
_ = v.back()

test/Interop/Cxx/class/invalid-class-errors.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ struct Nested {
2727

2828
import Test
2929

30-
// CHECK: note: record 'A' is not automatically available: does not have a copy constructor or destructor. Does this type have reference semantics?
30+
// CHECK: note: record 'A' is not automatically available: does not have a copy constructor or destructor; does this type have reference semantics?
3131
// CHECK: struct A {
3232
// CHECK: ^
3333
// CHECK: SWIFT_SHARED_REFERENCE(<#retain#>, <#release#>)
3434
public func test(x: A) { }
35-
// CHECK: note: record 'B' is not automatically available: does not have a copy constructor or destructor. Does this type have reference semantics?
35+
// CHECK: note: record 'B' is not automatically available: does not have a copy constructor or destructor; does this type have reference semantics?
3636
// CHECK: struct {{.*}}B {
3737
// CHECK: ^
3838
// CHECK: SWIFT_SHARED_REFERENCE(<#retain#>, <#release#>)
3939
public func test(x: B) { }
40-
// CHECK: note: record 'Nested' is not automatically available: does not have a copy constructor or destructor. Does this type have reference semantics?
40+
// CHECK: note: record 'Nested' is not automatically available: does not have a copy constructor or destructor; does this type have reference semantics?
4141
// CHECK: struct Nested {
4242
// CHECK: ^
4343
// CHECK: SWIFT_SHARED_REFERENCE(<#retain#>, <#release#>)

test/Interop/Cxx/class/invalid-unsafe-projection-errors.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ struct M {
2727
import Test
2828

2929
public func test(x: M) {
30-
// CHECK: note: C++ method 'test1' that returns a pointer of type 'UnsafeMutablePointer' is unavailable.
31-
// CHECK: note: C++ method 'test1' may return an interior pointer.
30+
// CHECK: note: C++ method 'test1' that returns a pointer of type 'UnsafeMutablePointer' is unavailable
31+
// CHECK: note: C++ method 'test1' may return an interior pointer
3232
// CHECK: note: annotate method 'test1' with 'SWIFT_RETURNS_INDEPENDENT_VALUE' in C++ to make it available in Swift
3333
x.test1()
34-
// CHECK: note: C++ method 'test2' that returns a reference of type 'UnsafeMutablePointer' is unavailable.
35-
// CHECK: note: C++ method 'test2' may return an interior pointer.
34+
// CHECK: note: C++ method 'test2' that returns a reference of type 'UnsafeMutablePointer' is unavailable
35+
// CHECK: note: C++ method 'test2' may return an interior pointer
3636
// CHECK: note: annotate method 'test2' with 'SWIFT_RETURNS_INDEPENDENT_VALUE' in C++ to make it available in Swift
3737
x.test2()
38-
// CHECK: note: C++ method 'test3' that returns a value of type 'Ptr' is unavailable.
39-
// CHECK: note: C++ method 'test3' may return an interior pointer.
38+
// CHECK: note: C++ method 'test3' that returns a value of type 'Ptr' is unavailable
39+
// CHECK: note: C++ method 'test3' may return an interior pointer
4040
// CHECK: note: annotate method 'test3' with 'SWIFT_RETURNS_INDEPENDENT_VALUE' in C++ to make it available in Swift
41-
// CHECK: note: Mark type 'Ptr' as 'SWIFT_SELF_CONTAINED' in C++ to make methods that use it available in Swift.
41+
// CHECK: note: annotate type 'Ptr' with 'SWIFT_SELF_CONTAINED' in C++ to make methods that return it available in Swift
4242
x.test3()
4343
// CHECK: note: C++ method 'begin' that returns an iterator is unavailable
44-
// CHECK: note: C++ methods that return iterators are potentially unsafe. Try re-writing to use Swift iterator APIs.
44+
// CHECK: note: C++ methods that return iterators are potentially unsafe; try using Swift collection APIs instead
4545
x.begin()
4646

4747
// CHECK-NOT: error: value of type 'M' has no member 'stringLiteral'

test/Interop/Cxx/driver/dont-enable-interop-compat.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ module Test {
1515

1616
import Test
1717

18-
// CHECK: warning: the -enable-experimental-cxx-interop flag is deprecated. Please pass '-cxx-interoperability-mode=' instead.
19-
// CHECK: note: Swift will maintain source compatibility for imported APIs based on the selected compatibility mode, so updating the Swift compiler will not change how APIs are imported.
18+
// CHECK: warning: the '-enable-experimental-cxx-interop' flag is deprecated; please pass '-cxx-interoperability-mode=' instead
19+
// CHECK: note: Swift will maintain source compatibility for imported APIs based on the selected compatibility mode, so updating the Swift compiler will not change how APIs are imported

test/Interop/Cxx/driver/enable-interop-flag-depr.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ module Test {
1414

1515
import Test
1616

17-
// CHECK: error: do not pass both -enable-experimental-cxx-interop and -cxx-interoperability-mode. Remove -enable-experimental-cxx-interop.
18-
// CHECK: note: Swift will maintain source compatibility for imported APIs based on the selected compatibility mode, so updating the Swift compiler will not change how APIs are imported.
17+
// CHECK: error: do not pass both '-enable-experimental-cxx-interop' and '-cxx-interoperability-mode'; remove '-enable-experimental-cxx-interop'
18+
// CHECK: note: Swift will maintain source compatibility for imported APIs based on the selected compatibility mode, so updating the Swift compiler will not change how APIs are imported

test/Interop/Cxx/foreign-reference/invalid-retain-operation-errors.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ void badRelease(BadRetainRelease *v, int i);
3232

3333
import Test
3434

35-
// CHECK: error: cannot find retain function 'nonexistant' for reference type 'NonExistant'.
36-
// CHECK: error: cannot find release function 'nonexistant' for reference type 'NonExistant'.
35+
// CHECK: error: cannot find retain function 'nonexistant' for reference type 'NonExistant'
36+
// CHECK: error: cannot find release function 'nonexistant' for reference type 'NonExistant'
3737
public func test(x: NonExistant) { }
3838

39-
// CHECK: error: reference type 'NoRetainRelease' must have 'retain:' swift attribute.
40-
// CHECK: error: reference type 'NoRetainRelease' must have 'release:' swift attribute.
39+
// CHECK: error: reference type 'NoRetainRelease' must have 'retain:' swift attribute
40+
// CHECK: error: reference type 'NoRetainRelease' must have 'release:' swift attribute
4141
public func test(x: NoRetainRelease) { }
4242

43-
// CHECK: error: specified retain function 'badRetain' is invalid. Retain must have exactly one argument of type 'BadRetainRelease'
44-
// CHECK: error: specified release function 'badRelease' is invalid. Release must have exactly one argument of type 'BadRetainRelease'
45-
public func test(x: BadRetainRelease) { }
43+
// CHECK: error: specified retain function 'badRetain' is invalid; retain function must have exactly one argument of type 'BadRetainRelease'
44+
// CHECK: error: specified release function 'badRelease' is invalid; release function must have exactly one argument of type 'BadRetainRelease'
45+
public func test(x: BadRetainRelease) { }

test/Interop/Cxx/foreign-reference/value-type-errors.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ void takesRef(Ref r);
1919
import Test
2020

2121
public func test(x: Ref) {
22-
// CHECK: note: function uses foreign reference type 'Ref' as a value in the return types which breaks 'swift_shared_reference' contract (outlined in C++ Interop User Manual).
22+
// CHECK: note: function uses foreign reference type 'Ref' as a value in the return types which breaks 'swift_shared_reference' contract
2323
returnsRef()
24-
// CHECK: note: function uses foreign reference type 'Ref' as a value in a parameter types which breaks 'swift_shared_reference' contract (outlined in C++ Interop User Manual).
24+
// CHECK: note: function uses foreign reference type 'Ref' as a value in a parameter types which breaks 'swift_shared_reference' contract
2525
takesRef(x)
2626
}

test/Interop/Cxx/templates/class-template-instantiation-typechecker.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import ClassTemplateInstantiationErrors
44

5-
// CHECK: class-template-instantiation-typechecker.swift:7:11: error: could not generate C++ types from the generic Swift types provided. The following Swift type(s) provided to 'MagicWrapper' could not be converted: Optional<_>.
5+
// CHECK: class-template-instantiation-typechecker.swift:7:11: error: could not generate C++ types from the generic Swift types provided; the following Swift type(s) provided to 'MagicWrapper' could not be converted: Optional<_>
66
func swiftTemplateArgNotSupported() {
77
var _ = MagicWrapper<Optional>(t: "asdf")
88
}
99

10-
// CHECK: class-template-instantiation-typechecker.swift:12:11: error: could not generate C++ types from the generic Swift types provided. The following Swift type(s) provided to 'MagicWrapperWithExplicitCtor' could not be converted: String.
10+
// CHECK: class-template-instantiation-typechecker.swift:12:11: error: could not generate C++ types from the generic Swift types provided; the following Swift type(s) provided to 'MagicWrapperWithExplicitCtor' could not be converted: String
1111
func swiftTemplateArgNotSupportedExplicitCtor() {
1212
var _ = MagicWrapperWithExplicitCtor<String>("asdf")
1313
}

0 commit comments

Comments
 (0)