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