diff --git a/CHANGELOG.md b/CHANGELOG.md index 73874cf87b..cdfe762056 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,23 @@ workspace carried at those versions without a tag. ## Unreleased +- A semantic module nests as deeply as the project's `max_scope_depth` allows + (SPEC.md §17.17, §17.21.3, `SM-12`; no new diagnostic code; no language + identity moves). The front end read a module's JSON with a fixed 128-level + limit and its notation with a fixed 256-level one, so a list of more than + about 122 elements was refused, and past about 115 the semantic snapshot + panicked writing its own bytes. Both readers now take the project's bound + on the compile thread's stack, and every later reading of what the linker + admitted (rendering, declaration IDs, the snapshot and its canonical bytes) + reads to the same depth on a stack sized for it: a list of 1000 elements + checks, builds, verifies, and has a snapshot. Past the bound the notation is + `LLP2001` and the data `LLT4001`, each naming `max_scope_depth`. The + authoring API (`lexlean::sdk`) reads, converts, and writes a semantic module + to 1024 levels, the default `max_scope_depth`, on a stack of its own, where + it read the notation to 256 and the JSON to 128 on its caller's. A module + within the old limits reads, renders, and hashes to the same bytes as + before. This reverses the decision of #375 to keep the 128-level limit. + The register is unchanged. - `lexlean check` builds and runs on `wasm32-wasip1`, #494 (SPEC.md §8.3, `CL-25`). WASI has no threads, no file lock, and no processes: the check pipeline runs on the instance's stack, a command that changes the project diff --git a/CONFORMANCE.md b/CONFORMANCE.md index 9a0033212e..983ababa40 100644 --- a/CONFORMANCE.md +++ b/CONFORMANCE.md @@ -594,7 +594,7 @@ the error registry does not sanction (R5, `ERRORS.md`). | `SM-09` | `build` | Linked IR has stable schema-tagged canonical JSON with alpha-safe binder serialization. | | `SM-10` | `build` | Source ID and semantic ID use exactly the specified framed hash inputs. | | `SM-11` | `build` | Linked project result sets contain every selected module and imported module exactly once in stable order. | -| `SM-12` | `build` | No semantic IR node can contain opaque prose, raw backend text, or an unknown extension. Semantic modules retain the 128-level JSON nesting limit and an over-deep list is refused with LLT4001 naming smaller definitions joined by prim append as the remedy. | +| `SM-12` | `build` | No semantic IR node can contain opaque prose, raw backend text, or an unknown extension. A semantic module nests as deeply as the project's max_scope_depth allows, in its notation and in its data: a list of 1000 elements checks and builds, and its snapshot is written, and the authoring API reads and writes it, on a caller's default stack without a panic, while a list nested past the bound is refused, with LLP2001 in the notation and LLT4001 in the data, naming max_scope_depth. | | `SM-13` | `build` | Inherited section parameters are represented explicitly and emitted only on declarations that use them. | | `SM-14` | `build` | A numeral without a unique expected type is rejected rather than defaulted. | | `SM-15` | `build` | A native core module is closed typed DAG data shared by both backends, carries explicit declaration policies, and accepts no backend source text. | diff --git a/SPEC.md b/SPEC.md index 2fe180be2b..6ce6848158 100644 --- a/SPEC.md +++ b/SPEC.md @@ -5559,14 +5559,19 @@ because they bound what verification can be given. Checking a project holds memory that grows linearly with the number of its functions when they are independent (1500, 3000, 7000, and 14000 trivial functions take 56, 101, 223, and 435 MB), before any limit of this section or of `max_ir_nodes` is reached; -a chain of calls is the case above. And a semantic module is JSON read with the -reader's recursion limit of 128 levels: a term nested deeper than that (a chain -of 130 nested `let`s) is `LLT4001` for excessive JSON nesting, whatever -`max_scope_depth` says; a chain of 100 is read. -The `LLT4001` nesting diagnostic names the unchanged 128-level bound and -recommends splitting long lists into smaller definitions joined by `prim append`. -It locates the semantic-module body, not the nested term; it does not report -coordinates in generated JSON as positions in the authored source. +a chain of calls is the case above. And a semantic module nests as deeply as +the project's `max_scope_depth` allows, as the compile thread's stack hosts it +(§25.5), in its notation and in the JSON the notation reads to; a list of n +elements nests about n levels, and a chain of n nested `let`s about n. Notation +nested deeper is `LLP2001`, and JSON nested deeper is `LLT4001`, each naming +`max_scope_depth`; the JSON diagnostic also recommends splitting long lists +into smaller definitions joined by `prim append`. Both locate the +semantic-module body, not the nested term; neither reports coordinates in +generated JSON as positions in the authored source. Every later reading of +what the linker admitted (the rendering of a build, declaration IDs, the +semantic snapshot and its canonical bytes) reads it to the same depth, on a +stack sized for it, never on its caller's: a list of 1000 elements checks, +builds, verifies, and has a snapshot (`SM-12`). **Proof.** The proof follows the source term construct by construct through the library's compatibility lemmas. A recursive definition's relation is @@ -7495,8 +7500,13 @@ with that member left out. Members are written in the order `name`, `type_parameters`, `parameters`, `type`, `result`, `statement`, `fields`, `constructors`, `arguments`, `body`, `proof`, `axioms`, then the others in key order, and are read in any order; a member written twice, an integer -beyond 64 bits, a value nested deeper than 256 levels, and a word that is not -a name where a string is expected are errors. Because the generic notation +beyond 64 bits, a value nested deeper than its reader reads, and a word that +is not a name where a string is expected are errors. A project's semantic +module is read to its `max_scope_depth` (§17.17, the limits of the front end); +the authoring library (§24.8) reads a semantic module to 1024 levels, the +`max_scope_depth` a project is created with, on a stack sized for them; any +other text read with no project, to 256 levels. +Because the generic notation covers every value, no value of any schema is unspellable, and a variant added to a schema has a notation the day it is added. @@ -11774,7 +11784,7 @@ Every row below is normative, has honesty level `build`, and MUST be copied byte | `SM-09` | `semantic-ir` | Linked IR has stable schema-tagged canonical JSON with alpha-safe binder serialization. | §17.9 | | `SM-10` | `semantic-ir` | Source ID and semantic ID use exactly the specified framed hash inputs. | §21.3, §21.4 | | `SM-11` | `semantic-ir` | Linked project result sets contain every selected module and imported module exactly once in stable order. | §17.5, §23.3 | -| `SM-12` | `semantic-ir` | No semantic IR node can contain opaque prose, raw backend text, or an unknown extension. Semantic modules retain the 128-level JSON nesting limit and an over-deep list is refused with LLT4001 naming smaller definitions joined by prim append as the remedy. | §6 I4, §17 | +| `SM-12` | `semantic-ir` | No semantic IR node can contain opaque prose, raw backend text, or an unknown extension. A semantic module nests as deeply as the project's max_scope_depth allows, in its notation and in its data: a list of 1000 elements checks and builds, and its snapshot is written, and the authoring API reads and writes it, on a caller's default stack without a panic, while a list nested past the bound is refused, with LLP2001 in the notation and LLT4001 in the data, naming max_scope_depth. | §6 I4, §17 | | `SM-13` | `semantic-ir` | Inherited section parameters are represented explicitly and emitted only on declarations that use them. | §17.5, §18.3 | | `SM-14` | `semantic-ir` | A numeral without a unique expected type is rejected rather than defaulted. | §15.5 | | `SM-15` | `semantic-ir` | A native core module is closed typed DAG data shared by both backends, carries explicit declaration policies, and accepts no backend source text. | §17.10 | diff --git a/VERIFICATION.md b/VERIFICATION.md index ba49e222ed..4e12c67766 100644 --- a/VERIFICATION.md +++ b/VERIFICATION.md @@ -13504,6 +13504,64 @@ The nesting diagnostic retains the existing `recursion limit exceeded` category, which the `SP-02` 130-level let-chain refusal also asserts. Only its generated JSON coordinates are replaced by the bound and workaround advice. +## A semantic module nests to `max_scope_depth` (`SM-12`) + +This supersedes the record above: the 128-level limit is gone. A consumer +application whose acceptance vectors are one closed list could not carry more +than about 115 of them, and its design does not admit splitting the list. + +Before the change, on a Windows host with the debug compiler, a language-1.2 +project whose one definition is a list of n `Nat` cells: n = 100 and 120 +checked and their `build` overflowed the main thread's stack (the renderer ran +on the caller's thread); n = 130 was `LLT4001` from the 128-level JSON reader; +and past the snapshot's own bounded re-read (`SemanticSnapshot::to_json`) a +snapshot panicked writing its bytes, which is where the consumer stopped at +about 115. The notation had a fixed 256-level bound of its own behind that. + +The change bounds the notation and the JSON of a project's module by its +`max_scope_depth` as the compile thread's stack hosts it, read on that thread; +every later reading of what the linker admitted reads to the same depth on a +stack sized for it: `render_build` on a thread of the compile stack's size, +and the snapshot (`from_checked`, `to_json`, `canonical_bytes`) on one of the +largest compile stack's size, so a caller on any stack gets its bytes. The +re-reads of the linker's own data (document JSON, declaration IDs, definition +digests, the snapshot's values) read without the 128-level limit. Readers with +no project keep their bounds: `SemanticModule::parse` 127 levels, the +authoring library's notation 256, tooling modules 128 (`LLT4013`). + +After it, with the same compiler: n = 130, 256, and 1000 check and build, and +n = 1100 is `LLP2001` naming `max_scope_depth` 1024. `lexlean verify` with the +pinned Lean 4.32.1 verified n = 256 (45 s) and n = 1000 (29 s), so the +ceiling is the project's bound, not Lean's. `cargo xtask check-golden` passed +for every project (no published artifact moved), and the diff touches no +identity input (`language/`, `schemas/`, the embedded goldens). + +`conformance_sm_12` passes (4 s). It checks and builds the 1000-cell fixture, +writes its snapshot on a 2 MiB thread and requires the snapshot ID to be the +digest of the bytes and the bytes to nest past 1000 levels; refuses the +1100-cell fixtures with `LLP2001`; and under `max_scope_depth = 150` checks 145 +cells and refuses 146 and 147 with `LLT4001` and 148 with `LLP2001`, so both +bounds are the project's. Three planted defects, each restored: + +| Planted defect | `conformance_sm_12` | +| --- | --- | +| the linker reads the data with `parse` (127 levels) | fails: the 1000-cell list is refused | +| `to_json` re-reads with the bounded `Json::parse` | fails: `recursion limit exceeded` panic in the snapshot | +| `canonical_bytes` runs on its caller's stack | fails: `STATUS_STACK_OVERFLOW` on the 2 MiB thread | +| the authoring API reads the notation to 256 levels | fails: the 1000-cell list is not read | +| the authoring API runs on its caller's stack | fails: `STATUS_STACK_OVERFLOW` on the 2 MiB thread | + +The authoring API had the same limits on its caller's stack (notation 256, +JSON 128), so `conformance_au_08`, which reads every committed module through +it, failed on the 1000-cell fixture in the gate. It now reads a semantic +module to 1024 levels on a stack of its own; `conformance_sm_12` reads, +converts both ways, and writes the fixture on a 2 MiB thread and refuses the +1100-cell one, and `conformance_au_08` passes. + +`SP-02` asserted the 130-level let-chain refusal; it now asserts that the +chain checks. `conformance_au_01`, `conformance_au_03` (a 50,000-level +notation is still `LLP2001`), and `conformance_au_06` pass. + ## Release evidence consumes the whole jobs listing (RP-18, #408) The release gate piped the jobs listing into quiet `grep` with `pipefail` diff --git a/crates/conformance/src/cases/preservation.rs b/crates/conformance/src/cases/preservation.rs index 71e5026fbd..d2a3a3a7ab 100644 --- a/crates/conformance/src/cases/preservation.rs +++ b/crates/conformance/src/cases/preservation.rs @@ -1775,17 +1775,11 @@ pub fn run(id: &str) { } } } - // A semantic module is JSON, and the JSON of the front end nests - // at most 128 levels: a chain of 100 `let`s is read (a family - // above certifies it) and a chain of 130 is refused, as the - // module that is not valid JSON of this reader, before any limit - // of this section. - let deep = crate::stress::let_chain_default(130); - let error = deep.check_fails_with("LLT4001"); - assert!( - error.to_string().contains("recursion limit exceeded"), - "{error}" - ); + // A semantic module nests as deeply as the project's + // max_scope_depth allows (1024 here; `SM-12` holds the bound): a + // chain of 130 `let`s, past the 128 levels of the JSON reader + // the front end once had, is read. + crate::stress::let_chain_default(130).check_ok(); if let Some(stress) = stress { let quadratic = stress .join() diff --git a/crates/conformance/src/cases/semantic_ir.rs b/crates/conformance/src/cases/semantic_ir.rs index 07cf9c1768..a12c2c1047 100644 --- a/crates/conformance/src/cases/semantic_ir.rs +++ b/crates/conformance/src/cases/semantic_ir.rs @@ -15,6 +15,24 @@ mod nested; mod strings; mod widen; +fn depth_fixture(name: &str) -> String { + std::fs::read_to_string( + support::repo_root() + .join("tests/semantic-json-depth") + .join(name), + ) + .expect("committed semantic JSON depth fixture") +} + +/// A module whose one definition is a list of `cells` elements. +fn list_source(cells: usize) -> String { + format!( + "\\begin{{lexlean}}{{Main}}\n\\useglossary{{lexlean.std.nat@1.2.0}}\n\\title{{Natural number addition}}\n\\begin{{semanticmodule}}\ndefinition{{ name: xs, parameters: [], result: (List Nat), body: {}(nil Nat){} }}\n\\end{{semanticmodule}}\n\\end{{lexlean}}\n", + "(cons 1 ".repeat(cells), + ")".repeat(cells) + ) +} + fn semantic_json_depth_diagnostic() { let project = P::example(); project.edit("lexlean.toml", "language = \"1.0\"", "language = \"1.2\""); @@ -22,72 +40,191 @@ fn semantic_json_depth_diagnostic() { let stack_bytes = support::limits_of(&project) .compile_stack_plan() .stack_bytes; - std::thread::Builder::new() + let project = std::thread::Builder::new() .stack_size(stack_bytes) - .spawn(move || semantic_json_depth_diagnostic_on_stack(&project)) + .spawn(move || { + semantic_json_depth_diagnostic_on_stack(&project); + project + }) .expect("reader test thread") .join() .expect("semantic JSON depth assertions"); + + // A list of 1000 cells nests past every bounded reader's 128 levels. The + // build and the snapshot run after the compile thread, on their caller's + // stack: the CLI's main thread, and an SDK caller's default 2 MiB thread. + project.write("src/Main.lex.tex", &depth_fixture("list-1000.lex.tex")); + project.relock(); + let (code, stdout, stderr) = project.cli(&["build"]); + assert_eq!(code, 0, "a list of 1000 cells builds: {stdout}{stderr}"); + let engine = project.engine(); + let bytes = std::thread::Builder::new() + .stack_size(2 << 20) + .spawn(move || { + let snapshot = engine + .snapshot(lexlean::CheckRequest { + selection: lexlean::Selection::Entrypoints, + }) + .expect("a list of 1000 cells has a snapshot"); + let bytes = snapshot.canonical_bytes(); + assert_eq!( + snapshot.snapshot_id(), + lexlean::Sha256Digest::of(&bytes), + "the snapshot ID is the digest of its canonical bytes" + ); + bytes + }) + .expect("snapshot caller thread") + .join() + .expect("the snapshot of a list of 1000 cells is written without a panic"); + let text = String::from_utf8(bytes).expect("UTF-8"); + let depth = lexlean::production::lower::json_depth(&text); + assert!( + depth > 1000, + "the snapshot carries the whole list ({depth} levels)" + ); + + // The authoring API reads, converts, and writes the same module for a + // caller on a default 2 MiB stack, and refuses one nested past its bound. + std::thread::Builder::new() + .stack_size(2 << 20) + .spawn(|| { + let source = depth_fixture("list-1000.lex.tex"); + let value = lexlean::sdk::read_module(&source).expect("the API reads 1000 cells"); + let data = lexlean::sdk::to_data_form(&source).expect("to the data form"); + assert_eq!( + lexlean::sdk::read_module(&data).expect("the data form reads"), + value + ); + let notation = lexlean::sdk::to_notation(&data).expect("back to the notation"); + assert_eq!( + lexlean::sdk::read_module(¬ation).expect("it reads"), + value + ); + let written = lexlean::sdk::write_module(&source, &value).expect("written"); + assert_eq!( + lexlean::sdk::read_module(&written).expect("it reads"), + value + ); + let spans = lexlean::sdk::declaration_spans(&source).expect("spans"); + assert_eq!(spans.map(|spans| spans.len()), Some(1)); + let refused = lexlean::sdk::read_module(&depth_fixture("negative/list-1100.lex.tex")) + .expect_err("past the API's bound"); + assert!(refused.message.contains("nested more deeply"), "{refused}"); + }) + .expect("authoring API caller thread") + .join() + .expect("the authoring API reads a list of 1000 cells on a default stack"); } fn semantic_json_depth_diagnostic_on_stack(project: &P) { - let fixture = |name: &str| { - std::fs::read_to_string( - support::repo_root() - .join("tests/semantic-json-depth") - .join(name), - ) - .expect("committed semantic JSON depth fixture") - }; - for name in ["list-122.lex.tex", "split-list-200.lex.tex"] { - project.write("src/Main.lex.tex", &fixture(name)); + for name in ["list-1000.lex.tex", "split-list-200.lex.tex"] { + project.write("src/Main.lex.tex", &depth_fixture(name)); project.relock(); project.check_ok(); } - let parse_data = |data: &str| { - lexlean::ir::semantic::SemanticModule::parse( + let store = lexlean::ir::semantic::model::ArtifactStore::new(u64::MAX, u64::MAX); + let imported = std::collections::BTreeMap::new(); + let parse_data = |data: &str, max_depth: Option| match max_depth { + Some(max_depth) => lexlean::ir::semantic::SemanticModule::parse_bounded( + data, + "1.2", + "LexLeanExample", + &[], + &imported, + &store, + max_depth, + ), + None => lexlean::ir::semantic::SemanticModule::parse( data, "1.2", "LexLeanExample", &[], - &std::collections::BTreeMap::new(), - &lexlean::ir::semantic::model::ArtifactStore::new(u64::MAX, u64::MAX), - ) + &imported, + &store, + ), }; + // Past the project's max_scope_depth (1024), the notation is refused. for name in [ - "negative/list-123.lex.tex", - "negative/later-list-123.lex.tex", + "negative/list-1100.lex.tex", + "negative/later-list-1100.lex.tex", ] { - let source = fixture(name); - project.write("src/Main.lex.tex", &source); + project.write("src/Main.lex.tex", &depth_fixture(name)); project.relock(); - let error = project.check_fails_with("LLT4001"); + let error = project.check_fails_with("LLP2001"); let message = &error.diagnostics[0].message; - assert!(message.contains("128-level"), "{message}"); - assert!(message.contains("recursion limit exceeded"), "{message}"); - assert!(message.contains("smaller definitions"), "{message}"); - assert!(message.contains("prim append"), "{message}"); - assert!( - !message.contains("column"), - "generated JSON coordinates are not source positions: {message}" - ); - let data_form = lexlean::sdk::to_data_form(&source).expect("notation writes to data form"); - let data = data_form - .split_once("\\semanticdata{") - .expect("semantic data") - .1 - .split_once("}\n\\end{semanticmodule}") - .expect("module end") - .0; - let failure = parse_data(data).expect_err("same bound on semantic JSON input"); - assert_eq!(failure.code.as_str(), "LLT4001"); - assert!(failure.reason.contains("prim append")); + assert!(message.contains("nested more deeply"), "{message}"); + assert!(message.contains("1024 levels"), "{message}"); + assert!(message.contains("max_scope_depth"), "{message}"); for arguments in [vec!["check"], vec!["check", "--diagnostic-format", "json"]] { let (code, stdout, stderr) = project.cli(&arguments); assert_ne!(code, 0); - assert!(format!("{stdout}{stderr}").contains("prim append")); + assert!(format!("{stdout}{stderr}").contains("max_scope_depth")); + } + } + // The data form is bounded the same way: a list of 200 cells reads + // under a bound of 1024, and is refused under 150 and under the + // default of a reader with no project, which a default stack hosts. + let data_form = + lexlean::sdk::to_data_form(&list_source(200)).expect("notation writes to data form"); + let data = data_form + .split_once("\\semanticdata{") + .expect("semantic data") + .1 + .split_once("}\n\\end{semanticmodule}") + .expect("module end") + .0; + parse_data(data, Some(1024)).expect("a list of 200 cells reads under 1024 levels"); + for max_depth in [Some(150), None] { + let failure = parse_data(data, max_depth).expect_err("deeper than the bound"); + assert_eq!(failure.code.as_str(), "LLT4001"); + assert!(failure.reason.contains("max_scope_depth"), "{failure}"); + assert!(failure.reason.contains("prim append"), "{failure}"); + assert!( + !failure.reason.contains("column"), + "generated JSON coordinates are not source positions: {failure}" + ); + } + // Both bounds are the project's: under 150, a list of 145 cells (150 + // levels of JSON) checks, its JSON is refused at 146, and its notation at + // 148 (two levels shallower than its JSON). + project.edit( + "lexlean.toml", + "max_scope_depth = 1024", + "max_scope_depth = 150", + ); + for (cells, refusal) in [ + (145, None), + (146, Some(("LLT4001", "150 that max_scope_depth allows"))), + (147, Some(("LLT4001", "150 that max_scope_depth allows"))), + ( + 148, + Some(("LLP2001", "150 levels, the project's max_scope_depth")), + ), + ] { + project.write("src/Main.lex.tex", &list_source(cells)); + project.relock(); + match refusal { + None => { + project.check_ok(); + } + Some((code, words)) => { + let error = project.check_fails_with(code); + assert!( + error.diagnostics[0].message.contains(words), + "{cells} cells: {error}" + ); + } } } + project.edit( + "lexlean.toml", + "max_scope_depth = 150", + "max_scope_depth = 1024", + ); + project.relock(); + project.check_ok(); + let parse_data = |data: &str| parse_data(data, None); let empty = r#"{"declarations":[],"spec":"lexlean/semantic-module/2"}"#; let invalid = [ diff --git a/crates/lexlean/src/api.rs b/crates/lexlean/src/api.rs index 49013077f8..c851e239f2 100644 --- a/crates/lexlean/src/api.rs +++ b/crates/lexlean/src/api.rs @@ -249,10 +249,22 @@ fn file_row(kind: &str, path: &str, bytes: &[u8]) -> FileRow { /// Render the complete platform-independent build artifact set from a /// checked project (§21.5, §21.6). No Lean process runs here (CL-05). -#[allow(clippy::too_many_lines)] +/// The printers recurse once per level of what the compile thread admitted, +/// so they run on a stack of the same size (§25.5). pub fn render_build( project: &Project, checked: &CheckedProject, +) -> Result { + crate::on_stack( + project.config.limits.compile_stack_plan().stack_bytes, + || render_build_inline(project, checked), + ) +} + +#[allow(clippy::too_many_lines)] +fn render_build_inline( + project: &Project, + checked: &CheckedProject, ) -> Result { let mut modules = Vec::new(); let mut files: Vec<(String, Vec)> = Vec::new(); diff --git a/crates/lexlean/src/artifact/canonical_json.rs b/crates/lexlean/src/artifact/canonical_json.rs index 9d1be88d51..ea2f51a017 100644 --- a/crates/lexlean/src/artifact/canonical_json.rs +++ b/crates/lexlean/src/artifact/canonical_json.rs @@ -160,6 +160,18 @@ fn write_escaped(text: &str, out: &mut String) { out.push('"'); } +/// `serde_json::from_str` without its 128-level limit on nesting, for text +/// whose depth the caller has bounded and whose stack it has sized for it. +pub(crate) fn from_str_unbounded( + text: &str, +) -> Result { + let mut reader = serde_json::Deserializer::from_str(text); + reader.disable_recursion_limit(); + let value = T::deserialize(&mut reader)?; + reader.end()?; + Ok(value) +} + /// A streaming duplicate-key check over raw JSON bytes: every object level /// keeps the set of keys seen so far, compared after JSON escape decoding. /// The input need not be canonical yet, so `"a"` and `"\u0061"` are the same diff --git a/crates/lexlean/src/artifact/declaration_id.rs b/crates/lexlean/src/artifact/declaration_id.rs index 2e0885ee98..aaa47a2af5 100644 --- a/crates/lexlean/src/artifact/declaration_id.rs +++ b/crates/lexlean/src/artifact/declaration_id.rs @@ -174,7 +174,9 @@ pub fn declarations_json(module: &str, rows: &[DeclarationRow]) -> Json { } fn prepare(module: &str, declaration: &SemanticDeclaration, known: &BTreeSet) -> Prepared { - let raw = Json::parse( + // As deep as the linker admitted it (`max_scope_depth`), past the bounded + // reader's 128 levels. + let raw = Json::parse_unbounded( &serde_json::to_vec(declaration).expect("a declaration serializes to canonical JSON"), ) .expect("a declaration uses canonical JSON values"); diff --git a/crates/lexlean/src/artifact/snapshot.rs b/crates/lexlean/src/artifact/snapshot.rs index 5c1c4f3af0..c0aa5013db 100644 --- a/crates/lexlean/src/artifact/snapshot.rs +++ b/crates/lexlean/src/artifact/snapshot.rs @@ -182,15 +182,19 @@ fn range((start, end): (usize, usize)) -> SnapshotRange { SnapshotRange { start, end } } +// The values below nest as deeply as the linker admitted (`max_scope_depth`), +// beyond the bounded readers' 128 levels; the snapshot is built and written +// on a stack sized for that (`crate::on_stack`). fn json_value(value: &Json) -> serde_json::Value { - serde_json::from_str(&value.to_canonical_string()).expect("canonical linked IR is valid JSON") + crate::artifact::canonical_json::from_str_unbounded(&value.to_canonical_string()) + .expect("canonical linked IR is valid JSON") } /// One elaboration value as canonical JSON. fn canonical_value(item: &T) -> serde_json::Value { let text = serde_json::to_string(item).expect("elaboration serializes"); - serde_json::from_str( - &Json::parse(text.as_bytes()) + crate::artifact::canonical_json::from_str_unbounded( + &Json::parse_unbounded(text.as_bytes()) .expect("serialized elaboration is JSON") .to_canonical_string(), ) @@ -222,6 +226,16 @@ impl SemanticSnapshot { checked: &CheckedProject, language: &str, compiler_semantics_id: Sha256Digest, + ) -> Self { + crate::on_stack(crate::config::MAX_COMPILE_STACK_BYTES, || { + Self::from_checked_inline(checked, language, compiler_semantics_id) + }) + } + + fn from_checked_inline( + checked: &CheckedProject, + language: &str, + compiler_semantics_id: Sha256Digest, ) -> Self { let mut modules = Vec::with_capacity(checked.modules.len()); for (name, module) in &checked.modules { @@ -438,9 +452,17 @@ impl SemanticSnapshot { &self.lexicon_closure } - /// Canonical JSON value. + /// Canonical JSON value. It nests as deeply as the snapshot's data, so a + /// caller that walks or drops it does so on a stack sized for that; + /// [`Self::canonical_bytes`] needs no such care. #[must_use] pub fn to_json(&self) -> Json { + crate::on_stack(crate::config::MAX_COMPILE_STACK_BYTES, || { + self.to_json_inline() + }) + } + + fn to_json_inline(&self) -> Json { let value = serde_json::to_value(self).expect("snapshot DTO serializes"); // The DTO already has unique object keys. Re-parsing its serialization // imposes the raw JSON reader's nesting limit on accepted linked IR. @@ -450,7 +472,9 @@ impl SemanticSnapshot { /// Canonical JSON file bytes, including LexLean's single final LF. #[must_use] pub fn canonical_bytes(&self) -> Vec { - self.to_json().to_file_bytes() + crate::on_stack(crate::config::MAX_COMPILE_STACK_BYTES, || { + self.to_json_inline().to_file_bytes() + }) } /// SHA-256 of [`Self::canonical_bytes`]. diff --git a/crates/lexlean/src/backend/semantic.rs b/crates/lexlean/src/backend/semantic.rs index 4f3a5a81ec..2ea094f30e 100644 --- a/crates/lexlean/src/backend/semantic.rs +++ b/crates/lexlean/src/backend/semantic.rs @@ -1843,7 +1843,9 @@ pub(crate) fn notation_declaration_spans( let spans = if tooling { crate::surface::tooling::declaration_spans(body) } else { - crate::surface::semantic::declaration_spans(body) + // The linker has read this text to the project's `max_scope_depth`, + // and the renderer runs on a stack sized for it (§25.5). + crate::surface::semantic::declaration_spans_bounded(body, usize::MAX) } .ok()?; Some( diff --git a/crates/lexlean/src/config.rs b/crates/lexlean/src/config.rs index 099cd1d003..5e198b4acb 100644 --- a/crates/lexlean/src/config.rs +++ b/crates/lexlean/src/config.rs @@ -57,13 +57,13 @@ const COMPILE_STACK_BYTES_PER_SCOPE: usize = 64 * 1024; /// hosts is refused as `LLS8002` naming both the configured and the /// effective bound, never by exhausting the stack. #[cfg(not(target_os = "wasi"))] -const MAX_COMPILE_STACK_BYTES: usize = 1024 * 1024 * 1024; +pub(crate) const MAX_COMPILE_STACK_BYTES: usize = 1024 * 1024 * 1024; /// On WASI the pipeline runs on the executable's one stack, so the plan hosts /// no more than that stack holds and deeper input is `LLS8002` there too /// (§8.3); an embedder links its module with at least this stack. #[cfg(target_os = "wasi")] -const MAX_COMPILE_STACK_BYTES: usize = WASI_STACK_BYTES; +pub(crate) const MAX_COMPILE_STACK_BYTES: usize = WASI_STACK_BYTES; include!("wasi_stack.rs"); diff --git a/crates/lexlean/src/ir/document.rs b/crates/lexlean/src/ir/document.rs index 75515372a5..d19be153e2 100644 --- a/crates/lexlean/src/ir/document.rs +++ b/crates/lexlean/src/ir/document.rs @@ -251,7 +251,9 @@ impl DocumentModule { if let Some(semantic) = &self.semantic { fields.push(( "semantic", - Json::parse( + // As deep as the linker admitted it (`max_scope_depth`), which + // can be beyond the bounded reader's 128 levels. + Json::parse_unbounded( &serde_json::to_vec(semantic) .expect("semantic module serializes to canonical JSON domain"), ) diff --git a/crates/lexlean/src/ir/semantic.rs b/crates/lexlean/src/ir/semantic.rs index 33a576c9cc..3a5de13084 100644 --- a/crates/lexlean/src/ir/semantic.rs +++ b/crates/lexlean/src/ir/semantic.rs @@ -2052,7 +2052,8 @@ impl SemanticDeclaration { production: production.clone(), }; let text = serde_json::to_string(&normalized).expect("definition serializes"); - let canonical = crate::artifact::canonical_json::Json::parse(text.as_bytes()) + // As deep as the linker admitted the definition (`max_scope_depth`). + let canonical = crate::artifact::canonical_json::Json::parse_unbounded(text.as_bytes()) .expect("serialized definition is JSON") .to_canonical_string(); Some(crate::artifact::content_id::Sha256Digest::of( @@ -9353,10 +9354,15 @@ fn elimination_binder_types( Ok(expected) } +/// The nesting [`SemanticModule::parse`] reads, which is serde's own: deep +/// enough for any module a default thread's stack can decode, debug or not. +pub const DEFAULT_SEMANTIC_JSON_DEPTH: u64 = 127; + impl SemanticModule { /// Decode canonical JSON and enforce all conservative semantic checks. /// `module_prefix` is the project's Lean module prefix, under which the - /// backend names every imported declaration. + /// backend names every imported declaration. The data may nest + /// [`DEFAULT_SEMANTIC_JSON_DEPTH`] levels; see [`Self::parse_bounded`]. pub fn parse( text: &str, language: &str, @@ -9365,17 +9371,44 @@ impl SemanticModule { imported_modules: &BTreeMap, artifacts: &model::ArtifactStore, ) -> Result { - let module: Self = serde_json::from_str(text).map_err(|error| { - // The notation has already become JSON, so serde's coordinates - // cannot locate the offending term in the authored source. - if error.to_string().starts_with("recursion limit exceeded") { - "invalid semantic-module JSON: recursion limit exceeded (128-level semantic JSON bound); split long lists into smaller definitions joined by `prim append`".to_owned() - } else { - format!("invalid semantic-module JSON: {error}") - } - })?; - let canonical = - crate::artifact::canonical_json::Json::parse(text.as_bytes())?.to_canonical_string(); + Self::parse_bounded( + text, + language, + module_prefix, + imports, + imported_modules, + artifacts, + DEFAULT_SEMANTIC_JSON_DEPTH, + ) + } + + /// [`Self::parse`] with the data nesting at most `max_depth` levels (the + /// linker passes `max_scope_depth` as the compile thread's stack hosts + /// it, §25.5). The decoder recurses once per level, so the caller decodes + /// on a stack sized for `max_depth`. + pub fn parse_bounded( + text: &str, + language: &str, + module_prefix: &str, + imports: &[String], + imported_modules: &BTreeMap, + artifacts: &model::ArtifactStore, + max_depth: u64, + ) -> Result { + // Measured without recursing, so data too deep for the stack is + // refused before anything recurses on it. The notation has already + // become JSON, so no coordinate of it locates the term in the source. + let depth = crate::production::lower::json_depth(text); + if u64::try_from(depth).map_or(true, |depth| depth > max_depth) { + return Err(format!( + "invalid semantic-module JSON: nests {depth} levels, more than the {max_depth} that max_scope_depth allows; a list of n elements nests about n levels, so raise max_scope_depth or split long lists into smaller definitions joined by `prim append`" + ) + .into()); + } + let module: Self = crate::artifact::canonical_json::from_str_unbounded(text) + .map_err(|error| format!("invalid semantic-module JSON: {error}"))?; + let canonical = crate::artifact::canonical_json::Json::parse_unbounded(text.as_bytes())? + .to_canonical_string(); if canonical != text { return Err("semantic-module JSON is not canonical".to_owned().into()); } @@ -9384,8 +9417,9 @@ impl SemanticModule { // member must survive into the typed value, except an explicitly // written default (an empty list or `false`) that serialization // omits. - let source: serde_json::Value = serde_json::from_str(text) - .map_err(|error| format!("invalid semantic-module JSON: {error}"))?; + let source: serde_json::Value = + crate::artifact::canonical_json::from_str_unbounded(text) + .map_err(|error| format!("invalid semantic-module JSON: {error}"))?; let typed = serde_json::to_value(&module).expect("semantic module serializes"); if let Some(path) = ignored_member(&source, &typed, "$") { return Err(format!( diff --git a/crates/lexlean/src/lib.rs b/crates/lexlean/src/lib.rs index 3b6d37ec64..cc8db3a36e 100644 --- a/crates/lexlean/src/lib.rs +++ b/crates/lexlean/src/lib.rs @@ -245,6 +245,33 @@ pub fn identity_bytes<'a>(path: &str, bytes: &'a [u8]) -> std::borrow::Cow<'a, [ /// in four; this is sixteen times that, for modules that grow with the runtime. pub const READER_STACK: usize = 64 * 1024 * 1024; +/// Run `work` on a thread of `stack_bytes`, for work that recurses once per +/// level of data the compile thread admitted (§25.5) but that runs after it, +/// on a caller's thread of unknown size. A thread that cannot be had runs the +/// work on the caller's stack; a panic of the work is passed on as raised. +pub(crate) fn on_stack(stack_bytes: usize, work: impl FnOnce() -> T + Send) -> T { + let slot = std::sync::Mutex::new(Some(work)); + let run = || { + slot.lock() + .unwrap_or_else(std::sync::PoisonError::into_inner) + .take() + .map(|work| work()) + }; + std::thread::scope(|scope| { + match std::thread::Builder::new() + .name("lexlean-deep".to_owned()) + .stack_size(stack_bytes) + .spawn_scoped(scope, run) + { + Ok(thread) => thread + .join() + .unwrap_or_else(|panic| std::panic::resume_unwind(panic)), + Err(_) => run(), + } + }) + .expect("the work runs exactly once") +} + /// The §11.5 tree digest of the files of the embedded tree selected by `keep`. fn embedded_digest(keep: impl Fn(&str) -> bool) -> Sha256Digest { let selected: Vec<(&'static str, &'static [u8])> = embedded::FILES diff --git a/crates/lexlean/src/link.rs b/crates/lexlean/src/link.rs index 8c7ba00eec..6c558bd214 100644 --- a/crates/lexlean/src/link.rs +++ b/crates/lexlean/src/link.rs @@ -916,6 +916,13 @@ fn check_project_inline( // Artifact declarations are charged before they decode, against // the nodes every earlier module linked (§17.12 rule 2). artifacts.begin_module(ir_node_count, total_bytes); + // The notation and the data nest as deeply as the compile thread's + // stack hosts `max_scope_depth` (§25.5), and no deeper. + let max_depth = project + .config + .limits + .compile_stack_plan() + .effective_max_scope_depth; // The notation is read to the canonical JSON the decoder reads, so // that what a module means is decided in one place (§17.21). let data: std::borrow::Cow<'_, str> = if ast.surface { @@ -928,12 +935,23 @@ fn check_project_inline( } let spec = crate::ir::semantic::semantic_module_spec(&project.config.language) .expect("language 1.2 has a semantic-module schema"); - match crate::surface::semantic::parse_module(&ast.data.text, spec) { + match crate::surface::semantic::parse_module_bounded( + &ast.data.text, + spec, + usize::try_from(max_depth).unwrap_or(usize::MAX), + ) { Ok(json) => std::borrow::Cow::Owned(json.to_canonical_string()), Err(error) => { + let bound = if error.message == crate::surface::generic::TOO_DEEP { + format!( + " ({max_depth} levels, the project's max_scope_depth as its compile stack hosts it; a list of n elements nests about n levels)" + ) + } else { + String::new() + }; return Err(err(vec![Diagnostic::new( code!("LLP2001"), - format!("phase link: semantic notation: {}", error.message), + format!("phase link: semantic notation: {}{bound}", error.message), ) .with_span(notation_span( &load.path, @@ -958,36 +976,42 @@ fn check_project_inline( // A package's source writes a sibling module by its own name; the // linked project names it by its key, so the references are read // under the key and every later phase finds the module (§10.5). - let data: std::borrow::Cow<'_, str> = if renamed.is_empty() { + // Data deeper than the compile thread hosts is left as written, for + // the semantic reader to refuse by its depth. + let too_deep = u64::try_from(crate::production::lower::json_depth(&data)) + .map_or(true, |depth| depth > max_depth); + let data: std::borrow::Cow<'_, str> = if renamed.is_empty() || too_deep { data } else { let to_key: BTreeMap = renamed .iter() .map(|(key, written)| (written.clone(), key.clone())) .collect(); - let mut json = crate::artifact::canonical_json::Json::parse(data.as_bytes()) - .map_err(|reason| { - err(vec![Diagnostic::new( - code!("LLP2001"), - format!("phase link: semantic data: {reason}"), - ) - .with_span(span_of_range( - &load.path, - &load.atoms, - ast.data.range, - ))]) - })?; + let mut json = + crate::artifact::canonical_json::Json::parse_unbounded(data.as_bytes()) + .map_err(|reason| { + err(vec![Diagnostic::new( + code!("LLP2001"), + format!("phase link: semantic data: {reason}"), + ) + .with_span(span_of_range( + &load.path, + &load.atoms, + ast.data.range, + ))]) + })?; rename_member_modules(&mut json, &to_key); std::borrow::Cow::Owned(json.to_canonical_string()) }; Some( - SemanticModule::parse( + SemanticModule::parse_bounded( &data, &project.config.language, &load.prefix, &imports, &imported_semantic, &artifacts, + max_depth, ) .map_err(|failure| { err(vec![Diagnostic::new( diff --git a/crates/lexlean/src/sdk.rs b/crates/lexlean/src/sdk.rs index 7b398a5800..3b196a0c71 100644 --- a/crates/lexlean/src/sdk.rs +++ b/crates/lexlean/src/sdk.rs @@ -13,6 +13,50 @@ use serde_json::Value; use crate::artifact::canonical_json::Json; use crate::surface::module::{locate, Kind, Located, CORE, SEMANTIC, TOOLING}; +use crate::surface::SurfaceError; + +/// How deeply the authoring API reads a semantic module's notation: the +/// `max_scope_depth` a project is created with, so the API reads whatever a +/// project with the default limits checks (SPEC.md §17.17). A list of n +/// elements nests about n levels. +pub const AUTHORING_DEPTH: usize = 1024; + +/// The levels a module's JSON nests beyond its deepest term: the module, its +/// declarations, a declaration, and the members around the term. +const AUTHORING_JSON_MARGIN: usize = 16; + +/// The stack the authoring API reads and writes on, a compile thread's for +/// [`AUTHORING_DEPTH`] levels (§25.5): reading and printing recurse once per +/// level, and the API's caller may be on a stack of any size. +const AUTHORING_STACK: usize = 16 * 1024 * 1024 + AUTHORING_DEPTH * 64 * 1024; + +fn deep(work: impl FnOnce() -> T + Send) -> T { + crate::on_stack(AUTHORING_STACK, work) +} + +/// The canonical JSON text of the notation of a module of `kind`: a semantic +/// module read to [`AUTHORING_DEPTH`], the other kinds by their own bounds. +fn notation_data(kind: &Kind, notation: &str, spec: &str) -> Result { + if kind.is(&SEMANTIC) { + crate::surface::semantic::parse_module_bounded(notation, spec, AUTHORING_DEPTH) + .map(|module| module.to_canonical_string()) + } else { + kind.data_text(notation, spec) + } +} + +/// JSON text as a value, nested no deeper than the API reads, measured +/// without recursing before anything recurses on it. +fn read_json(text: &str) -> Result { + let depth = crate::production::lower::json_depth(text); + let bound = AUTHORING_DEPTH + AUTHORING_JSON_MARGIN; + if depth > bound { + return Err(format!( + "the module data nests {depth} levels, more than the {bound} the authoring API reads" + )); + } + crate::artifact::canonical_json::from_str_unbounded(text).map_err(|failure| failure.to_string()) +} /// The kinds of module that have an authoring notation. #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -73,12 +117,16 @@ fn found(text: &str) -> Result { /// The canonical JSON of `data`. fn canonical(data: &Value) -> Result { - Json::parse( - serde_json::to_string(data) - .map_err(|failure| error(failure.to_string(), None))? - .as_bytes(), - ) - .map_err(|failure| { + let text = serde_json::to_string(data).map_err(|failure| error(failure.to_string(), None))?; + let bound = AUTHORING_DEPTH + AUTHORING_JSON_MARGIN; + let depth = crate::production::lower::json_depth(&text); + if depth > bound { + return Err(error( + format!("the module data nests {depth} levels, more than the {bound} the authoring API reads"), + None, + )); + } + Json::parse_unbounded(text.as_bytes()).map_err(|failure| { error( format!("the module data is not canonical JSON: {failure}"), None, @@ -118,13 +166,14 @@ pub fn module_kind(text: &str) -> Option { /// reads (it is not the `\semanticdata` form, and it is well formed). #[must_use] pub fn is_notation(text: &str) -> bool { + deep(|| is_notation_inline(text)) +} + +fn is_notation_inline(text: &str) -> bool { locate(text).is_some_and(|located| { located.data.is_none() && (located.kind.spec)().is_some_and(|spec| { - located - .kind - .data_text(&text[located.body.0..located.body.1], spec) - .is_ok() + notation_data(located.kind, &text[located.body.0..located.body.1], spec).is_ok() }) }) } @@ -138,9 +187,13 @@ pub fn is_notation(text: &str) -> bool { /// A source with no module, a module whose data is not JSON, or notation that /// is not well formed (the error carries the offset in `text`). pub fn read_module(text: &str) -> Result { + deep(|| read_module_inline(text)) +} + +fn read_module_inline(text: &str) -> Result { let located = found(text)?; if let Some((start, end)) = located.data { - return serde_json::from_str(&text[start..end]).map_err(|failure| { + return read_json(&text[start..end]).map_err(|failure| { error( format!("the module data is not JSON: {failure}"), Some(start), @@ -149,16 +202,15 @@ pub fn read_module(text: &str) -> Result { } let spec = (located.kind.spec)().ok_or_else(|| error("the notation is a language-1.2 form", None))?; - let module = located - .kind - .data_text(&text[located.body.0..located.body.1], spec) - .map_err(|failure| { + let module = notation_data(located.kind, &text[located.body.0..located.body.1], spec).map_err( + |failure| { error( format!("the notation is not well formed: {}", failure.message), Some(located.body.0 + failure.offset), ) - })?; - serde_json::from_str(&module).map_err(|failure| error(failure.to_string(), None)) + }, + )?; + read_json(&module).map_err(|failure| error(failure, None)) } /// Whether the data form of `text` is its own canonical JSON as language 1.1 @@ -198,6 +250,10 @@ pub(crate) fn data_is_canonical(text: &str) -> Option { /// /// A source with no module, or `data` that is not a module of its kind. pub fn write_module(text: &str, data: &Value) -> Result { + deep(|| write_module_inline(text, data)) +} + +fn write_module_inline(text: &str, data: &Value) -> Result { let located = found(text)?; let json = canonical(data)?; if let Some((start, end)) = located.data { @@ -229,6 +285,10 @@ pub fn write_module(text: &str, data: &Value) -> Result /// /// A source with no well-formed module. pub fn to_data_form(text: &str) -> Result { + deep(|| to_data_form_inline(text)) +} + +fn to_data_form_inline(text: &str) -> Result { let located = found(text)?; // A module in the notation is read to its canonical JSON text directly: a // library of kernel terms is tens of megabytes, which a value of the whole @@ -236,17 +296,16 @@ pub fn to_data_form(text: &str) -> Result { let data = if located.data.is_none() { let spec = (located.kind.spec)() .ok_or_else(|| error("the notation is a language-1.2 form", None))?; - located - .kind - .data_text(&text[located.body.0..located.body.1], spec) - .map_err(|failure| { + notation_data(located.kind, &text[located.body.0..located.body.1], spec).map_err( + |failure| { error( format!("the notation is not well formed: {}", failure.message), Some(located.body.0 + failure.offset), ) - })? + }, + )? } else { - canonical(&read_module(text)?)?.to_canonical_string() + canonical(&read_module_inline(text)?)?.to_canonical_string() }; Ok(format!( "{}\n{}{{{data}}}\n{}", @@ -264,8 +323,12 @@ pub fn to_data_form(text: &str) -> Result { /// A source with no well-formed module, or a module that is not of the schema /// the notation names (a language-1.1 module has no notation). pub fn to_notation(text: &str) -> Result { + deep(|| to_notation_inline(text)) +} + +fn to_notation_inline(text: &str) -> Result { let located = found(text)?; - let json = canonical(&read_module(text)?)?; + let json = canonical(&read_module_inline(text)?)?; require_spec(located.kind, &json)?; let printed = (located.kind.print)(&json) .map_err(|failure| error(format!("the module has no notation: {failure}"), None))?; @@ -284,6 +347,10 @@ pub fn to_notation(text: &str) -> Result { /// /// A source with no module, or notation that is not well formed. pub fn declaration_spans(text: &str) -> Result>, AuthoringError> { + deep(|| declaration_spans_inline(text)) +} + +fn declaration_spans_inline(text: &str) -> Result>, AuthoringError> { let located = found(text)?; if located.data.is_some() { return Ok(None); @@ -294,7 +361,7 @@ pub fn declaration_spans(text: &str) -> Result>, Auth } else if located.kind.is(&CORE) { crate::surface::core::declaration_spans(body) } else { - crate::surface::semantic::declaration_spans(body) + crate::surface::semantic::declaration_spans_bounded(body, AUTHORING_DEPTH) } .map_err(|failure| { error( diff --git a/crates/lexlean/src/surface/generic.rs b/crates/lexlean/src/surface/generic.rs index 3fc09b3235..79c7a4d871 100644 --- a/crates/lexlean/src/surface/generic.rs +++ b/crates/lexlean/src/surface/generic.rs @@ -26,11 +26,15 @@ use super::SurfaceError; /// The width the printer lays a value out at. pub const WIDTH: usize = 100; -/// The deepest nesting the parser reads. The decoder that consumes the -/// canonical text reads 128 levels; this is the bound that keeps the parser -/// itself off the end of the stack on hostile text. +/// The deepest nesting the parser reads unless its reader is given another +/// bound ([`Reader::with_max_depth`]): the bound that keeps the parser off the +/// end of a default stack on hostile text. The linker reads a project's +/// modules to its `max_scope_depth` instead, on a stack sized for it. pub const MAX_DEPTH: usize = 256; +/// The refusal of text nested deeper than its reader reads. +pub const TOO_DEEP: &str = "nested more deeply than the notation reads"; + /// The members that print first, in this order; every other member follows in /// key order. The order is for the reader (a declaration's name comes before /// its body); it carries no meaning, and the parser takes members in any order. @@ -144,10 +148,12 @@ pub struct Reader<'t> { pub text: &'t str, tokens: Vec, at: usize, + /// The deepest nesting this reader reads. + pub max_depth: usize, } impl<'t> Reader<'t> { - /// Lex `text`. + /// Lex `text`, to be read to [`MAX_DEPTH`] levels. /// /// # Errors /// @@ -157,9 +163,18 @@ impl<'t> Reader<'t> { text, tokens: lex(text)?, at: 0, + max_depth: MAX_DEPTH, }) } + /// This reader, reading to `max_depth` levels; the caller reads on a + /// stack sized for them. + #[must_use] + pub const fn with_max_depth(mut self, max_depth: usize) -> Self { + self.max_depth = max_depth; + self + } + /// The next token, not consumed. #[must_use] pub fn peek(&self) -> Option<&Token> { @@ -265,8 +280,8 @@ fn integer(word: &str) -> Option<&str> { /// /// Text that is not a value. pub fn value(reader: &mut Reader<'_>, depth: usize) -> Result { - if depth > MAX_DEPTH { - return Err(reader.error("nested more deeply than the notation reads")); + if depth > reader.max_depth { + return Err(reader.error(TOO_DEEP)); } let offset = reader.offset(); match reader.bump() { diff --git a/crates/lexlean/src/surface/semantic.rs b/crates/lexlean/src/surface/semantic.rs index aeffe1343e..aaee6b458d 100644 --- a/crates/lexlean/src/surface/semantic.rs +++ b/crates/lexlean/src/surface/semantic.rs @@ -257,8 +257,8 @@ fn exact(object: &std::collections::BTreeMap, keys: &[&str]) -> bo /// Read the value at `pos`. fn read_at(reader: &mut Reader<'_>, pos: Pos, depth: usize) -> Result { - if depth > MAX_DEPTH { - return Err(reader.error("nested more deeply than the notation reads")); + if depth > reader.max_depth { + return Err(reader.error(generic::TOO_DEEP)); } match pos { Pos::Term => terms::read(reader, depth), @@ -574,8 +574,8 @@ mod types { /// Read a type. pub(super) fn read(reader: &mut Reader<'_>, depth: usize) -> Result { - if depth > super::MAX_DEPTH { - return Err(reader.error("nested more deeply than the notation reads")); + if depth > reader.max_depth { + return Err(reader.error(super::generic::TOO_DEEP)); } let offset = reader.offset(); match reader.peek() { @@ -1153,8 +1153,8 @@ mod terms { /// Read a term. pub(super) fn read(reader: &mut Reader<'_>, depth: usize) -> Result { - if depth > super::MAX_DEPTH { - return Err(reader.error("nested more deeply than the notation reads")); + if depth > reader.max_depth { + return Err(reader.error(super::generic::TOO_DEEP)); } let offset = reader.offset(); match reader.peek() { @@ -1684,7 +1684,21 @@ pub fn print_module(module: &Json) -> Result { /// /// Text that is not a sequence of declarations. pub fn parse_module(text: &str, spec: &str) -> Result { - let mut reader = Reader::new(text)?; + parse_module_bounded(text, spec, MAX_DEPTH) +} + +/// [`parse_module`] reading to `max_depth` levels of nesting, on a stack the +/// caller has sized for them (the linker: `max_scope_depth`, §25.5). +/// +/// # Errors +/// +/// Text that is not a sequence of declarations. +pub fn parse_module_bounded( + text: &str, + spec: &str, + max_depth: usize, +) -> Result { + let mut reader = Reader::new(text)?.with_max_depth(max_depth); let mut declarations = Vec::new(); while !reader.done() { declarations.push(read_at(&mut reader, declaration(), 1)?); @@ -1701,7 +1715,20 @@ pub fn parse_module(text: &str, spec: &str) -> Result { /// /// Text that is not a sequence of declarations. pub fn declaration_spans(text: &str) -> Result, SurfaceError> { - let mut reader = Reader::new(text)?; + declaration_spans_bounded(text, MAX_DEPTH) +} + +/// [`declaration_spans`] reading to `max_depth` levels of nesting, on a stack +/// the caller has sized for them. +/// +/// # Errors +/// +/// Text that is not a sequence of declarations. +pub fn declaration_spans_bounded( + text: &str, + max_depth: usize, +) -> Result, SurfaceError> { + let mut reader = Reader::new(text)?.with_max_depth(max_depth); let mut spans = Vec::new(); while !reader.done() { let start = reader.offset(); diff --git a/features/suites/semantic-ir.feature b/features/suites/semantic-ir.feature index feef7f6178..739dd8b133 100644 --- a/features/suites/semantic-ir.feature +++ b/features/suites/semantic-ir.feature @@ -78,11 +78,12 @@ Feature: semantic-ir And the `All` selection returns the same complete sorted set @SM-12 @build - Scenario: No semantic IR node can contain opaque prose, raw backend text, or an unknown extension. Semantic modules retain the 128-level JSON nesting limit and an over-deep list is refused with LLT4001 naming smaller definitions joined by prim append as the remedy. + Scenario: No semantic IR node can contain opaque prose, raw backend text, or an unknown extension. A semantic module nests as deeply as the project's max_scope_depth allows, in its notation and in its data: a list of 1000 elements checks and builds, and its snapshot is written, and the authoring API reads and writes it, on a caller's default stack without a panic, while a list nested past the bound is refused, with LLP2001 in the notation and LLT4001 in the data, naming max_scope_depth. Given the example project checked through the internal pipeline When the linked IR is serialized to canonical JSON Then the JSON contains none of `natural number`, `For every`, `reflexivity`, or `Close the goal` - And a 122-element list checks while a 123-element list, including in a subsequent declaration, fails with LLT4001 naming the 128-level JSON bound and smaller definitions joined by prim append + And a 1000-element list checks and builds, and its snapshot is written and the authoring API reads, converts, and writes it on a 2 MiB stack, while a 1100-element list, including in a subsequent declaration, fails with LLP2001 naming max_scope_depth 1024 + And under max_scope_depth 150 a 145-element list checks, 146 elements fail with LLT4001 and 148 with LLP2001, each naming max_scope_depth And two 100-element definitions joined by prim append check, and malformed, noncanonical, duplicate-member and out-of-schema data remain refused @SM-13 @build diff --git a/model/ids.toml b/model/ids.toml index a8ed485f31..6e26cb2ef3 100644 --- a/model/ids.toml +++ b/model/ids.toml @@ -581,7 +581,7 @@ statement = "Linked project result sets contain every selected module and import id = "SM-12" level = "build" suite = "semantic-ir" -statement = "No semantic IR node can contain opaque prose, raw backend text, or an unknown extension. Semantic modules retain the 128-level JSON nesting limit and an over-deep list is refused with LLT4001 naming smaller definitions joined by prim append as the remedy." +statement = "No semantic IR node can contain opaque prose, raw backend text, or an unknown extension. A semantic module nests as deeply as the project's max_scope_depth allows, in its notation and in its data: a list of 1000 elements checks and builds, and its snapshot is written, and the authoring API reads and writes it, on a caller's default stack without a panic, while a list nested past the bound is refused, with LLP2001 in the notation and LLT4001 in the data, naming max_scope_depth." [[id]] id = "SM-13" diff --git a/tests/semantic-json-depth/README.md b/tests/semantic-json-depth/README.md index b612b5af49..270660ae4b 100644 --- a/tests/semantic-json-depth/README.md +++ b/tests/semantic-json-depth/README.md @@ -1,16 +1,23 @@ # Semantic JSON depth fixtures `SM-12` reads these authored language-1.2 modules in a temporary project with -`max_scope_depth = 1024`. The semantic JSON reader still has its documented -128-level nesting limit: 122 `cons` cells check, while 123 fail with `LLT4001` -and advice to use smaller definitions joined by `prim append`. +`max_scope_depth = 1024`. A semantic module nests as deeply as that bound +allows, in its notation and in the JSON the notation reads to: a list of n +cells nests about n levels. -The refused sources live under `negative/`, matching the authoring API corpus's -classification of intentionally unreadable modules. `negative/list-123.lex.tex` -is the boundary refusal. `negative/later-list-123.lex.tex` puts the same failure -after another declaration; the diagnostic's source span covers the module body -and does not pretend to name -the nested term. `split-list-200.lex.tex` demonstrates the advised workaround -with two 100-cell definitions. The case also calls the semantic JSON reader -directly and checks that its existing canonical and closed-schema refusals +`list-1000.lex.tex` is a 1000-cell list, past every fixed 128-level JSON +reader: it checks, builds, and has a snapshot whose canonical bytes are written +on a caller's default 2 MiB stack. The refused sources live under `negative/`, +matching the authoring API corpus's classification of intentionally unreadable +modules. `negative/list-1100.lex.tex` is nested past the bound, and is refused +with `LLP2001` naming `max_scope_depth`. `negative/later-list-1100.lex.tex` puts +the same failure after another declaration; the diagnostic's source span +covers the module body and does not pretend to name the nested term. +`split-list-200.lex.tex` shows the workaround the diagnostic still names, two +100-cell definitions joined by `prim append`. + +The case also lowers the bound to 150 to show that both readers take it from +the project (a 145-cell list checks, 146 cells are refused by the JSON reader +with `LLT4001`, 148 by the notation with `LLP2001`), calls the semantic JSON +reader directly, and checks that its canonical and closed-schema refusals remain intact. No verification claim is made by these checking fixtures. diff --git a/tests/semantic-json-depth/list-1000.lex.tex b/tests/semantic-json-depth/list-1000.lex.tex new file mode 100644 index 0000000000..89dd480d5d --- /dev/null +++ b/tests/semantic-json-depth/list-1000.lex.tex @@ -0,0 +1,7 @@ +\begin{lexlean}{Main} +\useglossary{lexlean.std.nat@1.2.0} +\title{Natural number addition} +\begin{semanticmodule} +definition{ name: xs, parameters: [], result: (List Nat), body: (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (nil Nat))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) } +\end{semanticmodule} +\end{lexlean} diff --git a/tests/semantic-json-depth/list-122.lex.tex b/tests/semantic-json-depth/list-122.lex.tex deleted file mode 100644 index 4361519883..0000000000 --- a/tests/semantic-json-depth/list-122.lex.tex +++ /dev/null @@ -1,7 +0,0 @@ -\begin{lexlean}{Main} -\useglossary{lexlean.std.nat@1.2.0} -\title{Natural number addition} -\begin{semanticmodule} -definition{ name: xs, parameters: [], result: (List Nat), body: (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (nil Nat))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) } -\end{semanticmodule} -\end{lexlean} diff --git a/tests/semantic-json-depth/negative/later-list-1100.lex.tex b/tests/semantic-json-depth/negative/later-list-1100.lex.tex new file mode 100644 index 0000000000..b979d16386 --- /dev/null +++ b/tests/semantic-json-depth/negative/later-list-1100.lex.tex @@ -0,0 +1,8 @@ +\begin{lexlean}{Main} +\useglossary{lexlean.std.nat@1.2.0} +\title{Natural number addition} +\begin{semanticmodule} +definition{ name: first, parameters: [], result: (List Nat), body: (cons 1 (nil Nat)) } +definition{ name: later, parameters: [], result: (List Nat), body: (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (nil Nat))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) } +\end{semanticmodule} +\end{lexlean} diff --git a/tests/semantic-json-depth/negative/later-list-123.lex.tex b/tests/semantic-json-depth/negative/later-list-123.lex.tex deleted file mode 100644 index 7636ca8f08..0000000000 --- a/tests/semantic-json-depth/negative/later-list-123.lex.tex +++ /dev/null @@ -1,8 +0,0 @@ -\begin{lexlean}{Main} -\useglossary{lexlean.std.nat@1.2.0} -\title{Natural number addition} -\begin{semanticmodule} -definition{ name: first, parameters: [], result: (List Nat), body: (cons 1 (nil Nat)) } -definition{ name: later, parameters: [], result: (List Nat), body: (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (nil Nat)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) } -\end{semanticmodule} -\end{lexlean} diff --git a/tests/semantic-json-depth/negative/list-1100.lex.tex b/tests/semantic-json-depth/negative/list-1100.lex.tex new file mode 100644 index 0000000000..8a593c68ed --- /dev/null +++ b/tests/semantic-json-depth/negative/list-1100.lex.tex @@ -0,0 +1,7 @@ +\begin{lexlean}{Main} +\useglossary{lexlean.std.nat@1.2.0} +\title{Natural number addition} +\begin{semanticmodule} +definition{ name: xs, parameters: [], result: (List Nat), body: (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (nil Nat))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) } +\end{semanticmodule} +\end{lexlean} diff --git a/tests/semantic-json-depth/negative/list-123.lex.tex b/tests/semantic-json-depth/negative/list-123.lex.tex deleted file mode 100644 index a38645d78d..0000000000 --- a/tests/semantic-json-depth/negative/list-123.lex.tex +++ /dev/null @@ -1,7 +0,0 @@ -\begin{lexlean}{Main} -\useglossary{lexlean.std.nat@1.2.0} -\title{Natural number addition} -\begin{semanticmodule} -definition{ name: xs, parameters: [], result: (List Nat), body: (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (cons 1 (nil Nat)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) } -\end{semanticmodule} -\end{lexlean}