Repository navigation
Arrays: Array A as a primitive family of leaf places (SPEC §9, phase 1 of #8) - #73
Merged
Merged
Conversation
…ion 29
§9 is revised: [L] (VTy.fam) is the run-time family ⊛_{i<n} L of leaf places,
Array A = [Ref A], and a borrowed array is the family of its leaf borrows. The
entry states the values (base and length), the relation clause, the three
machine steps (tab, idx, drop), the constants of phase 1, the array borrows,
the LLVM-portable lowering, and what is library (Vec, Str, u8) and open
(split_at, iter, Uninit, sized types). Buffers and strings as externs are
withdrawn. Decision 29 records why arrays are primitive and records are not
arrays.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dxc29PmGiszpa6ndt21EuK
Prim gains tab, idx and drop. BoLo.Head gains one step each: tab places len(c) cells holding () at fresh consecutive locations and continues as tabFill, which stores f i in cell i and returns (ℓ, n); idx answers inj₁ (ℓ+i) when i < n unsigned and inj₂ () otherwise; drop continues as dropFill, which frees each cell in order and hands its contents to f. The interpreter allocates the block at next. The closure IR names the three operations. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dxc29PmGiszpa6ndt21EuK
VTy gains fam L, the run-time family ⊛_{i<n} L of leaf places, whose value is
(ℓ, n) with leaf i at ℓ+i. The relation and the shape relation read it as the
iterated separating conjunction sepRange (Core/SepRange.lean) of L's clause at
the leaf locations; Imm̲ 'b [L] = [Imm̲ 'b L]; [L] outlives what L outlives;
NoMut, Cl, Occ, substitution and TyEq pass through; [L] is not persistent.
RefPos and MutPos gain the leaf positions of a family, and every lemma the
typed world proves by induction on types or positions gets its family case:
6.131 (reborrow_vShape), 6.60 (vC_outlives), the image, invariant and
relabelling lemmas, stability along Ext and the observable view. The checker's
deciders and printer read the former; it has no destructor yet.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dxc29PmGiszpa6ndt21EuK
…es from withload §9 amended before the array constants land: an array is a value and is borrowed as any value is, in a cell (Imm/Mut @A (Array A)). withload at Imm @A (Array A) gives the family [Imm 'x A] at a shorter lifetime, sound by 6.131 at [L]; mutation through Mut is withswap over the owned operations. The primitive array borrows and mutable families move to Open. The constants are array_new, array_free, array_size, array_replace (owned), and on families array_len, array_get, array_copy, array_forget. Decision 29 follows. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dxc29PmGiszpa6ndt21EuK
…tor [spec §9] CDerives gains array_new (tab), array_free (drop), array_size and array_replace on owned arrays, and array_len, array_get (idx), array_copy and array_forget on the family of leaf views; fundamentalC covers each, so adequacyC is unchanged in statement. tab is n of TW.alloc at a fresh run of locations (alloc_block, wpTS_tab), and the fill and the drain are proved by induction over the cells (tabFill_wp, dropFill_wp). array_get hands out one leaf's imm cell at the family's lifetime and forgets the others, which hold no own cell. The family itself comes from withload at Imm @A (Array A), sound by the [L] cases of 6.131. HasDtor gains Array A (array_free with the element's destructor) and ArrayImm @A A (array_forget). ArrayPrograms.lean runs one program by adequacy and by the interpreter. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dxc29PmGiszpa6ndt21EuK
The core syntax gains the types array A ([ref A]) and array_imm @ A ([imm @ A]), and the constants array_new, array_free, array_size, array_replace, array_len, array_get, array_copy and array_forget, each read with its bracket arguments and checked by one CDerives constructor at a dead context. The destructor decider knows arrays: array A when A has one, array_imm @A A always. checkProgram_sound is unchanged. syntax-core §8b documents them; a round trip is checked by the kernel. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dxc29PmGiszpa6ndt21EuK
The closure IR interprets tab, idx and drop as the source machine does: an array is consecutive cells, tab calls a copy of the tabulator per element and drop hands each element to a copy of the consumer. The flat IR lowers them to runtime functions: an array is one range of max(n, 1) two-word slots (a cell header and the contents), element i at base + 16·i, so an element's location is an ordinary cell; idx is an unsigned compare and the address computation; the fill and the drain are tail-recursive loops that call the closure through the table; drop frees the range once. Wasm is lowered from the flat IR unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dxc29PmGiszpa6ndt21EuK
Corpus programs, each run by the interpreter of every stage and compiled to Wasm, all ending with live 0: array-sum (1000 elements built by array_new and summed by a 1024-step loop, 500500), array-get (the family of leaf views from withload: len, get in range, get out of range), array-replace (replace, read back, out of range, and through a mut borrow by withswap), array-refs (an array of owned cells dropped implicitly), array-empty (a negative length). Must-rejects: a leaf view escaping its family's lifetime, mutating while a view is held, an array used after array_free. The book gains the chapter Arrays with doc-tested examples, and the reference includes the constants. The introduction, the proved page, the overview, the READMEs and SPEC Status say what is implemented. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dxc29PmGiszpa6ndt21EuK
Grades: GDerives gains the eight array constants, translated to and from CDerives and sound by their compat lemmas. FrameTheorems: tab is nondeterministic like alloc, so the determinism of StepsNA also excludes array redexes (ArrRedex). TwoRun: idx, drop and tab compute locations, which a permutation of Loc does not preserve, so renaming and fresh runs are stated for runs with no array step (StepsR, Step1F). READMEs record the restriction. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dxc29PmGiszpa6ndt21EuK
Owner
Author
|
CI did not run: both jobs were refused before starting ("recent account payments have failed or your spending limit needs to be increased"). Local results at 3e4503c: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 1 of #8:
Array A, a primitive value-type former, is a run-time-length family of leaf places. This PR does not close #8.Spec (SPEC 0.8, §9 "Entry 8 — arrays"; decision 29)
Array A = [Ref A]andArrayImm 'a A = [Imm 'a A]. The new former[L](VTy.fam) is the iterated separating conjunction⊛_{i<n} L, and it is never persistent.Primsteps:tab (c, f)placeslen(c)fresh consecutive cells, then fills them fromf.idx ((ℓ,n), i)returnsinl (ℓ+i)wheni < nunsigned, andinr ()otherwise, so it never gets stuck.drop (f, (ℓ,n))frees each cell after handing its contents tof.withbor1/withbor2onRef (Array A).withloadatImm 'x (Array A)givesImm̲ 'y (Array A) = [Imm 'y A]at a shorter'y. This is sound by thefamcases of 6.131.Mutuseswithswapwith the ownedarray_replace.Mutfamilies, move to Open. The nested-frame proof needed aQ-stability fact that I did not establish; I have not verified that any obstruction there is real.array_new,array_free,array_size,array_replace,array_len,array_get,array_copy,array_forget.Vec,Strandu8are recorded as library forms over arrays.Why a same-lifetime leaf view is not the excluded view through a pointer
A family
[Imm 'y A]holds its leaves'immcells at the top level of the resource, and no cell owns them.array_gethands out one leaf at'yand forgets the rest (NoOwn). No view is taken through an owning cell.'xdirectly fromImm 'x (Array A), where the leaves sit under the owning cell. That isexperiments/FrameEnd'simm_view_rejected.withloadproduces the family at the shorter'y(6.131'sfamcase,reborrow_sepRange).The model did not forbid the family reading, so there was no STOP.
DoD
VTy.fam, never persistent, through relation,Imm̲, outlives, NoMut, shapes, invariant and destructor (HasDtor.array/arrayImm).Prim. Out of range goes toinr, never stuck.Core/Arrays.lean,Core/ArrayWp.lean).fundamentalCandadequacyCare unchanged in statement.arrProg_runs(adequacy) andarrProg_eval(interpreter, bydecide).withload(see above). The primitive borrow andMutfamilies are Open.array A,array_imm 'a A, the eight constants, implicit array destructors.checkProgram_soundis unchanged in statement.max(n,1)two-word slots,base + 16·iaddressing with a bounds check, element destructors on free. The closure IR and flat IR interpreters are extended.live 0including under Wasm:array-sum: a 1000-element tabulate and sum, giving 500500.array-get: includes an out-of-range get, which returnsinr ().array-replace: replace, then read back.array-refs: ownedRefs dropped implicitly.array-empty.array-view-escape,array-mut-while-viewed,array-use-after-free.book-doctestgives 53/53.lake buildis clean, and hygiene reports 0 forbidden keywords and 16522 declarations within[propext, Classical.choice, Quot.sound]. The parse, check and compile corpus scripts pass.mdbook buildwas not run locally becausemdbookis not installed; CI runs it.StepsNAalso excludes array redexes, becausetabis nondeterministic.ℓ + iis not preserved by a permutation. The READMEs say so. Whether they extend under a block renaming: not derived, not verified.Open
split_at,iter/iter_mut,Vec,Str,u8,Uninit, the primitive (cell-free) array borrow, andMutleaf families.Refs #8
🤖 Generated with Claude Code
https://claude.ai/code/session_01Dxc29PmGiszpa6ndt21EuK