|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: split-file %s %t |
| 3 | + |
| 4 | +// RUN: %target-swift-frontend \ |
| 5 | +// RUN: %t/C.swift \ |
| 6 | +// RUN: -emit-module \ |
| 7 | +// RUN: -enable-library-evolution \ |
| 8 | +// RUN: -module-name C \ |
| 9 | +// RUN: -emit-module-path %t/C.swiftmodule |
| 10 | + |
| 11 | +// RUN: %target-swift-frontend \ |
| 12 | +// RUN: %t/A.swift \ |
| 13 | +// RUN: -enable-anonymous-context-mangled-names \ |
| 14 | +// RUN: -I %t -emit-ir | %FileCheck %s |
| 15 | + |
| 16 | +// REQUIRES: PTRSIZE=64 |
| 17 | +// REQUIRES: OS=macosx || OS=ios |
| 18 | +// UNSUPPORTED: CPU=arm64e |
| 19 | + |
| 20 | +//--- A.swift |
| 21 | +import C |
| 22 | +public func callStuff() { |
| 23 | + var x: any P = Empty() |
| 24 | + if #available(iOS 17.3, macOS 14.3, *) { |
| 25 | + x = MyBuilder.f(Empty()) |
| 26 | + x = MyBuilder.h(Empty()) |
| 27 | + } |
| 28 | + print(x) |
| 29 | +} |
| 30 | + |
| 31 | +// Make sure that when we generate an anoynmous context descriptor its parent |
| 32 | +// relative reference to another module uses an indirect relative reference. |
| 33 | + |
| 34 | +// CHECK: @"$s1C9MyBuilderVMn" = external global %swift.type_descriptor |
| 35 | +// CHECK: @"got.$s1C9MyBuilderVMn" = private unnamed_addr constant ptr @"$s1C9MyBuilderVMn" |
| 36 | +// CHECK: @"$s1C9MyBuilderV1fyQrAA1P_pFZMXX" = linkonce_odr hidden constant <{ i32, i32, i32 }> <{ i32 {{[0-9]+}}, i32 add (i32 trunc (i64 sub (i64 ptrtoint (ptr @"got.$s1C9MyBuilderVMn" |
| 37 | +// CHECK: @"$s1C9MyBuilderV1hyQrAA1P_pFZMXX" = linkonce_odr hidden constant <{ i32, i32, i32 }> <{ i32 {{[0-9]+}}, i32 add (i32 trunc (i64 sub (i64 ptrtoint (ptr @"got.$s1C9MyBuilderVMn" |
| 38 | + |
| 39 | +//--- C.swift |
| 40 | +public protocol P { |
| 41 | + func g() |
| 42 | +} |
| 43 | + |
| 44 | +public struct Empty : P { |
| 45 | + public init() {} |
| 46 | + public func g() {} |
| 47 | +} |
| 48 | + |
| 49 | +@available(iOS 17.3, macOS 14.3, *) |
| 50 | +public struct S : P { |
| 51 | + public init<T: P>(_ c: T) {} |
| 52 | + |
| 53 | + public func g() { |
| 54 | + print("g") |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +public struct MyBuilder { |
| 59 | + @_alwaysEmitIntoClient |
| 60 | + @available(iOS 17.3, macOS 14.3, *) |
| 61 | + public static func f(_ content: any P) -> some P { |
| 62 | + if #unavailable(iOS 17.3, macOS 14.3) { |
| 63 | + return Empty() |
| 64 | + } |
| 65 | + return S(content) |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | + |
| 70 | +extension MyBuilder { |
| 71 | + @_alwaysEmitIntoClient |
| 72 | + @available(iOS 17.3, macOS 14.3, *) |
| 73 | + public static func h(_ content: any P) -> some P { |
| 74 | + if #unavailable(iOS 17.3, macOS 14.3) { |
| 75 | + return Empty() |
| 76 | + } |
| 77 | + return S(content) |
| 78 | + } |
| 79 | +} |
0 commit comments