|
1 | 1 | use crate::error::{LowerError, LowerErrorKind};
|
2 | 2 | use append_only_vec::AppendOnlyVec;
|
| 3 | +use arena::{Arena, LockFreeArena}; |
3 | 4 | use asg::PolyRecipe;
|
4 | 5 | use attributes::Tag;
|
5 | 6 | use std::{borrow::Borrow, cell::OnceCell, collections::HashMap, sync::RwLock};
|
6 | 7 |
|
7 | 8 | #[derive(Default)]
|
8 | 9 | pub struct Funcs {
|
9 |
| - funcs: AppendOnlyVec<ir::Func>, |
| 10 | + funcs: LockFreeArena<ir::FuncId, ir::Func>, |
10 | 11 | monomorphized: RwLock<HashMap<(asg::FuncRef, PolyRecipe), ir::FuncRef>>,
|
11 | 12 | jobs: AppendOnlyVec<(asg::FuncRef, PolyRecipe, ir::FuncRef)>,
|
12 | 13 | interpreter_entry_point: OnceCell<ir::FuncRef>,
|
13 | 14 | }
|
14 | 15 |
|
15 | 16 | impl Funcs {
|
16 |
| - pub fn build(self) -> ir::Funcs { |
17 |
| - ir::Funcs::new(self.funcs.into_iter().collect()) |
| 17 | + pub fn build(self) -> Arena<ir::FuncId, ir::Func> { |
| 18 | + self.funcs.into_arena() |
18 | 19 | }
|
19 | 20 |
|
20 | 21 | pub fn insert(&self, func_ref: asg::FuncRef, function: ir::Func) -> ir::FuncRef {
|
21 |
| - let index = self.funcs.len(); |
22 |
| - self.funcs.push(function); |
23 |
| - let ir_func_ref = ir::FuncRef::new(index); |
| 22 | + let ir_func_ref = self.funcs.alloc(function); |
24 | 23 | self.monomorphized
|
25 | 24 | .write()
|
26 | 25 | .unwrap()
|
@@ -62,7 +61,7 @@ impl Funcs {
|
62 | 61 | }
|
63 | 62 |
|
64 | 63 | pub fn get_mut(&mut self, key: ir::FuncRef) -> &mut ir::Func {
|
65 |
| - &mut self.funcs[key.get()] |
| 64 | + &mut self.funcs[key] |
66 | 65 | }
|
67 | 66 |
|
68 | 67 | pub fn monomorphized<'a>(
|
|
0 commit comments