Skip to content

#115 PR 2/5: TC-08, a calculus literal is charged its weight once per read - #230

Closed
afflom wants to merge 20 commits into
release/v0.5from
claude/issue-115-literal-weight
Closed

afflom wants to merge 20 commits into
release/v0.5from
claude/issue-115-literal-weight

Conversation

@afflom

@afflom afflom commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Part of #115 (L3.2 of #106), PR 2 of the stack. Stacked on #228: this branch contains its commits (merged with release/v0.5 at 42ce948); the TC-08 change is the last commits.

Change. Expr.value is charged its weight (one per node, plus a string's characters and a byte string's bytes) each time it is read, in compiler/src/TargetSemantics.lex.tex (the kernel-checked denotation), crates/lexlean/src/calculus/interp.rs (the reference interpreter) and the Cost list of SPEC §17.14. A scalar still costs one step. The TC-08 row (a record in spec/src/IdsTC.lex.tex), scenario and VERIFICATION.md record are written to this, after the correction posted on #115 (the calculus already had compound literals; only the cost was missing).

Library lemmas touched, by name (the maintainer's decision, option 1).

  • LexLeanPreservation.Rust.sem_value (RustLemmas): its term applies congrArg to eval.eq_2 with the explicit argument Outcome.value v 1; it is now Outcome.value v (weight v), because the charge of Expr.value changed. That is the only lemma: with TargetSemantics.lean regenerated locally, conformance_sp_13 refused it first (the loader stops at the first refusal), and after the repair passes over all 13 modules, so the count was found by iteration. conformance_sp_14, _15 and _16 pass over the same regenerated module. Recorded in VERIFICATION.md.

Gates (unregenerated tree). cargo fmt --all --check, clippy -D warnings, validate-model (438 ids), validate-spec-links, --test bdd, and conformance_tc_02, _06, _07, _08 pass.

Limit of the denotation check. conformance_tc_08 checks the Lean denotation only by reading TargetSemantics.lex.tex and requiring the line that charges weight literal: a text check, not the kernel's reduction. The kernel check is the fixtures' rfl theorems, which need cargo xtask check-calculus --write first. The library compile above is a kernel check of the regenerated denotation against the library, not of the fixtures.

Fails on this tree, by design (the landing regeneration is yours). conformance_tc_01, _03, _04, _05: 14 of 122 committed fixtures contain a literal heavier than one node (binding-and-shapes, byte-compare, byte-order, byte-slices, bytes-and-text, decimal-overflow-wide, decimal-overflow, decimal, equality, function-shapes, literals, ordering, split-and-join, string-escapes); e.g. binding-and-shapes is committed at 39 steps and now evaluates to 51. compiler/lexlean.lock needs relocking, language/preservation-1.2/modules/LexLeanTarget/TargetSemantics.lean regenerating (the library repair is valid only against it), and check-golden reports the compiler project's TargetSemantics coverage oracle stale.

Not established. No full just vv; I did not check which other committed records embed a literal's step count.

🤖 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

@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 TC-08 at f3376f5.

Verdict: ready for the gate with two should-fixes. The rule is charged at the one evaluation site of Expr::Value in the interpreter (interp.rs:448-451) and in the denotation (TargetSemantics.lex.tex:5260); Let evaluates its binding once, Call its body once per call, so a literal in a recursive body is charged once per read and a let-bound literal read twice is charged its weight once plus the local-read rule. No under-charge and no over-charge found; a scalar stays at 1 (§17.14). The Rust runtime ticks nothing for a literal, so TC-07/RB-06's bound keeps its direction. The test is falsifiable: steps = 1 planted in the interpreter fails at calculus.rs:1613 with string read 1 time(s) is charged its weight 4.

Should fix

  1. VERIFICATION.md:4012-4036 lacks the command run (§27.9; every neighbouring record quotes it). Add cargo test -p repo-conformance --test conformance -- conformance_tc_08.
  2. The denotation half of the case is a source-text contains (calculus.rs:1627-1632). A defect planted in weight itself (Value.string text => 1) passes TC-08 and is caught only by TC-03/04/05 once the 14 fixtures and compiler/lexlean.lock are regenerated at landing. The record says so; say it in the PR body's "Not established" as well. A fixture whose rfl theorem states a weighted count would close it after regeneration; not required for this PR.

Notes

  • conformance_tc_01/03/04/05 failing on the committed fixtures with a heavy literal is the identity move; expected until landing.
  • The three LLB6005 plants exercise pre-existing static rules of check.rs; fine as coverage, but the statement's "refused with LLB6005" clause is not new work.

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

afflom commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

A finding on this PR that the unregenerated tree hides: TC-08 breaks the preservation library on regeneration. With the compiler/ modules regenerated (TargetSemantics.lean with the weight charge) and nothing else changed, conformance_sp_13 (all 13 library modules compiled over the machine modules) fails in RustLemmas:

native core declaration 'LexLeanPreservation.Rust.sem_value':
  (kernel) application type mismatch
    congrArg (fun x => match x with | Outcome.value v x => some (Obs.value v) | ...)
      (LexLeanTarget.TargetSemantics.eval.eq_2 p env n t v)

sem_value applies congrArg to the equation lemma for Expr.value, and the library term spells the old charge (Outcome.value v 1) as an explicit argument, so the new eval.eq_2 (... (weight v)) no longer fits. The loader stops at the first refusal, so this is one break, not the count; other lemmas that unfold the literal arm may follow (for example the conv_value family in Core). I have not repaired it: it is kernel-term data (the same kind of edit I made for findDispatch_some._f on #238), and I want your word on the scope first.

Options: (1) repair the library terms for the weight charge in this PR (iterate the library compile until it passes; I can do it with the same programmatic method), or (2) keep the charge out of the library by stating Expr.value as weight-parametric in the equation lemma. I recommend (1). Until then this PR is correct on the unregenerated tree and breaks the library once TargetSemantics.lean is regenerated, so the regeneration cannot proceed with TC-08 as it stands.


Generated by Claude Code

afflom commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

Round two at 22df8de: both should-fixes met (the command line in the record, the limit of the contains check in the body). On the sem_value break, read in the library notation: the statement (RustLemmas.lex.tex:6640) is observation-based through LexLeanPreservation.obs, which drops the step, so the statement does not change; the proof (:294555-294600) applies TargetSemantics.eval.eq_2 and spells the right-hand side Outcome.value v 1 as an explicit term at :294590, which is what no longer fits Outcome.value v (weight v). A proof repair, in this PR, as decided: eval.eq_2 is cited by exactly that one proof in the library, so one break is the likely count; confirm by iterating conformance_sp_13 over the locally regenerated TargetSemantics.lean, and record the command and the lemma names. One nit for the same push: the TC-08 scenario (calculus.feature:54) names a result literal that literal_weight() (calculus.rs:1569-1600) never reads; add one or drop the word.


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

afflom commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

Library repaired (option 1), head ae95b2808.

Lemmas touched, by name (one): LexLeanPreservation.Rust.sem_value in RustLemmas. Reason: its term applies congrArg to LexLeanTarget.TargetSemantics.eval.eq_2 with the explicit argument Outcome.value v 1 (the old one-step charge of Expr.value); the new equation lemma states Outcome.value v (weight v), so that argument became weight v (one occurrence, via the module's data, written back in the notation; the diff is the renumbering of nodes after it).

Measurement. With TargetSemantics.lean regenerated from the changed source (working tree only, not committed, with the compiler/ and example locks refreshed locally and reverted): conformance_sp_13 (13 library modules) refused sem_value; the loader stops at the first refusal, so I iterated: after the one repair it passes over all 13 modules, no second refusal. Also passed over the same regenerated module: conformance_sp_14, conformance_sp_15 (certificates A of the four corpora as data, the production example verified under Lean, 629 s) and conformance_sp_16. Recorded in VERIFICATION.md.

Forward-merged up the stack, each merge clean apart from one VERIFICATION.md section I resolved by keeping both: #238 484668194, #239 55e000184; #228 is unchanged at its last head. On the tip (#239) with all three machine modules regenerated locally (TargetSemantics, RustSyntax, RustSemantics): conformance_sp_13, conformance_sp_24, conformance_md_14 pass together (317 s), so the two library repairs (sem_value here, findDispatch_some._f on #238) coexist.

Not committed, as instructed: the regenerated compiler modules and every lock. Still waiting for the landing regeneration: the items listed on this PR.


Generated by Claude Code

claude added 12 commits October 20, 2026 17:16
…rojection

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

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
…and MD IDs (RP-11)

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

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

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