|
| 1 | +/// Test @_implementationOnly internal import exportability diagnostics in embedded mode. |
| 2 | + |
| 3 | +// RUN: %empty-directory(%t) |
| 4 | +// RUN: %target-swift-frontend -emit-module -o %t/indirects.swiftmodule \ |
| 5 | +// RUN: %S/Inputs/implementation-only-imports/indirects.swift \ |
| 6 | +// RUN: -swift-version 5 -target arm64-apple-none-macho \ |
| 7 | +// RUN: -enable-experimental-feature Embedded |
| 8 | +// RUN: %target-swift-frontend -emit-module -o %t/directs.swiftmodule -I %t \ |
| 9 | +// RUN: %S/Inputs/implementation-only-imports/directs.swift \ |
| 10 | +// RUN: -swift-version 5 -target arm64-apple-none-macho \ |
| 11 | +// RUN: -enable-experimental-feature Embedded |
| 12 | + |
| 13 | +// RUN: %target-swift-frontend -typecheck -verify -verify-ignore-unrelated %s -I %t \ |
| 14 | +// RUN: -swift-version 5 -target arm64-apple-none-macho \ |
| 15 | +// RUN: -enable-experimental-feature Embedded |
| 16 | + |
| 17 | +// REQUIRES: swift_feature_Embedded |
| 18 | +// REQUIRES: embedded_stdlib_cross_compiling |
| 19 | + |
| 20 | +@_implementationOnly internal import directs |
| 21 | +// expected-warning @-1 {{using '@_implementationOnly' without enabling library evolution for 'main' may lead to instability during execution}} |
| 22 | +// expected-note @-2 11 {{struct 'StructFromDirect' imported as 'internal' from 'directs' here}} |
| 23 | +// expected-note @-3 6 {{initializer 'init()' imported as 'internal' from 'directs' here}} |
| 24 | +import indirects |
| 25 | + |
| 26 | +internal func localInternalFunc() {} // expected-note {{global function 'localInternalFunc()' is not '@usableFromInline' or public}} |
| 27 | + |
| 28 | +@inlinable |
| 29 | +public func explicitlyInlinable(arg: StructFromDirect = StructFromDirect()) { |
| 30 | +// expected-error @-1 {{initializer 'init()' is internal and cannot be referenced from a default argument value}} |
| 31 | +// expected-error @-2 {{struct 'StructFromDirect' is internal and cannot be referenced from a default argument value}} |
| 32 | +// expected-error @-3 {{struct 'StructFromDirect' is internal and cannot be referenced from an '@inlinable' function}} |
| 33 | +// expected-error @-4 {{function cannot be declared public because its parameter uses an internal type}} |
| 34 | +// expected-note @-5 {{struct 'StructFromDirect' is imported by this file as 'internal' from 'directs'}} |
| 35 | + _ = StructFromDirect() // expected-error {{initializer 'init()' is internal and cannot be referenced from an '@inlinable' function}} |
| 36 | + // expected-error@-1 {{struct 'StructFromDirect' is internal and cannot be referenced from an '@inlinable' function}} |
| 37 | + |
| 38 | + if (true) { |
| 39 | + _ = StructFromDirect() // expected-error {{initializer 'init()' is internal and cannot be referenced from an '@inlinable' function}} |
| 40 | + // expected-error@-1 {{struct 'StructFromDirect' is internal and cannot be referenced from an '@inlinable' function}} |
| 41 | + } |
| 42 | + |
| 43 | + func nested() { |
| 44 | + _ = StructFromDirect() // expected-error {{initializer 'init()' is internal and cannot be referenced from an '@inlinable' function}} |
| 45 | + // expected-error@-1 {{struct 'StructFromDirect' is internal and cannot be referenced from an '@inlinable' function}} |
| 46 | + } |
| 47 | + nested() |
| 48 | + |
| 49 | + localInternalFunc() // expected-error {{global function 'localInternalFunc()' is internal and cannot be referenced from an '@inlinable' function}} |
| 50 | + |
| 51 | + explicitlyInlinable() |
| 52 | + implicitlyInlinablePublic() |
| 53 | + implicitlyInlinablePrivate() // expected-error {{global function 'implicitlyInlinablePrivate(arg:)' is private and cannot be referenced from an '@inlinable' function}} |
| 54 | + explicitNonInliable() |
| 55 | +} |
| 56 | + |
| 57 | +public func implicitlyInlinablePublic(arg: StructFromDirect = StructFromDirect()) { |
| 58 | +// expected-error @-1 {{initializer 'init()' is internal and cannot be referenced from a default argument value}} |
| 59 | +// expected-error @-2 {{struct 'StructFromDirect' is internal and cannot be referenced from a default argument value}} |
| 60 | +// expected-error @-3 {{struct 'StructFromDirect' cannot be used in an embedded function not marked '@_neverEmitIntoClient' because 'directs' was imported implementation-only}} |
| 61 | +// expected-error @-4 {{function cannot be declared public because its parameter uses an internal type}} |
| 62 | +// expected-note @-5 {{struct 'StructFromDirect' is imported by this file as 'internal' from 'directs'}} |
| 63 | + _ = StructFromDirect() // expected-error {{initializer 'init()' cannot be used in an embedded function not marked '@_neverEmitIntoClient' because 'directs' was imported implementation-only}} |
| 64 | + // expected-error@-1 {{struct 'StructFromDirect' cannot be used in an embedded function not marked '@_neverEmitIntoClient' because 'directs' was imported implementation-only}} |
| 65 | + |
| 66 | + if (true) { |
| 67 | + _ = StructFromDirect() // expected-error {{initializer 'init()' cannot be used in an embedded function not marked '@_neverEmitIntoClient' because 'directs' was imported implementation-only}} |
| 68 | + // expected-error@-1 {{struct 'StructFromDirect' cannot be used in an embedded function not marked '@_neverEmitIntoClient' because 'directs' was imported implementation-only}} |
| 69 | + } |
| 70 | + |
| 71 | + func nested() { |
| 72 | + _ = StructFromDirect() // expected-error {{initializer 'init()' cannot be used in an embedded function not marked '@_neverEmitIntoClient' because 'directs' was imported implementation-only}} |
| 73 | + // expected-error@-1 {{struct 'StructFromDirect' cannot be used in an embedded function not marked '@_neverEmitIntoClient' because 'directs' was imported implementation-only}} |
| 74 | + } |
| 75 | + nested() |
| 76 | + |
| 77 | + localInternalFunc() |
| 78 | + |
| 79 | + explicitlyInlinable() |
| 80 | + implicitlyInlinablePublic() |
| 81 | + implicitlyInlinablePrivate() |
| 82 | + explicitNonInliable() |
| 83 | +} |
| 84 | + |
| 85 | +private func implicitlyInlinablePrivate(arg: StructFromDirect = StructFromDirect()) { |
| 86 | +// expected-error @-1 {{struct 'StructFromDirect' cannot be used in an embedded function not marked '@_neverEmitIntoClient' because 'directs' was imported implementation-only}} |
| 87 | +// expected-note @-2 {{global function 'implicitlyInlinablePrivate(arg:)' is not '@usableFromInline' or public}} |
| 88 | + _ = StructFromDirect() // expected-error {{initializer 'init()' cannot be used in an embedded function not marked '@_neverEmitIntoClient' because 'directs' was imported implementation-only}} |
| 89 | + // expected-error@-1 {{struct 'StructFromDirect' cannot be used in an embedded function not marked '@_neverEmitIntoClient' because 'directs' was imported implementation-only}} |
| 90 | + |
| 91 | + if (true) { |
| 92 | + _ = StructFromDirect() // expected-error {{initializer 'init()' cannot be used in an embedded function not marked '@_neverEmitIntoClient' because 'directs' was imported implementation-only}} |
| 93 | + // expected-error@-1 {{struct 'StructFromDirect' cannot be used in an embedded function not marked '@_neverEmitIntoClient' because 'directs' was imported implementation-only}} |
| 94 | + } |
| 95 | + |
| 96 | + func nested() { |
| 97 | + _ = StructFromDirect() // expected-error {{initializer 'init()' cannot be used in an embedded function not marked '@_neverEmitIntoClient' because 'directs' was imported implementation-only}} |
| 98 | + // expected-error@-1 {{struct 'StructFromDirect' cannot be used in an embedded function not marked '@_neverEmitIntoClient' because 'directs' was imported implementation-only}} |
| 99 | + } |
| 100 | + nested() |
| 101 | + |
| 102 | + localInternalFunc() |
| 103 | + |
| 104 | + explicitlyInlinable() |
| 105 | + implicitlyInlinablePublic() |
| 106 | + implicitlyInlinablePrivate() |
| 107 | + explicitNonInliable() |
| 108 | +} |
| 109 | + |
| 110 | +@_neverEmitIntoClient |
| 111 | +public func explicitNonInliable(arg: StructFromDirect = StructFromDirect()) { |
| 112 | +// expected-error @-1 {{initializer 'init()' is internal and cannot be referenced from a default argument value}} |
| 113 | +// expected-error @-2 {{struct 'StructFromDirect' is internal and cannot be referenced from a default argument value}} |
| 114 | +// expected-error @-3 {{cannot use struct 'StructFromDirect' here; 'directs' has been imported as implementation-only}} |
| 115 | +// expected-error @-4 {{function cannot be declared public because its parameter uses an internal type}} |
| 116 | +// expected-note @-5 {{struct 'StructFromDirect' is imported by this file as 'internal' from 'directs'}} |
| 117 | + _ = StructFromDirect() |
| 118 | + |
| 119 | + if (true) { |
| 120 | + _ = StructFromDirect() |
| 121 | + } |
| 122 | + |
| 123 | + @_neverEmitIntoClient |
| 124 | + func nested() { |
| 125 | + _ = StructFromDirect() |
| 126 | + } |
| 127 | + nested() |
| 128 | + |
| 129 | + localInternalFunc() |
| 130 | + |
| 131 | + explicitlyInlinable() |
| 132 | + implicitlyInlinablePublic() |
| 133 | + implicitlyInlinablePrivate() |
| 134 | + explicitNonInliable() |
| 135 | +} |
| 136 | + |
| 137 | +@_neverEmitIntoClient |
| 138 | +internal func explicitNonInliableInternal(arg: StructFromDirect = StructFromDirect()) { |
| 139 | + _ = StructFromDirect() |
| 140 | + |
| 141 | + if (true) { |
| 142 | + _ = StructFromDirect() |
| 143 | + } |
| 144 | + |
| 145 | + @_neverEmitIntoClient |
| 146 | + func nested() { |
| 147 | + _ = StructFromDirect() |
| 148 | + } |
| 149 | + nested() |
| 150 | + |
| 151 | + localInternalFunc() |
| 152 | + |
| 153 | + explicitlyInlinable() |
| 154 | + implicitlyInlinablePublic() |
| 155 | + implicitlyInlinablePrivate() |
| 156 | + explicitNonInliable() |
| 157 | +} |
| 158 | + |
| 159 | +public func legalAccessToIndirect(arg: StructFromIndirect = StructFromIndirect()) { |
| 160 | + _ = StructFromIndirect() |
| 161 | + |
| 162 | + if (true) { |
| 163 | + _ = StructFromIndirect() |
| 164 | + } |
| 165 | + |
| 166 | + func nested() { |
| 167 | + _ = StructFromIndirect() |
| 168 | + } |
| 169 | + nested() |
| 170 | +} |
| 171 | + |
| 172 | +public struct ExposedLayoutPublic { |
| 173 | + public var publicField: StructFromDirect // expected-error {{property cannot be declared public because its type uses an internal type}} |
| 174 | + // expected-error @-1 {{cannot use struct 'StructFromDirect' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; 'directs' has been imported as implementation-only}} |
| 175 | + // expected-note @-2 {{struct 'StructFromDirect' is imported by this file as 'internal' from 'directs'}} |
| 176 | + |
| 177 | + private var privateField: StructFromDirect |
| 178 | +} |
| 179 | + |
| 180 | +private struct ExposedLayoutPrivate { |
| 181 | + private var privateField: StructFromDirect |
| 182 | +} |
0 commit comments