Skip to content

#115 PR 3/5: RB-18, a heap literal read from a function of no parameters is a once-per-thread constant - #238

Closed
afflom wants to merge 31 commits into
release/v0.5from
claude/issue-115-rust-constant
Closed

afflom wants to merge 31 commits into
release/v0.5from
claude/issue-115-rust-constant

Conversation

@afflom

@afflom afflom commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Part of #115 (L3.2 of #106), PR 3 of the stack, round two after the review. Stacked on #230 (→ #228); merged with release/v0.5 at 42ce948.

Change (as reviewed). A function of no parameters that cannot fail, whose body is a closed literal of a list, string or byte string, is a constant in rust-std: a thread_local! cell evaluated once per thread, each call a clone (lower.rs, ast.rs). SPEC §17.16 Constants, RB-18 row (a record in spec/src/IdsRB.lex.tex), scenario.

Round two (the review's decision, R8). The constant is a construct of the certified machine, not a printer-only item:

  • compiler/src/RustSyntax.lex.tex: ItemDef.constant [Ident, RustType, Block]; RustSemantics.lex.tex: an arm in findFunction (a constant is a function of no parameters whose body is the value) and in findDispatch. The machine counts no work, so there is no tick to add: "one tick per read" is read as the differentials' counted work, which a clone leaves unchanged; say if you want it elsewhere.
  • Certificate B encodes the item as itself (data_b/syntax.rs → ItemDef.constant); the function() view in data_b.rs is only a lookup.
  • The rule (nullary by construction, result cannot fail, no binding, body a closed literal) is in validate.rs and in bootstrap/src/RustValidate.lex.tex (Def.DConstant, literalOk, noLets, constantShape; the constant correspondence row is in both tables, last). Five committed crates in the BS-05 differential (constant_crates: a literal accepted; a call, a failing result, a binding refused; a name declared twice) make the refusal reachable; both validators give the same message, and BS-05 counts are now 411/169 and 388 evaluator vectors (restated in SPEC §17.23, the register row, the scenario and VERIFICATION).
  • A literal of a declared algebraic type is not a constant (Type::heap); the case requires it and SPEC §17.16 says so.
  • The library: with the grown ItemDef the library refused at findDispatch_some._f (the break the [v0.4] #27 stage 6: complete the closed Rust AST so the runtime is generated from the calculus #91 walk predicted); one casesOn minor repaired (the function minor without its parameters), conformance_sp_13 passes over the regenerated machine modules (299 s), no other declaration changed. Method and numbers in VERIFICATION.md.
  • Should-fixes: command and quoted diagnostics in the record, the hand-written Some(7) 5 5 and its dependence on the not-yet-committed cached-literal fixture stated, scenario reworded ("read once to warm, then twice").

Gates on the unregenerated tree. fmt, clippy -D warnings, validate-model (438 ids), validate-spec-links, --test bdd, conformance_rb_18. With the regenerated RustSyntax/RustSemantics held in the working tree only (not committed): conformance_sp_13 (library, 299 s), lexlean verify in bootstrap/ (verified 6 modules), and conformance_bs_05 through the whole differential (rustc agreement on every vector including the constant crates, planted defects detected) up to the final comparison with the committed packages.

Wait for the regeneration (yours). conformance_rb_01 ([constant] row no committed package exercises), rb_07 (renderer record), conformance_bs_05 at packages/rust-std/audit_tokens/package.json differs from the committed package, the committed language/preservation-1.2/modules/LexLeanTarget/RustSyntax.lean/RustSemantics.lean (the library repair is only valid against them), bootstrap/lexlean.lock and the bootstrap expected records, compiler/lexlean.lock, the cached-literal fixture file, and everything listed on #230.

Not established. The certified package for RustValidate (the production export) after the new definitions: its axiom policies verified (verified 6 modules) but the export is not compared. No full just vv. conformance_sp_24 is #239's.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NZLb4yopYgjBGQngfSuFeQ

…cenarios and failing named tests

Rows, SPEC.md §31 rows, scenarios, and conformance_<id> tests only; the four
tests fail because no case is wired. No implementation, no identity moves.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZLb4yopYgjBGQngfSuFeQ
#91 stage 4's)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZLb4yopYgjBGQngfSuFeQ
The reference interpreter, the TargetSemantics denotation, and the SPEC.md
17.14 cost rules charge Expr.value its weight (one for a scalar). The case
conformance_tc_08 passes; the 14 fixtures with a literal heavier than one node,
their generated statements, and compiler/lexlean.lock are not regenerated, so
conformance_tc_01/03/04/05 fail on this tree until the maintainer sequences it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZLb4yopYgjBGQngfSuFeQ
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZLb4yopYgjBGQngfSuFeQ
…-per-thread constant

ItemDef::Constant (a thread-local cell and a clone per call) is lowered for a
nullary, infallible function whose body is a closed literal with a heap type in
rust-std; validate refuses a constant that calls or can fail; the machine reads
it as the function it caches. conformance_rb_18 counts allocations under the
pinned rustc, with the rebuilding rendering as a plant, and the calculus fixture
cached-literal puts a constant in TC-07's differential.

rb_01 and rb_07 wait on the maintainer's regeneration of the committed packages
and the rust_renderer record.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZLb4yopYgjBGQngfSuFeQ

afflom commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

conformance_bs_04 run alone on this branch (with CARGO_BUILD_JOBS=2): ok, 1 passed, 3090 s. The SIGKILL in the earlier parallel run was the container running out of memory with many rustc builds at once, not a rendering or lint failure; bootstrap root packages build under the pinned rustc with constants in the lowering.


Generated by Claude Code

@afflom afflom left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintainer review of RB-18 at ae0d10f. (A comment because the token cannot request changes on its own PR; read it as changes requested.)

Verdict: needs changes. The hoisting itself is right: nullary, infallible, heap-typed, literal body (lower.rs:2382-2405), a thread_local! cell read by an Rc clone so a read allocates nothing, the cached-literal fixture makes the differential and the evaluator agree, and the case is falsifiable (returning the rebuilt literal behind the cell fails at rust_backend.rs:1742 with left: 4 / right: 0). What is wrong is where the construct lives.

Must fix

  1. The certified machine does not state the crate the renderer writes. data_b/syntax.rs:611-622 encodes a Constant as ItemDef.function with the literal body, while the printed src/lib.rs holds thread_local! and CELL.with(|cell| cell.clone()), constructs RustSyntax (RustSyntax.lex.tex:284-292: enum, apply, function) does not declare. The PR adds a new ItemDef family on the Rust side (ast.rs:435) and a CORRESPONDENCE row (validate.rs:1154) and hides both from the machine, then SPEC §17.16 asserts the counted work is unchanged by fiat. That is the opaque-bypass shape R8 forbids, and it is not what the plan on #115 says ("RustSemantics gains the meaning of the hoisted constant"). Decision: add constant to RustSyntax and RustSemantics (its value is its body's, one tick per read, as planned), have certificate B encode it as itself, and let RustValidate state its rule (nullary, infallible, literal body) so the bootstrap differential covers it. No printer-only construct; no CORRESPONDENCE row that the machine does not have.
  2. The refusal in the statement is unreachable. ids.toml:1796 promises "a constant whose body calls, or that can fail, is refused before printing", but the only builder of a Constant (lower.rs:2385-2390) never builds one with a call or a fallible result; the refusal is reached only by hand-built ASTs in the test (rust_backend.rs:1776-1796). A gate nothing can reach is not a gate. Once the rule lives in RustValidate per item 1, a committed negative fixture (a constant with a call in its body, refused by the validator and by the differential) makes it reachable and the statement stays; if you choose not to, narrow the statement to what is built.

Should fix

  • VERIFICATION.md:4038-4059: add the command run; quote the observed diagnostic (assertion left == right failed: a read of a cached literal allocates nothing / left: 4 / right: 0 at rust_backend.rs:1742) rather than paraphrasing it.
  • A literal that must not be hoisted has no committed negative case: an ADT-typed nullary literal holding lists is rebuilt per call only because result.heap() says Adt(_) => false (ast.rs:150-164). Add the case, and a line in SPEC §17.16 Constants saying ADT-typed literals are not constants.
  • The RB-18 expectation "Some(7) 5 5" (rust_backend.rs:1741, 1769) is hand-written; the evaluator/rustc agreement rests on conformance_tc_07's cached-literal fixture, whose committed file does not exist until regeneration. State that in the record.
  • rust-backend.feature:98-101 says "read three times"; the test warms once and counts two (rust_backend.rs:1660-1667). Reword one.

Notes (expected on this tree, not findings)

conformance_rb_01 ([constant] row no run package exercises), rb_07 (renderer record), tc_01/03/04/05, and the missing cached-literal fixture file all wait on the landing regeneration. thread_local! passes #[forbid(unsafe_code)] because the std macro is allow_internal_unsafe; the rendered crate compiled with -D warnings.


Generated by Claude Code

…e records of spec/src

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZLb4yopYgjBGQngfSuFeQ
…mand and the limit of the text check

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZLb4yopYgjBGQngfSuFeQ
ItemDef.constant in RustSyntax with arms in RustSemantics; certificate B encodes
it as itself; the rule (infallible, closed literal, no binding) is stated by
validate and by the bootstrap RustValidate, held by five committed crates in
the BS-05 differential; the library repairs its one lemma that eliminates
ItemDef (findDispatch_some._f). A declared algebraic type is not a constant.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZLb4yopYgjBGQngfSuFeQ

@afflom afflom left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintainer review, round two, at 4d77480 (read on the stack's head 775bba0).

Verdict: accepted, with should-fixes. Both must-fixes are met. ItemDef.constant [Ident, RustType, Block] is a construct of the machine (RustSyntax.lex.tex:291; RustSemantics.lex.tex:1320 returns it from findFunction as a nullary function and :1346 skips it in dispatch), certificate B encodes it as itself (data_b/syntax.rs:609-619), the rule lives in both validators (validate.rs:771-787; RustValidate.lex.tex DConstant/constantShape/literalOk/noLets, correspondence row last, matching validate.rs:1343), and the refusal is reachable: constant_crates() (rust_validate.rs:1908-1965) refuses a call, a fallible result and a binding in both validators, and a planted constantShape that accepts a fallible result fires conformance_bs_05 at rust_validate.rs:2693 on the rendered leg. The printer plant still fires rb_18 at rust_backend.rs:1742.

On "one tick per read": the Rust machine has no cost component (ROutcome at RustSemantics.lex.tex:9-17; invoke/finished discard the steps), so the tick exists in the calculus (weight v, TC-08) and in the differential's counted work (TC-07), and §17.16 says so. Accepted as written.

Should fix (ride the next push)

  1. Stale counts: VERIFICATION.md:9809 (BS-05 record) still says "34 hand-built crates … 406 vectors (165 refused) … 675 in all" next to the restated "388 + 246"; SPEC.md:7520 (§17.23) still says "97 rows of the correspondence table" (now 98). Both must match the register row's restatement (SPEC.md:7536-7538).
  2. The RB-18 scenario (rust-backend.feature:100-101) promises "validated by the oracle and by the bootstrap validator" and "certificate B states the constant", but cached_literal() (rust_backend.rs:1706-1836) runs neither, and no case asserts certificate B's encoding: artifacts_as_data() counts ItemDef::Constant in the crate (preservation.rs:5310-5318) and compiles the certificates, which also compile if syntax.rs regressed to the round-one shape. Add one assertion that a certificate B text for a constant contains ItemDef.constant (in sp_24, where the ten constants are counted, or in rb_18 through the data_b writer), and point the Then clause at BS-05/SP-24 for the validator half.
  3. VERIFICATION.md:4058-4064, plant 2: quote the observed assertion line (assertion left == right failed: a read of a cached literal allocates nothing / left: 4 / right: 0 at rust_backend.rs:1742) rather than paraphrasing it.

Notes

Expected on this head, not findings: rb_01, rb_07, tc_01/03/04/05, tc_07's cached-literal fixture file, bs_05's package comparison, the three locks, and every case that compiles the shipped library (sp_13, the Lean SP cases): the committed RustSyntax.lean/RustSemantics.lean lack constant while the committed library repair (findDispatch_some._f) needs it. The regeneration at landing closes that gap. The library diff of the stack is +498/−83 in RustMatches.lex.tex, all from this PR's term-table re-serialisation; no Corr change.


Generated by Claude Code

…alue v (weight v))

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZLb4yopYgjBGQngfSuFeQ
…rust-constant

# Conflicts:
#	VERIFICATION.md
…ted, Then clause points at BS-05 and SP-24

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZLb4yopYgjBGQngfSuFeQ

afflom commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

Round-two should-fixes, head c82e5fd5c:

  1. Stale counts: VERIFICATION.md BS-05 record now says 34 loop crates and 5 constant crates, 411 validateCrate vectors (169 refused), 680 in all (and "all 680", and the stack-measure paragraph's 680); SPEC.md §17.23 says 98 rows of the correspondence table (the old "97" is kept in the record's history with the 98th named).
  2. conformance_rb_18 now builds certificate B for the cached crate and asserts its text and data name LexLeanTarget.RustSyntax.ItemDef.constant, and that the copy printed as a function does not; the scenario's Then clause no longer promises the validator half (it points at BS-05 for the committed crates and SP-24 for the models certificates).
  3. Plant 2 in the record quotes the observed line: assertion left == right failed: a read of a cached literal allocates nothing / left: 4 / right: 0 at rust_backend.rs:1742, produced with the printer returning the rebuilt literal behind the cell (the cell read into let _, then the literal as the tail, so every text the case looks for survives).

Gates: fmt, clippy -D warnings, validate-model, validate-spec-links, --test bdd, conformance_rb_18.


Generated by Claude Code

afflom commented Oct 25, 2026

Copy link
Copy Markdown
Member Author

Maintainer: closed as a stacked draft whose commits are contained in #239 (ce93e72b5), which lands the #115 stack as one regeneration on the 0.5.0 line after the v0.4 tag (owner direction, #15: one PR per landing). Nothing is lost; the review record stays here.


Generated by Claude Code

@afflom afflom closed this Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants