Repository navigation
feat(ts): translate std::panic where it matches panic=abort - #538
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… keeps Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated
marked this pull request as ready for review
November 3, 2026 19:08
|
This run was cancelled before it finished. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 36 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. CodeRabbit Verify
|
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.

Problem
rust2-ts refused
AssertUnwindSafeoutright (found by #528): it couldn't be made, so it couldn't wrap a future or a closure either. The rest ofstd::panicwas refused as unsupported calls:catch_unwind,resume_unwind,panic_any,Location,set_hook, andtake_hook, andDebugof adyn Any, whichcatch_unwind(..).unwrap()needs. No moq consumer calls these; the maintainer plans all of std.Approach
Panics abort, on wasm32's
panic=abortand in the translation alike, so most ofstd::panichas an exact translation:AssertUnwindSafe<T>is what it holds, asReverse<T>is, and JS erases it as it does aBoxorPinwhere a write in place checks what JS keeps: made, its field read and written,Deref/DerefMut,Default,From,Debug(AssertUnwindSafe(..), as std's derived-style tuple), drops, a call through itsFnOnce, and a poll through itsFuture, each forwarding to what it holds.catch_unwind(f)isOk(f()): a panic inside throws on, as native aborts after the hook.resume_unwindthrowsrt.Abort, as native aborts without running the hook.panic_any(p)panics withpif it is a&strorString, and withBox<dyn Any>otherwise, as std's hook writes it. Edition-2015begin_panichad the same bug (any payload was its JS string) and shares the fix.Debugof adyn AnywritesAny { .. }.What can't match yet stays refused with a span and a reason:
Location(it needs each#[track_caller]function's caller), andset_hook/take_hook(a hook reads each panic'sLocation, which panics don't carry).Tests: a new
lang/panicsdifferential fixture (673 cases, 97 panics, 31 aborts). It coversAssertUnwindSafeof numbers, aVec, a struct, nested wrappers, written through*,.0, and&mut *, and anArcshared with a clone and aVec<u8>replaced whole through a generic&mut;Debugplain, alternate, padded, and nested;DefaultandFrom; drop order moved, replaced, and at scope end; calls of closures, fn items, closures that write captures or own values that drop;catch_unwindof closures, fn items, borrowed closures, wrapped closures, aBox<dyn FnOnce>, and one that panics; futures polled by hand and awaited, nested, and dropped unpolled;panic_anyof each payload kind andresume_unwind. MutatingresumeUnwindto a plain panic and theBox<dyn Any>text gives 72 differences. The reject fixture gainsLocation::callerand the hooks.Impact
rt.resumeUnwind. No breaking change.Alternatives
AssertUnwindSafe's impls from core's MIR: itsFutureusesPin::map_unchecked_mut, and a class per wrapper would allocate for a marker. Erasing it, asReverseis, needs no runtime.Location::callerhere: it needs a hidden location parameter on every#[track_caller]function and refusals for indirect calls, a change of its own (quest below).Follow-ups
Location::callerand#[track_caller].set_hook,take_hook,PanicHookInfo; requires the first.Review
Codex (
quest review, gpt-6.1-sol, medium):1d4d13ab: "Unwrap AssertUnwindSafe in representation-sensitive helpers" (replacing anAssertUnwindSafe<Arc<_>>through a&mutwrote into the sharedArc; anAssertUnwindSafe<Vec<u8>>tookvecAssign). Fixed in7394ffcb:Translator::erasedpeelsAssertUnwindSafe. Reproduced first: theVeccase failedtscand theArccase alone gave 20 differences.7394ffcbca4f3f45f09f7c2bdeb8c1ca7e78ba2f: no findings. Since then,6833ceeband10b21680only mergeorigin/main(feat(ts): translate Rc::as_ptr, Arc::as_ptr, and ptr::addr_eq, and copy what their pointers compare #511, feat(ts): translate vec![x; n] of a value that drops #534, feat(ts): translate lossy and chunked UTF-8 decoding #537, fix(ts): keep a nested Vec's capacity where clone_from writes over it #533, chore(quest): plan matching a Cow<str>'s variant #541), with no conflicts;just cipasses on10b21680.🤖 Generated with Claude Code