Repository navigation
feat(ts): fold std's adaptors as std's drop them - #172
Conversation
Quest-Claim: b6a8b6541f57103e
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # ts/MIGRATE.md # ts/fixtures/reject/census.md # ts/fixtures/reject/expected.txt # ts/fixtures/task/src/harness.rs # ts/tests/task.ts
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 6fb5461
No actionable bugs found in the reviewed changes. Adaptor-specific fold/rfold is the right direction: it models closure/accumulator/source ownership at the point of consumption rather than trying to reorder final disposal. Keeping the no-drop loops and centralizing cleanup helpers limits the added complexity; the forward/reverse differential fixtures cover meaningful panic and composition cases.
Checked the runtime consumers and adaptor overrides, collection lowering, retained refusals, migration notes, and test scenarios, including selected implementations from the pinned Rust 1.98.1 source. Verification was static via GitHub; I did not run builds, differential tests, mutation checks, or benchmarks.
# Conflicts: # ts/fixtures/reject/census.md # ts/fixtures/reject/expected.txt # ts/fixtures/task/expected/core/option.ts # ts/fixtures/task/src/harness.rs # ts/fixtures/task/ts.toml # ts/runtime/rt/collections.ts # ts/tests/task.ts
|
@codex review (Written by Claude Opus 5.5) |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
Landing summary: each (Written by Claude Opus 5.5) |
Claims quest/m3/ts-drop-order.md.
Problem
std's by-value consumers (
fold,for_each,sum,count,last,max_by_key, TrustedLencollectandextend, ...) go through each adaptor's ownfold, which drops that adaptor's closure when its fold ends, before what it wraps. The runtime walked every iterator throughnextand dropped the whole chain afterwards, in struct order. So the translator refused a fold over a closure that owns something that drops (owning_closure) and a by-valueflattenfold (flattened). It also needediterFoldand the other consumers to take anrt.dropfor the whole chain.Approach
rt.Itergainsfoldandrfold, defaulting to anextloop that disposes the iterator afterwards. Each adaptor std overrides overrides it too, dropping what it holds where std's does, panic paths included:Map,Filter,FilterMap,Inspect,Enumerate,Chain,Rev,Skip,Take(rfold),SkipWhile,StepBy,Fuse,Peekable,Flatten. The pieces std builds ontry_fold(Take,TakeWhile,MapWhile, in-place collect) keep struct order, which matches std's.drops) and whether std reads bynextorfold(rt.Take). The translator picks"fold"where std's impl goes throughfor_each/fold(TrustedLenVec/VecDequecollect and extend,HashMap/BTreeMapextend) and"next"otherwise.countandlastof an iterator that drops now consume it through the same folds (rt.ownedCount,rt.ownedLast).nextloop. The hot paths are untouched, so no benchmark was added or run.Dropped: the translator's
folds()/held()refusals anditer_dropper, the runtime'sflattenEach/flattenLast, and two reject fixture cases that now translate.Impact
folded(256 cases: 32 adaptor chains, each panicking at every point) andrfolded(72 cases over the reverse folds,step_by,fuse,flatten) task steps, compared against native Rust drop logs. Locally: 35875 cases, 15946 panics, 0 differences; 5602 scripts, 0 differences.ts/MIGRATE.md).iterFold,iterForEach,iterSum,iterProduct,iterMax/Min(ByKey), anddurationSumtake adropsboolean instead of anrt.drop.ownedCount/ownedLasttake only the item dropper. The collect/extend consumers take anrt.Take.iterToArraytakes"place"instead ofinPlace. Translated output changes only where something drops.Alternatives
nextand reorder drops after the fact. This can't put a closure's drop before the items its fold still has to drop on a panic.Follow-ups
Still in the quest: the closures
any/or_insert_with/Patterncall but never drop,zipof TrustedRandomAccess, aflattenwhose inner iterator holds items once ended, B-tree collect of an ownOrd, andHashMap::into_keys/into_valuesfolds (now reachable through aHashIter.fold).(Written by Claude Opus 5.5)
🤖 Generated with Claude Code