|
| 1 | +// RUN: %empty-directory(%t/src) |
| 2 | +// RUN: split-file %s %t/src |
| 3 | + |
| 4 | +/// Build the library A |
| 5 | +// RUN: %target-swift-frontend -emit-module %t/src/A.swift \ |
| 6 | +// RUN: -module-name A -swift-version 5 -enable-library-evolution \ |
| 7 | +// RUN: -emit-module-path %t/A.swiftmodule \ |
| 8 | +// RUN: -emit-module-interface-path %t/A.swiftinterface |
| 9 | + |
| 10 | +// RUN: %FileCheck %t/src/A.swift < %t/A.swiftinterface |
| 11 | + |
| 12 | +// Build the client using module |
| 13 | +// RUN: %target-swift-emit-sil -verify -module-name Client -I %t %t/src/Client.swift | %FileCheck %t/src/Client.swift |
| 14 | + |
| 15 | +// RUN: rm %t/A.swiftmodule |
| 16 | + |
| 17 | +// Re-build the client using interface |
| 18 | +// RUN: %target-swift-emit-sil -verify -module-name Client -I %t %t/src/Client.swift | %FileCheck %t/src/Client.swift |
| 19 | + |
| 20 | +// REQUIRES: asserts |
| 21 | + |
| 22 | +//--- A.swift |
| 23 | +@frozen |
| 24 | +public struct Inlinable { |
| 25 | + var _x: Int |
| 26 | + |
| 27 | +// CHECK: public var x: Swift.Int { |
| 28 | +// CHECK-NEXT: @usableFromInline |
| 29 | +// CHECK-NEXT: @storageRestrictions(initializes: _x) init |
| 30 | +// CHECK-NEXT: get |
| 31 | +// CHECK-NEXT } |
| 32 | + |
| 33 | + public var x: Int { |
| 34 | + @usableFromInline |
| 35 | + @storageRestrictions(initializes: _x) |
| 36 | + init { |
| 37 | + self._x = newValue |
| 38 | + } |
| 39 | + |
| 40 | + get { |
| 41 | + _x |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + @inlinable |
| 46 | + public init(x: Int) { |
| 47 | + self.x = x |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +public struct Internal { |
| 52 | +// CHECK: public var y: Swift.Int { |
| 53 | +// CHECK-NEXT: get |
| 54 | +// CHECK-NEXT: } |
| 55 | + |
| 56 | + public var y: Int { |
| 57 | + init { |
| 58 | + } |
| 59 | + |
| 60 | + get { 0 } |
| 61 | + } |
| 62 | + |
| 63 | + init(y: Int) { |
| 64 | + self.y = y |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +@frozen |
| 69 | +public struct Transparent { |
| 70 | + @usableFromInline |
| 71 | + var _x: Int |
| 72 | + |
| 73 | +// CHECK: public var x: Swift.Int { |
| 74 | +// CHECK-NEXT: @_alwaysEmitIntoClient @storageRestrictions(initializes: _x) init { |
| 75 | +// CHECK-NEXT: self._x = newValue |
| 76 | +// CHECK-NEXT: } |
| 77 | +// CHECK-NEXT: get |
| 78 | +// CHECK-NEXT } |
| 79 | + |
| 80 | + public var x: Int { |
| 81 | + @_alwaysEmitIntoClient |
| 82 | + @storageRestrictions(initializes: _x) |
| 83 | + init { |
| 84 | + self._x = newValue |
| 85 | + } |
| 86 | + |
| 87 | + get { |
| 88 | + _x |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + @_alwaysEmitIntoClient |
| 93 | + public init(x: Int) { |
| 94 | + self.x = x |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +//--- Client.swift |
| 99 | +import A |
| 100 | + |
| 101 | +// CHECK-LABEL: sil hidden @$s6Client15testTransparentyyF : $@convention(thin) () -> () |
| 102 | +// CHECK: [[X:%.*]] = struct $Int (%1 : $Builtin.Int64) |
| 103 | +// CHECK-NEXT: // function_ref Transparent.init(x:) |
| 104 | +// CHECK-NEXT: [[TRANSPARENT_REF:%.*]] = function_ref @$s1A11TransparentV1xACSi_tcfC : $@convention(method) (Int, @thin Transparent.Type) -> Transparent |
| 105 | +// CHECK-NEXT: apply [[TRANSPARENT_REF]]([[X]], %0) : $@convention(method) (Int, @thin Transparent.Type) -> Transparent |
| 106 | +func testTransparent() { |
| 107 | + _ = Transparent(x: 42) |
| 108 | +} |
| 109 | + |
| 110 | +// CHECK-LABEL: sil shared @$s1A11TransparentV1xACSi_tcfC : $@convention(method) (Int, @thin Transparent.Type) -> Transparent |
| 111 | + |
| 112 | +// CHECK-LABEL: sil hidden @$s6Client13testInlinableyyF : $@convention(thin) () -> () |
| 113 | +// CHECK: [[X:%.*]] = struct $Int (%1 : $Builtin.Int64) |
| 114 | +// CHECK-NEXT: // function_ref Inlinable.init(x:) |
| 115 | +// CHECK-NEXT: [[INLINABLE_REF:%.*]] = function_ref @$s1A9InlinableV1xACSi_tcfC : $@convention(method) (Int, @thin Inlinable.Type) -> Inlinable |
| 116 | +// CHECK-NEXT: apply [[INLINABLE_REF]]([[X]], %0) : $@convention(method) (Int, @thin Inlinable.Type) -> Inlinable |
| 117 | +func testInlinable() { |
| 118 | + _ = Inlinable(x: 42) |
| 119 | +} |
| 120 | + |
| 121 | +// CHECK-LABEL: sil @$s1A9InlinableV1xACSi_tcfC : $@convention(method) (Int, @thin Inlinable.Type) -> Inlinable |
| 122 | + |
| 123 | +// CHECK-LABEL: sil shared @$s1A11TransparentV1xSivi : $@convention(thin) (Int, @thin Transparent.Type) -> @out Int |
0 commit comments