Repository navigation
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
Open
fix(check): an error page stops at a budget, so a huge or endless normal form still prints (#1041)#2370HamedShams wants to merge 1 commit into
HamedShams wants to merge 1 commit into
Conversation
…mal form still prints (bendlang#1041)
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 #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_showfirst builds the term's whole normal form. That form can be exponentially larger than the term (dup(22n, xs)is 2^22 calls ofList.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_showreads the term in a copy of the book that carries a budget:term_wnf)term_snfstops, 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
undefinedtest per unfold and perterm_snfcall.Why these numbers: the largest page in
tests/ispage/deep_list_walkwith 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-onlyon an M5 Pro, main at 698b3c9:{==}, 19 levels#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/:exponential_form: an unannotated let over a tree of 2^20 leaves. On main it prints a 6 MB page out of 550 MB.exponential_fields: a constructor missing a field, over the same tree. The same on main.unfold_forever: A goal or error that mentions a self-referential@unsafeplaceholder never prints: the checker unfolds it forever #1231's file. Does not return on main.What was run
tests/throughbun bend2/main.ts <file>, on main and on the branch: 1,873 files, same output on all of them.bendfiles in the repo with--check-only: same outputtests/pagethrough--checkup, built the waygates/test.tsbuilds it: all match their#|lines{==}, 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 same0n; one of 1,049,000 prints the call it stopped atbench/checker, alternating runs of main and the branch: no difference I can tell from noise. On the two that unfold the most,proofs_3200anddefs_12800, the fastest and the lower-quartile run of 30 are within 0.5% and 1.5%, in both directionsgates/repo.ts: passes.bend.tsgoes from 45,949 to 46,119 ttokNot run:
gates/test.ts,perf.tsandsafe.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_showif you'd rather have them elsewhere.This edits
bend2/bend.ts.