|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: split-file %s %t --leading-lines |
| 3 | +// REQUIRES: objc_interop |
| 4 | +// REQUIRES: executable_test |
| 5 | + |
| 6 | +/// Optimization active: public import |
| 7 | +// RUN: %target-build-swift-dylib(%t/%target-library-name(Lib)) \ |
| 8 | +// RUN: %t/optimized.swift -module-name Lib \ |
| 9 | +// RUN: -emit-module -emit-module-path %t/Lib.swiftmodule \ |
| 10 | +// RUN: -swift-version 5 -enable-library-evolution -O |
| 11 | +// RUN: %target-build-swift %t/main.swift -o %t/main -I%t -lLib -L%t -O |
| 12 | +// RUN: %target-codesign %t/main |
| 13 | +// RUN: %target-run %t/main | %FileCheck %s |
| 14 | + |
| 15 | +/// Ensure the client has the optimization we're testing here. |
| 16 | +// RUN: %target-swift-frontend -typecheck -emit-silgen %t/Lib.swiftmodule > %t/Lib.sil |
| 17 | +// RUN: %FileCheck --check-prefix CHECK-OPTIMIZED --input-file %t/Lib.sil %s |
| 18 | +// CHECK-OPTIMIZED: _getErrorEmbeddedNSError |
| 19 | + |
| 20 | +/// No optimization: internal import from resilient module |
| 21 | +// RUN: %target-build-swift-dylib(%t/%target-library-name(Lib)) \ |
| 22 | +// RUN: %t/non-optimized.swift -module-name Lib \ |
| 23 | +// RUN: -emit-module -emit-module-path %t/Lib.swiftmodule \ |
| 24 | +// RUN: -swift-version 5 -enable-library-evolution -O |
| 25 | +// RUN: %target-build-swift %t/main.swift -o %t/main -I%t -lLib -L%t -O |
| 26 | +// RUN: %target-codesign %t/main |
| 27 | +// RUN: %target-run %t/main | %FileCheck %s |
| 28 | + |
| 29 | +/// Ensure the client doesn't have the optimization we're testing here. |
| 30 | +// RUN: %target-swift-frontend -typecheck -emit-silgen %t/main.swift -I%t -O > %t/Lib.sil |
| 31 | +// RUN: %FileCheck --check-prefix CHECK-NOT-OPTIMIZED --input-file %t/Lib.sil %s |
| 32 | +// CHECK-NOT-OPTIMIZED-NOT: _getErrorEmbeddedNSError |
| 33 | + |
| 34 | +//--- optimized.swift |
| 35 | +public import Foundation |
| 36 | + |
| 37 | +@inlinable public func foo<E: Error>(e: E) -> Error { |
| 38 | + return e |
| 39 | +} |
| 40 | + |
| 41 | +//--- non-optimized.swift |
| 42 | +internal import Foundation |
| 43 | + |
| 44 | +@inlinable public func foo<E: Error>(e: E) -> Error { |
| 45 | + return e |
| 46 | +} |
| 47 | + |
| 48 | +//--- main.swift |
| 49 | +import Lib |
| 50 | +import Foundation |
| 51 | + |
| 52 | +let err: NSError = NSError(domain: "Not found", code: 404) |
| 53 | +let errOut: Error = foo(e: err) |
| 54 | +print(errOut.localizedDescription) |
| 55 | +// CHECK: Not found error 404. |
0 commit comments