Repository navigation
Conversation
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.
Fixes #2181.
emit_unfoldfolds a call whose constant arguments decide its matches. A live, non-constant argument becomes a probe, and the chosen arm body is wrapped in aletfor it. When the arm did not use that argument, the binding was dead, the emitter dropped it, and the argument was never evaluated: the C lane printed100forpick(boom(k), 0n, 100n)where the interpreter and JS evaluateboomand stop at the Nat wall.emit_unfoldnow refuses a fold whose body does not use one of its probes, so the call is emitted normally and evaluates its arguments like the other lanes.What changed
bend2/comp.ts,emit_unfold(+2/-1 lines): thebadpredicate that already rejects a fold now also reports a probe the folded body does not use.comp.tsmeasures 65,997 / 66,000 ttok (main is 65,981), so no cap change.tests/reg/unfold_drop_arg.bend: the issue's file; expectsbend: a Nat past the largest immediate 2^48-1andexit 1on all three lanes.tests/reg/unfold_drop_arg_run.bend: control; the same call withNat.sub(k, k)as the selector, so no fold happens. It already stopped on every lane before the fix, which isolates the literal selector as the trigger.Checks run (local, macOS arm64)
bun bend2/main.tsand-o .js && bun .jsprint the Nat wall (exit 1);-o drop && ./dropprinted100(exit 0). The emitted C had noboomcall and only100ullreachedNat.show.bend: a Nat past the largest immediate 2^48-1(exit 1); the emitted C now callsspin_boombeforespin_pick.bun gates/repo.ts->PASS: 56 / 56.tests/**/*.bend,bench/runtime/*/main.bendanddemos/*/main.bendthat compiles: 927 identical, 14 differ, plus the 2 new tests. The 14 aretests/check/{convoy_dependent,kind_domain_self_call,kind_generic_none,kind_none_is_type,kind_self_call_eta,meet_uses_in_arms},tests/compile/loop_peel_countdown,tests/cost/accumulator_loop,tests/io/bool_bridge,tests/proof/fold_assoc,tests/run/{bit_walking,graph_bfs,word_wrap_chains}andbench/runtime/raytrace. Each was built and run on the interpreted, JS and C lanes in both trees: byte-identical output, and their#|lines still match.tests/reg/unfold_arg_type.bend(prints0) andtests/run/nat_overflow.bend(wall, exit 1) still pass on all three lanes.The change is in the C emitter only; the interpreter and the JS emitter do not use
emit_unfold.Not run
bun gates/test.ts,gates/perf.ts,gates/ping.ts, Metal/CUDA: the cluster is unreachable from this checkout (ssh clusterrefused).gates/test.tsruns on the cluster, so this is a draft until it can run. No cluster qualification is claimed; the results above are local.AI-assisted.