Skip to content

[0.5.0] Content-addressed artifacts as compile-time constants of production roots #115

Open

Description

@afflom

Plan item L3.2 of #106. Found through MNIST (evidence only): its certified crate rebuilds ten parameter tensors from artifact literals on every call.

Item. A production root's content-addressed artifacts are decoded once at build and appear as data in the lowered program, never decoded per call.

Accepted when. The lowered program of a corpus root (#124) reading an artifact contains its decoded value as data and no per-call decoding.


Generated by Claude Code

Activity

  1. added this to the LexLean v0.5 milestone on Oct 16, 2026
  2. afflom commented on Oct 20, 2026

    @afflom
    MemberAuthor

    #115: plan (measured on release/v0.5 at 17f7e46)

    Finding: not delivered. The decoding already happens once, at link; what is missing is that the decoded value is data in the lowered program and the Rust crate. Today it is rebuilt on every call. Nothing below is built until the maintainer's go.

    What the tree does today (measured)

    • Elaboration (SPEC §17.12 rule 2, model.rs:2627-2638). An artifact declaration decodes its content-addressed bytes once, at link, into a term, and elaborates to an ordinary nullary definition W : T := <decoded term> plus W.bytes and the kernel-checked W.decoded. The registry row declaration.artifact is runtime ("A constant of its decoded value", language/production-1.2.toml:1007), realized as ["function"] (calculus/realization.rs:272).
    • Lowering. W lowers to a zero-parameter calculus function whose body is a chain of build nodes (the calculus has scalar literals only: §17.14, Programs). Every call of a root that reads W evaluates that chain: a call site is call W and the denotation charges the whole body each time.
    • Rust. The committed rendering is a function that rebuilds the list on every call, e.g. examples/models/expected/verify/preserve/crate/R0.rust-std.rs:558 (pub fn f14() -> List<List<i64>> { List::cons(List::cons(2i64, List::cons(... ) called at :473, and :554 (f13, a ten-element List::cons chain). A bytes artifact would likewise be Bytes::lit(..), an Rc::from copy per call (:83).
    • Counts from the tree.
      • 8 artifact{ declarations in committed positive sources: examples/models/src/Recognizer.lex.tex (6) and Triage.lex.tex (2); 14 more in negative fixtures under tests/negative/model-* (not roots).
      • In the committed lowered programs (program/R*.json, all roots of all examples), nullary functions with a build chain of at least two nodes occur only in examples/models/expected/verify/preserve/program/: R0: 4, R1: 4, R2: 2 (10 in all; 274 build nodes in each of R0 and R1 and 20 in R2). R3..R8 have none.
      • I did not count bootstrap/, stdlib/, compiler/ or examples/reasoning separately: no artifact{ appears in their sources.
    • MNIST evidence. The issue cites a crate that rebuilds ten parameter tensors per call. That repository is outside this session's scope, so I have not read it; the same shape is what the models example's R0/R1 show above.

    Design choice I need from the maintainer (the plan depends on it)

    The calculus has no compound literal and no constant form, so "decoded value as data" requires a calculus extension. Two shapes:

    • (a) A data literal (list, pair, option, ADT value of literals) in the calculus's literal position. Static rule: every literal has its type; denotation: the value it spells; Rust: each closed literal is hoisted to a once-initialised thread-local (List is Rc-based and not Sync, so not a static), and a use is an Rc clone.
    • (b) A program-level constants table (name, type, data value) and a constant expression.

    I recommend (a): it reuses the one place literals are already typed, checked and canonicalised, and an artifact read is then an ordinary nullary call or inline literal. (b) adds a declaration kind to schema, load, canonical form and every consumer. Also to settle: the cost of reading a constant. Today it is the body's step count per call; the Rust invariant (TC-07/RB-06) only requires counted work ≤ denotation steps, so charging the literal's node weight once per read in the denotation and a clone in the rendering keeps it sound. I propose charging by weight (as primitives are), not a flat step.

    Registry rows, scenarios, named tests (R3; IDs are the next free in each family)

    ID Statement (sketch) Suite Test
    TC-08 The calculus has a closed data literal with a type rule, a canonical form, a kernel-checked denotation and a stated cost; the realization table covers it. calculus conformance_tc_08
    RB-15 The Rust backend renders a closed data literal once per thread and a read as a clone; counted work never exceeds the denotation's. rust-backend conformance_rb_15
    SP-21 An artifact read lowers to the decoded value as data with no per-call construction; certificates A, B and E cover it on every committed root. preservation conformance_sp_21
    MD-14 A production root reading an artifact has its decoded value as data in the lowered program, equal to W's decoding of W.bytes; planted per-call decoding is detected. models conformance_md_14

    Each also needs its SPEC.md §31 row (bijective, validate-spec-links) and a @<ID> @build scenario in features/suites/. All at level build.

    Machine primitives and certificates

    • No new primitive: a literal is not a prim. RustSemantics gains the meaning of the hoisted constant (a read returns the literal's value, charging one tick per read).
    • Corr: under (a), I expect one new case (a data literal in the lowered program relates to its source value), because today only scalar literals are covered. I have not measured the library cost: the repair-round method of the [v0.4] #27 stage 6: complete the closed Rust AST so the runtime is generated from the calculus #91 stage-4 session needs the constructor to exist first, so it belongs to the first build PR. Not established.
    • Certificates A, B and E must cover the data literal on every committed root (the three models programs R0..R2 above are the roots that change; all other roots' programs are expected byte-identical).

    Identities that move

    • schemas/target-program.schema.json, calculus/ canonical form, the compiler/ project's TargetSyntax/TargetSemantics/TargetOracle and RustSyntax/RustSemantics, their shipped copies, the calculus fixtures, and the committed Rust packages.
    • compiler_semantics appears in 589 committed files (records, bundles, schemas), so if the calculus is part of that identity (§21 says it is) every one of those moves. This is an identity-moving landing, so it is yours to sequence one at a time; I regenerate nothing on my own. I have not confirmed the exact count of files whose bytes change.

    Plants (VERIFICATION.md falsifiability table, §27.9)

    1. A root whose lowered program builds the artifact per call (a build chain in the body) fails conformance_sp_21/conformance_md_14.
    2. One flipped element of a data literal fails the differential against W's decoding and certificate A.
    3. A Rust rendering that rebuilds instead of cloning fails the work/clone gate in conformance_rb_15.

    Order of stacked draft PRs (each a draft, against release/v0.5)

    1. R3 skeleton: the four rows, §31 rows, scenarios and failing tests only (no implementation).
    2. Calculus data literal: schema, load, canonical form, compiler/ semantics, fixtures (TC-08).
    3. Rust backend and RustSemantics (RB-15), rustc differential.
    4. Lowering and Corr, certificates A/B/E, library cost measured (SP-21).
    5. The models example's regenerated records and the acceptance root (MD-14), after you sequence the identity move.

    Not established

    • Whether (a) or (b); the cost rule above is a proposal.
    • The Corr library cost, and the exact set of files that change.
    • Whether the acceptance root should live in examples/models or in the corpus of [0.5.0] A general performance corpus #124 (which does not exist yet); the models example already has the shape.
    • I have not run any gate on this branch yet; the measurements are from committed records, not a fresh build.

    Generated by Claude Code

  3. afflom commented on Oct 20, 2026

    @afflom
    MemberAuthor

    Maintainer's decisions; the plan is agreed with these.

    1. (a), a closed data literal in the calculus's literal position. It reuses the one place literals are typed, checked and canonicalised, and an artifact read becomes an ordinary nullary call or inline literal; (b) adds a declaration kind that every consumer must learn for the same value. The literal is closed (lists, pairs, options and ADT values of scalar literals, nothing else), so the denotation stays total and the canonical form stays a comparison of bytes.
    2. Cost by weight, once per read. The denotation charges the literal's node weight per read, as a primitive is charged; the rendering is one clone per read of a once-initialised thread-local; TC-07/RB-06 stay "counted work never exceeds the denotation's steps", which this keeps sound. State the weight rule in §17.14 beside the primitives' weights.
    3. IDs. SP-21, SP-22, SP-23, RB-15, RB-16 and RB-17 are taken by [v0.4] #27 stage 6: complete the closed Rust AST so the runtime is generated from the calculus #91 stage 4 on release/v0.4 (its drafts #91 stage 4, PR 0: register rows SP-21 and RB-15 (R3 skeleton) #223, #91 stage 4, PR 1: the machine grows, and the Rust AST mirrors the machine callee and the overflow value (SP-21, RB-15) #224, #91 stage 4, PR 2a: the machine's natural and integer arithmetic, Some or None on overflow (SP-23) #227). Take TC-08, RB-18, SP-24 and MD-14; the register count is assigned at landing, so do not renumber on your own.
    4. The acceptance root lives in examples/models, which already has the shape (R0..R2); [0.5.0] A general performance corpus #124's corpus cites it when it exists (C1: evidence, not the definition of done).
    5. The Corr library cost is measured in PR 4 by the repair rounds, with the static walk first, as [v0.4] #27 stage 6: complete the closed Rust AST so the runtime is generated from the calculus #91 does; post the count on this issue before writing the certificate case.

    This is an identity-moving landing on release/v0.5; records are mine to regenerate in sequence, as you say. Go ahead: PR 1 (the R3 skeleton) then PR 2 (the data literal, TC-08), each a draft against release/v0.5, gates on the unregenerated tree where they can run.


    Generated by Claude Code

  4. added a commit that references this issue on Oct 20, 2026
  5. afflom commented on Oct 20, 2026

    @afflom
    MemberAuthor

    Correction to the plan, found reading the code for PR 2 (release/v0.5 at 17f7e46)

    I wrote that the calculus "has no compound literal". That was wrong; I read §17.14's prose, not the code. Expr::Value { ty, value } already takes a compound Value (list, pair, option, result, ADT value), and check.rs:173-184 types it, interp.rs:616 evaluates it, term.rs:139 emits it, and rust/lower.rs:1416 renders it. So decision 1 ((a), a closed data literal) is already the shape of the syntax, the static rules, the canonical form and the term emission. What is missing is smaller and different:

    1. Cost. TargetSemantics.lex.tex:5260 charges every literal one step (Outcome.value literal 1), and interp.rs:445 mirrors it, whatever its size. Decision 2 (node weight once per read) is therefore a change to the kernel-checked denotation, not an addition. The weight function already exists (TargetSemantics.lex.tex:650, interp.rs:59).
    2. Rendering. lower.rs:1416 expands a list literal into a Cons chain evaluated at each read, which is the per-call rebuild measured in the plan. Hoisting is RB-18.
    3. Lowering. The artifact lowering emits build chains instead of a Value literal (SP-24). That is where the 10 rebuilt constants in examples/models R0..R2 come from.

    Consequence for PR 2 (TC-08). It is now the weight rule, not a new literal form: Expr.value charges weight literal in the Lean denotation, the reference interpreter and §17.14's Cost list. A scalar literal still costs 1, so only literals heavier than one node change. Measured on the committed fixtures: 14 of 122 contain such a literal (strings, byte strings, and the compound values in literals/function-shapes): 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. Their step counts, the generated TargetFixtures statements and compiler/lexlean.lock move; I leave those unregenerated for you to sequence, as you said.

    I am rewording the TC-08 row to say this. No other decision changes.


    Generated by Claude Code

  6. afflom commented on Oct 20, 2026

    @afflom
    MemberAuthor

    Correction noted and accepted: the compound literal is already Expr::Value, so TC-08 is the weight rule in the kernel-checked denotation, the reference interpreter and §17.14's cost list, with scalar literals still at 1. The 14 fixtures, the generated TargetFixtures statements and compiler/lexlean.lock are identity-bound records; I regenerate them at the landing, as with every identity-moving PR. Go on with PR 3 (RB-18, the hoisted constant and the clone per read) stacked on #230, and PR 4 (SP-24) after it, running on the unregenerated tree the gates that can run there (conformance_tc_08 on the fixtures it builds itself, the rustc differential, clippy, fmt, validate-model) and saying on each PR which cases wait for the regeneration.


    Generated by Claude Code

  7. afflom commented on Oct 20, 2026

    @afflom
    MemberAuthor

    #115: Corr / library cost, measured before the certificate case (branch claude/issue-115-lowering, on #238 → #230 → #228)

    Result: the preservation library does not grow. No Corr constructor, no new lemma, no repair round, and RustSyntax.ItemDef is unchanged.

    Static walk.

    • Machine side. The Rust constant (RB-18, #115 PR 3/5: RB-18, a heap literal read from a function of no parameters is a once-per-thread constant #238) is the existing ItemDef.function with no parameters in the machine term (data_b/syntax.rs), so nothing that eliminates ItemDef sees a new constructor. This is the bound the [v0.4] #27 stage 6: complete the closed Rust AST so the runtime is generated from the calculus #91 stage-4 notes ask to stay under (findDispatch_some and the three rows are untouched). git diff -- language/ is empty.
    • Certificate A. conv_value (Core.lex.tex:1039) is stated for any v : Value, not for scalars only. Its caller prove.rs used it for Nat/Integer/String/Bytes and had no case for a source cons/nil met with a literal: the first run printed LLI9001 phase preservation: the lowering of a cons is not a build of two. The fix is a branch in the aligner, not the library: a source Nil/Cons lowered to an Expr::Value is proved by conv_value at the literal's type and value (value_term already emits Value.list).
    • Certificate B. The value rule of Corr (side conditions Decided) already accepts the Rust construct chain a list literal renders to; the aligner's Term::Value arm needed no change.

    Repair rounds: 0. I changed the lowering (production/lower.rs: an artifact definition whose lowered body is a closed Nil/Cons of literals becomes one Expr::Value; recognised through the declaration kind, Source::is_artifact), the prove.rs branch above, and nothing under language/.

    Measured end to end on a copy of examples/models (language 1.2, unchanged sources), lexlean verify with the built binary on this branch: verified 9 modules; attestation 2fd00b83…, 6 m 45 s. In the verified preserve/ records:

    • programs R0, R1, R2 have 4, 4 and 2 nullary functions with a list-literal body and 0 build-chain constants (before: 10 chains; R3..R8 have none, as before);
    • the crates R0, R1, R2 hold 4, 4 and 2 thread_local! constants (RB-18);
    • the audit lists the same axiom sets as before for the library constants (Conv, ConvA, … [propext, Classical.choice, Quot.sound]). I did not diff the whole audit against the committed examples/models/expected/verify/preserve/audit.txt.

    Caveats.

    • This run used the unregenerated shipped calculus modules (TC-08's weight is not in them), so it shows the certificates do not depend on a literal's step charge; it is not a statement about the regenerated tree.
    • Only artifact definitions fold; an ordinary definition with a literal list keeps its build chain, so no other root's program moves. I measured that on models' R3..R8, not on the other examples (production, reasoning, bootstrap, stdlib): those roots contain no artifact{, and the fold is keyed on the declaration, but I have not re-lowered them.
    • Not run: certificate E's statement for the new programs beyond what verify runs, and the committed-record comparison.

    Next: the SP-24 and MD-14 cases (R3 first), then the PR.


    Generated by Claude Code

  8. added 2 commits that reference this issue on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions