@@ -167,7 +167,7 @@ extension __ExpectationContext {
167
167
///
168
168
/// This function helps overloads of `callAsFunction(_:_:)` disambiguate
169
169
/// themselves and avoid accidental recursion.
170
- @usableFromInline func captureValue< T> ( _ value: consuming T , _ id: __ExpressionID ) -> T {
170
+ @usableFromInline func captureValue< T> ( _ value: borrowing T , _ id: __ExpressionID ) -> T {
171
171
let value = copy value
172
172
runtimeValues [ id] = { Expression . Value ( reflecting: value) }
173
173
return value
@@ -186,7 +186,7 @@ extension __ExpectationContext {
186
186
/// - Warning: This function is used to implement the `#expect()` and
187
187
/// `#require()` macros. Do not call it directly.
188
188
@_disfavoredOverload
189
- @inlinable public func callAsFunction< T> ( _ value: consuming T , _ id: __ExpressionID ) -> T {
189
+ @inlinable public func callAsFunction< T> ( _ value: borrowing T , _ id: __ExpressionID ) -> T {
190
190
captureValue ( value, id)
191
191
}
192
192
@@ -204,7 +204,7 @@ extension __ExpectationContext {
204
204
/// - Warning: This function is used to implement the `#expect()` and
205
205
/// `#require()` macros. Do not call it directly.
206
206
@_disfavoredOverload
207
- public func callAsFunction< T> ( _ value: consuming T , _ id: __ExpressionID ) -> T where T: ~ Copyable {
207
+ public func callAsFunction< T> ( _ value: borrowing T , _ id: __ExpressionID ) -> T where T: ~ Copyable {
208
208
// TODO: add support for borrowing non-copyable expressions (need @lifetime)
209
209
return value
210
210
}
@@ -345,8 +345,6 @@ extension __ExpectationContext {
345
345
_ rhs: borrowing U ,
346
346
_ rhsID: __ExpressionID
347
347
) rethrows -> Bool {
348
- let lhs = copy lhs
349
- let rhs = copy rhs
350
348
let result = try captureValue ( op ( captureValue ( lhs, lhsID) , captureValue ( rhs, rhsID) ) , opID)
351
349
352
350
if !result {
@@ -378,8 +376,7 @@ extension __ExpectationContext {
378
376
///
379
377
/// - Warning: This function is used to implement the `#expect()` and
380
378
/// `#require()` macros. Do not call it directly.
381
- @inlinable public func __as< T, U> ( _ value: consuming T , _ valueID: __ExpressionID , _ type: U . Type , _ typeID: __ExpressionID ) -> U ? {
382
- let value = copy value
379
+ @inlinable public func __as< T, U> ( _ value: borrowing T , _ valueID: __ExpressionID , _ type: U . Type , _ typeID: __ExpressionID ) -> U ? {
383
380
let result = captureValue ( value, valueID) as? U
384
381
385
382
if result == nil {
@@ -409,14 +406,6 @@ extension __ExpectationContext {
409
406
/// - Warning: This function is used to implement the `#expect()` and
410
407
/// `#require()` macros. Do not call it directly.
411
408
@inlinable public func __is< T, U> ( _ value: borrowing T , _ valueID: __ExpressionID , _ type: U . Type , _ typeID: __ExpressionID ) -> Bool {
412
- let value = copy value
413
- let result = captureValue ( value, valueID) is U
414
-
415
- if !result {
416
- let correctType = Swift . type ( of: value as Any )
417
- _ = captureValue ( correctType, typeID)
418
- }
419
-
420
- return result
409
+ __as ( value, valueID, type, typeID) != nil
421
410
}
422
411
}
0 commit comments