@@ -16,7 +16,8 @@ use tracing::debug;
1616// Use a thread-local global variable to track the current codegen item for debugging.
1717// If Kani panics during codegen, we can grab this item to include the problematic
1818// codegen item in the panic trace.
19- thread_local ! ( static CURRENT_CODEGEN_ITEM : RefCell <( Option <String >, Option <Location >) > = const { RefCell :: new( ( None , None ) ) } ) ;
19+ type FindCurrentItemFn = Box < dyn Fn ( ) -> String > ;
20+ thread_local ! ( static CURRENT_CODEGEN_ITEM : RefCell <( Option <FindCurrentItemFn >, Option <Location >) > = const { RefCell :: new( ( None , None ) ) } ) ;
2021
2122pub fn init ( ) {
2223 // Install panic hook
@@ -36,9 +37,9 @@ static DEFAULT_HOOK: LazyLock<Box<dyn Fn(&panic::PanicHookInfo<'_>) + Sync + Sen
3637
3738 // Print the current function if available
3839 CURRENT_CODEGEN_ITEM . with ( |cell| {
39- let t = cell. borrow ( ) . clone ( ) ;
40- if let Some ( current_item ) = t. 0 {
41- eprintln ! ( "[Kani] current codegen item: {current_item}" ) ;
40+ let t = cell. borrow ( ) ;
41+ if let Some ( get_current_item ) = & t. 0 {
42+ eprintln ! ( "[Kani] current codegen item: {}" , get_current_item ( ) ) ;
4243 } else {
4344 eprintln ! ( "[Kani] no current codegen item." ) ;
4445 }
@@ -55,14 +56,21 @@ static DEFAULT_HOOK: LazyLock<Box<dyn Fn(&panic::PanicHookInfo<'_>) + Sync + Sen
5556impl < ' tcx > GotocCtx < ' tcx > {
5657 // Calls the closure while updating the tracked global variable marking the
5758 // codegen item for panic debugging.
58- pub fn call_with_panic_debug_info < D : CrateDef , F : FnOnce ( & mut GotocCtx < ' tcx > ) > (
59+ pub fn call_with_panic_debug_info <
60+ D : CrateDef ,
61+ F : FnOnce ( & mut GotocCtx < ' tcx > ) ,
62+ S : Fn ( ) -> String + ' static ,
63+ > (
5964 & mut self ,
6065 call : F ,
61- panic_debug : String ,
66+ debug_str_generator : S ,
6267 def : D ,
6368 ) {
6469 CURRENT_CODEGEN_ITEM . with ( |odb_cell| {
65- odb_cell. replace ( ( Some ( panic_debug) , Some ( self . codegen_span_stable ( def. span ( ) ) ) ) ) ;
70+ odb_cell. replace ( (
71+ Some ( Box :: new ( debug_str_generator) ) ,
72+ Some ( self . codegen_span_stable ( def. span ( ) ) ) ,
73+ ) ) ;
6674 call ( self ) ;
6775 odb_cell. replace ( ( None , None ) ) ;
6876 } ) ;
0 commit comments