EXPERIMENT: emit the wrapper unconditionally, so exit binds at runtime too

ISHIKAWA: why did exit injection still need compile-time knowledge? Because the
body-helper wrapper was only emitted when codegen already knew an exit
construct existed. The wrapper being conditional was the cause, not the wrapper
being necessary.

PREDICTIONS AND RESULTS
  P1 exit becomes runtime-bindable                    TRUE  returns 14, bound
                                                            after the build
  P2 codegen shrinks                                  TRUE  5094 -> 5044
  P3 cost 5-15% from a call frame on every fn         FALSE 0.37s -> 0.38s, ~3%
  P4 fixpoint holds                                   TRUE

Every fn now gets a body helper and a wrapper. It has to be unconditional:
early returns must route through something for an exit construct to observe
them, and codegen cannot know which fns will be bound after the binary exists.

Removed with the machinery: declare_exit, decorator_exit, cg_exit_target,
cg_exit_construct, and the injects_at_exit scanner branch.

Two controls failed and were rewritten rather than repaired --
no-exit-construct-emits-no-wrapper asserted the optimisation this removes, so
it is now inverted. The integration harness gained a seventh assertion: an exit
construct declared after the build replaces the result.

99/99 native, 7/7 integration, fixpoint gen2==gen3.
This commit is contained in:
bigmerge
2026-08-17 09:01:55 -05:00
parent 24f7fb5143
commit 285166c25c
3 changed files with 39 additions and 72 deletions
+8 -1
View File
@@ -34,6 +34,9 @@ el_val_t observe(el_val_t fn, el_val_t con, el_val_t r){
printf("SEEN %s/%s\n", (const char*)(intptr_t)fn, (const char*)(intptr_t)con);
return r; /* zero = do not refuse */
}
el_val_t double_result(el_val_t fn, el_val_t con, el_val_t r){
(void)fn; (void)con; return r * 2; /* exit: replace the result */
}
el_val_t refuse(el_val_t fn, el_val_t con, el_val_t r){
(void)fn; (void)con; (void)r; return 42; /* non-zero = short-circuit */
}
@@ -80,6 +83,10 @@ check "two constructs compose on one crossing" \
SEEN work/b
7" "$(cd "$WORK" && EL_CONSTRUCTS=two.txt ./prog 2>&1)"
printf 'work doubler exit double_result\n' > "$WORK/exit.txt"
check "an EXIT construct declared after the build replaces the result" \
"14" "$(cd "$WORK" && EL_CONSTRUCTS=exit.txt ./prog 2>&1)"
echo
echo " 6 assertions, $((6-FAILS)) passed, $FAILS failed"
echo " 7 assertions, $((6-FAILS)) passed, $FAILS failed"
exit $FAILS