Repository navigation
Description
Pinned at 3877351 (release/v0.5 line, lexlean 0.4.0, language 1.2). origin/main 71defb4c6 and origin/release/v0.5 ed549c24f were read, not run; the reader and the SPEC text are unchanged on both.
This is a request to lift a recorded limit, not a bug report. SPEC §17.17 states that a semantic module is read with the JSON reader's recursion limit of 128 levels, "whatever max_scope_depth says".
Problem
The term schema has nil and cons but no list literal (it does have set_literal, map_literal and graph_literal), so a list is a cons chain and every element costs a nesting level. A one-declaration module (language = "1.2", lexicon sources lexlean.std.bool and lexlean.std.nat, max_scope_depth = 1024) with this definition, where the body nests n times:
definition{
name: xs,
parameters: [],
result: (List Nat),
body: (cons 1 (cons 1 ... (nil Nat)))
}
n |
lexlean check |
|---|---|
| 122 | checked 1 module |
| 123 | error[LLT4001]: phase link: invalid semantic-module JSON: recursion limit exceeded at line 1 column 6925 |
The n = 100 and n = 122 modules also pass lexlean verify, at about 435 MB.
The diagnostic has two further gaps. Its source location is the first line of the module body, whichever declaration holds the list (6:1 with the list in a later declaration too), and its column refers to the generated JSON rather than the source, so nothing in it points to the list or suggests a remedy.
Impact
A longer table has to be split by hand or by a generator into prim append chunks, which adds declarations that exist only to satisfy the reader. Two 100-element definitions joined by prim append do verify. afflom/rule30 splits its lexicon and character tables this way.
Options
Neither has been tried. Chains of 1,000 and 30,000 elements pass the notation reader and reach this same JSON error, so that reader is not the next limit below that length (beyond it, see #374). We do not know what limit a deeper term reaches in the checks, in Lean or in production. §17.12 item 11 has elaborated long list literals written as balanced appends of at most 32 elements, which may reflect such a limit.
- Read the semantic module without the JSON readers' limit, bounded by
max_scope_depth, on a suitably large stack. §17.17 already reads the extraction record this way, andcrates/lexlean/src/artifact/canonical_json.rs(parse_unbounded) andcrates/lexlean/src/production/lcnf.rscalldisable_recursion_limit.SemanticModule::parseincrates/lexlean/src/ir/semantic.rsreads the text three times (serde_json::from_strtwice andcanonical_json::Json::parseonce), and the derivedDeserialize, the walks and the drop would all need that stack. - Add a list-literal term variant, as
set_literalandmap_literalare, with a flat array of elements. A form only in the notation would not help, because the notation is read into canonical JSON and aconschain there hits the same limit. This would solve lists without changing the depth rule for other terms, but it is a new term in the schema and IR.
In either case, the diagnostic could name the declaration and suggest prim append.
Accepted when
- A 1,000-element list literal checks and verifies, or the limit is unchanged and the diagnostic names the fix.
- §17.17 records the new limit.
- A register row and fixture cover it (R3).
Activity
afflom commentedon Nov 3, 2026
I am taking the accepted bounded alternative on release/v0.4: retain the documented 128-level semantic JSON limit and make its diagnostic explain how to split long lists into smaller definitions joined by
prim append. I will cover the 122/123-element boundary, a later declaration, the workaround and unchanged validation. This does not lift the language limit or overlap #402's downstream package/program reader fix; no compiler identity regeneration is planned.afflom commentedon Nov 3, 2026
Completed through merged PR #403 on
release/v0.4, merge5a44fe49e5d73569c3bb377bb28b56e463ee0547. The final reviewed head215a9d591passed all 43 jobs in CI 41658939956, plus honesty 41658939965 and reproducibility 41658939998. Actual merge tree88d8b657f1ab621bf736b9d7e5d97fcb9c834e5eexactly equals the reviewed/tested head and synthetic merge tree. Explicitly closing this issue because the landing is on a non-default release branch.Explain the semantic JSON list nesting workaround (SM-12)