File: implicit-module-build-overload-availability-inlinable-function.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (56 lines) | stat: -rw-r--r-- 2,038 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/NonAPI)
// RUN: %empty-directory(%t/API)
// RUN: split-file %s %t

// RUN: %target-swift-emit-module-interface(%t/NonAPI/Library.swiftinterface) %t/Library.swift -module-name Library -target %target-swift-abi-5.8-triple
// RUN: %target-swift-emit-module-interface(%t/API/Library.swiftinterface) %t/Library.swift -module-name Library -target %target-swift-abi-5.8-triple -library-level api

// Build Client.swift against the Library.swiftinterface without
// `-library-level api`. Since the deployment target of the library is
// SwiftStdlib 5.8, the newer overload that returns a String should be selected
// by overload resolution during the implicit module build.

// RUN: %target-build-swift %t/Client.swift -o %t/NonAPI/client -I %t/NonAPI/
// RUN: %target-codesign %t/NonAPI/client
// RUN: %target-run %t/NonAPI/client | %FileCheck %s --check-prefix=CHECK-NON-API

// Build Client.swift against the Library.swiftinterface with
// `-library-level api`. Since the deployment target of the client that will
// get a copy of `fragileFuncUsingOverload()` is earlier than SwiftStdlib 5.8,
// the older overload returning an Int should be selected during the implicit
// module build even though the library targets SwiftStdlib 5.8.

// RUN: %target-build-swift %t/Client.swift -o %t/API/client -I %t/API/
// RUN: %target-codesign %t/API/client
// RUN: %target-run %t/API/client | %FileCheck %s --check-prefix=CHECK-API

// REQUIRES: executable_test
// REQUIRES: OS=macosx || OS=ios || OS=tvos || OS=watchos

//--- Library.swift

@_disfavoredOverload
@_alwaysEmitIntoClient
public func overloadedFunc() -> Int {
  return 1234
}

@available(SwiftStdlib 5.8, *)
@_alwaysEmitIntoClient
public func overloadedFunc() -> String {
  return "String"
}

@_alwaysEmitIntoClient
public func fragileFuncUsingOverload() -> any CustomStringConvertible {
  return overloadedFunc()
}

//--- Client.swift

import Library

// CHECK-NON-API: String
// CHECK-API: 1234
print(fragileFuncUsingOverload())