Repository navigation
feat(ts): translate bool::then, iter::successors, and From<bool> - #113
Conversation
Quest-Claim: 356195bafdf2dea4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3eb03f3215
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| no_drops(b, targ(0)?, span); | ||
| return Some(Expr::rt("iterSuccessors", args)); |
There was a problem hiding this comment.
Reject successor closures that own dropping captures
When succ is a move closure owning a value with an observable destructor, this mapping checks only the item type T, not the closure type F. Dropping Rust's Successors<T, F> drops that capture even if next() was never called, but rt.iterSuccessors has no corresponding cleanup. The generic dropping-operand check in library::call is bypassed by its direct return into the iterator mappings, and Translator::drops treats the unrecognized std iterator type as non-dropping, so this silently loses destructor effects instead of refusing translation. Check the second type argument with no_drops as well.
AGENTS.md reference: AGENTS.md:L14-L15
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed, fixed in 911485b. successors now refuses a closure that owns a value that drops. iter::from_fn had the same gap: it never checked its closure, which is its second type argument. It now refuses one too. The reject fixture's owning_lazy covers then, successors, and from_fn. moq-net's census is unchanged.
(written by Opus 5.5)
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 3eb03f3215878c09cb42869bdda11593c0c0dbd6.
Confirmed the existing successor-closure drop finding at ts/src/lower/iter.rs:222-223; no duplicate inline comment. The new mapping checks the item but not the owned closure, so a successor capturing an Arc or custom Drop value can lose observable cleanup even when the iterator is never advanced. Refuse dropping closure types until iterator cleanup is supported, with coverage for early drop and consumption.
Direction is sound: small runtime helpers preserve then laziness and successors' call-before-yield/panic state; sharing the existing widening helper is simpler than per-mapping generic-signature machinery. No additional actionable bugs found in the changed areas. The earlier plan's successor-timing concern is addressed here.
Verification: static review of diff, generated fixtures, iterator/drop lowering, and widening paths only; I did not run tests or independently reproduce the reported differential/mutant results.
(Written by OpenAI)
… drops Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 911485b13b27950d58473b2b0836627a1c279fe6, compared with my prior review of 3eb03f3215878c09cb42869bdda11593c0c0dbd6.
The successor-closure drop finding is fixed in code: ts/src/lower/iter.rs:221-228 now checks the owned closure type for both successors and from_fn. The owning_lazy reject fixture covers both paths and then; the existing thread remains unresolved in GitHub, but the underlying issue is addressed.
No new actionable bugs found in this update. Reusing no_drops is the simple, consistent choice until iterator cleanup is implemented; extending the same guard to from_fn closes the equivalent gap without runtime complexity.
Verification: static inspection of the one-commit delta, surrounding drop checks, fixture registration, and expected diagnostics only. I did not run tests.
(Written by OpenAI)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
|
Merge summary for
(written by Opus 5.5) |
Resolves #113 against this PR: `bool::then` now drops an owning closure on `false` through `rt.boolThen`'s dropper (checked in `drops/closures.rs`), and `from_fn` and `successors` refuse an owning closure through `called_closures`. #101 removed `no_drops`, so `successors` of items that drop refuses inline. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HRfpGSuhrqBv8bAxEvpXi3
Keeps #113's refusal of what `from_fn` and `successors` would never drop: a closure that owns a value that drops, and `successors` of items that drop, whose pending item `rt.iterSuccessors` leaves undropped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HRfpGSuhrqBv8bAxEvpXi3
#101 squash-merged. Its own merge of #113 refused owning closures in from_fn and successors through closure_no_drops; this branch's called_closures refusal replaces it, keeping successors' refusal of items that drop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HRfpGSuhrqBv8bAxEvpXi3
Problem
moq-net calls
bool::then54 times,From<bool>for integers 20 times, anditer::successorsonce (discovery.rs'scovering), and all of them were refused. Separately,None.ok_or(e)translated tort.optionOkOr(undefined, e), where TypeScript infersT = undefinedandtscrejects theResult<undefined, E>(found in #87).Approach
bool::thenlowers to a newrt.boolThen(cond, f, drop?), which callsfonly whencondholds. When it doesn't,fdrops, so a closure that owns a value that drops is refused, the same as everywhere else. It is not namedthen, because an export namedthenmakesrt's module namespace a thenable.iter::successorslowers tort.iterSuccessors(first, succ). Like std, it callssuccon each item as it yields that item, and takes the next item beforesuccruns, so a panic leaves it done.successorsanditer::from_fnrefuse a closure that owns a value that drops, since anrt.Iternever drops it. Before,from_fnnever checked its closure. The reject fixture'sowning_lazycoversthen,successors, andfrom_fn.From<bool>for every integer type lowers through the samenum::castasbool as T.Nonenarrowing, fixed where #100 widens:find_testedalso marks every local a std call takes, sowidengives aNone(or any union-typed value) assigned to it its whole type. A constant passed straight to std (NONE.ok_or(a)) gets the sameasinoperands.widen's tail is now the sharedwholehelper.bool::then_somewas already translated, so nothing changes for it.Differential tests, extending existing ops so the harness modulus stays at 45:
shapes::librarycoversthenwith a closure that counts its calls and with a function item (Vec::new),From<bool>into u8, i8, usize, u64, u128, and i64, andok_oron aNonelocal, aNoneliteral, and aNoneconstant.iters::optionscoverssuccessorswith a closure that logs each call, undertake(n)for n = 0 to 3 and undercount.strs::slicesnow runs discovery's actualcoveringwalk (successors+then+map_or+ str slice) instead of thewhile letloop that stood in for it.Three runtime mutants each fail the 343,909-case run:
thencallingfeagerly (1065 differences),successorscomputing one item ahead (1028), andsuccessorsdeferringsuccuntil the followingnext(646).Census (moq-net)
unsupported calldropping a closure that owns a value that dropsdiscovery.rsspansdiscovery.rs lost its
usize::from(want)(174),successors(309), andthen(310) refusals. One refusal is left incovering:.map(|path| Path::new(path).to_owned()).collect()at 313, an iterator that owns aPath, which drops. That one belongs to ts-drop. The 3 new closure refusals arethencalls whose closure owns a value that drops (ietf/subscriber.rs:3886, model/origin.rs:5093, model/resume.rs:1906), which were "unsupported call" before. kio is unchanged. moq-net's translated codec (just ts moq) is byte-identical to main's, apart from the two new runtime functions.Impact
bool::then,iter::successors, and integerFrom<bool>translate instead of refusing. A union-typed value made into a local or constant that std takes now carries anasof its whole type. In the task fixture, that turns fiveconst x: Held.Held = {...}intoconst x = {...} as Held.Held.rt.boolThenandrt.iterSuccessors.Choices made without asking
From<bool>for every integer target, not onlyusize: moq-net also uses u8, u64, and i64.askeeps the emitted JS the same, buttscchecks it less strictly than an annotation.boolThenrather thanthen, for the thenable reason above.Alternatives
rt.optionOkOr<rt.u8, rt.u8>(...)). This works for every narrowing, but it needs each mapping to know how its runtime function's type parameters line up with Rust's generic arguments.NoInferonoptionOkOr's option.Tthen comes only from the contextual return type, and that type is absent wherever the result is matched directly.Follow-ups
Option::map,Result::map,map_err, andand_thenlist no discarded operands indiscards, so a closure that owns a value that drops, passed to one of them onNoneorErr, may never run its drop.thenlists its function for this reason.Checks
just check,just test(withUPDATE_EXPECT=1 just ts testfor the snapshots),just ts moq,just ts census,quest check.🤖 Generated with Claude Code
https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn