You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Built-in methods get real bodies and declared signatures in the standard library (D110); delete the freeze door and the method-value adapter #3483
Eric, 2026-11-19 (the freeze door: "A now, B as the direction").
Today. The methods the compiler implements itself (List.len, List.push, HashMap.get, str.to_upper, Option.unwrap, the float math methods, …) have no declaration: their parameter modes are rows in src/BuiltinSigs.w, their receiver modes a table in Sema.builtin_method_receiver_mode, their bodies MirIntrinsics. To name one as a value (D223, List[i32].len), Sema writes the closure (x, a) => x.method(a) after the syntax tree is frozen, through one purpose-built entry, AstPool.add_method_value_closure.
Wanted. Each built-in method is a method declared in the standard library, with its signature written once in With (D110: "builtin container methods have declared signatures") and a body that calls the intrinsic. Then Type.method is an ordinary method value, and calls, values, move checking and lowering all read the one declaration.
Definition of done.
Every row of BuiltinSigs.w and every case of builtin_method_receiver_mode is a declaration in lib/std; both tables are deleted.
AstPool.add_method_value_closure, add_after_freeze, adapter_node_count, Sema.builtin_method_as_value, method_value_closures, method_adapter_param_types and the freeze-door-check gate target are deleted. Nothing adds to the tree after the freeze.
First step merged (#3489): List.len is declared in lib/std/collections.w. What the pilot established:
A declaration in std takes precedence over the built-in, at a call and as a method value, with no compiler change. So the migration is one method at a time.
Run time is unchanged: 300 million calls in a loop take the same time (the body inlines at -O1).
Compile time is unchanged: the self-check is 106 s with the declaration, 107 s without.
Plan for the rest: move each built-in method to a declaration in std, deleting its BuiltinSigs row and its case in builtin_method_receiver_mode in the same change; methods whose bodies need storage the library cannot reach yet (growth, hashing) call the intrinsic from their declared body. When the last one has moved, delete the freeze door, the adapter and freeze-door-check.
A constraint found by :release-checks (2026-11-20), which stopped the third step (str.contains, starts_with, ends_with declared in std.string with their built-ins deleted; branch builtin-bodies-3, not merged):
Units compiled without the prelude call str methods and rely on the built-ins: the Clang bridge object (--no-prelude), and a migrated corpus's generated test harness (stc-test: ctest_assert_str). With the built-in gone, the method resolves to the std.string declaration, whose body that unit never checked, and lowering aborts with BUG: user generic call lacks a concrete contract … sig=-1.
Two things follow:
Before a str (or any primitive's) built-in method is deleted, a unit without the prelude must still reach its std declaration: the module that declares a primitive's methods has to be loaded and checked on demand, or such units must import it. A corpus cannot be edited (D112), so it has to be the first.
The abort is a tool that stayed silent: a call that resolves to a declaration with no checked body should be a diagnostic naming the missing import, not an ICE in lowering.
List.len and List.is_empty (merged) are not affected: :release-checks was green for both.
Every str method is now a library declaration (#3489, #3490, #3495, #3496, #3504, #3507): thirteen built-ins moved, two on List (len, is_empty) and eleven on str (contains, starts_with, ends_with, index_of, to_upper, to_lower, replace, repeat, split, byte_at, slice), each with its compiler copies deleted in the same change.
What each move had to touch, for the ones still to do: the entry in builtin_method_intrinsic; the name-based return-type table (compute_builtin_intrinsic_method_return_type), which otherwise types a call that has nothing to call; the BuiltinSigs row; the MirIntrinsic and CcBuiltin members with their arms in both code generators; any special case elsewhere (a MIR validator rule for slice/byte_at, the copy-on-write list for split); the C header prototype when the runtime function takes a list out-pointer; and err_2358_builtin_extra_arg, which needs an example that is still built in.
Left: the rest of List, HashMap/HashSet/SlotMap, Option/Result, the numeric methods, channels and fibers. Then the freeze door and the method-value adapter go.
Fourteen moved; the thin ones are done.List.join landed in #3510 (declared for List[str]; it exposed #3508, fixed in #3509).
What is left is not a runtime call behind a name:
List core (push, get, pop, remove, clear, slot, range, split_at, iter_place, get_disjoint, contains): the code generator emits element-size arithmetic and per-element drops around the runtime call. A library body needs those spelled in With over the list's storage.
Channels and fibers (send, recv, close, cancel, is_done, was_cancelled): raw calls on handle types the compiler knows by name; their types need library declarations first.
FixedString, SlotMap, the slot types, the numeric methods (rotate_left, popcount, min, max, abs, mul_add): each maps to an LLVM operation, not a runtime function.
D110 asks for a real body and a declared signature. For the numeric ones the body is an intrinsic operation; for the List core it is With code over raw storage. I will write that split up as the plan for the rest before moving more.
The plan for the rest, as promised (2026-11-25, main 8509133). Fourteen are moved; BuiltinSigs still has 93 rows. They fall into four families, and each needs a different thing.
1. Numeric methods (rotate_left, rotate_right, swap_bytes, bitreverse, popcount, clz, ctz, abs, min, max, mul_add, the float math functions)
Each is one operation over every integer width (or both float widths). A library declaration needs one of:
a declaration per type: twelve integer types times ten methods, each body the same line. It works today and is exactly the repetition the mission is against.
one declaration for every integer type. Both spellings work today, when the trait declares its receiver (D7). Checked on main: impl[T: Ord] Smaller for T: fn least(other: T) -> T: if *self < other: *self else: other serves i32 and i64, and a trait default method with one impl per type does too. (An earlier version of this comment said neither worked. My probes had left the receiver out of the trait, which makes the method an associated one; the fault was mine. What it did turn up is real and separate: Eq, Ord and Default were not implemented for i8, i16, u16, u32 and u64, fixed on its own.)
So the numeric family needs no new language surface for min and max: an integer trait with the methods as defaults, or a blanket impl over Ord.
And the body itself: min/max are plain With (if self < other: self else: other compiles to the same select). The bit operations need the operation to be nameable from With: a small set of generic intrinsic functions in std (bits.rotate_left[T](x, n), …) that the method bodies call, lowered as the MirIntrinsic is today. abs returns the unsigned counterpart of its receiver, which a signature cannot say yet (-> Unsigned[Self]).
The one question in this family that is yours: how abs's return type is written. Today it is a rule in the compiler (unsigned_counterpart). Prediction: an associated type on the integer trait (Self.Unsigned), 70%.
2. The List core (push, get, pop, remove, clear, slot, range, split_at, get_disjoint, contains, with_capacity), ListSlot, ListRange
The code generator emits element-size arithmetic and per-element drops around the runtime call. A library body is With over the list's storage, as Stack and Deque already are over theirs. It needs List[T]'s representation declared in std (it is the compiler's today) and sizeof[T], raw element access and drop-in-place in the body. Nothing to rule. The risk is speed: the done-when says no slowdown, so each move is measured on the compiler's own check time and the pipeline benchmark before it lands.
3. Iter adapters (22 rows: map, filter, fold, …)
These have library bodies already in spirit (D69's push generators); the rows exist for the intrinsic fast path. This is step 3 of the ruled iterator campaign, family by family, and what #2220 (collections at compile time) waits on.
4. Channels, fibers, SlotMap, FixedString
Handle types the compiler knows by name. Their types get library declarations first, then their methods are ordinary extern-backed bodies like the str ones.
Order
2 and 4 need no ruling and no new language surface, so they go first: SlotMap and FixedString (4), then the List core (2) with measurements. Then family 1's min and max through a trait, and 3. The freeze door and the method-value adapter are deleted when the last row goes.
FixedString is moved (#3611): ten methods are library declarations, new stays built in (it needs a zeroed value of a generic type). About 200 lines of compiler copies are gone, and the move closed two soundness holes in the built-in as_view (it returned a str aliasing the buffer; now -> &str from self).
Also on the way: Eq, Ord and Default for the five integer widths that lacked them (#3610).
BuiltinSigs rows left: 90 (93 before this; my plan above said 59, which was a miscount, since corrected). Next in the posted order: SlotMap.
Progress (merged in PR #3674): moved f32/f64min and max onto impl MinMax in lib/std/traits.with (IEEE 754 minNum/maxNum NaN semantics), removed float.min/float.max from src/BuiltinSigs.with, and deleted MirIntrinsic.MIN/MAX and CcBuiltin.MIN/MAX from Sema, LLVM codegen, and C codegen. BuiltinSigs rows left: 78 (77 pre-existing + List.new_in added in #570).
Activity
The tree's freeze has one door that builds one thing, for one caller;…
List.len is declared in the standard library (the first built-in meth…
ehartford commentedon Nov 20, 2026
First step merged (#3489):
List.lenis declared inlib/std/collections.w. What the pilot established:Plan for the rest: move each built-in method to a declaration in std, deleting its
BuiltinSigsrow and its case inbuiltin_method_receiver_modein the same change; methods whose bodies need storage the library cannot reach yet (growth, hashing) call the intrinsic from their declared body. When the last one has moved, delete the freeze door, the adapter andfreeze-door-check.List.is_empty is declared in the standard library and its built-in is…
ehartford commentedon Nov 21, 2026
A constraint found by
:release-checks(2026-11-20), which stopped the third step (str.contains,starts_with,ends_withdeclared in std.string with their built-ins deleted; branchbuiltin-bodies-3, not merged):Units compiled without the prelude call
strmethods and rely on the built-ins: the Clang bridge object (--no-prelude), and a migrated corpus's generated test harness (stc-test:ctest_assert_str). With the built-in gone, the method resolves to the std.string declaration, whose body that unit never checked, and lowering aborts withBUG: user generic call lacks a concrete contract … sig=-1.Two things follow:
str(or any primitive's) built-in method is deleted, a unit without the prelude must still reach its std declaration: the module that declares a primitive's methods has to be loaded and checked on demand, or such units must import it. A corpus cannot be edited (D112), so it has to be the first.List.lenandList.is_empty(merged) are not affected::release-checkswas green for both.str.contains, starts_with and ends_with are declared in the standard …
str.index_of, to_upper, to_lower, replace and repeat are declared in …
str.split is declared in the standard library and its built-in is del…
str.byte_at and str.slice are declared in the standard library and th…
ehartford commentedon Nov 21, 2026
Every
strmethod is now a library declaration (#3489, #3490, #3495, #3496, #3504, #3507): thirteen built-ins moved, two onList(len,is_empty) and eleven onstr(contains,starts_with,ends_with,index_of,to_upper,to_lower,replace,repeat,split,byte_at,slice), each with its compiler copies deleted in the same change.What each move had to touch, for the ones still to do: the entry in
builtin_method_intrinsic; the name-based return-type table (compute_builtin_intrinsic_method_return_type), which otherwise types a call that has nothing to call; theBuiltinSigsrow; theMirIntrinsicandCcBuiltinmembers with their arms in both code generators; any special case elsewhere (a MIR validator rule forslice/byte_at, the copy-on-write list forsplit); the C header prototype when the runtime function takes a list out-pointer; anderr_2358_builtin_extra_arg, which needs an example that is still built in.Left: the rest of
List,HashMap/HashSet/SlotMap,Option/Result, the numeric methods, channels and fibers. Then the freeze door and the method-value adapter go.List.join is declared in the standard library for List[str] and its b…
ehartford commentedon Nov 21, 2026
Fourteen moved; the thin ones are done.
List.joinlanded in #3510 (declared forList[str]; it exposed #3508, fixed in #3509).What is left is not a runtime call behind a name:
Listcore (push,get,pop,remove,clear,slot,range,split_at,iter_place,get_disjoint,contains): the code generator emits element-size arithmetic and per-element drops around the runtime call. A library body needs those spelled in With over the list's storage.send,recv,close,cancel,is_done,was_cancelled): raw calls on handle types the compiler knows by name; their types need library declarations first.FixedString,SlotMap, the slot types, the numeric methods (rotate_left,popcount,min,max,abs,mul_add): each maps to an LLVM operation, not a runtime function.D110 asks for a real body and a declared signature. For the numeric ones the body is an intrinsic operation; for the
Listcore it is With code over raw storage. I will write that split up as the plan for the rest before moving more.ehartford commentedon Nov 25, 2026
The plan for the rest, as promised (2026-11-25, main 8509133). Fourteen are moved;
BuiltinSigsstill has 93 rows. They fall into four families, and each needs a different thing.1. Numeric methods (
rotate_left,rotate_right,swap_bytes,bitreverse,popcount,clz,ctz,abs,min,max,mul_add, the float math functions)Each is one operation over every integer width (or both float widths). A library declaration needs one of:
a declaration per type: twelve integer types times ten methods, each body the same line. It works today and is exactly the repetition the mission is against.
one declaration for every integer type. Both spellings work today, when the trait declares its receiver (D7). Checked on main:
impl[T: Ord] Smaller for T: fn least(other: T) -> T: if *self < other: *self else: otherservesi32andi64, and a trait default method with oneimplper type does too. (An earlier version of this comment said neither worked. My probes had left the receiver out of the trait, which makes the method an associated one; the fault was mine. What it did turn up is real and separate:Eq,OrdandDefaultwere not implemented fori8,i16,u16,u32andu64, fixed on its own.)So the numeric family needs no new language surface for
minandmax: an integer trait with the methods as defaults, or a blanket impl overOrd.And the body itself:
min/maxare plain With (if self < other: self else: othercompiles to the same select). The bit operations need the operation to be nameable from With: a small set of generic intrinsic functions instd(bits.rotate_left[T](x, n), …) that the method bodies call, lowered as theMirIntrinsicis today.absreturns the unsigned counterpart of its receiver, which a signature cannot say yet (-> Unsigned[Self]).The one question in this family that is yours: how
abs's return type is written. Today it is a rule in the compiler (unsigned_counterpart). Prediction: an associated type on the integer trait (Self.Unsigned), 70%.2. The
Listcore (push,get,pop,remove,clear,slot,range,split_at,get_disjoint,contains,with_capacity),ListSlot,ListRangeThe code generator emits element-size arithmetic and per-element drops around the runtime call. A library body is With over the list's storage, as
StackandDequealready are over theirs. It needsList[T]'s representation declared instd(it is the compiler's today) andsizeof[T], raw element access and drop-in-place in the body. Nothing to rule. The risk is speed: the done-when says no slowdown, so each move is measured on the compiler's own check time and the pipeline benchmark before it lands.3.
Iteradapters (22 rows:map,filter,fold, …)These have library bodies already in spirit (D69's push generators); the rows exist for the intrinsic fast path. This is step 3 of the ruled iterator campaign, family by family, and what #2220 (collections at compile time) waits on.
4. Channels, fibers,
SlotMap,FixedStringHandle types the compiler knows by name. Their types get library declarations first, then their methods are ordinary
extern-backed bodies like thestrones.Order
2 and 4 need no ruling and no new language surface, so they go first:
SlotMapandFixedString(4), then theListcore (2) with measurements. Then family 1'sminandmaxthrough a trait, and 3. The freeze door and the method-value adapter are deleted when the last row goes.FixedString's methods are declared in the library; as_view is a view …
ehartford commentedon Nov 25, 2026
FixedStringis moved (#3611): ten methods are library declarations,newstays built in (it needs a zeroed value of a generic type). About 200 lines of compiler copies are gone, and the move closed two soundness holes in the built-inas_view(it returned astraliasing the buffer; now-> &str from self).Also on the way:
Eq,OrdandDefaultfor the five integer widths that lacked them (#3610).BuiltinSigsrows left: 90 (93 before this; my plan above said 59, which was a miscount, since corrected). Next in the posted order:SlotMap.SlotMap's contains, is_empty and len family are declared in the libra…
Integer min and max are library methods: the MinMax trait's default b…
ehartford commentedon Nov 25, 2026
Two more moved (2026-11-25):
SlotMap:contains,is_emptyand thelenfamily are library methods over the runtime functions.min/max: default bodies of aMinMaxtrait with one bodilessimplper integer type. Measured against the built-in on a 400-million-iteration loop: 0.40 s both ways.BuiltinSigsrows left: 87 of 93. Next:SlotMap's ownership-moving methods, then theListcore.SlotMap's get, insert, remove and replace are library methods; a repl…
Wave 2a: D34-A demand-site builder finalization (#920), #3483 std mov…
Wave 3: @[ffi_stack] (#583), List.new_in(allocator) (#570), float Min…
ehartford commentedon Nov 28, 2026
Progress (merged in PR #3674): moved
f32/f64minandmaxontoimpl MinMaxinlib/std/traits.with(IEEE 754minNum/maxNumNaN semantics), removedfloat.min/float.maxfromsrc/BuiltinSigs.with, and deletedMirIntrinsic.MIN/MAXandCcBuiltin.MIN/MAXfrom Sema, LLVM codegen, and C codegen.BuiltinSigsrows left: 78 (77 pre-existing +List.new_inadded in #570).