Repository navigation
feat(ts): translate panic::Location and #[track_caller] - #551
Merged
Merged
Conversation
Quest-Claim: 4b1cf21d5188c852
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ified pointer as a value, and write a Location's Display in parts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated
marked this pull request as ready for review
November 3, 2026 21:36
|
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 54 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
panic::Locationwith a span (left by #538), soLocation::caller, its accessors, and#[track_caller]didn't translate.Approach
Locationis a newStd::Location, an immutablert.Location { file, line, col }(runtime/rt/location.ts) with std'sDisplay,Debug,==,Ord, andHash, usable as a key in std's collections.file,line, andcolumnread its fields.InstanceKind::requires_caller_location) gets a trailingcaller: rt.Locationparameter (ts/src/lower/caller.rs). As in rustc's codegen, each call passes the location of the call'sfn_span: the outermost macro call, with the file named asspan_as_caller_locationnames it. Inside a tracked function, a call passes its owncallerinstead.Location::callerevaluates to that same location.Index), and trait objects are handled. Adynmethod takescallerwhen the trait declares#[track_caller]. When only the impl does, the wrapper passes the impl's own location, as rustc's vtable shim does.constorstaticof&Locationis read out of its allocation.Fnimpls call (opt.map(tracked),iter.map(tracked), a genericimpl Fncalled with one), a crate call that reaches a tracked function only through std's code, a tracked method std calls by name (an iterator'snextand other own methods, aDrop::drop), andLocation::calleras a pointer.file_as_c_strfalls to the usual refusal.unwrap, indexing,borrow_mut, and the from-MIRunwrap_or_else, take none, because nothing reads it: translated panics carry no location, and the hook is ts-panic-hook. Somap(Option::unwrap)still translates.Native results that set the rules above, checked with rustc: a fn pointer reports the definition span,
Fn-trait calls reportcore/src/ops/function.rs, and an impl-only tracked method called throughdynreports the impl's span.Proof:
ts/fixtures/lang/panics/src/located.rsruns differentially against native wasm32. It covers every case above, plus{:>60}(which std doesn't pad),{:#?},{:x?}, ordering, dedup,BTreeSetandHashSet, aLocationheld in a struct and anOption, and a panic message carrying the location. Refusals are infixtures/reject/src/panics.rs.Cost
Measured by output, not timing: the moq-net codec (
just ts moq) and both bench fixtures (fixtures/codec,fixtures/task) contain no tracked function, and their translations are byte-identical tomain(nort.Locationin the output, snapshots unchanged). Sojust ts benchtimes the same code, and hot paths pay nothing. The cost of passing a location into std's runtime calls (unwrap, indexing) is left to the hook quest, the first place one is read.Impact
dynmethod its trait tracks, takes an extra lastrt.Locationargument. A TS caller or implementer of such a trait object passes or accepts it. No existing output changes otherwise.rt.Location,locationEq,locationCmp,locationHash,fmtLocationDisplay,fmtLocationDebug.Alternatives
rt.unwrap(o, loc),rt.index(..., loc)): that is what the hook needs, but nothing reads it yet, and it would cost every hot call. Left to ts-panic-hook, whose plan now says so.Fn-impl location for a tracked fn item called throughFn: it names the native build's sysroot path, which translation can't know. Refused instead.Follow-ups
Review
quest review, Codex gpt-6.1-sol, medium effort. Round 2 on head88604e185reported no findings. Round 1 (headc95095cfb) had three findings:#[track_caller]Iterator::nextor other own iterator method is called by the runtime's protocol with no location. Fixed: a tracked crate function that std's code calls by symbol (iterator protocol,collect, drop glue'sDrop::drop) is refused at its definition (caller::refuse_std_call). Covered infixtures/reject.()function was typedvoidwhere values areundefined. Fixed: cast asfn_valuedoes, covered by a[fn(bool); 2]in the fixture.Displayshould write in parts, as std'swrite!does. Fixed: it now goes throughfmtWriteFmt. Refuted the request for a capped-writer differential case: translation already refuses placeholders written into a crate's ownfmt::Write(reproduced while adding the case), and the runtime's writers never fail, so translated code can't observe it.Since then: a conflict-free merge of
origin/main(head7117ecc02).🤖 Generated with Claude Code