Skip to content

Commit 18a3f08

Browse files
authored
Merge pull request #81827 from hnrklssn/swiftify-fixes-6.2
Swiftify fixes for 6.2
2 parents 4225fbc + 58366a8 commit 18a3f08

Some content is hidden

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

50 files changed

+1266
-479
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9201,9 +9201,10 @@ void ClangImporter::Implementation::swiftify(FuncDecl *MappedDecl) {
92019201
paramHasLifetimeInfo = true;
92029202
}
92039203
if (clangParam->hasAttr<clang::LifetimeBoundAttr>()) {
9204-
printer.printLifetimeboundReturn(
9205-
index, !paramHasBoundsInfo &&
9206-
swiftParamTy->isEscapable());
9204+
// If this parameter has bounds info we will tranform it into a Span,
9205+
// so then it will no longer be Escapable.
9206+
bool willBeEscapable = swiftParamTy->isEscapable() && !paramHasBoundsInfo;
9207+
printer.printLifetimeboundReturn(index, willBeEscapable);
92079208
paramHasLifetimeInfo = true;
92089209
returnHasLifetimeInfo = true;
92099210
}

lib/Macros/Sources/SwiftMacros/SwiftifyImportMacro.swift

Lines changed: 254 additions & 158 deletions
Large diffs are not rendered by default.

stdlib/public/Cxx/CxxSpan.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ extension CxxSpan {
8888
unsafe self.init(unsafeMutableBufferPointer.baseAddress!, Size(unsafeMutableBufferPointer.count))
8989
}
9090

91-
@available(SwiftStdlib 6.2, *)
91+
@available(SwiftCompatibilitySpan 5.0, *)
9292
@inlinable
9393
@unsafe
9494
public init(_ span: Span<Element>) {
@@ -99,7 +99,7 @@ extension CxxSpan {
9999
}
100100
}
101101

102-
@available(SwiftStdlib 6.2, *)
102+
@available(SwiftCompatibilitySpan 5.0, *)
103103
extension Span {
104104
@_alwaysEmitIntoClient
105105
@unsafe
@@ -115,7 +115,7 @@ extension Span {
115115
}
116116
}
117117

