1
+ //===--- FakeStdlib.swift -------------------------------------------------===//
2
+ //
3
+ // This source file is part of the Swift.org open source project
4
+ //
5
+ // Copyright (c) 2025 Apple Inc. and the Swift project authors
6
+ // Licensed under Apache License v2.0 with Runtime Library Exception
7
+ //
8
+ // See https://swift.org/LICENSE.txt for license information
9
+ // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10
+ //
11
+ //===----------------------------------------------------------------------===//
12
+ //
13
+ // A handful of standard library stubs to allow Span.swift and RawSpan.swift
14
+ // to be compiled as part of the compatibility shim.
15
+ //
16
+ //===----------------------------------------------------------------------===//
17
+
18
+ import Swift
19
+
20
+ @_alwaysEmitIntoClient @_transparent
21
+ internal func _precondition(
22
+ _ condition: @autoclosure ( ) -> Bool , _ message: StaticString = StaticString ( ) ,
23
+ file: StaticString = #file, line: UInt = #line
24
+ ) {
25
+ fatalError ( )
26
+ }
27
+
28
+ @_alwaysEmitIntoClient @_transparent
29
+ internal func _internalInvariantFailure(
30
+ _ message: StaticString = StaticString ( ) ,
31
+ file: StaticString = #file, line: UInt = #line
32
+ ) -> Never {
33
+ fatalError ( )
34
+ }
35
+
36
+ /// Unsafely discard any lifetime dependency on the `dependent` argument. Return
37
+ /// a value identical to `dependent` with a lifetime dependency on the caller's
38
+ /// borrow scope of the `source` argument.
39
+ @unsafe
40
+ @_unsafeNonescapableResult
41
+ @_alwaysEmitIntoClient
42
+ @_transparent
43
+ @lifetime ( borrow source)
44
+ internal func _overrideLifetime<
45
+ T: ~ Copyable & ~ Escapable, U: ~ Copyable & ~ Escapable
46
+ > (
47
+ _ dependent: consuming T , borrowing source: borrowing U
48
+ ) -> T {
49
+ // TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence
50
+ // should be expressed by a builtin that is hidden within the function body.
51
+ dependent
52
+ }
53
+
54
+ /// Unsafely discard any lifetime dependency on the `dependent` argument. Return
55
+ /// a value identical to `dependent` that inherits all lifetime dependencies from
56
+ /// the `source` argument.
57
+ @unsafe
58
+ @_unsafeNonescapableResult
59
+ @_alwaysEmitIntoClient
60
+ @_transparent
61
+ @lifetime ( source)
62
+ internal func _overrideLifetime<
63
+ T: ~ Copyable & ~ Escapable, U: ~ Copyable & ~ Escapable
64
+ > (
65
+ _ dependent: consuming T , copying source: borrowing U
66
+ ) -> T {
67
+ // TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence
68
+ // should be expressed by a builtin that is hidden within the function body.
69
+ dependent
70
+ }
71
+
72
+ extension Range {
73
+ @_alwaysEmitIntoClient
74
+ internal init ( _uncheckedBounds bounds: ( lower: Bound , upper: Bound ) ) {
75
+ self . init ( uncheckedBounds: bounds)
76
+ }
77
+ }
78
+
79
+ extension Optional {
80
+ /// - Returns: `unsafelyUnwrapped`.
81
+ ///
82
+ /// This version is for internal stdlib use; it avoids any checking
83
+ /// overhead for users, even in Debug builds.
84
+ @_alwaysEmitIntoClient
85
+ internal var _unsafelyUnwrappedUnchecked : Wrapped {
86
+ get {
87
+ if let x = self {
88
+ return x
89
+ }
90
+ _internalInvariantFailure ( " _unsafelyUnwrappedUnchecked of nil optional " )
91
+ }
92
+ }
93
+ }
0 commit comments