# Limits A program can arrive in a share link, so every reader and every run in core has to answer any text with diagnostics, an output, a stop or a refusal: never with an exception from the JavaScript engine underneath, a run without end, or an allocation the size of the text's mistake. This page lists each limit that makes that so: where it is, its value, and what the student sees past it. Each is far beyond what a program written to be read or stepped through needs, and each is proven just past its value by a test. ## Reading | What | Where | Value | Past it | |---|---|---|---| | Mojo nesting: brackets, call and index arguments, blocks, prefix operators, `**`, `if`/`else`, `:=`, lambdas | `MAX_NESTING`, `src/mojo/parse.ts` | 200 levels | The statement is not read: one note, "nested more than 200 levels deep; Programming+ cannot read this yet, and Compile & run asks the real compiler", where the limit is passed. The checks stay quiet and a run is declined, as for any code the parser cannot read | | Mojo tree height: each operand of a chain such as `a + b + c`, each `elif` arm, each level above | `MAX_TREE`, `src/mojo/parse.ts` | 1,000 levels | The statement (the innermost one that is too tall) is not read: one note, "more than 1000 levels deep once read" | | Mojo liveness and moved-value analyses (a loop's body is walked twice or more per enclosing loop) | `MAX_VISITS`, `src/mojo/lifetimes.ts`, `src/mojo/flow.ts` | 200,000 statements per function | The function is not analyzed: the interpreter declines to say when a value with a visible lifecycle dies, and the moved-value check says nothing more about it | | Generated inputs for Mojo functions (`mojoProperties`) | `MAX_PARAMS`, `MAX_FUNCTIONS`, `src/mojo/properties.ts` | 64 parameters, the first 100 functions | The report says the function has too many parameters, or is past the first 100 | | Pseudo nesting, one chain of an operator, and the tree both make together | `MAX_NESTING`, `MAX_CHAIN`, `MAX_TREE`, `src/engines/pseudo/parse.ts` | 200 levels, 400 operands, and an expression's tree 400 levels tall (brackets that each hold a long chain) | One `too-deep` error | | One pseudocode program (the pseudo pane, and the pseudocode any other pane becomes) | `MAX_PSEUDO_LINES`, `MAX_PSEUDO_CHARS`, `src/services/pseudo-study.ts` | 2,000 lines, 100,000 characters | One `too-long` error on the line that passes it: "This program is more than 2,000 lines long" (or "longer than 100,000 characters"), "which is more than this tool reads: the lines from here on are not read, and the program is not run or proved." Blank lines past it do not count | | lingo nesting: brackets, "not", "minus", quantifiers, steps inside steps | `MAX_NESTING`, `src/engines/pseudo/english.js` | 200 levels | One `too-deep` error: "This is nested more than 200 levels deep, which is more than this tool reads" | | One lingo sentence | `MAX_SENTENCE`, `src/engines/pseudo/english.js` | 1,000 words and symbols | One `too-long` error; the rest of the sentence is not read | | lingo routines and defined phrases (every value is tried against each one's first line) | `MAX_HEADS`, `src/engines/pseudo/english.js` | 200 | One `too-long` error; the ones past it are not read | | One lingo program | `MAX_PSEUDO_LINES`, `src/engines/pseudo/english.js` | 2,000 lines | One `too-long` error; the lines past it are not read | | The pseudocode lingo steps become | `MAX_PSEUDO_LINES`, `src/engines/pseudo/english.js` | 2,000 lines | One `too-long` error; it is not checked or run | | matho nesting: brackets, groups, `\frac`, `\sqrt`, powers and subscripts in braces, functions of functions, signs | `MAX_NESTING`, `src/services/matho.ts` | 200 levels | `matho-too-deep` on that equation | | One matho equation | `MAX_TOKENS`, `src/services/matho.ts` | 2,000 symbols | `matho-too-long` on that equation; it is not read | | Equations in one matho pane | `MAX_EQUATIONS`, `src/services/matho.ts` | 500 | `matho-too-long`; none is read | | The pseudocode matho equations become | `MAX_PSEUDO_LINES`, `src/services/matho.ts` | 2,000 lines | `matho-too-long`; it is not checked or run | | `LENGTH(X)` written back as `\|X\|` when the speco is made from the pseudocode | `MAX_BARS`, `src/services/speco.ts` | 200 per claim | The rest stay `LENGTH(X)` | | A reader, translator or the prover that throws anyway | `src/common/workspace.ts`, `src/sync/hub.ts` | | One `engine-stop` error on the pane ("Programming+ could not read this pane (...)"); in the hub, every other pane keeps its text, marked stale with the reason | ## Running Mojo Past any of these the run stops as it does at its step limit: the trace ends with a stop at the line, and the result is `limited` (exit code -1), because how the compiled program would have ended is not known (`RUN_LIMITS`, `src/mojo/interp.ts`; a run may ask for lower limits, never higher). | What | Value | The stop says | |---|---|---| | Steps | 20,000 (the caller's `maxSteps`) | "Stopped after 20,000 steps." | | Calls inside calls | 200 | "Stopped at 200 calls deep" | | Characters in one String | 10,000,000 | "Stopped: this makes a String of N characters, more than Programming+ holds (10,000,000)." | | Values in one List, Dict or Set | 2,000,000 | "Stopped: this makes a List of N values, more than Programming+ holds (2,000,000)." | | Characters printed | 10,000,000 | "Stopped after printing 10,000,000 characters." | | Values made or copied into collections, over the run (what it can come to hold) | 5,000,000 | "Stopped after making or copying 5,000,000 values in Lists, Dicts and Sets" | | Characters and values built, copied or searched through, over the run (how long it can take; the whole length of a concatenation counts, because the trace keeps every step's String) | 100,000,000 | "Stopped after building, copying and searching through 100,000,000 characters and values" | | Variables' values the trace records, one per variable per step | 1,000,000 | "Stopped after recording 1,000,000 values of variables" | | Passes of one call of std.math's `gcd` or `comb` (`MATH_STEPS`), which the interpreter runs as Mojo 1.2.0's own loops: its `gcd` of an even number and a much larger odd one subtracts about 10^15 times, and the built program does not come back | 1,000,000 | "Stopped: gcd(6, 4503599627370597) takes more than 1,000,000 steps in Mojo's std.math ..., more than Programming+ follows in one call." | | The engine's own stack or size limit, past all of the above | | "Stopped: the run went deeper ... than Programming+ can follow." or "Stopped: a value grew larger than Programming+ can hold." | A `for` loop lists only the items it can reach before the step limit. The trace shows a String past 1,000 characters and a collection past 20 items cut short; `print` writes them whole. What the engine underneath cannot compute is declined, as anything the interpreter does not model is ("Programming+ cannot run this yet: ..."): a shift by more than 64 bits, converting `inf` or `nan` to an integer, a float literal with more than 10,000 digits or an exponent past 10,000, and any other exception, which is a fault in Programming+ rather than an answer. ## The model machine | What | Where | Value | Past it | |---|---|---|---| | Steps | `maxSteps`, `src/engines/asm86/interp.js` | 20,000 | The run is truncated | | One memory region a setup maps | `MAX_REGION` | 1 MiB | The run does not start: "this machine maps regions of 0 to 1,048,576 bytes (1 MiB)" | | Memory copied while writing (each step that writes a region keeps a copy for stepping back) | `MAX_COPIED` | 128 MiB | The run stops: "the steps so far wrote to memory regions totaling 128 MiB" | | The stack | `stackSize` | 512 bytes | A page fault, explained as a stack overflow | ## Proving and testing The prover's work is counted, not timed: each term it builds or visits, each case of a case split, each pair of constraints it combines, each fact it copies is a unit (`work` in `src/engines/pseudo/logic.ts`). A budget therefore runs out at the same point on every machine and in every test, and because the units are counted where memory is allocated, memory stays in proportion. Past a budget the answer is never "proved": an obligation is open with the reason "too large to prove here", or the subroutine is partial and says so (in the Prove tab a partial subroutine has nothing marked proved). Every program of the corpus takes far less than each budget, and proves the same as before they were added (`tests/prover-limits.test.mjs` proves each budget past its value). | What | Where | Value | Past it | |---|---|---|---| | Proving one obligation | `PROVE_WORK`, `src/engines/pseudo/solver.ts` | 2,000,000 units | The obligation is open: "too large to prove here" | | Following one subroutine's paths and finding its loops' invariants | `UNIT_WORK`, `src/engines/pseudo/vcgen.ts` | 40,000,000 units | The subroutine is partial, with the note "This subroutine is too large to prove here: the checker stopped before the end of it, so nothing in it is marked proved. Every run still checks it." | | Proving one subroutine's obligations | `PROOF_WORK`, `src/engines/pseudo/vcgen.ts` | 20,000,000 units | Each obligation not yet proved is open: "too large to prove here" | | Everything above, for a whole program | `PROGRAM_WORK`, `src/engines/pseudo/vcgen.ts` | 60,000,000 units | The subroutines after it are partial, with the same note | | How deep a value the checker follows is (`T <- T + A[T] + ...` line after line builds one operation inside another) | `MAX_DEPTH`, `src/engines/pseudo/vcgen.ts` | 500 operations (the corpus's deepest: 18) | The value becomes one the checker knows nothing about, with the note "The value on line N is built from more than 500 operations one inside another, more than the checker follows: from there on it treats such a value as one it knows nothing about, so what depends on it stays open." The engine's own stack or size limit, past everything, is the same as running out of work: the unit is partial, or the obligation open, too large to prove here | | A term's key, which finds equal terms (a term that shares its parts, such as nested `ABS`, is far longer written out) | `MAX_KEY`, `src/engines/pseudo/logic.ts` | 2,000 characters | The term is equal only to itself: the prover concludes less about it, never more | | A fact or goal written out with an obligation | `SHOW_PARTS`, `src/engines/pseudo/logic.ts` | 1,000 parts | The rest is written "…" | | The facts and goals one subroutine's report writes out | `SHOWN_CHARS`, `src/engines/pseudo/vcgen.ts` | 1,000,000 characters | Each further obligation shows its goal alone, cut at 400 characters | | The hypotheses looked through for the facts shown with an obligation | `SHOWN_FROM`, `src/engines/pseudo/vcgen.ts` | the nearest 400 | The facts shown come from those | | The generated inputs that cross-check a proof (`checkProperties`), counted in steps and positions visited by FORALL, EXISTS, SUM and sets written by rule | `CROSS_CHECK_ROUTINE`, `CROSS_CHECK_PROGRAM`, `src/services/pseudo.ts` | 600,000 for one routine, 1,200,000 for a program | No more inputs are tried (the routines after it, none): an obligation they would have shown broken stays open. A run cut short by the budget is not a failure | | The sample runs that check the equations a matho pane is given give the pseudo's values | `READ_BACK_VISITS`, `src/sync/pseudo-to-matho.ts` | 100,000 quantifier positions a run | The run stops there, on both sides alike, and the check compares where they stopped | | The fuzzer's inputs for one routine (the Tests view, `Workspace.fuzz`), counted the same way | `WORK_PER_INPUT`, `src/common/fuzz.ts` | 3,000 for each input the budget asks for: 900,000 at the default 300 | No more inputs are run, and the report's `problem` says "Stopped after N steps of work, all one routine's inputs may take here (M): the inputs listed were run, and no more." A failure found before is kept, shrunk as far as the work allowed | | The routines of one program the fuzzer tests | `FUZZ_ROUTINES`, `src/common/workspace.ts` | the first 100 | A report with no cases: "Not tested: generated inputs cover the first 100 routines of a program, and this is routine N." | | The fuzzer's work for a whole program | `FUZZ_PROGRAM_INPUTS`, `src/common/workspace.ts` | 600 inputs' worth: 1,800,000 at the default budget | A report with no cases: "Not tested: the routines before this one took all the work the tests of one program may take (1,800,000 steps)." | The wall-clock budget the Prove tab gives each subroutine (3 seconds, `PROVE_BUDGET_MS` in `src/services/pseudo.ts`) stays behind these as a last resort. It is the caller's: `provePseudo` and `Workspace.proofBudgetMs` take another, and what has to say the same thing on every machine takes none (`pixi run cli prove` unless `--budget-ms` gives one, `library-check`, the tests), so the counted budgets decide alone. The clock is the one part of a proof that depends on the machine: on CI's runner, where the README's example took more than its 3 seconds (it takes 5 milliseconds on the machine this was written on), 4 of its 6 obligations stayed open. A slow or busy device shows the same in the Prove tab: fewer obligations proved, more open, none wrongly proved. The report says when that happened (`clock.stopped` names the routines, each has `timedOut` and a note), and the site lets the reader give the prover more time (its `docs/app.md`). Measured on the machine this was written on: 20 nested `ABS` (or a matho pane `f(x) = ||||...x...||||` of 20 bars) took a 1 GB heap down before, and now ends in 0.1 seconds in a 128 MB heap; a subroutine at `UNIT_WORK` takes 0.7 to 2 seconds, one at `PROOF_WORK` about 1 second, and a program at `PROGRAM_WORK` about 4 seconds, each in a 128 MB heap. The most any program of the corpus takes is 234,000 units for one obligation, 145,000 for one subroutine's paths, 783,000 for its proofs and 886,000 for the whole program. `prove-fuzz` makes larger programs than anyone writes: the most in seeds 9137 and 22051 (800 programs each) are 768,000, 35,000,000 (a subroutine its 1.5-second wall-clock budget had already cut short), 5,100,000 and 38,000,000, and the proved obligations of both seeds are the same with the budgets as without. The cross-check is counted the same way: one input of a routine whose ENSURE nests 8 quantifiers visited 5,000,000 positions (7 seconds) before, and the whole cross-check of a routine now takes at most about 2 seconds; the most any routine of the corpus takes is 347,000 (`match-off-by-one`). The fuzzer runs a routine's inputs within its budget in about a second, a program's in about 2 (a program of 2,000 small routines, the first 100 fuzzed: 2 seconds); the most the corpus takes is 400,000 for one routine (kmers' `kmer_counts` in Mojo), 1,300 for one input, and every corpus program's report is the same as before. ## What the compiler does The checker may never report an error on a program the compiler accepts, so the Mojo limits are a refusal to read, not an error. Asked through `mojo build` at the pin (Mojo 1.2.0), the compiler accepts 5,000 nested parentheses, 5,000 nested calls, 1,000 nested blocks, 5,000 `elif` arms and a 10,000-term sum, and crashes (exit 139, a stack overflow in the compiler) on 30,000 nested parentheses, a 30,000-term sum, or 30,000 minus signs. There is no depth it refuses with an error message. ## The tests `tests/mojo-robustness.test.mjs` proves the Mojo limits and `tests/reader-limits.test.mjs` the others, each just past its value with inputs small enough to keep the test quick, and each shape just under it still reading and running. `tests/pseudo-robustness.test.mjs` has the pseudocode's.