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

View File

@ -1344,14 +1344,16 @@ impl TopLevelComposer {
calls: &mut calls, calls: &mut calls,
}; };
let fun_body = if let ast::StmtKind::FunctionDef { body, decorator_list, .. } = let fun_body =
if let ast::StmtKind::FunctionDef { body, decorator_list, .. } =
ast.clone().unwrap().node ast.clone().unwrap().node
{ {
if !decorator_list.is_empty() && if !decorator_list.is_empty()
matches!(&decorator_list[0].node, && matches!(&decorator_list[0].node,
ast::ExprKind::Name{ id, .. } if id == "syscall") { ast::ExprKind::Name{ id, .. } if id == "syscall")
{
instance_to_symbol.insert("".to_string(), simple_name.clone()); instance_to_symbol.insert("".to_string(), simple_name.clone());
continue continue;
} }
body body
} else { } else {
@ -1393,7 +1395,12 @@ impl TopLevelComposer {
}) })
.join(", ") .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 { } else {

View File

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