feat(tvix/eval): add Chunk::pop_op method
This is used to drop an already emitted operation from a chunk again and clean up its span tracking. This is required in cases where the compiler has to backtrack. Change-Id: I8112da9427688bb2dec96a2ddd12390f6e9734c3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6499 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
		
							parent
							
								
									a0acbfa470
								
							
						
					
					
						commit
						675bd36ea5
					
				
					 1 changed files with 22 additions and 0 deletions
				
			
		| 
						 | 
					@ -60,6 +60,28 @@ impl Chunk {
 | 
				
			||||||
        CodeIdx(idx)
 | 
					        CodeIdx(idx)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// Pop the last operation from the chunk and clean up its tracked
 | 
				
			||||||
 | 
					    /// span. Used when the compiler backtracks.
 | 
				
			||||||
 | 
					    pub fn pop_op(&mut self) {
 | 
				
			||||||
 | 
					        // Simply drop the last op.
 | 
				
			||||||
 | 
					        self.code.pop();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // If the last span only had this op, drop it, otherwise
 | 
				
			||||||
 | 
					        // decrease its operation counter.
 | 
				
			||||||
 | 
					        match self.spans.last_mut() {
 | 
				
			||||||
 | 
					            // If the last span had more than one op, decrease the
 | 
				
			||||||
 | 
					            // counter.
 | 
				
			||||||
 | 
					            Some(span) if span.count > 1 => span.count -= 1,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Otherwise, drop it.
 | 
				
			||||||
 | 
					            Some(_) => {
 | 
				
			||||||
 | 
					                self.spans.pop();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            None => unreachable!(),
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn push_constant(&mut self, data: Value) -> ConstantIdx {
 | 
					    pub fn push_constant(&mut self, data: Value) -> ConstantIdx {
 | 
				
			||||||
        let idx = self.constants.len();
 | 
					        let idx = self.constants.len();
 | 
				
			||||||
        self.constants.push(data);
 | 
					        self.constants.push(data);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue