|
| 1 | +// REQUIRES: swift_swift_parser |
| 2 | + |
| 3 | +// RUN: %empty-directory(%t) |
| 4 | +// RUN: split-file %s %t |
| 5 | +// RUN: %target-swift-frontend %t/test.swift -typecheck -plugin-path %swift-plugin-dir -strict-memory-safety -verify |
| 6 | +// RUN: %target-swift-frontend %t/test.swift -typecheck -plugin-path %swift-plugin-dir -strict-memory-safety -dump-macro-expansions 2> %t/expansions.txt |
| 7 | +// RUN: diff %t/expansions.txt %t/expansions.txt.expected |
| 8 | + |
| 9 | +//--- test.swift |
| 10 | +@_SwiftifyImport(.sizedBy(pointer: .return, size: "size")) |
| 11 | +public func nonnullUnsafeRawBufferPointer(_ size: CInt) -> OpaquePointer {} |
| 12 | + |
| 13 | +@_SwiftifyImport(.sizedBy(pointer: .return, size: "size")) |
| 14 | +public func nullableUnsafeRawBufferPointer(_ size: CInt) -> OpaquePointer? {} |
| 15 | + |
| 16 | +@_SwiftifyImport(.sizedBy(pointer: .return, size: "size")) |
| 17 | +public func impNullableUnsafeRawBufferPointer(_ size: CInt) -> OpaquePointer! {} |
| 18 | + |
| 19 | +@_SwiftifyImport(.sizedBy(pointer: .return, size: "size"), .sizedBy(pointer: .param(1), size: "size"), .lifetimeDependence(dependsOn: .param(1), pointer: .return, type: .copy)) |
| 20 | +public func nonnullSpan(p: OpaquePointer, size: CInt) -> OpaquePointer {} |
| 21 | + |
| 22 | +@_SwiftifyImport(.sizedBy(pointer: .return, size: "size"), .sizedBy(pointer: .param(1), size: "size"), .lifetimeDependence(dependsOn: .param(1), pointer: .return, type: .copy)) |
| 23 | +public func nullableSpan(p: OpaquePointer?, _ size: CInt) -> OpaquePointer? {} |
| 24 | + |
| 25 | +@_SwiftifyImport(.sizedBy(pointer: .return, size: "size"), .sizedBy(pointer: .param(1), size: "size"), .lifetimeDependence(dependsOn: .param(1), pointer: .return, type: .copy)) |
| 26 | +public func impNullableSpan(p: OpaquePointer!, _ size: CInt) -> OpaquePointer! {} |
| 27 | + |
| 28 | +//--- expansions.txt.expected |
| 29 | +@__swiftmacro_4test29nonnullUnsafeRawBufferPointer15_SwiftifyImportfMp_.swift |
| 30 | +------------------------------ |
| 31 | +/// This is an auto-generated wrapper for safer interop |
| 32 | +@_alwaysEmitIntoClient @_disfavoredOverload |
| 33 | +public func nonnullUnsafeRawBufferPointer(_ size: CInt) -> UnsafeRawBufferPointer { |
| 34 | + return unsafe UnsafeRawBufferPointer(start: unsafe UnsafeRawPointer(unsafe nonnullUnsafeRawBufferPointer(size)), count: Int(size)) |
| 35 | +} |
| 36 | +------------------------------ |
| 37 | +@__swiftmacro_4test30nullableUnsafeRawBufferPointer15_SwiftifyImportfMp_.swift |
| 38 | +------------------------------ |
| 39 | +/// This is an auto-generated wrapper for safer interop |
| 40 | +@_alwaysEmitIntoClient @_disfavoredOverload |
| 41 | +public func nullableUnsafeRawBufferPointer(_ size: CInt) -> UnsafeRawBufferPointer? { |
| 42 | + return unsafe { () in |
| 43 | + let _resultValue = unsafe nullableUnsafeRawBufferPointer(size) |
| 44 | + if unsafe _resultValue == nil { |
| 45 | + return nil |
| 46 | + } else { |
| 47 | + return unsafe _swiftifyOverrideLifetime(UnsafeRawBufferPointer(start: unsafe UnsafeRawPointer(_resultValue!), count: Int(size)), copying: ()) |
| 48 | + } |
| 49 | + }() |
| 50 | +} |
| 51 | +------------------------------ |
| 52 | +@__swiftmacro_4test33impNullableUnsafeRawBufferPointer15_SwiftifyImportfMp_.swift |
| 53 | +------------------------------ |
| 54 | +/// This is an auto-generated wrapper for safer interop |
| 55 | +@_alwaysEmitIntoClient @_disfavoredOverload |
| 56 | +public func impNullableUnsafeRawBufferPointer(_ size: CInt) -> UnsafeRawBufferPointer { |
| 57 | + return unsafe UnsafeRawBufferPointer(start: unsafe UnsafeRawPointer(unsafe impNullableUnsafeRawBufferPointer(size)), count: Int(size)) |
| 58 | +} |
| 59 | +------------------------------ |
| 60 | +@__swiftmacro_4test11nonnullSpan15_SwiftifyImportfMp_.swift |
| 61 | +------------------------------ |
| 62 | +/// This is an auto-generated wrapper for safer interop |
| 63 | +@_alwaysEmitIntoClient @_lifetime(copy p) @_disfavoredOverload |
| 64 | +public func nonnullSpan(p: RawSpan) -> RawSpan { |
| 65 | + let size = CInt(exactly: p.byteCount)! |
| 66 | + return unsafe _swiftifyOverrideLifetime(RawSpan(_unsafeStart: unsafe UnsafeRawPointer(unsafe p.withUnsafeBytes { _pPtr in |
| 67 | + return unsafe nonnullSpan(p: OpaquePointer(_pPtr.baseAddress!), size: size) |
| 68 | + }), byteCount: Int(size)), copying: ()) |
| 69 | +} |
| 70 | +------------------------------ |
| 71 | +@__swiftmacro_4test12nullableSpan15_SwiftifyImportfMp_.swift |
| 72 | +------------------------------ |
| 73 | +/// This is an auto-generated wrapper for safer interop |
| 74 | +@_alwaysEmitIntoClient @_lifetime(copy p) @_disfavoredOverload |
| 75 | +public func nullableSpan(p: RawSpan?) -> RawSpan? { |
| 76 | + let size = CInt(exactly: p?.byteCount ?? 0)! |
| 77 | + return unsafe _swiftifyOverrideLifetime({ () in |
| 78 | + let _resultValue = { () in |
| 79 | + return if p == nil { |
| 80 | + unsafe nullableSpan(p: nil, size) |
| 81 | + } else { |
| 82 | + unsafe p!.withUnsafeBytes { _pPtr in |
| 83 | + return unsafe nullableSpan(p: OpaquePointer(_pPtr.baseAddress), size) |
| 84 | + } |
| 85 | + } |
| 86 | + }() |
| 87 | + if unsafe _resultValue == nil { |
| 88 | + return nil |
| 89 | + } else { |
| 90 | + return unsafe _swiftifyOverrideLifetime(RawSpan(_unsafeStart: unsafe UnsafeRawPointer(_resultValue!), byteCount: Int(size)), copying: ()) |
| 91 | + } |
| 92 | + }(), copying: ()) |
| 93 | +} |
| 94 | +------------------------------ |
| 95 | +@__swiftmacro_4test15impNullableSpan15_SwiftifyImportfMp_.swift |
| 96 | +------------------------------ |
| 97 | +/// This is an auto-generated wrapper for safer interop |
| 98 | +@_alwaysEmitIntoClient @_lifetime(copy p) @_disfavoredOverload |
| 99 | +public func impNullableSpan(p: RawSpan) -> RawSpan { |
| 100 | + let size = CInt(exactly: p.byteCount)! |
| 101 | + return unsafe _swiftifyOverrideLifetime(RawSpan(_unsafeStart: unsafe UnsafeRawPointer(unsafe p.withUnsafeBytes { _pPtr in |
| 102 | + return unsafe impNullableSpan(p: OpaquePointer(_pPtr.baseAddress!), size) |
| 103 | + }), byteCount: Int(size)), copying: ()) |
| 104 | +} |
| 105 | +------------------------------ |
0 commit comments