You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Handle new caller_location intrinsic the right way #374
If adding support for caller_location would allow us to avoid panic messages such as thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', that'd be a major improvement in how we report such failures.
One thing that I don't see mentioned there is the relation to panic strategies. This isn't mentioned in the RFC neither, so I guess it's independent.
For the current Rust implementation, the compiler will add an extra argument to functions that contain #[track_caller]. Unfortunately, this operation is done in the codegen stage, instead of a MIR pass. :(
My guess is that MIR passes can't really change the function signature, so they push it down to the codegen stage. I'm tempted to just encode this as a global variable for now.
@adpaco-aws I don't think CBMC really supports formatting error messages, so I'm not sure implementing this intrinsic will make much of a difference on how we report failures.
In order to fix that, we would have to either inline these functions or generate a different copy per location they are invoked from.
pubfnloc() -> u32{let l = std::panic::Location::caller();
l.line()}pubfnclock(x:u8) -> u8{let _t = std::time::Instant::now();
x
}pubfnok_fn(x:u8,y:u8) -> u8{ x.wrapping_mul(y)}
$ cargo kani autoharness -Z autoharness
Thread 60: VERIFICATION RESULT:
Thread 60: Failed Checks: caller_location is not currently supported by Kani. Please post your example at https://github.com/model-checking/kani/issues/374
Thread 60: VERIFICATION:- FAILED
Thread 62: VERIFICATION RESULT:
Thread 62: VERIFICATION:- SUCCESSFUL
Thread 59: VERIFICATION RESULT:
Context: we ran AI agents that use the Kani agent plugin (#5059) to verify 101 of the most downloaded crates on crates.io with Kani 0.68.0, CBMC 6.11.0 and nightly-2026-10-22. The minimal reproducer above was re-run by hand with the same versions. This text was written with AI assistance.
Activity
celinval commentedon Feb 21, 2023
This is a nice explanation on what this does: https://hegdenu.net/posts/track-caller/
adpaco commentedon Mar 2, 2023
Thanks for the update, @celinval !
If adding support for
caller_locationwould allow us to avoid panic messages such asthread 'main' panicked at 'called `Option::unwrap()` on a `None` value', that'd be a major improvement in how we report such failures.One thing that I don't see mentioned there is the relation to panic strategies. This isn't mentioned in the RFC neither, so I guess it's independent.
celinval commentedon Mar 3, 2023
I was wondering if it would help with: #1740
celinval commentedon Jul 3, 2023
For the current Rust implementation, the compiler will add an extra argument to functions that contain
#[track_caller]. Unfortunately, this operation is done in the codegen stage, instead of a MIR pass. :(My guess is that MIR passes can't really change the function signature, so they push it down to the codegen stage. I'm tempted to just encode this as a global variable for now.
@adpaco-aws I don't think CBMC really supports formatting error messages, so I'm not sure implementing this intrinsic will make much of a difference on how we report failures.
In order to fix that, we would have to either inline these functions or generate a different copy per location they are invoked from.
celinval commentedon Jul 3, 2023
Implementation notes for myself:
const_caller_location[1].pub fn caller_location_ty(self) -> Ty<'tcx>[2]requires_caller_location[3]joshlf commentedon Aug 27, 2025
Ran into this when implementing zstd decompression (RFC 8878). Should I consider the
prooffunction to be an incomplete proof as a result?Source:
zhassan-aws commentedon Sep 5, 2025
No, it shouldn't. Verification would fail if the intrinsic is reachable from the proof harness.
celinval commentedon Jul 22, 2026
This CR might be of interest here. It adds support to compute caller location using rustc_public APIs: rust-lang/rust#159204
feliperodri commentedon Nov 6, 2026
More evidence for this issue. Kani hit it while verifying these 2 crate(s):
Minimal reproducer (Kani 0.68.0):
Context: we ran AI agents that use the Kani agent plugin (#5059) to verify 101 of the most downloaded crates on crates.io with Kani 0.68.0, CBMC 6.11.0 and nightly-2026-10-22. The minimal reproducer above was re-run by hand with the same versions. This text was written with AI assistance.