perf(compile): fix O(N^2) map-lookup compiler hang (audit-resolve regression) + attest sha fix#14
Merged
Merged
Conversation
…e_bytes builtin sha256_hex_file read file bytes through the bare `read_file_bytes` builtin, which returns a string-like buffer whose arr_len reads its first content bytes as the length (0x6161 for "aa"; garbage-negative for bytes >=128). arr_len + sha_final_block then overran and segfaulted on any non-ASCII file -- including the physicify coinage. Read via read_file_bytes_open (stdlib/file.rail), which returns a real int array; file_size_bytes uses read_file_size. verify.rail and attest.rail both fixed; they now mint+verify the coinage clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Regression from the audit-resolve merge: the float-dataflow passes (collect_argf_unified / collect_hofpos) search the arity/marker maps millions of times, and two compounding costs made any json-importing TLS program -- e.g. tools/attest/attest.rail -- take >30 min to compile, a de-facto hang. 1. efind/afind/rmap_set/rmap_eq used `length env == 0` as their empty check. _rail_length walks the whole list, so that test is O(N) PER recursion step, making each map lookup O(N^2). Switched to `== []` (O(1)). Identical return values -> identical codegen. 2. collect_argf_unified always ran a second collect_argf_fix, even when the higher-order-float seed had already converged (hof2 == hof1). Return argf1 directly there -- a pure re-derivation. Only a float FOLD needs the 2nd pass. attest.rail >30min -> 12s; self-compile faster; 177/177 tests; 2-pass self-host fixed point byte-identical (rail_native reseeded). Bootstrapped from master's B1-capable seed since compile.rail's own source uses char_from_int 0. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Lands the compiler perf fix on master, rebased onto current master (incl. B1/B2 PR #12).
The hang: audit-resolve's float-dataflow passes search the arity/marker maps millions of times through efind/afind, whose
length env == 0empty-check is O(N) per step (_rail_length walks the list) -> O(N^2) lookups. Any json-importing TLS program (attest.rail) took >30 min to compile. Fixed to== [](O(1)) + skip a redundant float-path fixpoint when the HOF seed already converged. Both byte-identical.Verified on this branch (bootstrapped from master's B1-capable seed, since compile.rail uses char_from_int 0):
Also includes the attest sha fix (read_file_bytes_open) so verify.rail/attest.rail digest binaries correctly.
🤖 Generated with Claude Code