Add the Windows half of the converged Kernel.Lock surface - #6
Conversation
Byte-range file locking had only one realised L3 policy tier — swift-posix's POSIX Kernel Lock. Portable code that needed a machine-wide file lock therefore had to name POSIX.Kernel.Lock directly: an unconditional edge from portable code to a host substrate, which compiles on POSIX and drags swift-iso-9945 into the Windows build, where it does not compile. The Win32 syscall surface already existed at L2 (Windows.`32`.Kernel.Lock in swift-windows-32) with the same shape as the POSIX side. This adds the missing L3-policy tier so swift-kernel's L3-unifier can export one lock API on every platform. Token is not aliased yet: it is the sole content of the L2 Windows 32 Kernel Lock target, which does not compile off-Windows on swift-windows-32 main.
coenttb
left a comment
There was a problem hiding this comment.
Independent review at head b6365aa145e29bee8b2459437e80e29c5b786af9.
Verdict: blocking — the new target does not compile on Windows
The design is right. The implementation collides with a declaration that already exists in this package, and the Windows leg proves it.
The evidence
The Windows leg on the reviewed head had no conclusion — it was cancelled by the CI regime at about an hour. I re-dispatched it (run 31251521303). It was cancelled again at the same ceiling, but not before the compiler reached this target and failed it. Six hard errors, all the same:
Sources/Windows Kernel Lock/Windows.Kernel.Lock.swift:50:30: error: ambiguous type name 'Lock' in 'Windows.Kernel'
Sources/Windows Kernel Lock/Windows.Kernel.Lock.swift:69:30: error: ambiguous type name 'Lock' in 'Windows.Kernel'
Sources/Windows Kernel Lock/Windows.Kernel.Lock.swift:108:30: error: ambiguous type name 'Lock' in 'Windows.Kernel'
Sources/Windows Kernel Lock/Windows.Kernel.Lock.swift:123:35: error: ambiguous type name 'Lock' in 'Windows.Kernel'
Sources/Windows Kernel Lock/Windows.Kernel.Lock.swift:124:34: error: ambiguous type name 'Lock' in 'Windows.Kernel'
Sources/Windows Kernel Lock/Windows.Kernel.Lock.swift:125:33: error: ambiguous type name 'Lock' in 'Windows.Kernel'
error: emit-module command failed with exit code 1
with the compiler naming both candidates:
Sources/Windows Kernel/Windows.Kernel.Lock.swift:23:26:
note: found candidate with type 'Windows.Kernel.Lock' (aka 'Windows.`32`.Kernel.Lock')
Sources/Windows Kernel Lock/Windows.Kernel.Lock.swift:45:
note: found candidate with type 'Windows.Kernel.Lock'
So the cancellation is not an evidence gap any more. The leg is red on substance, and it would be red regardless of the time ceiling.
The cause
Sources/Windows Kernel/Windows.Kernel.Lock.swift already declares, on main:
extension Windows.Kernel {
public typealias Lock = Windows.`32`.Kernel.Lock
}This PR adds a second Windows.Kernel.Lock — the empty policy enum — in a new target that itself public imports Windows_Kernel. Both declarations are visible at the same time, in the same namespace, under the same name, so every reference in the new file is ambiguous.
The header comment in the new file cites [PLAT-ARCH-008k] and states the point exactly:
Windows.Kernel.Lockis a distinct empty policy enum, not a whole-namespace typealias to the L2-canonicalWindows.\32`.Kernel.Lock`
That is the correct reading of the rule. But the whole-namespace typealias the comment argues against is still present in Windows Kernel and was not removed. The PR adds the intended form beside the form it is meant to replace instead of in place of it.
What the fix has to do
The whole-namespace typealias in Windows Kernel has to go, and the policy tier has to live only in the new target. That is a decision with consequences worth stating rather than patching around:
- Any existing consumer resolving
Windows.Kernel.Lockthrough theWindows Kernelumbrella will stop resolving unless it also depends onWindows Kernel Lock. Please check the in-package and in-org consumers before landing, not after. - Deleting the typealias narrows what
Windows.Kernel.Lockmeans. Today it forwards the entire L2 namespace; afterwards it exposes exactly the members this PR aliases. See the next point — that set is currently short.
Renaming the new enum or qualifying the references would silence the compiler and leave two competing spellings of the same policy namespace, which is the outcome [PLAT-ARCH-008k] exists to prevent. I would not accept that.
Second finding: the converged surface is asymmetric
Independent of the compile error, and worth fixing in the same pass, because it reproduces the exact failure class this chain exists to eliminate.
POSIX.Kernel.Lock aliases Error, Range, Kind, Acquire, Token, Scope, plus Immediate, lock, unlock. This PR aliases Error, Range, Kind, Acquire, Immediate, lock, unlock — no Token, no Scope.
Once swift-kernel exports these as Kernel.Lock, that difference becomes portable-facing: Kernel.Lock.Token and Kernel.Lock.Scope will resolve on POSIX and fail on Windows. Portable code that reaches for the RAII handle compiles for its author and breaks on the Windows leg — which is precisely the shape of the defect the chain is fixing, relocated behind a converged name.
On the two members specifically:
Token. The stated reason for omitting it is that the L2Windows 32 Kernel Locktarget does not compile off-Windows on swift-windows-32mainbecause ofClock.Continuous.now. That is no longer true.2aec5a2("Fix Windows lock deadline clock access") is already an ancestor of swift-windows-32main— I verified the ancestry directly.Windows.32.Kernel.Lock.Tokenexists and its file is#if os(Windows)-guarded throughout. Please re-measure and alias it; the blocker cited in both the description and the source comment has been resolved upstream.Scope. There is noScopeanywhere in swift-windows-32 — I searched bothWindows 32 Kernel CoreandWindows 32 Kernel Lock. IfScopeis inherently a POSIX record-locking notion with no Win32 counterpart, then it should not be reachable through the convergedKernel.Lockname at all, and the asymmetry belongs upstream in swift-kernel's export rather than here. Worth resolving deliberately rather than by omission.
What is right, and should survive the fix
I want to be clear that the approach is sound, because the fix should not be mistaken for a redesign.
- The three-tier placement is correct: L2 canonical at swift-windows-32, L3 policy here, L3 unifier at swift-kernel. The layering table in the file header is accurate.
- The composition is genuinely conditional, not a widened unconditional edge. The whole body is
#if os(Windows); the manifest target carries no cross-platform substrate edge; and the consuming side in swift-kernel conditions both the manifest product and the source import. Off-Windows this target contributes nothing. - The wrappers correctly compose the L2 typed syscall forms with the
Windows.Kernel.Descriptorpolicy typealias, and the function surface (lock,unlock,Immediate.lock) matchesPOSIX.Kernel.Lockmember for member. Range.fileexists at L2 with a documented Win32 translation of the POSIXl_len == 0idiom, so the downstreamrange: .filecall site in swift-build-coordinator will resolve.
Chain note
The description says this package's non-Windows build is red on main because of a swift-windows-32 defect not yet on that repository's main. That is no longer accurate: 2aec5a2 is on swift-windows-32 main. swift-microsoft/swift-windows-32#19 is therefore not a prerequisite for this PR — its remaining delta is Windows directory-stream work unrelated to locking. Please re-measure the non-Windows legs rather than carrying the pre-existing-red claim forward.
Next owner and downstream
Author, in this repository: remove the whole-namespace typealias from Windows Kernel, alias Token, settle Scope, and re-run the Windows leg to a real conclusion.
I am holding review of swift-foundations/swift-kernel#9 and swift-foundations/swift-build-coordinator#2 until this compiles. Neither can be soundly assessed while the product they consume does not build.
The umbrella target's whole-namespace `typealias Lock = Windows.`32`.Kernel.Lock` collided with the L3-policy enum this target declares, making `Lock` an ambiguous type name in Windows.Kernel. [PLAT-ARCH-008k] calls for the policy enum, not the whole-namespace alias, so the alias is deleted; it had no in-repo consumers. Also aliases the RAII `Token`. The stated reason for omitting it (the L2 "Windows 32 Kernel Lock" target not building off-Windows) is stale: the clock fix is an ancestor of swift-windows-32 main. `Scope` stays absent — it has no Win32 counterpart and must not be exposed one-sided.
Repair lane: both review blocks cleared (head
|
Correction —
|
coenttb
left a comment
There was a problem hiding this comment.
Independent re-review at exact head ba57485eb0f7100410413a039857a2909bd68641.
Verdict: BLOCKED — source clean, package approval gate not met
I reviewed all three commits and the complete four-file diff. The repair removes the conflicting whole-namespace Windows.Kernel.Lock alias, makes the L3 policy enum the sole declaration, adds the correct Windows 32 Kernel Lock product dependency, and aliases Token. The changed Scope note says the exposure remains one-sided and states what must happen on both platforms; it does not claim that the POSIX exposure problem has been solved. swift-foundations/swift-posix#7 remains the separate owner of that follow-up.
Exact-head source evidence is good: PR run 31264288112 concluded success, and Windows job 93119879917 genuinely compiled both Windows_32_Kernel_Lock and Windows_Kernel_Lock before completing successfully.
The approval gate is nevertheless not satisfied. The later exact-head full-tier run 31265590263 concluded failure. Its Windows job and ci / matrix / ci-ok succeeded, but the DocC job was killed with exit 137 in the central symbol-graph combiner after the package build completed. I found no source diagnostic in that failure; resource exhaustion is the inference. The sanctioned public-package approval transaction requires both exact-head ci / matrix / ci-ok and a successful exact-head full tier, so approval must remain withheld.
Smallest next step: the repository maintainer or CI operator should dispatch one fresh full-tier run at this unchanged head. If it succeeds, re-guard this SHA and approve through the bot transaction. If exit 137 repeats, the smallest fixer scope moves to the central DocC workflow owner in swift-institute/.github; no source patch in this PR is presently justified.
Checked evidence: live PR/head/base/state, complete commits and diff, both exact-head runs, Windows logs, and the sanctioned approval contract. Task-attributed evidence: the prior repair and Scope correction records. Inferred evidence: exit 137 reflects runner capacity rather than a product diagnostic. No merge or PR-state change is authorized.
|
Owner Issue: #7. This pull request is linked implementation for that record; this comment does not auto-close it. |
|
Semantic owner link (swift-institute/.github#591): this open PR implements swift-foundations/swift-windows#7. Exact PR head at adjudication: ba57485. |
What
Adds the
Windows Kernel LockL3-policy target and product:Windows.Kernel.Lockas a distinct empty policy enum with per-member typealiases to the L2-canonicalWindows.\32`.Kernel.Lock, pluslock/unlock/Immediate.lockwrappers over theWindows.Kernel.Descriptorpolicy typealias. MirrorsWindows.Kernel.Filein this package andPOSIX.Kernel.Lock` in swift-posix.Why
Byte-range file locking was the one kernel domain with only a POSIX L3 policy tier. Portable code needing a machine-wide file lock had to name
POSIX.Kernel.Lockdirectly — an unconditional edge from portable code to a host substrate. It compiles on POSIX and drags swift-iso-9945 into the Windows build, where it does not compile (cannot find 'errno' in scope). That is exactly the failure mode observed in swift-foundations/swift-build-coordinator's Windows leg.The Win32 syscall surface (
LockFileEx/UnlockFileEx, error/range/kind vocabulary) already existed at L2 with the same shape as the POSIX side. Only this policy tier and the matching swift-kernel export were missing. With both,Kernel.Lockresolves on every supported platform and consumers reach the substrate only behind swift-kernel's own platform conditions.Paired with swift-foundations/swift-kernel (converged export), which consumes the product this PR publishes.
Notes for review
#if os(Windows)-guarded, so no non-Windows target changes shape.Token(the~CopyableRAII handle) is deliberately not aliased. It is the sole content of the L2Windows 32 Kernel Locktarget, which does not compile off-Windows on swift-windows-32main(type 'Clock.Continuous' has no member 'now'). Every other lock member is canonical inWindows 32 Kernel Core, already reachable viaWindows Kernel.mainfor that same swift-windows-32 defect (Windows 32 Kernelumbrella depends onWindows 32 Kernel Lock). Reproduced onmainwith this branch stashed. This PR neither causes nor fixes it; a fix exists upstream but is not on swift-windows-32mainyet.