118-
@available(SwiftStdlib 6.2, *)
118+
@available(SwiftCompatibilitySpan 5.0, *)
119119
extension MutableSpan {
120120
@_alwaysEmitIntoClient
121121
@unsafe
@@ -151,7 +151,7 @@ extension CxxMutableSpan {
151151
unsafe self.init(unsafeMutableBufferPointer.baseAddress!, Size(unsafeMutableBufferPointer.count))
152152
}
153153

154-
@available(SwiftStdlib 6.2, *)
154+
@available(SwiftCompatibilitySpan 5.0, *)
155155
@inlinable
156156
@unsafe
157157
public init(_ span: consuming MutableSpan<Element>) {

test/Interop/C/swiftify-import/Inputs/counted-by-lifetimebound.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ int * __counted_by(len) _Nonnull nonnull(int len, int len2, int * __counted_by(l
1616
int * __counted_by(len) _Nullable nullable(int len, int len2, int * __counted_by(len2) __lifetimebound _Nullable p);
1717

1818
int * __counted_by(len) noncountedLifetime(int len, int * __lifetimebound p);
19+
20+
int * __counted_by(13) _Nullable constant(int * __counted_by(13) __lifetimebound _Nullable p);

test/Interop/C/swiftify-import/Inputs/counted-by-noescape.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,58 @@ int * __counted_by(len) __noescape returnPointer(int len);
2424
int * __counted_by(len1) returnLifetimeBound(int len1, int len2, int * __counted_by(len2) p __lifetimebound);
2525

2626
void anonymous(int len, int * __counted_by(len) _Nullable __noescape);
27+
28+
void keyword(int len, int * __counted_by(len) _Nullable func __noescape,
29+
int extension,
30+
int init,
31+
int open,
32+
int var,
33+
int is,
34+
int as,
35+
int in,
36+
int guard,
37+
int where
38+
);
39+
40+
void pointerName(int len, int * __counted_by(len) _Nullable pointerName __noescape);
41+
42+
void lenName(int lenName, int size, int * __counted_by(lenName * size) _Nullable p __noescape);
43+
44+
void func(int len, int * __counted_by(len) _Nullable func __noescape);
45+
46+
void *funcRenameKeyword(int len, int * __counted_by(len) _Nullable func __noescape,
47+
int extension __lifetimebound,
48+
int init,
49+
int open,
50+
int var,
51+
int is,
52+
int as,
53+
int in,
54+
int guard,
55+
int where) __attribute__((swift_name("funcRenamed(len:func:extension:init:open:var:is:as:in:guard:where:)")));
56+
57+
void *funcRenameKeywordAnonymous(int len, int * __counted_by(len) _Nullable __noescape,
58+
int __lifetimebound,
59+
int,
60+
int,
61+
int,
62+
int,
63+
int,
64+
int,
65+
int,
66+
int) __attribute__((swift_name("funcRenamedAnon(len:func:extension:init:open:var:is:as:in:guard:where:)")));
67+
68+
void funcRenameClash(int len, int * __counted_by(len) _Nullable func __noescape, int where)
69+
__attribute__((swift_name("clash(len:func:clash:)")));
70+
71+
void funcRenameClashKeyword(int len, int * __counted_by(len) _Nullable func __noescape, int where)
72+
__attribute__((swift_name("open(len:func:open:)")));
73+
74+
void funcRenameClashAnonymous(int len, int * __counted_by(len) _Nullable func __noescape, int)
75+
__attribute__((swift_name("clash2(len:func:clash2:)")));
76+
77+
void funcRenameClashKeywordAnonymous(int len, int * __counted_by(len) _Nullable func __noescape, int)
78+
__attribute__((swift_name("in(len:func:in:)")));
79+
80+
typedef struct actor_ *actor;
81+
actor _Nonnull keywordType(int len, actor * __counted_by(len) __noescape p, actor _Nonnull p2);

test/Interop/C/swiftify-import/comments.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
// CHECK-NEXT:func blockDocComment(_ len: Int32, _ p: UnsafeMutablePointer<Int32>!)
2828

2929
// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop
30-
// CHECK-NEXT:@_alwaysEmitIntoClient public func blockComment(_ p: UnsafeMutableBufferPointer<Int32>)
30+
// CHECK-NEXT:@_alwaysEmitIntoClient @_disfavoredOverload public func blockComment(_ p: UnsafeMutableBufferPointer<Int32>)
3131

3232
// CHECK-NEXT:/**
3333
// CHECK-NEXT: * block doc comment
@@ -37,10 +37,10 @@
3737
// CHECK-NEXT: * @param p some integers to play with
3838
// CHECK-NEXT: */
3939
// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop
40-
// CHECK-NEXT:@_alwaysEmitIntoClient public func blockDocComment(_ p: UnsafeMutableBufferPointer<Int32>)
40+
// CHECK-NEXT:@_alwaysEmitIntoClient @_disfavoredOverload public func blockDocComment(_ p: UnsafeMutableBufferPointer<Int32>)
4141

4242
// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop
43-
// CHECK-NEXT:@_alwaysEmitIntoClient public func lineComment(_ p: UnsafeMutableBufferPointer<Int32>)
43+
// CHECK-NEXT:@_alwaysEmitIntoClient @_disfavoredOverload public func lineComment(_ p: UnsafeMutableBufferPointer<Int32>)
4444

4545
// CHECK-NEXT:/// line doc comment
4646
// CHECK-NEXT:///
@@ -49,4 +49,4 @@
4949
// CHECK-NEXT:/// @param len the buffer length
5050
// CHECK-NEXT:/// @param p the buffer
5151
// CHECK-NEXT:/// This is an auto-generated wrapper for safer interop
52-
// CHECK-NEXT:@_alwaysEmitIntoClient public func lineDocComment(_ p: UnsafeMutableBufferPointer<Int32>)
52+
// CHECK-NEXT:@_alwaysEmitIntoClient @_disfavoredOverload public func lineDocComment(_ p: UnsafeMutableBufferPointer<Int32>)

test/Interop/C/swiftify-import/counted-by-lifetimebound.swift

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ import CountedByLifetimeboundClang
1515
// CHECK-NEXT: @available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)
1616
// CHECK-NEXT: @lifetime(copy p)
1717
// CHECK-NEXT: @lifetime(p: copy p)
18-
// CHECK-NEXT: @_alwaysEmitIntoClient public func complexExpr(_ len: Int32, _ offset: Int32, _ len2: Int32, _ p: inout MutableSpan<Int32>) -> MutableSpan<Int32>
18+
// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func complexExpr(_ len: Int32, _ offset: Int32, _ p: inout MutableSpan<Int32>) -> MutableSpan<Int32>
19+
20+
// CHECK: /// This is an auto-generated wrapper for safer interop
21+
// CHECK-NEXT: @available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)
22+
// CHECK-NEXT: @lifetime(copy p)
23+
// CHECK-NEXT: @lifetime(p: copy p)
24+
// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func constant(_ p: inout MutableSpan<Int32>?) -> MutableSpan<Int32>?
1925

2026
// CHECK-NEXT: /// This is an auto-generated wrapper for safer interop
2127
// CHECK-NEXT: @available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)
@@ -26,37 +32,37 @@ import CountedByLifetimeboundClang
2632
// CHECK-NEXT: @available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)
2733
// CHECK-NEXT: @lifetime(copy p)
2834
// CHECK-NEXT: @lifetime(p: copy p)
29-
// CHECK-NEXT: @_alwaysEmitIntoClient public func nonnull(_ len: Int32, _ p: inout MutableSpan<Int32>) -> MutableSpan<Int32>
35+
// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func nonnull(_ len: Int32, _ p: inout MutableSpan<Int32>) -> MutableSpan<Int32>
3036

3137
// CHECK-NEXT: /// This is an auto-generated wrapper for safer interop
3238
// CHECK-NEXT: @available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)
3339
// CHECK-NEXT: @lifetime(copy p)
3440
// CHECK-NEXT: @lifetime(p: copy p)
35-
// CHECK-NEXT: @_alwaysEmitIntoClient public func nullUnspecified(_ len: Int32, _ p: inout MutableSpan<Int32>) -> MutableSpan<Int32>
41+
// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func nullUnspecified(_ len: Int32, _ p: inout MutableSpan<Int32>) -> MutableSpan<Int32>
3642

3743
// CHECK-NEXT: /// This is an auto-generated wrapper for safer interop
3844
// CHECK-NEXT: @available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)
3945
// CHECK-NEXT: @lifetime(copy p)
4046
// CHECK-NEXT: @lifetime(p: copy p)
41-
// CHECK-NEXT: @_alwaysEmitIntoClient public func nullable(_ len: Int32, _ p: inout MutableSpan<Int32>?) -> MutableSpan<Int32>?
47+
// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func nullable(_ len: Int32, _ p: inout MutableSpan<Int32>?) -> MutableSpan<Int32>?
4248

4349
// CHECK-NEXT: /// This is an auto-generated wrapper for safer interop
4450
// CHECK-NEXT: @available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)
4551
// CHECK-NEXT: @lifetime(copy p)
4652
// CHECK-NEXT: @lifetime(p: copy p)
47-
// CHECK-NEXT: @_alwaysEmitIntoClient public func shared(_ len: Int32, _ p: inout MutableSpan<Int32>) -> MutableSpan<Int32>
53+
// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func shared(_ p: inout MutableSpan<Int32>) -> MutableSpan<Int32>
4854

4955
// CHECK-NEXT: /// This is an auto-generated wrapper for safer interop
5056
// CHECK-NEXT: @available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)
5157
// CHECK-NEXT: @lifetime(copy p)
5258
// CHECK-NEXT: @lifetime(p: copy p)
53-
// CHECK-NEXT: @_alwaysEmitIntoClient public func simple(_ len: Int32, _ p: inout MutableSpan<Int32>) -> MutableSpan<Int32>
59+
// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func simple(_ len: Int32, _ p: inout MutableSpan<Int32>) -> MutableSpan<Int32>
5460

5561

5662
@available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)
5763
@inlinable
5864
public func callComplexExpr(_ p: inout MutableSpan<CInt>) {
59-
let _: MutableSpan<CInt> = complexExpr(73, 37, 42, &p)
65+
let _: MutableSpan<CInt> = complexExpr(73, 37, &p)
6066
}
6167

6268
@available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)
@@ -80,7 +86,7 @@ public func callNullable(_ p: inout MutableSpan<CInt>?) {
8086
@available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)
8187
@inlinable
8288
public func callShared(_ p: inout MutableSpan<CInt>) {
83-
let _: MutableSpan<CInt> = shared(CInt(p.count), &p)
89+
let _: MutableSpan<CInt> = shared(&p)
8490
}
8591

8692
@available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)
@@ -94,3 +100,9 @@ public func callSimple(_ p: inout MutableSpan<CInt>) {
94100
public func callNoncountedLifetime(_ p: UnsafeMutablePointer<CInt>) {
95101
let _: MutableSpan<CInt> = noncountedLifetime(73, p)
96102
}
103+
104+
@available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)
105+
@inlinable
106+
public func callConstant(_ p: inout MutableSpan<CInt>?) {
107+
let _: MutableSpan<CInt>? = constant(&p)
108+
}

0 commit comments

Comments
 (0)