# Decoupling Swift Compiler and Runtime Testing

**URL:** <https://forums.swift.org/t/decoupling-swift-compiler-and-runtime-testing/90047>\
**Category:** Compiler\
**Tags:** testing\
**Created:** [October 14, 2026, 12:08am UTC](https://forums.swift.org/t/decoupling-swift-compiler-and-runtime-testing/90047 "2026-10-14T00:08:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![etcwilde](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/etcwilde/32/13687_2.png) [@etcwilde](https://forums.swift.org/u/etcwilde)\
**Post date:** [October 14, 2026, 12:08am UTC](https://forums.swift.org/t/decoupling-swift-compiler-and-runtime-testing/90047/1 "2026-10-14T00:08:47Z")

</div>

# Decoupling Swift Compiler and Runtime Testing

The Swift compiler and runtime execution testing are tightly coupled to the internal layout of the compiler build directory. This prevents testing installed SDK layouts, complicates cross-compilation, and creates significant CI bottlenecks.

This proposal outlines a strategy to decouple the test suite into three  
independent categories:

- Compiler Tests: Tests that verify the output of the compiler using a mock SDK but do not depend on the runtime.
- Execution Tests: Runtime-dependent tests structured into separate Build, Run, and Verify phases, enabling execution on air-gapped or embedded devices without requring Python or SSH.
- Validation Tests: End-to-end integration tests requiring a complete SDK and host sysroot.

This separation enables horizontal scaling in CI, early failure feedback, and testing across arbitrary deployment targets and SDK layouts with prebuilt Swift toolchains.

For more details, here is a link to the full proposal: [Swift Build · GitHub](https://gist.github.com/etcwilde/b23fc96f50478083ec77bd1163dac834)

---

<div class="post-metadata">

**Author:** ![Finagolfin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/finagolfin/32/34388_2.png) [@Finagolfin](https://forums.swift.org/u/Finagolfin)\
**Post date:** [October 14, 2026, 7:58am UTC](https://forums.swift.org/t/decoupling-swift-compiler-and-runtime-testing/90047/2 "2026-10-14T07:58:55Z")

</div>

Read the whole proposal, interesting approach, agree that such a decoupling of the current monolithic compiler validation suite would help. For example, the CI currently runs the compiler-only tests repeatedly for each target platform, wasting time when multiple target stdlibs are built.

Some questions and a note:

- What platforms do you see the full cross-compilation split you lay out at the end being applied to on CI? It would obviously be useful for mobile platforms like iOS, but will it be employed for desktop platforms like linux and Windows too?

- What proportion of the current tests "do not strictly require a full standard library [and] can be moved to the pure compiler test suite?" Do you know this yet or will we need to figure it out?

- You mention building the full target SDK before running the validation tests. Currently, we only build libdispatch on Unixy platforms before running the compiler test suite, so the compiler tests that invoke Foundation or XCTest appear to be limited to Darwin only, and can presumably be expanded to non-Darwin with this change (Windows also builds the full SDK first, but doesn't appear to have enabled all those compiler tests).

---

<div class="post-metadata">

**Author:** ![hnrklssn](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hnrklssn/32/38698_2.png) [@hnrklssn](https://forums.swift.org/u/hnrklssn)\
**Post date:** [October 14, 2026, 8:23am UTC](https://forums.swift.org/t/decoupling-swift-compiler-and-runtime-testing/90047/3 "2026-10-14T08:23:56Z")

</div>

I'm in favour of getting us away from `remote-run`, as it adds constraints that aren't visible until you run the tests in a remote configuration.

I have three concerns around the execution test carve-out however:

1. Would the entire "Build, Run, Validate" pipeline integrate into lit (à la GTest) so that we can still launch the tests using `run-test`? Or would the Build and/or Run steps require a `ninja` invocation before running `llvm-lit`? Or even `build-script`? If so, that could further increase the friction to writing executable tests, which I think we need to be mindful of. I and many others have not been able to wrangle `build-script` into a quick, iterative build-and-test workflow, and only use it for the initial CMake configuration, and then use `ninja` and `run-test`/`llvm-lit` directly to rebuild and test only the things that are actually relevant. If a certain test category were to require involving `build-script` in the iterative workflow I think that would be very unfortunate.
2. Where do compiler tests involving macros fall? Macros are essentially Swift programs that need to be compiled and executed, but generally the intent of macro tests are not for testing the macro implementation itself, but rather the compiler. Perhaps we can include some useful macros in the mock SDK? I'm quite partial to the `unstringify` macro, where each invocation simply passes a string literal with the intended macro expansion contents. That way each macro test doesn't have to compile the macros separately, which can contribute a fair bit of overhead due to code signing and validation of the macro binary.
3. One test category _does_ aim to test the implementation of a macro, namely `@_SwiftifyImport`. Since this macro is currently shipped in the standard library and automatically applied by ClangImporter when relevant, quite a few interop tests require access to this macro from the standard library. On the one hand it would be nice to be able to test the compiler with different versions of the standard library to check for compatibility issues accross stdlib and compiler versions (which we currently have no way of testing), but on the other hand these tests also need a way to specifically test against the same version of the stdlib, since exact output may vary between macro versions. I have loose plans for how we can (and probably should) move away from this "automatically invoked macro living in stdlib" architecture, but until we do I think compiler tests may need access to a little more than a stub stdlib.

---

<div class="post-metadata">

**Author:** ![Slava\_Pestov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/slava_pestov/32/30204_2.png) [@Slava\_Pestov](https://forums.swift.org/u/Slava_Pestov)\
**Post date:** [October 14, 2026, 5:16pm UTC](https://forums.swift.org/t/decoupling-swift-compiler-and-runtime-testing/90047/4 "2026-10-14T17:16:41Z")

</div>

> [@etcwilde](#):
>
> - Tests that verify the output of the compiler using a mock SDK but do not depend on the runtime.

For tests that exercise Foundation features that require compiler support, such as bridging, or the CGFloat-Double implicit conversion in the type checker, I’ve found that the mock SDK is not a good substitute because the overload sets it declares are much simpler than the real thing. A few bugs were not caught as a result of this.

So while I agree that making test cases self-contained where possible is a good thing, I also believe that quite a number of the existing ClangImporter and Sema tests that exercise these features would give us better coverage if they used the real Foundation on Apple platforms.

---

<div class="post-metadata">

**Author:** ![etcwilde](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/etcwilde/32/13687_2.png) [@etcwilde](https://forums.swift.org/u/etcwilde)\
**Post date:** [October 14, 2026, 5:32pm UTC](https://forums.swift.org/t/decoupling-swift-compiler-and-runtime-testing/90047/5 "2026-10-14T17:32:11Z")

</div>

> [@Finagolfin](#):
>
> - What platforms do you see the full cross-compilation split you lay out at the end being applied to on CI? It would obviously be useful for mobile platforms like iOS, but will it be employed for desktop platforms like linux and Windows too?

I see it mostly being useful for new platform bringup workflows to produce the initial toolchain, especially now that the compiler requires Swift. That said, there is work involved with supporting fleets of new platforms. For the FreeBSD bringup, for instance, being able to use the existing Linux fleet to cross-compile the runtime and compiler to FreeBSD and reserve the FreeBSD node for testing would be incredibly helpful.

> [@Finagolfin](#):
>
> - What proportion of the current tests "do not strictly require a full standard library [and] can be moved to the pure compiler test suite?" Do you know this yet or will we need to figure it out?

I don't have an exact number but roughly 1168 tests are passing `-parse-stdlib`. Only about 8 are passing `-module-name Swift` and declaring their own standard library type declarations. From walking through the tests, many of the type checking, SIL/SILGen, and IRGen tests should be pretty easy to migrate to a mock SDK since they are just using the SDK type declarations and don't actually need to link or run code.

> [@Finagolfin](#):
>
> - You mention building the full target SDK before running the validation tests. Currently, we only build libdispatch on Unixy platforms before running the compiler test suite, so the compiler tests that invoke Foundation or XCTest appear to be limited to Darwin only, and can presumably be expanded to non-Darwin with this change (Windows also builds the full SDK first, but doesn't appear to have enabled all those compiler tests).

Heh, I should have been clearer with "full target SDK". I'm focusing on the standard library Swift runtimes. I would actually like to go the opposite direction and have the standard library tests stop depending on Foundation and Dispatch as much as possible. CDispatch is necessary for concurrency testing since it's the backend (unless someone wants to write a libuv or Android Looper concurrency backend 🙂), but I've certainly had to build Swift runtimes for devices where Foundation is simply too big, but I would still like to be able to verify that the standard library is working correctly. For the tests that do require it, CMake makes it fairly easy to detect whether we can find certain libraries and we can mark the tests that require those libraries as skipped if they aren't found.

> [@hnrklssn](#):
>
> 1. Would the entire "Build, Run, Validate" pipeline integrate into lit (à la GTest) so that we can still launch the tests using `run-test`? Or would the Build and/or Run steps require a `ninja` invocation before running `llvm-lit`? Or even `build-script`? If so, that could further increase the friction to writing executable tests, which I think we need to be mindful of. I and many others have not been able to wrangle `build-script` into a quick, iterative build-and-test workflow, and only use it for the initial CMake configuration, and then use `ninja` and `run-test`/`llvm-lit` directly to rebuild and test only the things that are actually relevant. If a certain test category were to require involving `build-script` in the iterative workflow I think that would be very unfortunate.

Not build-script, no. It will require re-running `ninja` and then `llvm-lit` since `llvm-lit` will no longer be driving the compilation of the tests. Since the test executable is a target, rebuilding should be `ninja <target>`. Maybe as future work, we could support something like LLVM's `ninja check-llvm` that would build the tests and then run `llvm-lit` on it, but for the runtimes?

> [@hnrklssn](#):
>
> 1. Where do compiler tests involving macros fall? Macros are essentially Swift programs that need to be compiled and executed, but generally the intent of macro tests are not for testing the macro implementation itself, but rather the compiler. Perhaps we can include some useful macros in the mock SDK? I'm quite partial to the `unstringify` macro, where each invocation simply passes a string literal with the intended macro expansion contents. That way each macro test doesn't have to compile the macros separately, which can contribute a fair bit of overhead due to code signing and validation of the macro binary.

We already have to build Swift Syntax for the compiler, we could likely throw in a few macro executables here. Much like how `FileCheck` and `not` are wired up in LLVM, these could be marked as test dependencies.

> [@hnrklssn](#):
>
> 1. One test category _does_ aim to test the implementation of a macro, namely `@_SwiftifyImport`. Since this macro is currently shipped in the standard library and automatically applied by ClangImporter when relevant, quite a few interop tests require access to this macro from the standard library. On the one hand it would be nice to be able to test the compiler with different versions of the standard library to check for compatibility issues accross stdlib and compiler versions (which we currently have no way of testing), but on the other hand these tests also need a way to specifically test against the same version of the stdlib, since exact output may vary between macro versions. I have loose plans for how we can (and probably should) move away from this "automatically invoked macro living in stdlib" architecture, but until we do I think compiler tests may need access to a little more than a stub stdlib.

These sound like validation tests to me since they require the full implementation from the standard library. I think the goal is less about comparing version drift between the compiler and standard library and more so about being able to build the compiler once and being able to test multiple builds (multi-platform, sanitizer, etc...) of the runtime without rebuilding the compiler. Binary swiftmodules are highly volatile and often don't work with a different version of the compiler that produced it and even for platforms with ABI stability and textual interfaces, they often only work within a single minor version of the compiler, so comparing a 6.3 and 6.4 compiler on the same SDK is already unlikely to work. Any testing around version drift would need to be local experiments since the compiler itself doesn't support consuming any of the interfaces produced by a different version of the compiler.

---

<div class="post-metadata">

**Author:** ![etcwilde](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/etcwilde/32/13687_2.png) [@etcwilde](https://forums.swift.org/u/etcwilde)\
**Post date:** [November 16, 2026, 8:00pm UTC](https://forums.swift.org/t/decoupling-swift-compiler-and-runtime-testing/90047/6 "2026-11-16T20:00:40Z")

</div>

> [@Slava\_Pestov](#):
>
> So while I agree that making test cases self-contained where possible is a good thing, I also believe that quite a number of the existing ClangImporter and Sema tests that exercise these features would give us better coverage if they used the real Foundation on Apple platforms.

I'm not suggesting that we don't test against the real thing, but migrate certain tests to use a self-contained mock. The validation suite will still require a full platform sysroot and Swift SDK. In theory, this could enable us to run those tests against the real sysroot instead of the clang importer mock sysroot that we have today.

I would like to steer the pure compiler-only testing away from being platform-specific so that we get even test coverage across the platforms. It has gotten better since around 2022 but there were a number of tests that had been disabled on Windows and Linux, but ended up being a result of undefined behavior in the compiler, rather than an issue with the platform itself. Having a set of tests verifying the behavior of the compiler that isn't tied to a specific platform should help catch those issues.
