README Source History Refs Reviews Compare Notes Search Review guide refactor: deslop pass over sealed wasi, alloc, http, session, agent
0b0de9c6beb6718d4152f6d966fec0adaa3bb7d3
Oliver Jan Krylow <oliver@bugabinga.net > · 26 Sep 2026
unsigned
Browse files Compare with HEAD
Changed files (5) Diff layout Auto Unified Split
smith-alloc/src/lib.rs Modified +47 / −17 text lines
52 52 pub peak: u64 , pub peak: u64 ,55 - struct Counters ( [AtomicU64; 4] ) ; 56 + allocations: AtomicU64,57 - static COUNTERS : [Counters; 6 ] = [const { Counters([const { AtomicU64::new(0 ) }; 4 ]) }; 6 ];62 + static COUNTERS : [Counters; SCOPES .len ()] = [const {64 + allocations: AtomicU64::new(0 ),65 + bytes: AtomicU64::new(0 ),66 + live: AtomicU64::new(0 ),67 + peak: AtomicU64::new(0 ),59 71 const DEPTH : usize = 16 ;const DEPTH : usize = 16 ;124 136 pub fn snapshot (scope: Scope) -> Stats {pub fn snapshot (scope: Scope) -> Stats {125 - let [allocations, bytes, live, peak] = & COUNTERS [scope as usize ].0 ;137 + let counters = & COUNTERS [scope as usize ];127 - allocations: allocations.load (Relaxed),128 - bytes: bytes.load (Relaxed),129 - live: live.load (Relaxed),130 - peak: peak.load (Relaxed),139 + allocations: counters . allocations.load (Relaxed),140 + bytes: counters . bytes.load (Relaxed),141 + live: counters . live.load (Relaxed),142 + peak: counters . peak.load (Relaxed),135 - pub fn snapshot_all () -> [(Scope, Stats); 6 ] {147 + pub fn snapshot_all () -> [(Scope, Stats); SCOPES . len ( ) ] {136 148 SCOPES .map (|scope| (scope, snapshot (scope))) SCOPES .map (|scope| (scope, snapshot (scope)))139 151 fn record_alloc (scope: Scope, size: usize ) {fn record_alloc (scope: Scope, size: usize ) {140 - let [allocations, bytes, live, peak] = & COUNTERS [scope as usize ].0 ;141 - allocations.fetch_add (1 , Relaxed);142 - bytes.fetch_add (size as u64 , Relaxed);143 - let now = live.fetch_add (size as u64 , Relaxed) + size as u64 ;144 - peak.fetch_max (now, Relaxed);152 + let counters = & COUNTERS [scope as usize ];153 + counters . allocations.fetch_add (1 , Relaxed);154 + counters . bytes.fetch_add (size as u64 , Relaxed);155 + let now = counters . live.fetch_add (size as u64 , Relaxed) + size as u64 ;156 + counters . peak.fetch_max (now, Relaxed);147 159 fn record_free (tag: u8 , size: usize ) {fn record_free (tag: u8 , size: usize ) {149 161 if let Some (counters) = COUNTERS .get (usize ::from(tag)) { if let Some (counters) = COUNTERS .get (usize ::from(tag)) {150 - counters.0 [ 2 ] .fetch_sub (size as u64 , Relaxed);162 + counters.live .fetch_sub (size as u64 , Relaxed);212 224 unsafe fn realloc (& self, ptr: *mut u8 , layout: Layout, new_size: usize ) -> *mut u8 { unsafe fn realloc (& self, ptr: *mut u8 , layout: Layout, new_size: usize ) -> *mut u8 {213 - let (Some ((outer, pad)), Some (new_outer)) = 214 - (padded (layout), new_size.checked_add (layout.align ()))226 + let new_layout = Layout::from_size_align(new_size, layout.align ()).ok ();227 + let (Some ((outer, pad)), Some (( new_outer, _ ))) = 228 + (padded (layout), new_layout.and_then (padded))216 230 return std::ptr::null_mut(); return std::ptr::null_mut();220 234 let tag = ptr.sub (1 ).read (); let tag = ptr.sub (1 ).read ();221 - let base = System.realloc (ptr.sub (pad), outer, new_outer);235 + let base = System.realloc (ptr.sub (pad), outer, new_outer. size ( )) ;222 236 if base.is_null () { if base.is_null () {223 237 return base; return base;283 297 assert_eq! (page.0 [4095 ], 0 ); assert_eq! (page.0 [4095 ], 0 );
301 + fn realloc_past_header_capacity_fails_and_keeps_block () {302 + use std::alloc::{GlobalAlloc, Layout};303 + let layout = Layout::new::<u64 >();305 + let new_size = isize ::MAX .cast_unsigned () - 7 ;309 + let block = Counting.alloc (layout);310 + assert! (! block.is_null ());311 + assert! (Counting.realloc (block, layout, new_size).is_null ());312 + Counting.dealloc (block, layout);287 317 fn spawned_threads_start_at_process_scope () { fn spawned_threads_start_at_process_scope () {288 318 let _turn = enter (Scope::Turn); let _turn = enter (Scope::Turn);smith-cli/src/main.rs Modified +4 / −4 text lines
348 348 api_key: None , api_key: None ,350 350 let mut agent = build_agent (& config)? ; let mut agent = build_agent (& config)? ;351 - let turn = smith_alloc::enter(smith_alloc::Scope::Turn);352 - let outcome = agent.run_turn (prompt);354 - let outcome = outcome? ;352 + let _turn = smith_alloc::enter(smith_alloc::Scope::Turn);353 + agent.run_turn (prompt)355 355 if json { if json {356 356 println! ( println! (smith-core/src/session.rs Modified +29 / −4 text lines
281 281 Some ((branch, idx)) Some ((branch, idx))283 283 let chain = & branch.entries[..= idx]; let chain = & branch.entries[..= idx];
284 + let rooted = chain.first ().is_some_and (|root| root.parent.is_none ());284 285 let linked = chain let linked = chain287 - .all (|(i, entry)| entry.parent == i.checked_sub (1 ).map (|p| chain[p].id));288 - linked.then_some (chain)287 + .all (|pair| pair[1 ].parent == Some (pair[0 ].id));288 + ( rooted && linked) .then_some (chain)575 575 assert_eq! (err.code (), "ENTRY_NOT_FOUND" ); assert_eq! (err.code (), "ENTRY_NOT_FOUND" );
579 + fn fork_rejects_broken_ancestry_and_forks_sibling_branches () {581 + let orphan = message ("orphan" , Some (EntryId::new()));582 + let child = message ("child" , Some (orphan.id));583 + let broken = Session::from_entries(None , & [orphan, child.clone ()], None );584 + assert_eq! (broken.selected_id (), Some (child.id));585 + let err = broken.fork_at (child.id).unwrap_err ();586 + assert_eq! (err.code (), "ENTRY_NOT_FOUND" );589 + let root = message ("root" , None );590 + let first = message ("first" , Some (root.id));591 + let second = message ("second" , Some (root.id));592 + let siblings = Session::from_entries(None , & [root.clone (), first.clone (), second], None );593 + let forked = siblings.fork_at (first.id).unwrap ();594 + let ids: Vec <EntryId> = forked600 + assert_eq! (ids, vec! [root.id, first.id]);579 604 fn compaction_boundary_survives_a_frame_round_trip () { fn compaction_boundary_survives_a_frame_round_trip () {580 605 let mut session = Session::new(); let mut session = Session::new();smith-core/tests/alloc_bounds.rs Modified +15 / −19 text lines
4 4 use smith::message::{Message, Role};use smith::message::{Message, Role};5 - use smith_alloc::{Counting, Scope, Stats , enter, snapshot};5 + use smith_alloc::{Counting, Scope, enter, snapshot};6 6 use smith_core::session::{Entry, Session};use smith_core::session::{Entry, Session};8 8 #[global_allocator]#[global_allocator]27 - fn fork_cost (session: & Session, scope : Scope ) -> Stats {28 + fn fork_cost (session: & Session) -> ( u64 , u64 ) {28 29 let leaf = session.selected_id ().expect ("non-empty session" ); let leaf = session.selected_id ().expect ("non-empty session" );29 - let before = snapshot (scope );30 - let guard = enter (scope );30 + let before = snapshot (Scope :: Session );31 + let guard = enter (Scope :: Session );31 32 let fork = session.fork_at (leaf).expect ("leaf is known" ); let fork = session.fork_at (leaf).expect ("leaf is known" );32 33 drop (guard); drop (guard);33 - let after = snapshot (scope );34 + let after = snapshot (Scope :: Session );34 35 assert_eq! ( assert_eq! (35 36 fork.active_branch ().entries.len (), fork.active_branch ().entries.len (),36 37 session.active_branch ().entries.len () session.active_branch ().entries.len ()38 39 drop (fork); drop (fork);40 - allocations : after.allocations - before.allocations,41 - bytes : after.bytes - before.bytes,42 - live: after.live - before.live,41 + after.allocations - before.allocations,42 + after.bytes - before.bytes,48 47 fn fork_at_over_1000_entries_is_bounded_and_reproducible () {fn fork_at_over_1000_entries_is_bounded_and_reproducible () {49 48 let session = linear_session (1000 ); let session = linear_session (1000 );50 - let first = fork_cost (& session, Scope :: Session );51 - let second = fork_cost (& session, Scope :: Session );49 + let first = fork_cost (& session);50 + let second = fork_cost (& session);53 - first.allocations <= FORK_AT_1000_ALLOCATIONS ,52 + first.0 <= FORK_AT_1000_ALLOCATIONS ,54 53 "fork_at allocated {} times, bound is {FORK_AT_1000_ALLOCATIONS}" , "fork_at allocated {} times, bound is {FORK_AT_1000_ALLOCATIONS}" ,58 - (first.allocations, first.bytes),59 - (second.allocations, second.bytes)
56 + assert_eq! (first, second);smith-harness/src/http.rs Modified +3 / −3 text lines
41 41 Self ::with_timeouts(HEAD_TIMEOUT , CHUNK_TIMEOUT ) Self ::with_timeouts(HEAD_TIMEOUT , CHUNK_TIMEOUT )46 46 #[must_use] #[must_use]47 47 pub fn with_timeouts (head: Duration, gap: Duration) -> Self { pub fn with_timeouts (head: Duration, gap: Duration) -> Self {48 48 let config = ureq::Agent::config_builder() let config = ureq::Agent::config_builder()181 181 Ok (0 ) | Err (_ ) => return , Ok (0 ) | Err (_ ) => return ,182 182 Ok (read) => read, Ok (read) => read,184 - total + = u64 ::try_from(read).unwrap_or (u64 ::MAX );184 + total = total . saturating_add ( u64 ::try_from(read).unwrap_or (u64 ::MAX )) ;185 185 if cancel.is_cancelled () || total > MAX_BODY_BYTES { if cancel.is_cancelled () || total > MAX_BODY_BYTES {