SystemExtras: stop shadowing the C stat type (fixes build with swift-system 1.7.0)#349
SystemExtras: stop shadowing the C stat type (fixes build with swift-system 1.7.0)#349jackguac wants to merge 3 commits into
stat type (fixes build with swift-system 1.7.0)#349Conversation
…tem 1.7.0
`var stat: stat = stat()` names a local `stat` that shadows the imported C
`stat` type. swift-system 1.7.0 adds a public top-level `struct Stat`, after
which the unqualified initializer `stat()` no longer resolves to the C struct
(it binds to `Stat`, whose initializer even throws), so the file fails to
compile:
error: cannot convert value of type 'Stat' to specified type 'stat'
Rename the local to `statBuffer` and construct it via an explicitly-typed
`.init()` so the C `stat` type is selected unambiguously regardless of the
resolved swift-system version. No behavior change.
Affects FileOperations.swift (fstat) and FileAtOperations.swift (fstatat).
MaxDesiatov
left a comment
There was a problem hiding this comment.
Thanks for the contribution! The change makes sense to me overall, but it introduces CI failures. Would you be able to address those?
WasmKit 0.2.2's SystemExtras won't compile against swift-system 1.7.0 (new public `struct Stat` makes its shadowing `var stat: stat = stat()` mis-resolve). WasmKit requires swift-system with an open upper bound, so apps adding PatchSDK floated swift-system to 1.7.0 and failed to build. Declare swift-system 1.5.0..<1.7.0. Anchored on the SHIPPED PatchSDK target (NOT tests): SwiftPM prunes test-target deps for consumers, so a test-only anchor would not propagate the cap (a consuming app floats swift-system back to 1.7.0 — verified against IceCubesApp). SystemPackage is already linked transitively via WasmKit SystemExtras, so this adds no size. Upstream fix: swiftwasm/WasmKit#349 — remove cap when it ships.
….0-ready) swift-system 1.7.0 moved the C `stat` members into the `CSystem` shim, which breaks swift-nio's `_NIOFileSystem` (`st_ino`/`st_blocks`/`st_atim` unavailable without `import CSystem`) on Linux/Swift 6.2 under MemberImportVisibility. swift-nio is only a benchmark / component-model test dependency, but with the open `from: "1.5.0"` bound CI now resolves 1.7.0 and the Linux legs fail to compile it. WasmKit's own SystemExtras is made 1.7.0-ready by the source change in this PR; this cap only holds the test deps on swift-system 1.6.x until swift-nio's `_NIOFileSystem` builds against 1.7.0. Drop the upper bound at that point.
Hi @MaxDesiatov - thanks for flagging, sorry I didn't see this earlier. I've had a look into this and I'm 99% sure it's unrelated to this change (especially given this change is so minor).
To get CI to pass, I've pinned swift-system to pre 1.7.0 - but it's a little unrelated to my change here so if you'd prefer to fix separately or you want me to open a separate branch, let me know. It works locally for me now against Mac and Linux but I'll keep an eye on the CI steps when you run those. Edit: this was the swift-system push a few hours ago: https://github.com/apple/swift-system |
swift-format requires no spaces around the range operator in the swift-system version bound: "1.5.0"..<"1.7.0".
|
Looks like everything passed except formatting - pushed a commit for that |
|
All green now! :) Thanks for your patience |
|
Incidentally this will fix a few of the other PRs' CI checks I think because they started failing for the same reason as the above^ |

Summary
SystemExtrasfails to compile when the resolved swift-system is 1.7.0:Both call sites write:
The local variable is named
stat, which shadows the imported Cstattype. swift-system 1.7.0 adds a public top-levelstruct Stat. With that type now in scope, the unqualified initializerstat()no longer resolves to the Cstatstruct — it binds to swift-system'sStat(whose initializer is eventhrows), so the value is aStatwhile the annotation still wants the Cstat, and the file no longer type-checks.WasmKit'sPackage.swiftrequiresswift-systemwith an open upper bound (from: "1.5.0"), so any consumer whose dependency graph floats swift-system to 1.7.0 hits this — even with WasmKit itself pinned. swift-system ≤ 1.6.x is unaffected (no top-levelStat).Fix
Rename the local so it no longer shadows the C type, and construct it through an explicitly-typed
.init()so the Cstattype is selected unambiguously regardless of which swift-system version resolves:No behavior change —
statBufferis still a zeroed Cstatpassed by reference tosystem_fstat/system_fstatat. The two affected functions areFileDescriptor._attributes()(fstat) andFileDescriptor._attributes(at:options:)(fstatat).Verification
Built
SystemExtras(and the full package) on macOS / Apple Swift 6.3.2 with swift-system pinned to 1.7.0 (reproduces the failure onmain, compiles clean with the fix) and to 1.6.4 (still compiles — backward compatible):mainBuild complete!Build complete!Notes
swift-systemrequirement to an explicit supported range so consumers get a clear resolution diagnostic rather than a deep compile error when a future swift-system changes these APIs. This PR is the minimal source fix and is independent of that.