Skip to content

Language 1.2: list literals are limited to about 122 elements by the semantic-module JSON reader #375

Closed

Description

@afflom

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.

  1. 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, and crates/lexlean/src/artifact/canonical_json.rs (parse_unbounded) and crates/lexlean/src/production/lcnf.rs call disable_recursion_limit. SemanticModule::parse in crates/lexlean/src/ir/semantic.rs reads the text three times (serde_json::from_str twice and canonical_json::Json::parse once), and the derived Deserialize, the walks and the drop would all need that stack.
  2. Add a list-literal term variant, as set_literal and map_literal are, with a flat array of elements. A form only in the notation would not help, because the notation is read into canonical JSON and a cons chain 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

  1. afflom commented on Nov 3, 2026

    @afflom
    MemberAuthor

    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.

  2. added this to the LexLean v0.4.1 milestone on Nov 3, 2026
  3. afflom commented on Nov 3, 2026

    @afflom
    MemberAuthor

    Completed through merged PR #403 on release/v0.4, merge 5a44fe49e5d73569c3bb377bb28b56e463ee0547. The final reviewed head 215a9d591 passed all 43 jobs in CI 41658939956, plus honesty 41658939965 and reproducibility 41658939998. Actual merge tree 88d8b657f1ab621bf736b9d7e5d97fcb9c834e5e exactly equals the reviewed/tested head and synthetic merge tree. Explicitly closing this issue because the landing is on a non-default release branch.

  4. added a commit that references this issue on Nov 11, 2026
    5f52d90
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions