Skip to content

fix(check): an error page stops at a budget, so a huge or endless normal form still prints (#1041) - #2370

Open
HamedShams wants to merge 1 commit into
bendlang:mainfrom
HamedShams:fix/bounded-error-print
Open

HamedShams wants to merge 1 commit into
bendlang:mainfrom
HamedShams:fix/bounded-error-print

Conversation

@HamedShams

Copy link
Copy Markdown
Contributor

Fixes #1041, including the endless case from #1231 that was folded into it. Probably #2362 too: I can't run that program, but a field-count mismatch that reports nothing and grows past any memory cap is exactly what the second test below does on main.

What goes wrong

To print an error or a goal, expr_show first builds the term's whole normal form. That form can be exponentially larger than the term (dup(22n, xs) is 2^22 calls of List.append), or not exist at all (@unsafe def two(): two). So one missing annotation costs gigabytes before a single character is printed, or the page never comes.

It is only the printing. #1041's file with the annotation added checks in 0.06 s.

The fix

The note on #1231 says a bounded printer would cover both, so that is what this is. expr_show reads the term in a copy of the book that carries a budget:

  • past 2^20 unfolds, a def stays folded as it stands (term_wnf)
  • past 2^16 nodes, term_snf stops, and the page keeps the first 1024 characters of the form and ends in ...

A page that stays under both prints exactly what it prints on main. An ordinary book has no budget, so checking itself only pays one undefined test per unfold and per term_snf call.

Why these numbers: the largest page in tests/ is page/deep_list_walk with 3,001 nodes and 3,001 unfolds, and every other one is under 70. 2^16 nodes is about 200 KB of text, and nobody reads past that. Unfolds get more room because they cost time but little memory: 2^20 of them take about 0.3 s, and a def that grows its argument forever stops after 0.9 s at about 400 MB.

Numbers

bun bend2/main.ts f.bend --check-only on an M5 Pro, main at 698b3c9:

file main this PR
#1041's file at 18 levels 0.46 s, 444 MB, a 6.8 MB page 0.09 s, 106 MB, a 1.4 KB page
at 20 levels 1.64 s, 1.56 GB, a 27 MB page the same
at 22 levels not run here: 4x again, and the issue has it killed at a 2 GB cap the same
a constructor missing a field, 19 levels 0.86 s, 770 MB 0.09 s, 104 MB
a false {==}, 19 levels 0.85 s, 1.09 GB 0.09 s, 103 MB
#1231's file does not return (stopped at 10 s) 0.09 s

#1231's goal now prints as {(%two : P(_); x) == y : P(2n)}, with the rewrite left where it stands.

Tests

All three are in tests/page/:

What was run

  • every file under tests/ through bun bend2/main.ts <file>, on main and on the branch: 1,873 files, same output on all of them
  • the other 103 .bend files in the repo with --check-only: same output
  • the 26 files of tests/page through --checkup, built the way gates/test.ts builds it: all match their #| lines
  • pages around the budget, main against the branch, in four error shapes (unannotated let, missing field, false {==}, a goal): identical up to 14 levels of the tree, which is a 98 KB page, and cut from 15 or 16 levels on. An evaluation of 1,048,000 unfolds prints the same 0n; one of 1,049,000 prints the call it stopped at
  • the 5 benches of bench/checker, alternating runs of main and the branch: no difference I can tell from noise. On the two that unfold the most, proofs_3200 and defs_12800, the fastest and the lower-quartile run of 30 are within 0.5% and 1.5%, in both directions
  • gates/repo.ts: passes. bend.ts goes from 45,949 to 46,119 ttok

Not run: gates/test.ts, perf.ts and safe.ts, since they need the minis.

What changes for a page past the budget

Such a page used to print in full, however long, and is cut now. So a page between 2^16 nodes and whatever memory allowed, hundreds of KB that did print, is 1 KB. And an evaluation that needs more than 2^20 unfolds shows the call it stopped at instead of its value. Both numbers are one edit in expr_show if you'd rather have them elsewhere.

This edits bend2/bend.ts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A "cannot infer" error on a let is printed fully expanded, so it grows as 2^n and exhausts memory

1 participant