File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3069,11 +3069,15 @@ c_callable! {
30693069 unsafe { Rc :: increment_strong_count( iseq_call_ptr as * const IseqCall ) ; }
30703070 let iseq_call = unsafe { Rc :: from_raw( iseq_call_ptr as * const IseqCall ) } ;
30713071 let iseq = iseq_call. iseq. get( ) ;
3072- let entry_insn_idxs = crate :: hir:: jit_entry_insns( iseq) ;
3072+ let params = unsafe { iseq. params( ) } ;
3073+ let entry_idx = iseq_call. jit_entry_idx. to_usize( ) ;
3074+ let entry_insn_idx = params. opt_table_slice( ) . get( entry_idx)
3075+ . unwrap_or_else( || panic!( "function_stub: opt_table out of bounds. {params:#?}, entry_idx={entry_idx}" ) )
3076+ . as_u32( ) ;
30733077 // gen_push_frame() doesn't set PC or ISEQ, so we need to set them before exit.
30743078 // function_stub_hit_body() may allocate and call gc_validate_pc(), so we always set PC and ISEQ.
30753079 // Clear jit_return so the interpreter reads cfp->pc and cfp->iseq directly.
3076- let pc = unsafe { rb_iseq_pc_at_idx( iseq, entry_insn_idxs [ iseq_call . jit_entry_idx . to_usize ( ) ] ) } ;
3080+ let pc = unsafe { rb_iseq_pc_at_idx( iseq, entry_insn_idx ) } ;
30773081 unsafe { rb_set_cfp_pc( cfp, pc) } ;
30783082 unsafe { ( * cfp) . _iseq = iseq } ;
30793083 unsafe { ( * cfp) . jit_return = std:: ptr:: null_mut( ) } ;
Original file line number Diff line number Diff line change @@ -738,6 +738,24 @@ impl IseqAccess for IseqPtr {
738738 }
739739}
740740
741+ impl IseqParameters {
742+ /// The `opt_table` is a mapping where `opt_table[number_of_optional_parameters_filled]`
743+ /// gives the YARV entry point of ISeq as an index of the iseq_encoded array.
744+ /// This method gives over the table that additionally works when `opt_num==0`,
745+ /// when the table is stored as `NULL` and implicit.
746+ /// The table stores the indexes as raw VALUE integers; they are not tagged as fixnum.
747+ pub fn opt_table_slice ( & self ) -> & [ VALUE ] {
748+ let opt_num: usize = self . opt_num . try_into ( ) . expect ( "ISeq opt_num should always >=0" ) ;
749+ if opt_num > 0 {
750+ // The table has size=opt_num+1 because opt_table[opt_num] is valid (all optionals filled)
751+ unsafe { std:: slice:: from_raw_parts ( self . opt_table , opt_num + 1 ) }
752+ } else {
753+ // The ISeq entry point is index 0 when there are no optional parameters
754+ & [ VALUE ( 0 ) ]
755+ }
756+ }
757+ }
758+
741759impl From < IseqPtr > for VALUE {
742760 /// For `.into()` convenience
743761 fn from ( iseq : IseqPtr ) -> Self {
Original file line number Diff line number Diff line change @@ -6726,25 +6726,6 @@ fn insn_idx_at_offset(idx: u32, offset: i64) -> u32 {
67266726 ( ( idx as isize ) + ( offset as isize ) ) as u32
67276727}
67286728
6729- /// List of insn_idx that starts a JIT entry block
6730- pub fn jit_entry_insns ( iseq : IseqPtr ) -> Vec < u32 > {
6731- // TODO(alan): Make an iterator type for this instead of copying all of the opt_table each call
6732- let params = unsafe { iseq. params ( ) } ;
6733- let opt_num = params. opt_num ;
6734- if opt_num > 0 {
6735- let mut result = vec ! [ ] ;
6736-
6737- let opt_table = params. opt_table ; // `opt_num + 1` entries
6738- for opt_idx in 0 ..=opt_num as isize {
6739- let insn_idx = unsafe { opt_table. offset ( opt_idx) . read ( ) . as_u32 ( ) } ;
6740- result. push ( insn_idx) ;
6741- }
6742- result
6743- } else {
6744- vec ! [ 0 ]
6745- }
6746- }
6747-
67486729struct BytecodeInfo {
67496730 jump_targets : Vec < u32 > ,
67506731}
@@ -6904,7 +6885,7 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
69046885 fun. was_invalidated_for_singleton_class_creation = payload. was_invalidated_for_singleton_class_creation ;
69056886
69066887 // Compute a map of PC->Block by finding jump targets
6907- let jit_entry_insns = jit_entry_insns ( iseq) ;
6888+ let jit_entry_insns = unsafe { iseq. params ( ) } . opt_table_slice ( ) . iter ( ) . copied ( ) . map ( VALUE :: as_u32 ) . collect :: < Vec < _ > > ( ) ;
69086889 let BytecodeInfo { jump_targets } = compute_bytecode_info ( iseq, & jit_entry_insns) ;
69096890
69106891 // Make all empty basic blocks. The ordering of the BBs matters for getting fallthrough jumps
You can’t perform that action at this time.
0 commit comments