Repository navigation
perf: first-slice string concat and buffered text I/O (#747) - #1337
Merged
Merged
Conversation
A chain like a + b + c + d allocated n-1 buffers and recopied every prefix. Pure-string chains of three or more parts now lower to one __flowc_str_concatn call. std.string parses and formats integers on the caller buffer with explicit overflow and junk errors; std.io reads and writes with fread/fwrite. Cross-harness rows cover concat, parse/format and buffered file transform (Part of #747). Co-authored-by: Abhishek Shivakumar <[email protected]>
Make need/wrote mutable, expect concatn for the four-part chain and nested pairwise only for mixed numeric joins, and update the Stage-A roundtrip strcat fixture. Regenerate stdlib-api.md. Co-authored-by: Abhishek Shivakumar <[email protected]>
The checked-in bootstrap C now emits __flowc_str_concatn for pure-string + chains, matching compiler/src/cgen.flow (#747). Co-authored-by: Abhishek Shivakumar <[email protected]>
godofecht
marked this pull request as ready for review
October 4, 2026 18:51
import io.flow now sees libc free (void) from the #747 buffered I/O helpers, so assigning free(0) to i32 fails typecheck. Call it as void. Co-authored-by: Abhishek Shivakumar <[email protected]>
The stdlib catalog already indexes export functions from lib/stdlib, so live completion id 9 includes the nine new str_* APIs. The transcript golden was still at 203 items. Co-authored-by: Abhishek Shivakumar <[email protected]>
cgen.flow auto-merged: n-way string concat and record-update copy elision both remain. Bootstrap C regenerated to the combined fixed point after #1338. Co-authored-by: Abhishek Shivakumar <[email protected]>
Generated C grew by the __flowc_str_concatn helper, so compile_hello, compile_isolated_root and python_source file checksums needed a refresh on linux and darwin. MLIR corpus digests follow the changed io.flow and string.flow modules; file_transform is no longer accepted (std.io import). Co-authored-by: Abhishek Shivakumar <[email protected]>
This was referenced Oct 4, 2026
cgen.flow auto-merged: n-way string concat and #739 SIMD loop hints both remain. Bootstrap C regenerated to the combined fixed point. MLIR corpus already includes the for_vectorize_pragma_skip digest. Co-authored-by: Abhishek Shivakumar <[email protected]>
cgen and roundtrip auto-merged: n-way concat and #775 type identity both remain. Bootstrap C regenerated to the combined fixed point. MLIR corpus already includes test_type_identity. Co-authored-by: Abhishek Shivakumar <[email protected]>
cursor Bot
pushed a commit
that referenced
this pull request
Oct 4, 2026
Rebased onto #1337 string/IO (7b2dccb). Bootstrap C is the fixed point of compiler/src including concatn lowering and the cross-module RT/lifetime summary slice. Co-authored-by: Abhishek Shivakumar <[email protected]>
cursor Bot
pushed a commit
that referenced
this pull request
Oct 4, 2026
Fixed-point C after rebasing onto string/IO (#1337 / 7b2dccb). bootstrap_from_c.sh --regen (FIXED POINT at gen3) then --verify PASS. Co-authored-by: Abhishek Shivakumar <[email protected]>
7 of 8 tasks
cursor Bot
pushed a commit
that referenced
this pull request
Oct 4, 2026
Co-authored-by: Abhishek Shivakumar <[email protected]>
cursor Bot
pushed a commit
that referenced
this pull request
Oct 4, 2026
Rebased onto 7b2dccb (#1337). Source already includes FLOWC_PROFILE. Regen reached a fixed point at gen2; --verify matches compiler/src. Co-authored-by: Abhishek Shivakumar <[email protected]>
7 of 8 tasks
godofecht
added a commit
that referenced
this pull request
Oct 4, 2026
* feat: emit and consult cross-module RT/lifetime summaries (#765) Add a compact $fname effect/lifetime summary for public functions (callback/frame safety, alloc/free, block/lock, I/O, declared domain, one provenance edge) and consult it during type checking so imported calls compose. Summaries ride in the module effect table and are erased before codegen. Co-authored-by: Abhishek Shivakumar <[email protected]> * fix: use let mut and typed null in RT summary helpers The edited compiler rejected immutable reassignment and a bare null string in the new summary worklist and selftest. Co-authored-by: Abhishek Shivakumar <[email protected]> * fix: wire rt_summary into Stage-A roundtrip and MLIR corpus typecheck and sem_check import the new module, so per-module compile and the frontend link need its object. The overload-integration lang test imports typecheck.flow, so its recorded MLIR digest picks up the new module. Co-authored-by: Abhishek Shivakumar <[email protected]> * fix: regenerate bootstrap C after RT/lifetime summaries Rebased onto #1337 string/IO (7b2dccb). Bootstrap C is the fixed point of compiler/src including concatn lowering and the cross-module RT/lifetime summary slice. Co-authored-by: Abhishek Shivakumar <[email protected]> --------- Co-authored-by: Cursor Agent <[email protected]>
cursor Bot
pushed a commit
that referenced
this pull request
Oct 4, 2026
Co-authored-by: Abhishek Shivakumar <[email protected]>
godofecht
added a commit
that referenced
this pull request
Oct 4, 2026
* feat: opt-in runtime memory profiler for #740 Add a FLOW_MEM_PROFILE runtime in flowc-generated C that counts heap allocations, peak live heap, peak RSS, compiler-temp bytes and copy volume without rewriting workload sources. The #728 harness records those fields from FLOW_MEM_PROFILE_OUT, and the memory/allocation cross-harness rows now do real allocate/copy/RSS work. Co-authored-by: Abhishek Shivakumar <[email protected]> * test: tighten mem_profile golden around wrapped malloc flow_mem_malloc(32) contains the substring malloc(32), so the negative check now looks for the unwrapped call form. Co-authored-by: Abhishek Shivakumar <[email protected]> * test: retarget goldens after FLOW_MEM_PROFILE prelude The profiler prelude wraps malloc/realloc, mentions temp lifetime bytes, and uses a constructor attribute. Tighten the attribute and lifetime goldens to the annotation-splice payload, expect the counting wrappers in grow helpers, and refresh hello.c checksums. Co-authored-by: Abhishek Shivakumar <[email protected]> * test: refresh CLI hello.c checksums after #1337 concatn Co-authored-by: Abhishek Shivakumar <[email protected]> * test: update MLIR corpus digests for filled #740 workloads Co-authored-by: Abhishek Shivakumar <[email protected]> * fix: regenerate bootstrap C after rebase onto main Co-authored-by: Abhishek Shivakumar <[email protected]> --------- Co-authored-by: Cursor Agent <[email protected]>
This was referenced Oct 5, 2026
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.
Part of #747.
Intent
Audit strings, parse/format and file I/O for short-job Python comparisons, then ship a first slice that cuts per-join heap traffic and gives explicit, buffered stdlib paths.
This ports the
archive/perf/747-string-iodesign (one-pass concat of pure-string+chains) to flowc and adds the linear-scan helpers the acceptance criteria need.Overlap check
No open PR implements #747. Nearby PRs (#1265 native baselines, #1267 parallel scaling, #1268 cold-start vs Python) touch the harness, not string concat or stdlib I/O.
What changed
a + b + c + dof already-string operands lowers to one__flowc_str_concatncall (one length pass, one allocation, each part copied once). Two-part joins and mixed numeric chains keep pairwise__flowc_str_concat.std.stringparses/formats i64 on the caller buffer with explicit overflow, empty, sign-only and trailing-junk errors (Pythonint()on ASCII). Line walking does not allocate.std.ioreads and writes withfread/fwriteof a known size; a missing file isok = false.runtime_string_concat,runtime_parse_format,runtime_buffered_iorows plus CPython twins. Existingcold_file_transformnow uses the buffered path instead of per-characterfgetc/fputc.Evidence
Baseline before this change: nested
__flowc_str_concatfor every+;lib/stdlib/string.flowwasstrlen/strcmp/concatonly;io.flowhad no file helpers;cold/file_transformusedfgetc/fputc.Targeted proofs:
flowc: PASS(concatn present in the preamble)./compiler/scripts/bootstrap_from_c.sh --verify— PASS (fixed point at gen3)./flow tool tests/cgen/run.flow— 114 passed, 0 failed (includesstring_concat_chain)./flow test-langontest_string_concat_chain,test_stdlib_string_io,test_strings,test_string_concat_numbers,test_const_string_concat,test_cast_in_string_concat— 6/6./flow tool tests/bench_harness/run.flow— pass=43 fail=0./flow tool gen_stdlib_docs --checkandstdlib_api_drift— pass./flow tool python_ratchet— PASS (new twins are under the exemptbenchmarks/baselines/python/tree)./flow tool bench_harness --smokeon this Linux host (3 reps, medians in seconds):runtime_string_concat+chainruntime_parse_formatruntime_buffered_iocold_file_transformflow run(compile+run) vspython3; not the I/O kernelThe four-part golden fails on nested pairwise joins. Parse tests fail if overflow wraps or junk is accepted.
Remaining gaps (not this PR)
"x=" + n + " y=" + mstill uses nested pairwise joins.+to__flow_str_concatonly.parse_floatyet; float format still goes through__flowc_str_of_f64/ snprintf.malloc, never freed).int()on ASCII.memory/allocation_copyis still a stub).flow runpays compile; that belongs with [Performance #727] Minimize compiled-program cold start and runtime initialization overhead #746, not this I/O kernel.Risk
io_read_filerefuses files larger than 2^31-1 rather than truncating.Agent handoff
Bootstrap C is committed separately (
fix: regenerate bootstrap C after n-way string concat). Do not merge.