Make DataFlowGraph::insts public, but restricted (#5450)
We have some operations defined on DataFlowGraph purely to work around borrow-checker issues with InstructionData and other data on DataFlowGraph. Part of the problem is that indexing the DFG directly hides the fact that we're only indexing the insts field of the DFG. This PR makes the insts field of the DFG public, but wraps it in a newtype that only allows indexing. This means that the borrow checker is better able to tell when operations on memory held by the DFG won't conflict, which comes up frequently when mutating ValueLists held by InstructionData.
This commit is contained in:
@@ -676,7 +676,7 @@ impl<'a> FunctionBuilder<'a> {
|
||||
/// **Note:** You are responsible for maintaining the coherence with the arguments of
|
||||
/// other jump instructions.
|
||||
pub fn change_jump_destination(&mut self, inst: Inst, new_dest: Block) {
|
||||
let old_dest = self.func.dfg[inst]
|
||||
let old_dest = self.func.dfg.insts[inst]
|
||||
.branch_destination_mut()
|
||||
.expect("you want to change the jump destination of a non-jump instruction");
|
||||
self.func_ctx.ssa.remove_block_predecessor(*old_dest, inst);
|
||||
|
||||
@@ -611,7 +611,7 @@ impl SSABuilder {
|
||||
}
|
||||
|
||||
// Redo the match from `analyze_branch` but this time capture mutable references
|
||||
match &mut func.dfg[branch] {
|
||||
match &mut func.dfg.insts[branch] {
|
||||
InstructionData::BranchTable {
|
||||
destination, table, ..
|
||||
} => {
|
||||
@@ -1192,7 +1192,7 @@ mod tests {
|
||||
ssa.use_var(&mut func, x_var, I32, block0);
|
||||
assert_eq!(func.dfg.num_block_params(block0), 0);
|
||||
assert_eq!(
|
||||
func.dfg[func.layout.first_inst(block0).unwrap()].opcode(),
|
||||
func.dfg.insts[func.layout.first_inst(block0).unwrap()].opcode(),
|
||||
Opcode::Iconst
|
||||
);
|
||||
}
|
||||
@@ -1213,7 +1213,7 @@ mod tests {
|
||||
ssa.seal_block(block0, &mut func);
|
||||
assert_eq!(func.dfg.num_block_params(block0), 0);
|
||||
assert_eq!(
|
||||
func.dfg[func.layout.first_inst(block0).unwrap()].opcode(),
|
||||
func.dfg.insts[func.layout.first_inst(block0).unwrap()].opcode(),
|
||||
Opcode::Iconst
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user