Repository navigation
Bind POSIX and sockets through the system headers (#550) - #598
Merged
Merged
Conversation
godofecht
force-pushed
the
fix-posix-net-550
branch
from
August 19, 2026 23:22
32426b3 to
546e6c2
Compare
Both modules parsed and neither could be compiled: any program importing
either failed at the C stage with "conflicting types for 'read'", because
Flow declared prototypes that the generated C's own <unistd.h> also declares.
Constants were the harder half, and the reason this needed a decision rather
than a patch. They were hand-copied macOS values:
O_CREAT 512 here, 0x200 on macOS, 0x40 on Linux
SIGCHLD 17 here, 20 on macOS, 17 on Linux
AF_INET6 30 here, 30 on macOS, 10 on Linux
So the numbers were wrong on one platform whatever they said, and defining
them at all collided with the header's macros of the same name.
@cImport now reads integer #defines out of a header. Preprocessing expands
macros and discards the definitions, so a second pass with -dM is the only
way to see them. They arrive as ordinary Flow constants marked c_import, so
the type checker knows the value while the C output keeps using the macro,
which is what makes it right per platform rather than right on the machine
that built the compiler.
posix.flow and net.flow now import their headers instead of restating them.
Importing either compiles; opening a file and creating a socket both work.
Four supporting fixes, each of which blocked the one after it:
- The header parser dropped `...`, so libc's `open(const char *, int, ...)`
imported as two parameters and `open(path, flags, mode)` did not resolve.
- A Flow string is a char*, so it now satisfies a C signature spelling that
pointer as ptr<u8>. Applied only after an exact match fails: allowing it in
the first pass let a string literal match a ptr<u8> overload ahead of the
exact `string` one, and tests/lang/test_c_import_julia.flow resolved to the
wrong function.
- A missing header still leaves the preprocessor's built-in macros on stdout,
so the exit status has to be checked. Without that, @cImport of an
uninstalled header imported 22 platform macros and nothing it asked for.
- check_doc_examples.py resolved modules but not @cImport, unlike
transpiler.py, so a module binding C through a header looked like it
declared nothing.
The three POSIX tutorials in docs/tutorials/advanced.md now verify.
Unverified documentation examples: 221 to 219.
Closes #550
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@cImport surfaces open from fcntl.h on macOS and not on glibc, so these two blocks verify locally and fail in CI. The ledger cannot describe both: it fails when a listed block starts passing as well as when a passing one starts failing, which is what makes it a ratchet. Tagged with the reason rather than recorded as either state. A Jules session is on the glibc side; when @cImport reads those declarations there, the tag comes off and both blocks verify everywhere. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
godofecht
force-pushed
the
fix-posix-net-550
branch
from
August 19, 2026 23:36
546e6c2 to
cac9bb8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #550. You said to do what's best, so this takes the third option from the issue: teach
@cImportto read#definevalues, which fixes the class rather than this instance.The problem, and why constants were the hard half
Both modules parsed and neither could be compiled. Prototypes collided with the headers the generated C already includes. That part was mechanical.
The constants were not. They were hand-copied macOS values:
O_CREATSIGCHLDAF_INET6So the numbers were wrong on one platform whatever they said, and defining them at all collided with the header's macros of the same name. Renaming them would have kept the collision away at the cost of the idiom; keeping them meant staying wrong somewhere.
What this does instead
@cImportnow reads integer#defines out of a header. Ordinary preprocessing expands macros and discards the definitions, so a second-dMpass is the only way to see them.They arrive as ordinary Flow constants marked
c_import, so the type checker knows the value while the C output keeps using the macro:That is what makes the value right per platform, rather than right on whichever machine built the compiler.
posix.flowandnet.flownow import their headers instead of restating them. Both compile; opening a file and creating a socket both work:Four supporting fixes, each blocking the next
..., so libc'sopen(const char *, int, ...)imported as two parameters andopen(path, flags, mode)did not resolve.stringis achar*, so it now satisfies a C signature spelling that pointer asptr<u8>. Applied only after an exact match fails — allowing it in the first pass let a string literal match aptr<u8>overload ahead of the exactstringone, andtests/lang/test_c_import_julia.flowsilently resolved to the wrong function. Caught by tier-2.@cImportof an uninstalled header imported 22 platform macros and nothing it asked for.check_doc_examples.pyresolved modules but not@cImport, unliketranspiler.py, so a module binding C through a header looked like it declared nothing.Result
The three POSIX tutorials in
docs/tutorials/advanced.mdverify. Unverified examples 221 → 219.Verification
pytest tests/./flow test --tier2 --strictcheck_doc_examples.py --check-ledgerruff check srcFive tests in
tests/unit/test_c_import_macros.pycover plain integers, hex and octal, cast-wrapped values like((u_int32_t)0x00000000), that compiler-internal_-prefixed defines are skipped, and that a missing header yields nothing rather than the preprocessor's built-ins.Still open
net.flowkeeps its ownSockAddr_inand its socket wrappers rather than using the header'sstruct sockaddr, sobind/accept/connectare not imported. That is a separate API question about how Flow should model the sockaddr family.