@@ -103,23 +103,28 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
103103 }
104104 }
105105
106- fn get_or_create_block ( & mut self , label : & Label ) -> Block {
106+ fn get_or_create_block ( & mut self , label : Label ) -> Block {
107107 let builder = & mut self . builder ;
108108 * self
109109 . label_to_block
110- . entry ( * label)
110+ . entry ( label)
111111 . or_insert_with ( || builder. create_block ( ) )
112112 }
113113
114114 pub fn compile < C : bytecode:: Constant > (
115115 & mut self ,
116116 bytecode : & CodeObject < C > ,
117117 ) -> Result < ( ) , JitCompileError > {
118- let offset_to_label: HashMap < & usize , & Label > =
119- bytecode. label_map . iter ( ) . map ( |( k, v) | ( v, k) ) . collect ( ) ;
118+ // TODO: figure out if this is sufficient -- previously individual labels were associated
119+ // pretty much per-bytecode that uses them, or at least per "type" of block -- in theory an
120+ // if block and a with block might jump to the same place. Now it's all "flattened", so
121+ // there might be less distinction between different types of blocks going off
122+ // label_targets alone
123+ let label_targets = bytecode. label_targets ( ) ;
120124
121125 for ( offset, instruction) in bytecode. instructions . iter ( ) . enumerate ( ) {
122- if let Some ( & label) = offset_to_label. get ( & offset) {
126+ let label = Label ( offset) ;
127+ if label_targets. contains ( & label) {
123128 let block = self . get_or_create_block ( label) ;
124129
125130 // If the current block is not terminated/filled just jump
@@ -190,7 +195,7 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
190195 let cond = self . stack . pop ( ) . ok_or ( JitCompileError :: BadBytecode ) ?;
191196
192197 let val = self . boolean_val ( cond) ?;
193- let then_block = self . get_or_create_block ( target) ;
198+ let then_block = self . get_or_create_block ( * target) ;
194199 self . builder . ins ( ) . brz ( val, then_block, & [ ] ) ;
195200
196201 let block = self . builder . create_block ( ) ;
@@ -203,7 +208,7 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
203208 let cond = self . stack . pop ( ) . ok_or ( JitCompileError :: BadBytecode ) ?;
204209
205210 let val = self . boolean_val ( cond) ?;
206- let then_block = self . get_or_create_block ( target) ;
211+ let then_block = self . get_or_create_block ( * target) ;
207212 self . builder . ins ( ) . brnz ( val, then_block, & [ ] ) ;
208213
209214 let block = self . builder . create_block ( ) ;
@@ -213,7 +218,7 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
213218 Ok ( ( ) )
214219 }
215220 Instruction :: Jump { target } => {
216- let target_block = self . get_or_create_block ( target) ;
221+ let target_block = self . get_or_create_block ( * target) ;
217222 self . builder . ins ( ) . jump ( target_block, & [ ] ) ;
218223
219224 Ok ( ( ) )
0 commit comments