@@ -1842,7 +1842,7 @@ impl Compiler {
18421842 fn jump_to_fail_pop ( & mut self , pattern_context : & mut PatternContext ) -> CompileResult < ( ) > {
18431843 let pops = pattern_context. on_top + pattern_context. stores . len ( ) ;
18441844 self . ensure_fail_pop ( pattern_context, pops) ?;
1845- self . switch_to_block ( pattern_context. fail_pop [ pops] ) ;
1845+ // self.switch_to_block(pattern_context.fail_pop[pops]);
18461846 Ok ( ( ) )
18471847 }
18481848 // static int
@@ -2057,7 +2057,11 @@ impl Compiler {
20572057 self . compile_expression ( subject) ?;
20582058 // Blocks at the end of the switch statement that we jump to after finishing a branch
20592059 // TODO: optimize, we can reuse the same block for all cases
2060- let mut end_block = self . new_block ( ) ;
2060+ let pattern_blocks = std:: iter:: repeat_with ( || self . new_block ( ) )
2061+ . take ( cases. len ( ) + 1 )
2062+ . collect :: < Vec < _ > > ( ) ;
2063+ eprintln ! ( "created pattern_blocks: {:?} - {:?}(end block)" , pattern_blocks. first( ) . unwrap( ) , pattern_blocks. last( ) . unwrap( ) ) ;
2064+ let end_block = * pattern_blocks. last ( ) . unwrap ( ) ;
20612065
20622066 let match_case_type = cases. last ( ) . expect ( "cases is not empty" ) ;
20632067 let has_default = match_case_type. pattern . is_match_star ( ) && 1 < cases. len ( ) ;
@@ -2066,6 +2070,7 @@ impl Compiler {
20662070 // m = asdl_seq_GET(s->v.Match.cases, i);
20672071 let m = & cases[ i] ;
20682072 // Only copy the subject if we're *not* on the last case:
2073+ self . switch_to_block ( pattern_blocks[ i] ) ;
20692074 if i != cases. len ( ) - has_default as usize - 1 {
20702075 // ADDOP_I(c, LOC(m->pattern), COPY, 1);
20712076 emit ! ( self , Instruction :: Duplicate ) ;
@@ -2091,7 +2096,7 @@ impl Compiler {
20912096 // }
20922097 if let Some ( guard) = & m. guard {
20932098 self . ensure_fail_pop ( pattern_context, 0 ) ?;
2094- self . compile_jump_if ( guard, false , pattern_context . fail_pop [ 0 ] ) ?;
2099+ self . compile_jump_if ( guard, false , pattern_blocks [ i + 1 ] ) ?;
20952100 }
20962101 if i != cases. len ( ) - ( has_default as usize ) - 1 {
20972102 // ADDOP(c, LOC(m->pattern), POP_TOP);
@@ -2106,6 +2111,7 @@ impl Compiler {
21062111 // A trailing "case _" is common, and lets us save a bit of redundant
21072112 // pushing and popping in the loop above:
21082113 let m = & cases. last ( ) . unwrap ( ) ;
2114+ self . switch_to_block ( * pattern_blocks. last ( ) . unwrap ( ) ) ;
21092115 if cases. len ( ) == 1 {
21102116 // No matches. Done with the subject:
21112117 // ADDOP(c, LOC(m->pattern), POP_TOP);
@@ -3423,6 +3429,7 @@ impl Compiler {
34233429 u32 :: MAX ,
34243430 "switching {prev:?} -> {block:?} from block that's already got a next"
34253431 ) ;
3432+ eprintln ! ( "switch_to_block {prev:?} -> {block:?}" ) ;
34263433 prev_block. next = block;
34273434 code. current_block = block;
34283435 }
0 commit comments