forked from M-Labs/nac3
1
0
Fork 0

nac3core: use Arc to reduce copy

This commit is contained in:
pca006132 2021-09-22 16:04:25 +08:00
parent 1b5ac3cd25
commit 891056631f
3 changed files with 28 additions and 21 deletions

View File

@ -42,7 +42,7 @@ pub struct CodeGenContext<'ctx, 'a> {
pub var_assignment: HashMap<String, PointerValue<'ctx>>,
pub type_cache: HashMap<Type, BasicTypeEnum<'ctx>>,
pub primitives: PrimitiveStore,
pub calls: HashMap<CodeLocation, CallId>,
pub calls: Arc<HashMap<CodeLocation, CallId>>,
pub registry: &'a WorkerRegistry,
// stores the alloca for variables
pub init_bb: BasicBlock<'ctx>,
@ -187,8 +187,8 @@ pub struct CodeGenTask {
pub subst: Vec<(Type, Type)>,
pub symbol_name: String,
pub signature: FunSignature,
pub body: Vec<Stmt<Option<Type>>>,
pub calls: HashMap<CodeLocation, CallId>,
pub body: Arc<Vec<Stmt<Option<Type>>>>,
pub calls: Arc<HashMap<CodeLocation, CallId>>,
pub unifier: (SharedUnifier, PrimitiveStore),
pub resolver: Arc<Box<dyn SymbolResolver + Send + Sync>>,
}

View File

@ -1344,22 +1344,24 @@ impl TopLevelComposer {
calls: &mut calls,
};
let fun_body = if let ast::StmtKind::FunctionDef { body, decorator_list, .. } =
ast.clone().unwrap().node
{
if !decorator_list.is_empty() &&
matches!(&decorator_list[0].node,
ast::ExprKind::Name{ id, .. } if id == "syscall") {
instance_to_symbol.insert("".to_string(), simple_name.clone());
continue
let fun_body =
if let ast::StmtKind::FunctionDef { body, decorator_list, .. } =
ast.clone().unwrap().node
{
if !decorator_list.is_empty()
&& matches!(&decorator_list[0].node,
ast::ExprKind::Name{ id, .. } if id == "syscall")
{
instance_to_symbol.insert("".to_string(), simple_name.clone());
continue;
}
body
} else {
unreachable!("must be function def ast")
}
body
} else {
unreachable!("must be function def ast")
}
.into_iter()
.map(|b| inferencer.fold_stmt(b))
.collect::<Result<Vec<_>, _>>()?;
.into_iter()
.map(|b| inferencer.fold_stmt(b))
.collect::<Result<Vec<_>, _>>()?;
let returned =
inferencer.check_block(fun_body.as_slice(), &mut identifiers)?;
@ -1393,7 +1395,12 @@ impl TopLevelComposer {
})
.join(", ")
},
FunInstance { body: fun_body, unifier_id: 0, calls, subst },
FunInstance {
body: Arc::new(fun_body),
unifier_id: 0,
calls: Arc::new(calls),
subst,
},
);
}
} else {

View File

@ -30,8 +30,8 @@ mod test;
#[derive(Clone, Debug)]
pub struct FunInstance {
pub body: Vec<Stmt<Option<Type>>>,
pub calls: HashMap<CodeLocation, CallId>,
pub body: Arc<Vec<Stmt<Option<Type>>>>,
pub calls: Arc<HashMap<CodeLocation, CallId>>,
pub subst: HashMap<u32, Type>,
pub unifier_id: usize,
}