This note explains why recent GCDX work spends meaningful time on Swift, even
though the core porting target is the C layer:
- kernel
TWQ/pthread_workqueue-style support libthrbridgelibdispatch
The short answer is:
Swift is both a first-class product target of
GCDXand the best high-value test vehicle for the C stack underneath it.
Swift work in this repo is not a side project and not a shift away from
libdispatch or pthread_workqueue.
It serves two purposes at once:
-
Feature goal Swift concurrency is one of the main reasons to do this port at all. A FreeBSD-based system with real kernel-backed
libdispatchsemantics is much more valuable if Swift can benefit from it directly. -
Diagnostic lane Swift is an excellent way to exercise the real integrated behavior of:
/usr/src/sys/kern/kern_thrworkq.c/usr/src/lib/libthr/thread/thr_workq.c- the staged custom
libdispatch
Before the recent Swift-focused work, the project already proved the basic C stack was real:
- the kernel
TWQsubsystem exists and boots in the guest - the
bhyvelane is real and automated - the custom
libthrbridge works - staged
libdispatchruns on theTWQpath - pressure, admission, narrowing, and lifecycle behavior are observable
That earlier work is captured in:
- m10-libdispatch-bringup-progress.md
- m11-5-sustained-workload-progress.md
- m11-6-timeout-isolation-progress.md
At that point, adding more narrow C-only smoke tests would have had diminishing returns.
Swift workloads exercise integration surfaces that the simpler C probes only touch partially or not at all:
- delayed resumption
TaskGroupfan-out and completion- suspension and resume ordering
- executor-style queue behavior
- interaction between dispatch-managed work and Swift-managed task structure
Those are exactly the places where a pthread_workqueue-powered dispatch stack
either feels real or still behaves like a compatibility path.
So the Swift lane is not replacing C validation. It is forcing the C stack to behave correctly under realistic higher-level use.
Even when the symptom appears in Swift, the debugging target usually stays in the lower stack.
The current workflow is:
- reproduce a realistic failure with a small Swift probe
- compare behavior across staged/runtime combinations
- use those controls to identify which C layer is actually responsible
This matters because a Swift failure does not automatically mean “Swift is broken.”
Often it means one of these is wrong:
- custom
libdispatch - custom
libthr - kernel
TWQaccounting or admission - an interaction boundary between Swift concurrency and dispatch
The Swift lane has already produced more precise results than generic C stress tests alone.
Earlier, a suspended TaskGroup workload timed out in the guest. That looked
like a broad Swift-concurrency problem.
Further isolation showed that was too broad:
Task.yieldworked in some paths- continuation-resume paths worked
- several
dispatchMain()-rooted Swift probes worked
That moved the problem away from “Swift generally” and toward a narrower staged runtime boundary.
The strongest result came from the runtime matrix documented in:
The same Swift binaries were run against three guest lanes:
- stock
libdispatch+ stocklibthr - stock
libdispatch+ customlibthr - custom staged
libdispatch+ customlibthron theTWQpath
That showed:
- stock-dispatch + custom
libthrsucceeds - full staged
libdispatch+ customlibthrfails only on a narrower delayed child-completion case
So Swift testing helped narrow blame away from:
- the FreeBSD kernel in general
- custom
libthrin general - “Swift concurrency” as a broad category
and toward:
- custom
libdispatchdelayed work / child completion on theTWQpath
That is exactly the kind of diagnosis we want.
When deciding whether to use Swift as part of the porting effort, follow this rule:
- Use C probes to prove basic mechanics.
- Use Swift probes to expose realistic integrated behavior.
- Use guest runtime matrices to decide which lower layer is actually at fault.
In other words:
Swift is not the replacement for the C-layer port. It is the best realistic pressure test for whether the C-layer port is actually good enough.
For this repo, Swift work currently has three roles:
-
Toolchain lane The local Swift 6.3 setup and staging process are documented in freebsd-swift63-toolchain-reference.md.
-
Validation lane A stable Swift guest validation profile exists and should stay green while new diagnostics are added.
-
Diagnostic lane Small targeted Swift probes are used to isolate failures that simple C workload generators do not explain clearly enough.
If future work appears “too Swift-focused,” the right question is not:
Why are we leaving the C layer?
The right question is:
Which lower C layer is this Swift workload helping us distinguish?
If the answer is clear, the Swift work is justified.
If the answer is not clear, the Swift probe should be simplified or replaced with a better control.