@@ -16,7 +16,7 @@ use crate::{
1616} ;
1717
1818pub struct MIRContext {
19- pub functions : Vec < MIRFunction > ,
19+ pub functions : HashMap < usize , MIRFunction > ,
2020 pub blocks : Vec < MIRBlock > ,
2121
2222 pub block_to_func : HashMap < usize , usize > ,
@@ -29,7 +29,7 @@ pub struct MIRContext {
2929impl MIRContext {
3030 pub fn new ( ) -> Self {
3131 MIRContext {
32- functions : vec ! [ ] ,
32+ functions : HashMap :: new ( ) ,
3333 ssa_hints : HintStorage :: new ( ) ,
3434 blocks : vec ! [ ] ,
3535 writer : InstructionWriterPosition {
@@ -45,7 +45,7 @@ impl MIRContext {
4545
4646 self . blocks . push ( MIRBlock :: new ( ind) ) ;
4747
48- self . functions [ func] . blocks . push ( ind) ;
48+ self . functions . get_mut ( & func) . unwrap ( ) . blocks . push ( ind) ;
4949
5050 self . block_to_func . insert ( ind, func) ;
5151
@@ -67,11 +67,10 @@ impl MIRContext {
6767 }
6868
6969 pub fn append_function ( & mut self , func : MIRFunction ) -> usize {
70- let ind = self . functions . len ( ) ;
70+ let id = func. id ;
71+ self . functions . insert ( id, func) ;
7172
72- self . functions . push ( func) ;
73-
74- return ind;
73+ return id;
7574 }
7675
7776 pub fn append_inst ( & mut self , inst : MIRInstruction ) -> InstructionValue {
@@ -156,7 +155,7 @@ impl MIRContext {
156155impl Display for MIRContext {
157156 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
158157 for func in & self . functions {
159- writeln ! ( f, "{}" , func) ?;
158+ writeln ! ( f, "{}" , func. 1 ) ?;
160159 }
161160
162161 for block in & self . blocks {
0 commit comments