Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -829,10 +829,10 @@ jobs:
# 41478333299), 124.5 of them in the conformance binary. #235 moves SP-02's
# complete stress families and TC-03's seeded fuel sweep to the normative
# host, keeping fixed vectors here, and reads the shared declaration
# inventory once in TC-03 and TC-05. The post-change Intel measurement is
# recorded with the PR's full-gate results before closing #235. This limit
# stays until that evidence supports lowering it: a timeout is a bound on
# a hung job, not a performance result.
# inventory once in TC-03 and TC-05. At 30612d265 on 2026-11-03 the
# post-change leg took 117m01s (run 41592896657), 100m21s in conformance.
# The 240-minute bound is about twice that observed runtime; no timeout
# reduction.
timeout-minutes: 240
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand Down
2 changes: 1 addition & 1 deletion CONFORMANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,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. |
| `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-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. |
Expand Down
10 changes: 7 additions & 3 deletions SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -5412,8 +5412,12 @@ 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`, `invalid semantic-module JSON: recursion
limit exceeded`, whatever `max_scope_depth` says; a chain of 100 is read.
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.

**Proof.** The proof follows the source term construct by construct through
the library's compatibility lemmas. A recursive definition's relation is
Expand Down Expand Up @@ -11034,7 +11038,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. | §6 I4, §17 |
| `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-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 |
Expand Down
31 changes: 31 additions & 0 deletions VERIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -12306,3 +12306,34 @@ this environment installs Lean under `ELAN_HOME` while the conformance
helper requires `$HOME/.elan`. That is a blocked Lean-backed test, not a
pass or an Intel timing measurement. The full normative cases and actual
non-normative host paths remain for CI; neither helper nor home was changed.

## Semantic JSON nesting diagnostic names the list workaround (`SM-12`, #375)

The 128-level semantic JSON reader limit is unchanged. Before the diagnostic
change, `cargo test --offline --locked -p repo-conformance --test conformance
conformance_sm_12 -- --exact --nocapture` failed on the new assertion with:

```text
phase link: invalid semantic-module JSON: recursion limit exceeded at line 1 column 6925
```

The committed fixtures under `tests/semantic-json-depth/` exercise a 122-cell
list that checks, a 123-cell list that fails, the same failure in a subsequent
declaration, and a 200-cell list split into two definitions joined by
`prim append` that checks. The failure is checked through the project API,
human and JSON CLI output, and the semantic JSON reader directly. Malformed,
noncanonical, duplicate-member and out-of-schema data (including an extra
member on a tagged unit variant) remain refused without list-depth advice.
The source span still covers the module body; generated JSON coordinates are
not presented as a nested term's source position.

After the change, the same command passes (1.83 s on this host). Removing
the append recommendation from the diagnostic, leaving the bound and
smaller-definitions advice intact, makes that command
fail on its `prim append` assertion (1.32 s). The planted edit was restored.
The diagnostic change does not run Lean or establish a new verification claim;
#375 already records verification of two 100-cell lists joined by append.

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.
91 changes: 91 additions & 0 deletions crates/conformance/src/cases/semantic_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,96 @@ mod names;
mod strings;
mod widen;

fn semantic_json_depth_diagnostic() {
let project = P::example();
project.edit("lexlean.toml", "language = \"1.0\"", "language = \"1.2\"");
// Direct reader assertions use the same configured stack as the pipeline.
let stack_bytes = support::limits_of(&project)
.compile_stack_plan()
.stack_bytes;
std::thread::Builder::new()
.stack_size(stack_bytes)
.spawn(move || semantic_json_depth_diagnostic_on_stack(&project))
.expect("reader test thread")
.join()
.expect("semantic JSON depth assertions");
}

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));
project.relock();
project.check_ok();
}
let parse_data = |data: &str| {
lexlean::ir::semantic::SemanticModule::parse(
data,
"1.2",
"LexLeanExample",
&[],
&std::collections::BTreeMap::new(),
&lexlean::ir::semantic::model::ArtifactStore::new(u64::MAX, u64::MAX),
)
};
for name in ["list-123.lex.tex", "later-list-123.lex.tex"] {
let source = fixture(name);
project.write("src/Main.lex.tex", &source);
project.relock();
let error = project.check_fails_with("LLT4001");
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"));
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"));
}
}

let empty = r#"{"declarations":[],"spec":"lexlean/semantic-module/2"}"#;
let invalid = [
empty.replace(",\"spec\"", " \"spec\""),
empty.replace("{\"declarations\"", "{ \"declarations\""),
empty.replace("\"spec\":", "\"spec\":\"lexlean/semantic-module/2\",\"spec\":"),
empty.replace("\"declarations\":[]", "\"declarations\":[],\"foreign\":true"),
r#"{"declarations":[{"body":{"kind":"nat","prose":"foreign","value":"1"},"kind":"definition","name":"x","parameters":[],"result":{"kind":"nat"}}],"spec":"lexlean/semantic-module/2"}"#.to_owned(),
];
for data in invalid {
let error =
parse_data(&data).expect_err("malformed, noncanonical or foreign data stays refused");
assert_eq!(error.code.as_str(), "LLT4001");
assert!(
!error.reason.contains("prim append"),
"depth advice belongs only to nesting failures: {error}"
);
}
}

/// Every `"k"` and `"kind"` tag value in a canonical JSON document.
fn collect_tags(value: &serde_json::Value, key: &str, out: &mut BTreeSet<String>) {
match value {
Expand Down Expand Up @@ -692,6 +782,7 @@ pub(crate) fn run(id: &str) {
}
// §17.5, I7: no opaque prose inside semantic IR.
"SM-12" => {
semantic_json_depth_diagnostic();
let project = P::example();
let json = support::checked_project(&project)
.linked_json()
Expand Down
11 changes: 9 additions & 2 deletions crates/lexlean/src/ir/semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8815,8 +8815,15 @@ impl SemanticModule {
imported_modules: &BTreeMap<String, &Self>,
artifacts: &model::ArtifactStore,
) -> Result<Self, SemanticFailure> {
let module: Self = serde_json::from_str(text)
.map_err(|error| format!("invalid semantic-module JSON: {error}"))?;
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();
if canonical != text {
Expand Down
4 changes: 3 additions & 1 deletion features/suites/semantic-ir.feature
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +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.
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.
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 two 100-element definitions joined by prim append check, and malformed, noncanonical, duplicate-member and out-of-schema data remain refused

@SM-13 @build
Scenario: Inherited section parameters are represented explicitly and emitted only on declarations that use them.
Expand Down
2 changes: 1 addition & 1 deletion model/ids.toml
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,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."
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."

[[id]]
id = "SM-13"
Expand Down
13 changes: 13 additions & 0 deletions tests/semantic-json-depth/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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`.

`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
remain intact. No verification claim is made by these checking fixtures.
8 changes: 8 additions & 0 deletions tests/semantic-json-depth/later-list-123.lex.tex
Original file line number Diff line number Diff line change
@@ -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 (nil Nat)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) }
\end{semanticmodule}
\end{lexlean}
7 changes: 7 additions & 0 deletions tests/semantic-json-depth/list-122.lex.tex
Original file line number Diff line number Diff line change
@@ -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 (nil Nat))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) }
\end{semanticmodule}
\end{lexlean}
7 changes: 7 additions & 0 deletions tests/semantic-json-depth/list-123.lex.tex
Original file line number Diff line number Diff line change
@@ -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 (nil Nat)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) }
\end{semanticmodule}
\end{lexlean}
Loading
Loading