You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[cxx-interop] Re-word message and documentation for FRT diagnostics
Several changes:
- shorten the warning at the call-site of unannotated functions that
return FRTS
- place the call to action ("annotate 'X' with 'Y'") at the diagnostic
note attached to the unannotated callee, where the annotation should
be made
- re-word the foreign-reference-type.md documentation to (1) reflect the
diagnostic wording change, (2) give a little bit more background about
why the annotations are needed, and (3) not be specific to C++ (since
we can import FRTs from C as well)
// C++ APIs returning cxx frts (for testing diagnostics)
181
181
structStructWithAPIsReturningCxxFrt {
182
-
static FRTStruct *_Nonnull StaticMethodReturningCxxFrt(); // expected-note {{'StaticMethodReturningCxxFrt()' is defined here}}
182
+
static FRTStruct *_Nonnull StaticMethodReturningCxxFrt(); // expected-note {{annotate 'StaticMethodReturningCxxFrt()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
FRTStruct *_Nonnull global_function_returning_cxx_frt(); // expected-note {{'global_function_returning_cxx_frt()' is defined here}}
187
+
FRTStruct *_Nonnull global_function_returning_cxx_frt(); // expected-note {{annotate 'global_function_returning_cxx_frt()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
FRTOverloadedOperators *_Nonnull returnFRTOverloadedOperators(); // expected-note {{'returnFRTOverloadedOperators()' is defined here}} // expected-note {{'returnFRTOverloadedOperators()' is defined here}}
RefType *returnRefType() { returnnewRefType(); } // expected-note {{'returnRefType()' is defined here}}
376
+
RefType *returnRefType() { returnnewRefType(); } // expected-note {{annotate 'returnRefType()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
BaseTypeNonDefault *createBaseTypeNonDefault() { // expected-note {{'createBaseTypeNonDefault()' is defined here}}
425
+
BaseTypeNonDefault *createBaseTypeNonDefault() { // expected-note {{annotate 'createBaseTypeNonDefault()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
424
426
returnnewBaseTypeNonDefault();
425
427
}
426
-
DerivedTypeNonDefault *createDerivedTypeNonDefault() { // expected-note {{'createDerivedTypeNonDefault()' is defined here}}
428
+
DerivedTypeNonDefault *createDerivedTypeNonDefault() { // expected-note {{annotate 'createDerivedTypeNonDefault()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
RefCountedType& getRefCountedByRef(); // expected-note {{'getRefCountedByRef()' is defined here}}
12
-
RefCountedType& createRefCountedByRef(); // expected-note {{'createRefCountedByRef()' is defined here}}
13
-
RefCountedType& copyRefCountedByRef(); // expected-note {{'copyRefCountedByRef()' is defined here}}
11
+
RefCountedType& getRefCountedByRef(); // expected-note {{annotate 'getRefCountedByRef()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
12
+
RefCountedType& createRefCountedByRef(); // expected-note {{annotate 'createRefCountedByRef()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
13
+
RefCountedType& copyRefCountedByRef(); // expected-note {{annotate 'copyRefCountedByRef()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
DerivedFromImmortalRefType *returnDerivedFromImmortalRefType() { // expected-note {{'returnDerivedFromImmortalRefType()' is defined here}}
112
+
DerivedFromImmortalRefType *returnDerivedFromImmortalRefType() { // expected-note {{annotate 'returnDerivedFromImmortalRefType()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
RefType *returnRefType() { returnnewRefType(); } // expected-note {{'returnRefType()' is defined here}}
125
+
RefType *returnRefType() { returnnewRefType(); } // expected-note {{annotate 'returnRefType()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
DerivedFromValueTypeAndAnnotated *returnDerivedFromValueTypeAndAnnotated() { // expected-note {{'returnDerivedFromValueTypeAndAnnotated()' is defined here}}
136
+
DerivedFromValueTypeAndAnnotated *returnDerivedFromValueTypeAndAnnotated() { // expected-note {{annotate 'returnDerivedFromValueTypeAndAnnotated()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
137
137
returnnewDerivedFromValueTypeAndAnnotated();
138
138
}
139
139
140
140
structDerivedFromRefTypefinal : RefType {};
141
-
DerivedFromRefType *returnDerivedFromRefType() { // expected-note {{'returnDerivedFromRefType()' is defined here}}
141
+
DerivedFromRefType *returnDerivedFromRefType() { // expected-note {{annotate 'returnDerivedFromRefType()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
DerivedFromRefTypeAndAnnotated *returnDerivedFromRefTypeAndAnnotated() { // expected-note {{'returnDerivedFromRefTypeAndAnnotated()' is defined here}}
149
+
DerivedFromRefTypeAndAnnotated *returnDerivedFromRefTypeAndAnnotated() { // expected-note {{annotate 'returnDerivedFromRefTypeAndAnnotated()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
DerivedFromRefTypeAAndBAnnotated *returnDerivedFromRefTypeAAndBAnnotated() { // expected-note {{'returnDerivedFromRefTypeAAndBAnnotated()' is defined here}}
187
+
DerivedFromRefTypeAAndBAnnotated *returnDerivedFromRefTypeAAndBAnnotated() { // expected-note {{annotate 'returnDerivedFromRefTypeAAndBAnnotated()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
RefType *returnRefType() { returnnewRefType(); }; // expected-note {{'returnRefType()' is defined here}}
209
+
RefType *returnRefType() { returnnewRefType(); }; // expected-note {{annotate 'returnRefType()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
210
210
211
211
structDerivedFromRefTypefinal : RefType {};
212
-
DerivedFromRefType *returnDerivedFromRefType() { // expected-note {{'returnDerivedFromRefType()' is defined here}}
212
+
DerivedFromRefType *returnDerivedFromRefType() { // expected-note {{annotate 'returnDerivedFromRefType()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
DerivedFromBaseRef3 *returnDerivedFromBaseRef3() { // expected-note {{'returnDerivedFromBaseRef3()' is defined here}}
239
+
DerivedFromBaseRef3 *returnDerivedFromBaseRef3() { // expected-note {{annotate 'returnDerivedFromBaseRef3()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
structD : B1, B2 {}; // expected-error {{multiple functions 'sameretain' found; there must be exactly one retain function for reference type 'D'}}
314
314
// expected-error@-1 {{multiple functions 'samerelease' found; there must be exactly one release function for reference type 'D'}}
315
-
D *returnD() { returnnewD(); }; // expected-note {{'returnD()' is defined here}}
315
+
D *returnD() { returnnewD(); }; // expected-note {{annotate 'returnD()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
316
316
} // namespace OverloadedRetainRelease
317
317
318
318
voidsameretain(OverloadedRetainRelease::B1 *v) {}
@@ -339,7 +339,7 @@ struct BVirtual : virtual A {};
339
339
structCVirtual : virtual A {};
340
340
341
341
structVirtualDiamond : BVirtual, CVirtual {};
342
-
VirtualDiamond *returnVirtualDiamond() { returnnewVirtualDiamond(); }; // expected-note {{'returnVirtualDiamond()' is defined here}}
342
+
VirtualDiamond *returnVirtualDiamond() { returnnewVirtualDiamond(); }; // expected-note {{annotate 'returnVirtualDiamond()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
343
343
} // namespace RefTypeDiamondInheritance
344
344
345
345
voidretainA(RefTypeDiamondInheritance::A *a) {};
@@ -355,7 +355,7 @@ __attribute__((swift_attr("release:releaseB"))) B : A {};
355
355
structC : A {};
356
356
357
357
structDiamond : B, C {};
358
-
Diamond *returnDiamond() { returnnewDiamond(); }; // expected-note {{'returnDiamond()' is defined here}}
358
+
Diamond *returnDiamond() { returnnewDiamond(); }; // expected-note {{annotate 'returnDiamond()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
Forest *returnForest() { returnnewForest(); }; // expected-note {{'returnForest()' is defined here}}
387
+
Forest *returnForest() { returnnewForest(); }; // expected-note {{annotate 'returnForest()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
Copy file name to clipboardExpand all lines: test/Interop/Cxx/foreign-reference/frt-reference-returns-diagnostics.swift
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -6,11 +6,11 @@ import FRTReferenceReturns
6
6
7
7
func testNoAnnotations(){
8
8
let _ =NoAnnotations.getRefCountedByRef()
9
-
// expected-warning@-1 {{cannot infer the ownership of the returned value, annotate 'getRefCountedByRef()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
9
+
// expected-warning@-1 {{cannot infer ownership of foreign reference value returned by 'getRefCountedByRef()'}}
10
10
let _ =NoAnnotations.createRefCountedByRef()
11
-
// expected-warning@-1 {{cannot infer the ownership of the returned value, annotate 'createRefCountedByRef()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
11
+
// expected-warning@-1 {{cannot infer ownership of foreign reference value returned by 'createRefCountedByRef()'}}
12
12
let _ =NoAnnotations.copyRefCountedByRef()
13
-
// expected-warning@-1 {{cannot infer the ownership of the returned value, annotate 'copyRefCountedByRef()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
13
+
// expected-warning@-1 {{cannot infer ownership of foreign reference value returned by 'copyRefCountedByRef()'}}
letfrtLocalVar3=StructWithAPIsReturningCxxFrt.StaticMethodReturningCxxFrt() // expected-warning {{cannot infer the ownership of the returned value, annotate 'StaticMethodReturningCxxFrt()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
11
+
letfrtLocalVar3=StructWithAPIsReturningCxxFrt.StaticMethodReturningCxxFrt() // expected-warning {{cannot infer ownership of foreign reference value returned by 'StaticMethodReturningCxxFrt()'}}
letfrtLocalVar5=global_function_returning_cxx_frt() // expected-warning {{cannot infer the ownership of the returned value, annotate 'global_function_returning_cxx_frt()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
13
+
letfrtLocalVar5=global_function_returning_cxx_frt() // expected-warning {{cannot infer ownership of foreign reference value returned by 'global_function_returning_cxx_frt()'}}
letx=returnFRTOverloadedOperators() // expected-warning {{cannot infer the ownership of the returned value, annotate 'returnFRTOverloadedOperators()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
27
-
lety=returnFRTOverloadedOperators() // expected-warning {{cannot infer the ownership of the returned value, annotate 'returnFRTOverloadedOperators()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
26
+
letx=returnFRTOverloadedOperators() // expected-warning {{cannot infer ownership of foreign reference value returned by 'returnFRTOverloadedOperators()'}}
27
+
lety=returnFRTOverloadedOperators() // expected-warning {{cannot infer ownership of foreign reference value returned by 'returnFRTOverloadedOperators()'}}
28
28
letz= x + y
29
29
letw= x - y
30
30
letf=FunctionVoidToFRTStruct()
@@ -34,18 +34,18 @@ let nonFrtLocalVar1 = global_function_returning_templated_retrun_frt_owned(nonFr
34
34
let _ =DefaultOwnershipConventionOnCXXForeignRefType.returnRefTyDefUnretained()
35
35
let _ =FunctionAnnotationHasPrecedence.returnRefTyDefUnretained()
36
36
let _ =FunctionAnnotationHasPrecedence.returnRefTyDefUnretainedAnnotatedRetained()
37
-
let _ =DefaultOwnershipSuppressUnannotatedAPIWarning.returnRefType() // expected-warning {{cannot infer the ownership of the returned value, annotate 'returnRefType()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
37
+
let _ =DefaultOwnershipSuppressUnannotatedAPIWarning.returnRefType() // expected-warning {{cannot infer ownership of foreign reference value returned by 'returnRefType()'}}
38
38
let _ =DefaultOwnershipSuppressUnannotatedAPIWarning.returnRefTyDefUnretainedd()
39
39
let _ =DefaultOwnershipInheritance.createBaseType()
40
40
let _ =DefaultOwnershipInheritance.createDerivedType()
41
41
let _ =DefaultOwnershipInheritance.createDerivedType2()
42
-
let _ =DefaultOwnershipInheritance.createBaseTypeNonDefault() // expected-warning {{cannot infer the ownership of the returned value, annotate 'createBaseTypeNonDefault()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
43
-
let _ =DefaultOwnershipInheritance.createDerivedTypeNonDefault() // expected-warning {{cannot infer the ownership of the returned value, annotate 'createDerivedTypeNonDefault()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
42
+
let _ =DefaultOwnershipInheritance.createBaseTypeNonDefault() // expected-warning {{cannot infer ownership of foreign reference value returned by 'createBaseTypeNonDefault()'}}
43
+
let _ =DefaultOwnershipInheritance.createDerivedTypeNonDefault() // expected-warning {{cannot infer ownership of foreign reference value returned by 'createDerivedTypeNonDefault()'}}
44
44
let _ =DefaultOwnershipInheritance.createDerivedTypeNonDefaultUnretained()
45
-
let _ =SourceLocationCaching.FactoryA.make() // expected-warning {{cannot infer the ownership of the returned value, annotate 'make()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
46
-
let _ =SourceLocationCaching.FactoryB.make() // expected-warning {{cannot infer the ownership of the returned value, annotate 'make()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
45
+
let _ =SourceLocationCaching.FactoryA.make() // expected-warning {{cannot infer ownership of foreign reference value returned by 'make()'}}
46
+
let _ =SourceLocationCaching.FactoryB.make() // expected-warning {{cannot infer ownership of foreign reference value returned by 'make()'}}
47
47
48
48
letrefTemplate=FRTStructRef()
49
49
lettemplatePtr= refTemplate.ptr()
50
50
lettemplateGet= refTemplate.get()
51
-
lettemplateValue= refTemplate.value() // expected-warning {{cannot infer the ownership of the returned value, annotate 'value()' with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED}}
51
+
lettemplateValue= refTemplate.value() // expected-warning {{cannot infer ownership of foreign reference value returned by 'value()'}}
0 commit comments