ocaml: && / || short-circuit fix + bfs_grid.ml baseline (5x5 grid, dist 8)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
Before: `:op` handler always evaluated both operands before dispatching
to ocaml-eval-op. For pure binops that's fine, but `&&` / `||` MUST
short-circuit:
if nr >= 0 && grid.(nr).(nc) = 0 then ...
When nr = -1, real OCaml never evaluates `grid.(-1)`. Our evaluator
did, and crashed with "nth: list/string and number".
Fix: special-case `&&` and `||` in :op dispatch, mirroring the same
pattern already used for `:=` and `<-`. Evaluate lhs, branch on it,
and only evaluate rhs when needed.
Latent since baseline 1 — earlier programs never triggered it because
the rhs was unconditionally safe.
bfs_grid.ml: shortest path through a 5x5 grid with walls. Standard
BFS using Queue.{push,pop,is_empty} + Array.init for the 2D distance
matrix. Path 0,0 -> ... -> 4,4 has length 8. 155 baseline programs
total.
This commit is contained in:
@@ -407,6 +407,19 @@ _Newest first._
|
||||
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
|
||||
'a tree`) with insert + in-order traversal. Tests parametric ADT,
|
||||
recursive match, List.append, List.fold_left.
|
||||
- 2026-05-10 Phase 5.1 — `&&` / `||` short-circuit fix + bfs_grid.ml
|
||||
baseline (BFS shortest path on 5×5 grid with walls, dist 8). The
|
||||
evaluator's `:op` handler was evaluating BOTH sides of `&&`/`||`
|
||||
before dispatching, mismatching OCaml's left-to-right
|
||||
short-circuit semantics. This was invisible in earlier baselines
|
||||
because their rhs was always safe regardless of lhs, but a guard
|
||||
like `if nr >= 0 && grid.(nr).(nc) = 0 then …` crashes with
|
||||
"nth: list/string and number" when nr = -1 because `grid.(-1)`
|
||||
still gets evaluated. Fix: dispatch `&&` and `||` specially in
|
||||
`:op` to evaluate lhs first and only evaluate rhs if needed.
|
||||
Bug latent since baseline 1; surfaced by bfs_grid with bounds-
|
||||
checked grid access. bfs_grid optimal path 0→1→1→2→2→3→3→3→4 of
|
||||
weighted length 8. 155 baseline programs total.
|
||||
- 2026-05-10 Phase 5.1 — tarjan_scc.ml baseline (Tarjan's
|
||||
strongly-connected components on 8-node digraph → 4 SCCs).
|
||||
Graph: 0→1→2→0 (cycle) plus 2→3, 3→4, 4→5→6→4 (cycle), 4→7.
|
||||
|
||||
Reference in New Issue
Block a user