@@ -62,7 +62,9 @@ const INHERITED_STATE_FRAME_KEY_OFFSET: i32 = 8;
6262const INHERITED_STATE_STACK_BASE_OFFSET : i32 = 16 ;
6363const INHERITED_STATE_LOCAL_BASE_OFFSET : i32 = 24 ;
6464const INHERITED_STATE_DYNAMIC_TARGET_OFFSET : i32 = 32 ;
65- const INHERITED_STATE_VALUES_OFFSET : i32 = 40 ;
65+ const INHERITED_STATE_TARGET_IP_OFFSET : i32 = 40 ;
66+ const INHERITED_STATE_VALUE_COUNT_OFFSET : i32 = 48 ;
67+ const INHERITED_STATE_VALUES_OFFSET : i32 = 56 ;
6668
6769type TaggedConstants = ( Box < [ Value ] > , HashMap < SsaValueId , usize > ) ;
6870
@@ -260,7 +262,7 @@ pub(crate) fn compile_system_inherited_tail_wrapper(
260262 let vm_ptr = builder. block_params ( entry) [ 0 ] ;
261263 let pointer_bytes = pointer_type. bits ( ) / 8 ;
262264 let packet_bytes = pointer_bytes
263- . checked_mul ( ( MAX_INHERITED_ENTRY_VALUES + 5 ) as u32 )
265+ . checked_mul ( ( MAX_INHERITED_ENTRY_VALUES + 7 ) as u32 )
264266 . ok_or_else ( || {
265267 VmError :: JitNative ( "native inherited-state packet is too large" . to_string ( ) )
266268 } ) ?;
@@ -359,7 +361,7 @@ pub(crate) fn compile_tail_trace_dispatcher(
359361 let dynamic_target_is_null = builder. ins ( ) . icmp_imm ( IntCC :: Equal , dynamic_target, 0 ) ;
360362 builder. ins ( ) . brif (
361363 dynamic_target_is_null,
362- static_dispatch ,
364+ return_status ,
363365 & [ status. into ( ) ] ,
364366 dynamic_linked,
365367 & [ ] ,
@@ -858,8 +860,40 @@ fn try_compile_ssa_trace(
858860 let frame_matches = b
859861 . ins ( )
860862 . icmp ( IntCC :: Equal , inherited_frame_key, expected_frame_key) ;
863+ let inherited_target_ip = b. ins ( ) . load (
864+ pointer_type,
865+ MemFlags :: new ( ) ,
866+ inherited_state_ptr,
867+ INHERITED_STATE_TARGET_IP_OFFSET ,
868+ ) ;
869+ let expected_target_ip = b. ins ( ) . iconst (
870+ pointer_type,
871+ i64:: try_from ( trace. root_ip ) . map_err ( |_| {
872+ VmError :: JitNative ( "SSA inherited target ip exceeds i64" . to_string ( ) )
873+ } ) ?,
874+ ) ;
875+ let target_matches =
876+ b. ins ( )
877+ . icmp ( IntCC :: Equal , inherited_target_ip, expected_target_ip) ;
878+ let inherited_value_count = b. ins ( ) . load (
879+ pointer_type,
880+ MemFlags :: new ( ) ,
881+ inherited_state_ptr,
882+ INHERITED_STATE_VALUE_COUNT_OFFSET ,
883+ ) ;
884+ let expected_value_count = b. ins ( ) . iconst (
885+ pointer_type,
886+ i64:: try_from ( entry_ssa_block. params . len ( ) ) . map_err ( |_| {
887+ VmError :: JitNative ( "SSA inherited value count exceeds i64" . to_string ( ) )
888+ } ) ?,
889+ ) ;
890+ let value_count_matches =
891+ b. ins ( )
892+ . icmp ( IntCC :: Equal , inherited_value_count, expected_value_count) ;
893+ let metadata_matches = b. ins ( ) . band ( frame_matches, target_matches) ;
894+ let metadata_matches = b. ins ( ) . band ( metadata_matches, value_count_matches) ;
861895 b. ins ( )
862- . brif ( frame_matches , inherited_entry, & [ ] , normal_entry, & [ ] ) ;
896+ . brif ( metadata_matches , inherited_entry, & [ ] , normal_entry, & [ ] ) ;
863897
864898 b. switch_to_block ( inherited_entry) ;
865899 let active_stack_base = b. ins ( ) . load (
@@ -4472,6 +4506,28 @@ fn write_inherited_state_packet(
44724506 ctx. inherited_state_ptr ,
44734507 INHERITED_STATE_LOCAL_BASE_OFFSET ,
44744508 ) ;
4509+ let target_ip = b. ins ( ) . iconst (
4510+ ctx. pointer_type ,
4511+ i64:: try_from ( exit. exit_ip )
4512+ . map_err ( |_| VmError :: JitNative ( "SSA inherited target ip exceeds i64" . to_string ( ) ) ) ?,
4513+ ) ;
4514+ b. ins ( ) . store (
4515+ MemFlags :: new ( ) ,
4516+ target_ip,
4517+ ctx. inherited_state_ptr ,
4518+ INHERITED_STATE_TARGET_IP_OFFSET ,
4519+ ) ;
4520+ let value_count = b. ins ( ) . iconst (
4521+ ctx. pointer_type ,
4522+ i64:: try_from ( entry_value_count)
4523+ . map_err ( |_| VmError :: JitNative ( "SSA inherited value count exceeds i64" . to_string ( ) ) ) ?,
4524+ ) ;
4525+ b. ins ( ) . store (
4526+ MemFlags :: new ( ) ,
4527+ value_count,
4528+ ctx. inherited_state_ptr ,
4529+ INHERITED_STATE_VALUE_COUNT_OFFSET ,
4530+ ) ;
44754531 let stack_ptr = b. ins ( ) . load (
44764532 ctx. pointer_type ,
44774533 MemFlags :: new ( ) ,
0 commit comments