Repository navigation
stdlib: process API, regular expressions, extern const with errno and signals, shared byte buffer - #1083
Merged
Conversation
This was referenced Sep 30, 2026
godofecht
force-pushed
the
feat/stdlib-process-regex
branch
from
September 30, 2026 14:46
a4353f9 to
7ab7fc8
Compare
… env and cwd (#961) std.process runs a program through posix_spawnp with an argument vector, captures stdout and stderr through a poll loop, feeds stdin text, applies environment and working-directory overrides, and kills the child with SIGKILL at a timeout. exit_code follows Python's subprocess: minus the signal number when a signal ended the child. It also reads this program's argv, environment and working directory, and resolves names on PATH. The loop and the bookkeeping are Flow. A small @cembed shim covers the calls whose prototypes or layouts differ by platform. It declares read, write, pipe and the rest under private asm names, so a program that declares them itself through extern still compiles. Nothing from runtime/ is linked, so Stage-A tools can use it. std.bytebuf re-exports compiler/src/bytebuf.flow, a leaf growable byte buffer with the ASCII class tests (#985). The process module collects output in it.
…962) scripts/tools/lib/regex.flow moves to lib/stdlib/regex.flow (std.regex) and grows capture groups, named groups, backreferences, lookahead, fixed-width lookbehind, IGNORECASE and ASCII flags, inline flags, search, match, fullmatch, finditer, findall, sub, split and escape. Match positions count code points as Python does; byte offsets into the Flow string are available too. findall, finditer, sub and split step over empty matches as Python 3.7 and later do. tests/lang/test_stdlib_regex.flow checks 82 calls against CPython's results. The challenge checker, triage_verify_failures, flow check and the doc-example checker now import std.regex. Their output is unchanged: the challenge scan over every tracked .flow file and its 43 recorded re.search cases, the doc-example report and ledger, and the triage report match the old matcher byte for byte. build_tool.sh and flow-driver rebuild a tool when lib/stdlib changes. docs/library/process.md and regex.md document both modules.
#1075) `const NAME: T` in an extern block (or `extern const NAME: T`) declares a C macro or constant with a Flow type. It emits nothing, so the value is the one in this platform's headers. `const NAME: T = "expr"` binds NAME to a C expression the C compiler evaluates, which reads sizeof and offsetof. The parser records it as an AST_CONST with ival 2, both type checkers bind the name with its declared type, and cgen writes a static const for the expression form. std.os declares the common signal and errno constants that way, reads and sets errno, and installs signal handlers: a counting handler the program polls (os_signal_watch / os_signal_take), or a Flow function passed as ptr<void>. tests/lang/test_extern_const.flow covers macro values that differ between macOS and Linux, struct sizes and offsets, errno after a failed call, and both handler kinds.
Both shims ran git in bash and left the output in build/ for the Flow program to read. The programs now run git themselves with std.process (ls-files, rev-parse, show and the stats-commit skipping walk), take --check and --update from argv, and the scripts only build and run them. Parity: python_ratchet prints the same report and --update leaves the baseline unchanged; with an entry removed from the baseline it reports the file and exits 1. repo_stats writes the same file list, commit and date as before; its line totals differ only by the lines of the two files this change edits.
The dynamics DSL (DySb), flow blocks (FbBuf) and shader DSL (ShBuf) each carried their own growable buffer with putc, puts, span and integer writers. They now use ByteBuf from bytebuf.flow, a leaf module, and the self-emit and roundtrip scripts emit it and link it into the frontend object beside fileio. The field DSL keeps FxBuf: it is fixed-capacity and reports overflow as an error, so moving it to a growable buffer would change behaviour. parity_dynamics_dsl, parity_flow_blocks and parity_shader_dsl (all but its Metal toolchain step) pass on the edited compiler. check_doc_examples.sh rebuilds its checker when lib/stdlib changes.
std.bytebuf re-exports ../../compiler/src/bytebuf.flow, so a program that imports std.regex (which uses std.bytebuf) and a compiler module (which imports .bytebuf) reached one file as lib/stdlib/../../compiler/src/ bytebuf.flow and as compiler/src/bytebuf.flow, loaded it twice, and failed with "Struct 'ByteBuf' already defined". tools/doc_examples hit this. Import paths are now normalized (`.` dropped, `name/..` folded), and a path that still differs is compared with the known ones as an absolute path against $PWD, which covers a program given by absolute path. tests/lang/test_import_normalized_path.flow imports the file three ways. test_shader_dsl_port uses ByteBuf. The MLIR corpus digests for it and for test_typecheck_overload_integration are re-recorded: flowc's normalized MLIR for both equals the Python generator's. lib/stdlib/process.flow leaves the MLIR corpus, since both generators refuse @cembed.
Adds docs/library/bytebuf.md, lists the four pages in mkdocs.yml and docs/nav.json, maps the modules in docs/coverage.json, and regenerates docs/library/stdlib-api.md.
…pty list tests/scripts/repo_stats.sh (from #1076) runs the counter in a scratch tree with a hand-written file list and no git. repo_stats now takes --inputs DIR to read files.txt, meta.txt and mode.txt from DIR, and the test passes it. ./flow test-scripts passes. With the ratchet baseline at total 0, git lists no Python and the file list was a read-only string literal that split_lines wrote into (SIGBUS). The list is now always a heap copy. The ratchet carries #1076's two excluded trees in its git call.
The MLIR corpus is re-recorded from 84806b0 for the programs that import changed compiler modules. The LSP completion transcript loses str_eq: the rewritten lib/stdlib/process.flow no longer exports the old helpers (run_cmd, have_cmd, env_is, str_eq), and no tracked program or document imported them from std.process.
…r and import path normalization
godofecht
force-pushed
the
feat/stdlib-process-regex
branch
from
September 30, 2026 15:25
7ab7fc8 to
a8cdecf
Compare
godofecht
added a commit
that referenced
this pull request
Sep 30, 2026
#1091 takes the Python resolver's rule: a string import may not be absolute, start with ~, or hold a .. component. After #1083, lib/stdlib/bytebuf.flow reaches the compiler's byte buffer as ../../compiler/src/bytebuf.flow, and std.regex depends on it, so the rule now exempts modules under lib/stdlib and lib/runtime. A program's own imports keep the Python rule. test_import_normalized_path still reaches bytebuf three ways: through std.bytebuf (the .. spelling), directly, and as ./compiler/src/./bytebuf.flow in place of the .. spelling it wrote itself. test_import_dot_paths and test_import_normalized_path both pass.
godofecht
added a commit
that referenced
this pull request
Sep 30, 2026
…1091) flowc prints the strict checker's warnings: non-exhaustive match, address-of-pointer and unknown handle handler, with the Python checker's text. FLOWC_WARNINGS=0 silences them and FLOWC_WERROR=1 makes them errors. It also ports the last strict checks: invalid `\x` escapes, unsafe import paths, `for` step 0, and flow stage params outside a flow output (#678). The C backend lowers record update `Name { ..base }` (#996). Import rule, reconciled with #1083: a string import may not be absolute, start with `~`, or hold a `..` component, as on the Python host. Modules of the Flow distribution itself (lib/stdlib, lib/runtime) are exempt, since std.bytebuf reaches the compiler's byte buffer as ../../compiler/src/bytebuf.flow and std.regex depends on it. #1083's normalization stays the only one. test_import_dot_paths and test_import_normalized_path both pass; the latter reaches bytebuf through std.bytebuf, directly, and as ./compiler/src/./bytebuf.flow. Corpus parity, per status, with main measured on the same machine: at parity 1025 + flowc better 10 = 1035 on both, with every per-status count identical. No file drops out of parity because of this PR, and the floor stays at 1033. Two earlier local runs scored 1031 and 1032; the difference was flowc build timeouts on examples/concurrency programs while other gates loaded the machine. The MLIR corpus is re-recorded from 84806b0 with #908's span_elem_addr fixture set aside, because the Python generator mis-emits it. Its goldens are unchanged.
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.
Standard library support so Flow tools stop needing bash shims and hand-rolled matchers and buffers.
std.process (#961)
lib/stdlib/process.flowruns a program with an argument vector throughposix_spawnp: captured stdout and stderr (or inherit,/dev/null, or stderr into stdout), stdin text, exit status (minus the signal number when a signal ended the child, as in Python'ssubprocess), a SIGKILL timeout, environment overrides or a cleared environment, and a working directory. It also reads this program's argv, environment and working directory, and resolves names onPATH.The spawn loop,
pollloop, environment merge andPATHsearch are Flow. A short@cEmbedshim covers the platform-specific calls. It declaresread,write,pipeand the rest under private asm names, so a program that declares them itself throughexternstill compiles. Nothing fromruntime/is linked, so Stage-A tools can use it. The oldrun_cmd/have_cmdwrappers pointed at runtime C that no longer exists;scripts/tools/install/setup.flownow uses the new API.std.regex (#962)
scripts/tools/lib/regex.flowmoves tolib/stdlib/regex.flowand gains capture groups, named groups, backreferences, lookahead, fixed-width lookbehind, IGNORECASE/ASCII flags, inline flags, andsearch,match,fullmatch, finditer (rx_next),findall,sub,splitandescape. Positions count code points as Python does; byte offsets are available too. Empty matches are stepped over as in Python 3.7+.The challenge checker,
triage_verify_failures,flow checkand the doc-example checker now import it. Their output is unchanged: the challenge scan over every tracked.flowfile plus its 43 recordedre.searchcases, the doc-example report and ledger, and the triage report match the old matcher byte for byte.extern const and std.os (#1075)
const NAME: Tin an extern block (orextern const NAME: T) declares a C macro or constant with a Flow type, and emits nothing, so the value is the platform's.const NAME: T = "C expr"binds NAME to a C expression, which readssizeofandoffsetof.std.osdeclares the common signal and errno constants that way, reads and setserrno, and installs signal handlers: a counting handler the program polls, or a Flow function passed asptr<void>.Shared byte buffer (#985)
compiler/src/bytebuf.flowis a leaf growable buffer with the ASCII class tests;std.bytebufre-exports it. The dynamics DSL, flow blocks and shader DSL now use it in place ofDySb,FbBufandShBuf, and the self-emit and roundtrip scripts link it into the frontend object. The field DSL keeps its fixed-capacityFxBuf, because it reports overflow as an error.The re-export exposed a resolver gap: one file reached as
lib/stdlib/../../compiler/src/bytebuf.flowand ascompiler/src/bytebuf.flowwas loaded twice. Import paths are now normalized, and paths that still differ are compared as absolute paths against$PWD.Shims converted
scripts/python_ratchet.shandscripts/update_repo_stats.shno longer run git. The Flow programs call git throughstd.processand take--update/--checkfrom argv; the scripts only build and run them. The ratchet report is identical and--updateleaves the baseline unchanged; with an entry removed it reports the file and exits 1. repo_stats produces the same file list, commit and date; its line totals differ only by the lines of the files this PR edits.Tests
tests/lang/test_stdlib_process.flow:echowith spaces and quotes,sh -c 'exit 3', asleep 5killed at 200 ms, stderr apart and merged, a missing program, env overrides and a cleared env, cwd, stdin and stdout larger than a pipe buffer, argv/env/cwd/which, and clashingexterndeclarations ofread,write,getcwdand friends.tests/lang/test_stdlib_regex.flow: 82 calls checked against CPython's results.tests/lang/test_extern_const.flow: macros that differ between macOS and Linux, struct sizes and offsets, errno after a failed call, both signal handler kinds.tests/lang/test_stdlib_bytebuf.flow,tests/lang/test_import_normalized_path.flow.Docs:
docs/library/process.md,regex.md,os.md,bytebuf.md, and the extern grammar indocs/LANGUAGE_SPEC.md.Gates
On macOS:
bootstrap_from_c.sh --verify,self_host_full.sh,roundtrip.sh,parse_coverage.sh --check,fmt_check.sh --check,tests/cgen/run.sh,./flow test-lang(224/224),corpus_parity.sh --check,parity_typecheck.sh --check,typecheck_rules.sh,parity_lowering,parity_effects,parity_proofs,parity_mlir,parity_field_dsl,parity_dynamics_dsl,parity_flow_blocks,parity_targets,parity_dap,parity_project_test,./flow test-scripts,check_doc_links.sh,check_doc_coverage.sh,check_doc_examples.sh --check-ledger,python_ratchet.shandchallenges/flow-specific/check.sh self-testall pass.parity_shader_dslpasses except its Metal step (no Metal toolchain on this Mac).Three MLIR corpus digests (test_dynamics_dsl, test_parser_python_forms, test_parser_span_mutability) are re-recorded: they import compiler modules this PR edits, and main's flowc and this branch's flowc emit identical MLIR from the same inputs.
On Linux (Ubuntu 24.04, glibc 2.39, gcc 13) the four new stdlib tests build from the bootstrap C and pass, both with default flags and with
-std=c11 -D_DEFAULT_SOURCE.The bootstrap C is regenerated last, in its own commit.
Fixes #961
Fixes #962
Fixes #1075
Fixes #985