Repository navigation
-mm=own: a tuple of owned values, and a record a call returns, are values - #679
Merged
Merged
Conversation
…lues Three refusals of one shape, a tuple or record of owned values as a value: - `[mk(1), mk(2)]` as `[N, N]`, built in a local or returned: `ts.CreateTuple` took each value beside the temporary's own release, a second reference own could not place. Under own a tuple literal holding a value the expression made is built in a slot, as an object literal is (createTupleInSlot), which own reads as the literal taking it. A tuple of literals or of reads (`[items[1]]`, own_facts::isConstantData) stays one `ts.CreateTuple`. - `const r = rec(); r.a.x + r.b.x`: a field taken out of the record value (`ts.ExtractProperty`) moved it, so the second read was a use after the move. A field only read is a read of the record (fieldOnlyRead), and so is each read of it, so a use after a move of the record is still one. - `let [a, b] = pair()`: each `let` takes a field out of the returned record. It borrows the field, bounded by the record's release, as a `let` borrows a temporary (fieldTakersOf in checkValueMoves); decideRetains skips the `let`s' retains that borrow already erased. Still errors (pinned): returning a field or a destructured borrow, a field read after the record moved into a callee that keeps it, and a spec-32 borrowing record's field read after its argument is overwritten. Own corpus 535 -> 537 (00tuple_runtime_arrays, arrayLiterals3; same output as gc), none lost. Tests: own_tuple_record_values under every model and own's no-counting check, four negatives. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ASDAlexander77
added a commit
that referenced
this pull request
Oct 24, 2026
…-4.7x faster (#684) * Declare the process-heap allocator to LLVM as LLVM declares malloc ProcessHeapPass marked __tslang_heap_malloc/calloc/aligned_alloc as writing other memory and gave their result no `noalias`. So every allocation clobbered whatever the program had just stored: a field written into a fresh object was loaded back from the heap after the next `new` instead of reused, and the object could never be deleted. In the ray tracer every vector of `Vector.plus(Vector.times(k, d), p)` stayed on the heap although LLVM had inlined the helpers. An allocation now touches only the allocator's state (`memory(inaccessiblemem: readwrite)`) and returns a `noalias` block, as LLVM's own malloc does. Writing the allocator's state still keeps two equal allocations from merging (the GC_malloc case in GCPass). Ray tracer, 512x512, median of 7: own 597 -> 444 ms, none 642 -> 434 ms, gc unchanged (its own allocator), rc 606 -> 630 ms. The benchmark README records the numbers and what is left between own and Rust. Test: 00fresh_objects_folded.ts runs, and fresh-objects-folded.cmake checks that the optimized IR of `keep` loads no field back under none, rc and own (it fails before this change). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Design: @value classes and interfaces A marked class or interface is a value of its readonly fields: no heap object, no identity, copied on assign, pass and return. Aimed at the ray tracer's Vector/Color/Ray/Intersection allocations; the benchmark keeps its object literals as written. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Plan: @value classes and interfaces Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * @value: parse, store, reject invalid combinations, print Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * @value interfaces: a literal of a @value interface type is a value Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * @value interfaces: print their fields readonly for importers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * @value classes: new makes a value, methods take this by value Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * @value classes: statics set by new, constructor this as the value, nominal conversion Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * @value: T | null is an optional value; null into a plain @value type is an error Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * @value: one three-state encoding for a missing value; reading one throws Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * @value: an interface's f?: T is read as the class's optional value Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * @value: a plain field for an optional @value member names the reason; intersection members too Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * @value: values holding references, through generics and closures Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * @value: an interface cycle through a @value type, and a literal-or-null ternary A @value interface's type is taken only once all its fields are resolved (getValueTypeOfInterfaceIfLaidOut, as getValueTypeOfClassIfLaidOut does for a class): `Hit { thing: Thing }` declared before `Thing { intersect(): Hit | null }` gave Thing's method the Hit of the first discovery pass (fields resolved so far), and the class implementing Thing the complete one, so the signatures did not match. Its fields are also laid out in declaration order, not in the order the passes resolved them. An object literal received as a @value type that may be missing (`T | null`) is built as the T, so `c ? { d: 1 } : null` is the missing type of T and null rather than a cast of `null | {d}` to T. Tests: value_iface_cycle (gc rc none), value_ternary_null (gc rc none own), AOT and JIT. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * -mm=own: @value records A tuple that holds borrows and owns nothing - a @value record such as the ray tracer's Intersection, or a type literal - is a borrowing record with no box (own spec 36): its uses are bounded by what it borrows, as a boxed record's are, and nothing of it is counted or released. Signature pass: - classifyUnboxedRecord: an object literal's local whose read is never boxed, read whole, whose block-holding fields all borrow (this, a parameter, a place read, a borrowing call's result, a let's value, a captured variable's, an immortal value; a fresh value only in a temporary given to calls that do not keep it). Never a handle, a string, or a generator state's field. Marked __own_record_unboxed_fields (+ __own_record_temporary); its reads are records. - Facts.unboxed / __own_result_record_unboxed beside __own_result_record; boxes and unboxed records in one value or on two return paths give no facts; an exported @Lends @record function returning one is an error. - The type walkers read a @value type as its storage tuple (asStorageTuple): castMakesInterface(value, tuple) opened Thing, so S.intersect's facts were "reached through an interface". Inference pass: - classifyRecords takes the unboxed records; walkRecord follows a field taken out of the tuple (ExtractProperty) and a field read in place out of the local that holds it (PropertyRef of the local or of its storage-tuple cast), whose write is a keep; a temporary's fresh field is bounded by its own release. The flow and release walks look through that cast too (slotVariableOf, valuesStoredInto). - unboxedRecordFlow: such a value has no owner check, its retains go, and dropUnboxedRecordCounts erases every retain/release of it and of locals that hold only such values (edge releases too); a local or merge mixing one with an owning value is an error. - isView: a cast between a @value type and its storage tuple is the same value. - recordRetainOf follows the literal's read through its views. - fieldTakersOf / fieldOnlyRead: a field that holds no block takes nothing (print(h.dist) made the record's number field a taker). - A non-escaping closure capturing frame or parameter storage that holds no block (this of a @value constructor with number fields) needs no owner. Tests: own_value_record, own_value_loop, own_value_temporaries (own, rc, gc, none, AOT+JIT; no counting under own), value_iface_cycle under own; negatives own_err_value_record_{place_dropped,stored,let_reassigned,mixed_local, field_written,param_field_kept}; own_err_record_literal_let_field now rejected at the push. value_interface stays off under own (nested owning literal; record converted to an ordinary interface); value_refs is not registered under own (its copies outlive the originals' Nodes: correct rejections). The marked ray tracer compiles under own (13 errors before) and prints 38837369. Corpus 542 -> 543. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * @value: pin own record exits and split value_interface - own negatives for the exits of a record that borrows a `let`: own_err_value_record_{returned,captured,field_stored,global}, and own_err_value_refs_copy (a copy out of an array read after the element is overwritten; own rejects the read even without the overwrite, an over-rejection that predates spec 36). - own_value_record prints a record's number field straight; own_value_temporaries prints one of a value that owns its vector (the owner check's fieldTakersOf / fieldOnlyRead number-field fix; without it, "used here after its value was moved"). - value_interface runs under own; its two own gaps (a nested owning literal, #679; a record converted to an ordinary interface) move to value_interface_own_gaps, which runs under gc, rc and none and stays off under own. - own spec 36: the new tests, and a constant-index call on a const array outside a loop (records boxed or not) in "Not here". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * @value: -shared import A library's @value class and interfaces reach an importer through __decls, which prints them in source order. An interface naming one declared after it (`Hit { ray: Ray }` before `Ray`) failed to import with "can't find type by name: Ray", @value or not: the importer read the declarations in one pass. It now tries each that failed again once the others are in, as a module's own statements are, and drops what the failed tries reported. The pair builds V and R, Hit and Ray (nested, Hit first) on both sides, gives them back, reads Hit | null after narrowing and through ?., under gc, rc and own, compiled and JIT. An object literal for the imported V is the nominal conversion error, and own's export of a @value that only borrows its argument names why it cannot be told to another module. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * -shared: pin forward references in __decls A plain pair, no @value: the library's exported interface A holds a B declared after it, and the importer reads a.b.k and a.n of the A a library function returns, under gc, rc and own, compiled and JIT. A library whose exported interface holds a type it does not export still fails to import, with "can't find type by name". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Ray tracer: Vector/Color/Ray/Intersection are @value; results Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * @value: 'this' is not a value inside the constructor In a @value class's constructor `this` is the slot `new` is filling. Read whole (`const self = this`, `f(this)`, `arr.push(this)`, `[this]`, `{ v: this }`, `() => this`) it was a copy of the fields stored so far, so a later `this.a = 1` did not reach it (`self.a` read 0 where TypeScript reads 1). Such a use is now an error; `this.f`, `this.f = x`, `this.m()` and `this["f"]` stay allowed, in the constructor and in arrow functions inside it. value_class.ts's Q passed `this` to a function; it now reads the fields. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * @value: a value cannot contain itself A @value type is the tuple of its fields held in place, so one that holds itself (`next: L | null`, or `A.b: B | null` with `B.a: A`) can never be laid out: each discovery pass found the other type not laid out yet and the end result was "can't find type by name: L". While a @value type's field is typed, a @value type it needs that is not laid out yet is now recorded as one it waits for; a type that waits, through the types it waits for, for itself is reported: @value type 'L' contains itself through 'next'; a value cannot hold itself @value type 'A' contains itself through 'b.a'; ... and "can't find type by name" for it is left out. `next: L[]` did not compile before either and now gets the same error. A reference through an ordinary class (`box: Box`, `Box.l: L | null`) still works. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * optional chain: skip the rest of the chain after a missing value TypeScript skips the whole rest of a chain once a `?.` in it meets null or undefined. Each link read only the link before it, so in `g?.ray.dir.x` `.dir` read `g?.ray`'s undefined: a missing @value type threw there, a missing type literal read 0. A chain link that is not a `?.` itself (`.c`, `[i]`, `.m()`, `!`) and has one below it is now made whole: the `?.`'s object is read once and tested as the `?.` tests it, and the chain - generated as before, on the value read - runs only when it is there, as an optional; undefined otherwise. A chain ending in a void call moves into an `if` with no result. Code without @value changes too: such a chain on a missing object is undefined instead of reading on (a type literal gave 0). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * @value spec: the missing-value encoding as emitted `T | null` of a @value type is an optional holding a tagged union: isMissingValueUnion makes isUnionTypeNeedsTag answer yes, so it is a packed `<{ ptr tag, payload }>` (the tag points at a type descriptor's name, `object` or `null`) inside `{ ..., i1 }`. The spec now says what is emitted, what undefined, null and a value look like, and how the comparisons test them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * @value: report 'this' used whole in a discovery run too `{ ...this }` in a @value constructor failed in the discovery run with "Spread in an object literal is not supported for type: V" before the check, which ran only in the real run, could say why. The check is AST-only, so it now runs in both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * @value: 'this' in a field initializer is not a value either An instance field's initializer runs in the constructor (in the one made for it when none is written), where `this` is the slot being filled: `readonly f = mk(this)` captured a copy taken before `this.a = 7` (f() gave 0, TypeScript 7), and `readonly b = show(this)` read a = 0. The constructor's check now walks the class's instance field initializers too; `this.a` in one stays allowed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * @value: a field cannot hold a generic made from its own type `box: Box<L>` in a @value type L: while L's fields were typed, L was not laid out, so instantiating Box<L> failed and the unspecialized generic `Box` became the field's type for good. Box<L> was later made from that L, a literal of L with a Box<L> converted between two class types, and the compiler crashed (0xC0000005, already at --emit=mlir). A generic whose instantiation waited for a @value type that is not laid out yet now fails the field instead, so it is typed again in the next pass (`box: Box<K>` with K declared later works). For L's own type that wait is a cycle, reported as @value type 'L' reaches itself through 'box' in the type arguments of 'Box<L>'; a @value type cannot hold a generic type made from it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * @value: never type a field as the unspecialized generic ffd2996 failed a @value field's generic only when its instantiation had waited for a @value type. With the generic declared before the @value types, the type argument (`Box<B>`, B declared after A) was not even registered on the first pass: no wait, so the unspecialized `Box` still became the field's type. `A.p: Box<B>` with `B.a: A` crashed again at a literal of A, `box: Box<K>` read `.l` as "Can't resolve property", and `Box<Nope>` compiled. While a @value type's field is typed, a failed instantiation now always fails the field, which is typed again in the next pass; the generic's own declaration, specialized meanwhile, is not the field (suspendValueLayoutFrames). The cycle is reported, `Box<K>` works in either declaration order, and `Box<Nope>` is "can't find type by name: Nope". Fields of other types keep the fallback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
What
Under
-mm=own, a tuple or record that holds owned objects can now be used as a value. This removes three refusals of that one shape.[mk(1), mk(2)]as[N, N], built in a local or returnedcreateTupleInSlot), and reads that as the literal taking each valueconst r = rec(); r.a.x + r.b.xts.ExtractPropertymoved the record, so the second read was "used here after its value was moved"fieldOnlyRead), and so does each read of that field, so a use after the record is moved is still caughtlet [a, b] = pair()letborrows its field until the record is released, the same way aletalready borrows a temporary (fieldTakersOfincheckValueMoves);decideRetainsskips the retains that borrow already erasedA tuple of literals or of existing reads (
[1, "a"],[[1, "x"], 2],[items[1]]) is still onets.CreateTuple. The check usesown_facts::isConstantDataand looks through casts and views. Other memory models are unchanged.Still refused
Each is pinned by a new negative test:
own_err_record_field_returned);own_err_destructured_field_returned);own_err_record_field_after_move);own_err_borrowing_record_const_field).Tests
own_tuple_record_valuesruns under own (including the no-counting check) and under rc, gc and none.00tuple_runtime_arrays,arrayLiterals3), both giving the same output as gc underMALLOC_PERTURB_. None lost.🤖 Generated with Claude Code