Skip to content

Split platform code into Posix and Win32 modules - #647

Merged
kazu-yamamoto merged 6 commits into
haskell:masterfrom
kazu-yamamoto:platform-modules
Nov 15, 2026
Merged

kazu-yamamoto merged 6 commits into
haskell:masterfrom
kazu-yamamoto:platform-modules

Conversation

@kazu-yamamoto

@kazu-yamamoto kazu-yamamoto commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Fewer #if defined(mingw32_HOST_OS): where a module had POSIX and Windows versions of the same functions side by side, each platform now defines them in Network.Socket.Posix.* or Network.Socket.Win32.*, as Cmsg, MsgHdr and HostName already did, and the shared module imports one of them under a single conditional. The conditionals on mingw32_HOST_OS go from 90 to 36. No behaviour changes.

  • Join two adjacent conditionals in Network/Socket/ByteString/IO.hsc into one.

  • Network.Socket.Buffer: sendBufTo, sendBuf, recvBufFrom, recvBuf, recvBufNoWaitOr, sendBufMsg and recvBufMsg move to Posix.Buffer and Win32.Buffer. Network.Socket.Buffer keeps their types and documentation, the length checks and recvBufNoWait, and calls them qualified, so the documentation is not duplicated.

  • Network.Socket.Internal: the error guards, the readiness waits and withSocketsDo move to Posix.Internal and Win32.Internal, which also holds the Windows-only functions; Network.Socket.Internal keeps the documentation and what is shared. On POSIX, two definitions used to sit under each other's type signatures; they no longer do.

  • Network.Socket.Syscall: only the platform parts move (Posix.Syscall, Win32.Syscall): preparing a new or an accepted socket, accepting, telling what a failed connect means, and reportConnReset. socket, bind, connect, listen and accept stay shared.

  • The rest: the gathering writes of Network.Socket.ByteString (sendManyOnce, and one sendmsg for sendManyTo) with their foreign imports (Posix.ByteString, Win32.ByteString), Network.Socket.Fcntl (Posix.Fcntl, Win32.Fcntl), and socketPair (Posix.Unix, Win32.Unix). Network.Socket.ByteString.Internal no longer has conditionals; its unused c_recvmsg is gone. The lazy sendWith no longer goes its own way on Windows: that was for the No IO Manager give-ups removed in Windows needs WinIO: remove the No IO Manager code #644.

  • Network.Socket.ByteString.Lazy.Posix and .Windows are renamed Network.Socket.Posix.ByteString.Lazy and Network.Socket.Win32.ByteString.Lazy, like the other platform modules. Both are internal.

What is left is either the base types (Types, Cbits), imports of these modules, or a line or two inside shared code (Wait, STM, Info, Handle, Options).

Each commit was built and tested on macOS (127 examples, 0 failures) and on Windows 11 with GHC 9.12.4.20260713 (124 examples, 0 failures), with no compiler warnings beyond those master already has.

🤖 Generated with Claude Code

kazu-yamamoto and others added 6 commits November 15, 2026 11:43
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each platform defines the same functions in a module of its own, and
Network.Socket.Buffer keeps their types and documentation, the argument
checks, and a single conditional import.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The error guards, the readiness waits and withSocketsDo are defined per
platform; Network.Socket.Internal keeps their documentation and what is
shared.  The POSIX definitions no longer sit under each other's types.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Preparing a new or an accepted socket, accepting, telling what a failed
connect means, and reportConnReset are defined per platform; socket,
bind, connect, listen and accept themselves stay shared.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The gathering writes of Network.Socket.ByteString with their foreign
imports, Network.Socket.Fcntl, and socketPair.  The lazy sendWith no
longer goes its own way on Windows: that was for the MIO give-ups.
c_recvmsg in Network.Socket.ByteString.Internal was unused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Network.Socket.ByteString.Lazy.Posix and .Windows become
Network.Socket.Posix.ByteString.Lazy and Network.Socket.Win32.ByteString.Lazy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kazu-yamamoto
kazu-yamamoto merged commit 282cc44 into haskell:master Nov 15, 2026
9 checks passed
kazu-yamamoto added a commit that referenced this pull request Nov 15, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kazu-yamamoto
kazu-yamamoto deleted the platform-modules branch November 15, 2026 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant