Skip to content

Merge 'main' branch to 'release/6.2' #1170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jun 25, 2025

Conversation

stmontgomery
Copy link
Contributor

This merges the main branch into the release/6.2 branch.

Note: The Swift Testing project will be periodically performing "backwards" merges like this for a period which extends beyond the date when the 6.2 branches were cut, since nearly all contributions are intended to be included in the 6.2 release.

Once this PR has been merged, I will adjust the milestones on the PRs included in this merge to be 6.2 wherever appropriate.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

Wouter01 and others added 18 commits June 7, 2025 20:47
…efault. (swiftlang#1145)

This PR makes file descriptors created by Swift Testing `FD_CLOEXEC` by
default (on Windows, `~HANDLE_FLAG_INHERIT`.) We then clear `FD_CLOEXEC`
for specific file descriptors that should be inherited. On Darwin, this
is effectively ignored because we use `POSIX_SPAWN_CLOEXEC_DEFAULT`, and
on Windows we use `PROC_THREAD_ATTRIBUTE_HANDLE_LIST` which has [much
the same
effect](https://devblogs.microsoft.com/oldnewthing/20111216-00/?p=8873).
(On non-Darwin POSIX platforms, there's no reliable way to ensure only
one child process inherits a particular file descriptor.)

This change is speculative. No additional unit tests are added because
existing test coverage _should be_ sufficient; the reported issue is on
a platform (Ubuntu 20.04) where we don't have any CI jobs.

Resolves swiftlang#1140.

### 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.
This declares Xcode 26.0 API availability for all Swift 6.2
declarations.

### 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.

Fixes rdar://151629765
…tlang#1147)

On
[FreeBSD](https://man.freebsd.org/cgi/man.cgi?query=posix_spawn_file_actions_adddup2),
[OpenBSD](https://github.com/openbsd/src/blob/master/lib/libc/gen/posix_spawn.c#L155),
[Android](https://android.googlesource.com/platform/bionic/+/master/libc/bionic/spawn.cpp#103),
and [Glibc ≥
2.29](https://sourceware.org/bugzilla/show_bug.cgi?id=23640),
`posix_spawn_file_actions_adddup2()` automatically clears `FD_CLOEXEC`
if the file descriptors passed to it are equal. Relying on this
behaviour eliminates a race condition when spawning child processes.
This functionality is standardized in
[POSIX.1-2024](https://pubs.opengroup.org/onlinepubs/9799919799/) thanks
to [Austin Group Defect
swiftlang#411](https://www.austingroupbugs.net/view.php?id=411).

Some older Linuxes (Amazon Linux 2 in particular) don't have this
functionality, so we do a runtime check of the Glibc version.

This PR is a follow-up to swiftlang#1145.
Resolves swiftlang#1140.

### 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.
…wiftlang#1105)

This PR ensures that suite types that don't have the `@Suite` attribute
but which _do_ have raw identifiers for names are correctly given
display names the same way those with `@Suite` would be. This PR also
ensures that we transform spaces in raw identifiers after they are
demangled by the runtime--namely, the runtime replaces ASCII spaces (as
typed by the user) with Unicode non-breaking spaces (which aren't
otherwise valid in raw identifers) in order to avoid issues with
existing uses of spaces in demangled names. We want to make sure that
identifiers as presented to the user match what the user has typed, so
we need to transform these spaces back. No changes in this area are
needed for display names derived during macro expansion because we do
the relevant work based on the source text which still has the original
ASCII spaces.

This PR also deletes the "`raw$`" hack that I put in place when
originally implementing raw identifier support as the entire toolchain
supports them now.

Resolves swiftlang#1104.

### 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.
…instead of `AnySequence`. (swiftlang#1122)

This PR changes how `DiscoverableAsTestContent` enumeration works so
that we can return `some Sequence` instead of `AnySequence`. We do so by
removing the `~Copyable` constraint on the protocol, which subsequently
causes the compiler to get confused and crash trying to represent `some
Sequence<TestContentRecord<T>>` where `T: DiscoverableAsTestContent`.

The only supported/allowed consumers of the `DiscoverableAsTestContent`
protocol are Swift Testing and the experimental Playgrounds package,
neither of which uses (or needs to use) a move-only type here. Earlier,
`ExitTest` conformed to `DiscoverableAsTestContent`, but this was
changed and is no longer necessary.

### 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.
This PR improves the diagnostics presented at compile time when an exit
test captures an unsupported value. For example, given the following
(bad) exit test:

```swift
struct NonCodableValue {}

let x = NonCodableValue()
await #expect(processExitsWith: .success) { [x = x as NonCodableValue] in
  _ = x
}
```

We currently get diagnostics of the form:

> 🛑 Global function
'__checkClosureCall(identifiedBy:encodingCapturedValues:processExitsWith:observing:performing:expression:comments:isRequired:isolation:sourceLocation:)'
requires that 'NonCodableValue' conform to 'Decodable'
> 🛑 Global function
'__checkClosureCall(identifiedBy:encodingCapturedValues:processExitsWith:observing:performing:expression:comments:isRequired:isolation:sourceLocation:)'
requires that 'NonCodableValue' conform to 'Encodable'
> ⚠️ No 'async' operations occur within 'await' expression

None of which actually tell the developer (clearly) what's wrong. With
this PR, we instead get:

> 🛑 Type of captured value 'x' must conform to 'Sendable' and 'Codable'
(from macro '__capturedValue')

Much better! The diagnostic is attributed to the temporary file
containing the expansion of `#expect()` rather than to the original
source file, but I've opened [an
issue](swiftlang/swift-syntax#3085) against
swift-syntax with a fix in mind. Even with the misattribution, this
diagnostic is still an improvement, yeah?

> [!NOTE]
> Exit test value capture remains an experimental feature.

### 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.
…ocess`. (swiftlang#1114)

We already have custom `async`-friendly code for spawning child
processes, so let's use it instead of relying on `Foundation.Process`
when we need to call the platform's `zip` or `tar` tool. Currently we do
this in the Foundation cross-import overlay (hence why we were using
`Foundation.Process` at all).

### 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.
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 swiftlang#16
movk   x3, #0x6361, lsl swiftlang#32
movk   x3, #0x6168, lsl swiftlang#48
mov    x4, #0x6c62               ; =27746
movk   x4, #0x65, lsl swiftlang#16
movk   x4, #0xeb00, lsl swiftlang#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.
…ang#1153)

`@convention(thin)` is not fully plumbed through the compiler and should
not be in our API surface, but also because of the experimental value
capturing feature the closures may be thick anyway.

See also swiftlang/swift-evolution#2884.

### 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.
…t test. (swiftlang#1130)

This PR adds the ability to infer the type of a parameter of a function
or closure that encloses an exit test. For example, `x` here:

```swift
func f(x: Int) async {
  await #expect(processExitsWith: .failure) { [x] in
    ...
  }
}
```

This inference still fails if a parameter is shadowed by a variable with
an incompatible type; we still need something like `decltype()` to solve
for such cases. We emit a custom diagnostic of the form "🛑 Type of
captured value 'x' is ambiguous" if the inferred type of the captured
value doesn't match what the compiler thinks it is (see swiftlang#1146). Still,
being able to capture `@Test` function arguments with minimal ceremony
is helpful:

```swift
@test(arguments: 0 ..< 100) func f(i: Int) async {
  await #expect(exitsWith: .failure) { [i] in
    ...
  }
}
```

Also type inference for literals because "why not?"

> [!NOTE]
> Exit test value capture remains an experimental feature.

### 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.
This PR fixes some typos/minor errors in our documentation.

Resolves swiftlang#1118.

### 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.
Revert "Update outdated Suite macro documentation"
… the lexical context. (swiftlang#1161)

This PR changes the behaviour of the testing library for expressions
such as:

```swift
try #expect(a == b)
```

Currently, we don't expand that expression correctly because we can't
tell where the `try` keyword should be applied. It sometimes expands and
sometimes doesn't. This PR detects the presence of those keywords (with
a recent-enough toolchain) and, if found, disables the fancy expansion
in favour of a simpler one that is less likely to fail to compile.

More thorough support for effectful expressions in expectations is
tracked by swiftlang#840 which involves fully refactoring the implementation of
the `#expect()` macro. See also swiftlang#162 for some more context.

### 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.
This PR refactors the (new) type inference logic for exit test capture
lists to use a syntax visitor, which allows for the types of more
complex expressions to be inferred.

For example, previously the type of this capture would not be inferred:

```swift
[x = try await f() as Int]
```

Even though the type (`Int`) is clearly present, because the
`AsExprSyntax` is nested in an `AwaitExprSyntax` and then a
`TryExprSyntax`.

### 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.
… an exit test. (swiftlang#1152)

Follow-up to swiftlang#1130, split out for clarity.

This PR adds a custom diagnostic at compile time if we incorrectly infer
the type of a captured function argument or `self` in an exit test. For
example:

```swift
func f(_ x: Int) async {
  let x = String(x) // local type of 'x' is String, not Int
  await #expect(processExitsWith: ...) { [x] in
    ...
  }
}
```

This improves our feedback to the developer when we encounter a pattern
like that. The developer will now see:

> 🛑 Type of captured value 'x' is ambiguous

### 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.
@stmontgomery stmontgomery added this to the Swift 6.2 milestone Jun 24, 2025
@stmontgomery stmontgomery self-assigned this Jun 24, 2025
@stmontgomery stmontgomery added the integration ⚙️ Integrating work to release branches label Jun 24, 2025
@stmontgomery
Copy link
Contributor Author

@swift-ci please test

@stmontgomery
Copy link
Contributor Author

@swift-ci please test

@stmontgomery stmontgomery merged commit ae7fe60 into swiftlang:release/6.2 Jun 25, 2025
3 checks passed
@stmontgomery stmontgomery deleted the main-6.2-merge branch June 25, 2025 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration ⚙️ Integrating work to release branches
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants