Skip to content

Conversation

@grynspan
Copy link
Contributor

@grynspan grynspan commented Sep 27, 2023

This change allows a developer to specify an argument to a test that is the result of an asynchronous function/operation. For example:

@Test(arguments: await downloadFilesFromInternet())
func readFile(file: File) {
  ...
}

These arguments are resolved at runtime during the test planning stage.

Note

This change does not enable throwing arguments. That's more complicated (because we need to potentially handle the errors on an individual basis rather than stopping the entire operation.) I'm leaving it for a separate PR.

@grynspan
Copy link
Contributor Author

@swift-ci please test

This change allows a developer to specify an argument to a test that is the result of an asynchronous function/operation. For example:

```swift
@test(arguments: await downloadFilesFromInternet())
func readFile(file: File) {
  ...
}
```

These arguments are resolved at runtime during the test planning stage.
@grynspan grynspan force-pushed the jgrynspan/async-arguments branch from 503c44e to c148ede Compare September 28, 2023 19:02
@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan grynspan merged commit 68d7f88 into main Sep 28, 2023
@grynspan grynspan deleted the jgrynspan/async-arguments branch September 28, 2023 19:47
grynspan added a commit that referenced this pull request Sep 28, 2023
As a small follow-up to #32, ensure callers can specify `async` traits on suites too.
@stmontgomery stmontgomery added the enhancement New feature or request label Oct 3, 2023
grynspan added a commit that referenced this pull request Jun 11, 2025
This PR adds a wrapper around `__builtin_unreachable()` (`Builtin.unreachable()`
when building the Swift standard library) that we can use in place of
`fatalError()`. The benefit is that the generated code size for unreachable
paths is significantly reduced. For example, given the following function
compiled with `-O`:

```swift
@available(*, unavailable) func f() {
  fatalError("Unreachable")
}
```

The compiler currently produces:

```asm
sub    sp, sp, #0x20
stp    x29, x30, [sp, #0x10]
add    x29, sp, #0x10
mov    w8, #0x1                  ; =1
str    w8, [sp, #0x8]
mov    w8, #0xc                  ; =12
str    x8, [sp]
adrp   x0, 0
add    x0, x0, #0x6a8            ; "Fatal error"
adrp   x5, 0
add    x5, x5, #0x690            ; "UnreachableTest/S.swift"
mov    x3, #0x6e55               ; =28245
movk   x3, #0x6572, lsl #16
movk   x3, #0x6361, lsl #32
movk   x3, #0x6168, lsl #48
mov    x4, #0x6c62               ; =27746
movk   x4, #0x65, lsl #16
movk   x4, #0xeb00, lsl #48
mov    w1, #0xb                  ; =11
mov    w2, #0x2                  ; =2
mov    w6, #0x17                 ; =23
mov    w7, #0x2                  ; =2
bl     0x100000680               ; symbol stub for: Swift._assertionFailure(_: Swift.StaticString, _: Swift.String, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never
brk    #0x1
```

But with this change:
```swift
@available(*, unavailable) func f() {
  swt_unreachable()
}
```

It instead compiles to simply:

```asm
brk    #0x1
```
grynspan added a commit that referenced this pull request Jun 11, 2025
This PR adds a wrapper around `__builtin_unreachable()` (`Builtin.unreachable()`
when building the Swift standard library) that we can use in place of
`fatalError()`. The benefit is that the generated code size for unreachable
paths is significantly reduced. For example, given the following function
compiled with `-O`:

```swift
@available(*, unavailable) func f() {
  fatalError("Unreachable")
}
```

The compiler currently produces:

```asm
sub    sp, sp, #0x20
stp    x29, x30, [sp, #0x10]
add    x29, sp, #0x10
mov    w8, #0x1                  ; =1
str    w8, [sp, #0x8]
mov    w8, #0xc                  ; =12
str    x8, [sp]
adrp   x0, 0
add    x0, x0, #0x6a8            ; "Fatal error"
adrp   x5, 0
add    x5, x5, #0x690            ; "UnreachableTest/S.swift"
mov    x3, #0x6e55               ; =28245
movk   x3, #0x6572, lsl #16
movk   x3, #0x6361, lsl #32
movk   x3, #0x6168, lsl #48
mov    x4, #0x6c62               ; =27746
movk   x4, #0x65, lsl #16
movk   x4, #0xeb00, lsl #48
mov    w1, #0xb                  ; =11
mov    w2, #0x2                  ; =2
mov    w6, #0x17                 ; =23
mov    w7, #0x2                  ; =2
bl     0x100000680               ; symbol stub for: Swift._assertionFailure(_: Swift.StaticString, _: Swift.String, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never
brk    #0x1
```

But with this change:
```swift
@available(*, unavailable) func f() {
  swt_unreachable()
}
```

It instead compiles to simply:

```asm
brk    #0x1
```
grynspan added a commit that referenced this pull request Jun 12, 2025
This PR adds a wrapper around `__builtin_unreachable()`
(`Builtin.unreachable()` when building the Swift standard library) that
we can use in place of `fatalError()`. The benefit is that the generated
code size for unreachable paths is significantly reduced. For example,
given the following function compiled with `-O`:

```swift
@available(*, unavailable) func f() {
  fatalError("Unreachable")
}
```

The compiler currently produces:

```asm
sub    sp, sp, #0x20
stp    x29, x30, [sp, #0x10]
add    x29, sp, #0x10
mov    w8, #0x1                  ; =1
str    w8, [sp, #0x8]
mov    w8, #0xc                  ; =12
str    x8, [sp]
adrp   x0, 0
add    x0, x0, #0x6a8            ; "Fatal error"
adrp   x5, 0
add    x5, x5, #0x690            ; "UnreachableTest/S.swift"
mov    x3, #0x6e55               ; =28245
movk   x3, #0x6572, lsl #16
movk   x3, #0x6361, lsl #32
movk   x3, #0x6168, lsl #48
mov    x4, #0x6c62               ; =27746
movk   x4, #0x65, lsl #16
movk   x4, #0xeb00, lsl #48
mov    w1, #0xb                  ; =11
mov    w2, #0x2                  ; =2
mov    w6, #0x17                 ; =23
mov    w7, #0x2                  ; =2
bl     0x100000680               ; symbol stub for: Swift._assertionFailure(_: Swift.StaticString, _: Swift.String, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never
brk    #0x1
```

But with this change:
```swift
@available(*, unavailable) func f() {
  swt_unreachable()
}
```

It instead compiles to simply:

```asm
brk    #0x1
```

### Checklist:

- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants