fixed some clippy warnings

This commit is contained in:
pca006132 2021-10-16 18:08:13 +08:00
parent 26076c37ba
commit c4259d14d1
13 changed files with 94 additions and 68 deletions

View File

@ -94,7 +94,7 @@ impl Nac3 {
})?; })?;
let parser_result = parser::parse_program(&source) let parser_result = parser::parse_program(&source)
.map_err(|e| exceptions::PySyntaxError::new_err(format!("parse error: {}", e)))?; .map_err(|e| exceptions::PySyntaxError::new_err(format!("parse error: {}", e)))?;
let resolver = Arc::new(Box::new(Resolver { let resolver = Arc::new(Resolver {
id_to_type: self.builtins_ty.clone().into(), id_to_type: self.builtins_ty.clone().into(),
id_to_def: self.builtins_def.clone().into(), id_to_def: self.builtins_def.clone().into(),
pyid_to_def: self.pyid_to_def.clone(), pyid_to_def: self.pyid_to_def.clone(),
@ -104,7 +104,7 @@ impl Nac3 {
class_names: Default::default(), class_names: Default::default(),
name_to_pyid: name_to_pyid.clone(), name_to_pyid: name_to_pyid.clone(),
module: obj, module: obj,
}) as Box<dyn SymbolResolver + Send + Sync>); }) as Arc<dyn SymbolResolver + Send + Sync>;
let mut name_to_def = HashMap::new(); let mut name_to_def = HashMap::new();
let mut name_to_type = HashMap::new(); let mut name_to_type = HashMap::new();
@ -334,7 +334,7 @@ impl Nac3 {
) )
}; };
let mut synthesized = parse_program(&synthesized).unwrap(); let mut synthesized = parse_program(&synthesized).unwrap();
let resolver = Arc::new(Box::new(Resolver { let resolver = Arc::new(Resolver {
id_to_type: self.builtins_ty.clone().into(), id_to_type: self.builtins_ty.clone().into(),
id_to_def: self.builtins_def.clone().into(), id_to_def: self.builtins_def.clone().into(),
pyid_to_def: self.pyid_to_def.clone(), pyid_to_def: self.pyid_to_def.clone(),
@ -344,7 +344,7 @@ impl Nac3 {
class_names: Default::default(), class_names: Default::default(),
name_to_pyid, name_to_pyid,
module: module.to_object(py), module: module.to_object(py),
}) as Box<dyn SymbolResolver + Send + Sync>); }) as Arc<dyn SymbolResolver + Send + Sync>;
let (_, def_id, _) = self let (_, def_id, _) = self
.composer .composer
.register_top_level( .register_top_level(

View File

@ -159,7 +159,7 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
let instance = instance_to_stmt.get(&key).unwrap(); let instance = instance_to_stmt.get(&key).unwrap();
let unifiers = self.top_level.unifiers.read(); let unifiers = self.top_level.unifiers.read();
let (unifier, primitives) = &unifiers[instance.unifier_id]; let (unifier, primitives) = &unifiers[instance.unifier_id];
let mut unifier = Unifier::from_shared_unifier(&unifier); let mut unifier = Unifier::from_shared_unifier(unifier);
let mut type_cache = [ let mut type_cache = [
(self.primitives.int32, primitives.int32), (self.primitives.int32, primitives.int32),

View File

@ -38,7 +38,7 @@ pub struct CodeGenContext<'ctx, 'a> {
pub module: Module<'ctx>, pub module: Module<'ctx>,
pub top_level: &'a TopLevelContext, pub top_level: &'a TopLevelContext,
pub unifier: Unifier, pub unifier: Unifier,
pub resolver: Arc<Box<dyn SymbolResolver + Send + Sync>>, pub resolver: Arc<dyn SymbolResolver + Send + Sync>,
pub var_assignment: HashMap<StrRef, PointerValue<'ctx>>, pub var_assignment: HashMap<StrRef, PointerValue<'ctx>>,
pub type_cache: HashMap<Type, BasicTypeEnum<'ctx>>, pub type_cache: HashMap<Type, BasicTypeEnum<'ctx>>,
pub primitives: PrimitiveStore, pub primitives: PrimitiveStore,
@ -190,7 +190,7 @@ pub struct CodeGenTask {
pub body: Arc<Vec<Stmt<Option<Type>>>>, pub body: Arc<Vec<Stmt<Option<Type>>>>,
pub calls: Arc<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<dyn SymbolResolver + Send + Sync>,
} }
fn get_llvm_type<'ctx>( fn get_llvm_type<'ctx>(
@ -287,7 +287,7 @@ pub fn gen_func<'ctx>(
.args .args
.iter() .iter()
.map(|arg| { .map(|arg| {
get_llvm_type(&context, &mut unifier, top_level_ctx.as_ref(), &mut type_cache, arg.ty) get_llvm_type(context, &mut unifier, top_level_ctx.as_ref(), &mut type_cache, arg.ty)
}) })
.collect_vec(); .collect_vec();
@ -295,7 +295,7 @@ pub fn gen_func<'ctx>(
context.void_type().fn_type(&params, false) context.void_type().fn_type(&params, false)
} else { } else {
get_llvm_type( get_llvm_type(
&context, context,
&mut unifier, &mut unifier,
top_level_ctx.as_ref(), top_level_ctx.as_ref(),
&mut type_cache, &mut type_cache,
@ -309,9 +309,9 @@ pub fn gen_func<'ctx>(
module.get_function(symbol).unwrap_or_else(|| module.add_function(symbol, fn_type, None)); module.get_function(symbol).unwrap_or_else(|| module.add_function(symbol, fn_type, None));
if let Some(personality) = &top_level_ctx.personality_symbol { if let Some(personality) = &top_level_ctx.personality_symbol {
let personality = module.get_function(&personality).unwrap_or_else(|| { let personality = module.get_function(personality).unwrap_or_else(|| {
let ty = context.i32_type().fn_type(&[], true); let ty = context.i32_type().fn_type(&[], true);
module.add_function(&personality, ty, None) module.add_function(personality, ty, None)
}); });
fn_val.set_personality_function(personality); fn_val.set_personality_function(personality);
} }
@ -324,7 +324,7 @@ pub fn gen_func<'ctx>(
for (n, arg) in task.signature.args.iter().enumerate() { for (n, arg) in task.signature.args.iter().enumerate() {
let param = fn_val.get_nth_param(n as u32).unwrap(); let param = fn_val.get_nth_param(n as u32).unwrap();
let alloca = builder.build_alloca( let alloca = builder.build_alloca(
get_llvm_type(&context, &mut unifier, top_level_ctx.as_ref(), &mut type_cache, arg.ty), get_llvm_type(context, &mut unifier, top_level_ctx.as_ref(), &mut type_cache, arg.ty),
&arg.name.to_string(), &arg.name.to_string(),
); );
builder.build_store(alloca, param); builder.build_store(alloca, param);
@ -334,7 +334,7 @@ pub fn gen_func<'ctx>(
builder.position_at_end(body_bb); builder.position_at_end(body_bb);
let mut code_gen_context = CodeGenContext { let mut code_gen_context = CodeGenContext {
ctx: &context, ctx: context,
resolver: task.resolver, resolver: task.resolver,
top_level: top_level_ctx.as_ref(), top_level: top_level_ctx.as_ref(),
calls: task.calls, calls: task.calls,

View File

@ -96,22 +96,22 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
match &stmt.node { match &stmt.node {
StmtKind::Pass => {}, StmtKind::Pass => {},
StmtKind::Expr { value } => { StmtKind::Expr { value } => {
self.gen_expr(&value); self.gen_expr(value);
} }
StmtKind::Return { value } => { StmtKind::Return { value } => {
let value = value.as_ref().map(|v| self.gen_expr(&v).unwrap()); let value = value.as_ref().map(|v| self.gen_expr(v).unwrap());
let value = value.as_ref().map(|v| v as &dyn BasicValue); let value = value.as_ref().map(|v| v as &dyn BasicValue);
self.builder.build_return(value); self.builder.build_return(value);
return true; return true;
} }
StmtKind::AnnAssign { target, value, .. } => { StmtKind::AnnAssign { target, value, .. } => {
if let Some(value) = value { if let Some(value) = value {
let value = self.gen_expr(&value).unwrap(); let value = self.gen_expr(value).unwrap();
self.gen_assignment(target, value); self.gen_assignment(target, value);
} }
} }
StmtKind::Assign { targets, value, .. } => { StmtKind::Assign { targets, value, .. } => {
let value = self.gen_expr(&value).unwrap(); let value = self.gen_expr(value).unwrap();
for target in targets.iter() { for target in targets.iter() {
self.gen_assignment(target, value); self.gen_assignment(target, value);
} }

View File

@ -66,11 +66,11 @@ fn test_primitives() {
let top_level = Arc::new(composer.make_top_level_context()); let top_level = Arc::new(composer.make_top_level_context());
unifier.top_level = Some(top_level.clone()); unifier.top_level = Some(top_level.clone());
let resolver = Arc::new(Box::new(Resolver { let resolver = Arc::new(Resolver {
id_to_type: HashMap::new(), id_to_type: HashMap::new(),
id_to_def: RwLock::new(HashMap::new()), id_to_def: RwLock::new(HashMap::new()),
class_names: Default::default(), class_names: Default::default(),
}) as Box<dyn SymbolResolver + Send + Sync>); }) as Arc<dyn SymbolResolver + Send + Sync>;
let threads = ["test"]; let threads = ["test"];
let signature = FunSignature { let signature = FunSignature {
@ -229,13 +229,13 @@ fn test_simple_call() {
codegen_callback: None, codegen_callback: None,
}))); })));
let resolver = Box::new(Resolver { let resolver = Resolver {
id_to_type: HashMap::new(), id_to_type: HashMap::new(),
id_to_def: RwLock::new(HashMap::new()), id_to_def: RwLock::new(HashMap::new()),
class_names: Default::default(), class_names: Default::default(),
}); };
resolver.add_id_def("foo".into(), DefinitionId(foo_id)); resolver.add_id_def("foo".into(), DefinitionId(foo_id));
let resolver = Arc::new(resolver as Box<dyn SymbolResolver + Send + Sync>); let resolver = Arc::new(resolver) as Arc<dyn SymbolResolver + Send + Sync>;
if let TopLevelDef::Function { resolver: r, .. } = if let TopLevelDef::Function { resolver: r, .. } =
&mut *top_level.definitions.read()[foo_id].write() &mut *top_level.definitions.read()[foo_id].write()

View File

@ -387,7 +387,7 @@ impl TopLevelComposer {
pub fn register_top_level( pub fn register_top_level(
&mut self, &mut self,
ast: ast::Stmt<()>, ast: ast::Stmt<()>,
resolver: Option<Arc<Box<dyn SymbolResolver + Send + Sync>>>, resolver: Option<Arc<dyn SymbolResolver + Send + Sync>>,
mod_path: String, mod_path: String,
) -> Result<(StrRef, DefinitionId, Option<Type>), String> { ) -> Result<(StrRef, DefinitionId, Option<Type>), String> {
let defined_names = &mut self.defined_names; let defined_names = &mut self.defined_names;
@ -720,7 +720,7 @@ impl TopLevelComposer {
// the function parse_ast_to make sure that no type var occured in // the function parse_ast_to make sure that no type var occured in
// bast_ty if it is a CustomClassKind // bast_ty if it is a CustomClassKind
let base_ty = parse_ast_to_type_annotation_kinds( let base_ty = parse_ast_to_type_annotation_kinds(
class_resolver.as_ref(), class_resolver,
&temp_def_list, &temp_def_list,
unifier, unifier,
&self.primitives_ty, &self.primitives_ty,
@ -926,7 +926,7 @@ impl TopLevelComposer {
.as_ref(); .as_ref();
let type_annotation = parse_ast_to_type_annotation_kinds( let type_annotation = parse_ast_to_type_annotation_kinds(
resolver.as_ref(), resolver,
temp_def_list.as_slice(), temp_def_list.as_slice(),
unifier, unifier,
primitives_store, primitives_store,
@ -975,7 +975,7 @@ impl TopLevelComposer {
let return_ty_annotation = { let return_ty_annotation = {
let return_annotation = returns.as_ref(); let return_annotation = returns.as_ref();
parse_ast_to_type_annotation_kinds( parse_ast_to_type_annotation_kinds(
resolver.as_ref(), resolver,
&temp_def_list, &temp_def_list,
unifier, unifier,
primitives_store, primitives_store,
@ -1132,7 +1132,7 @@ impl TopLevelComposer {
})? })?
.as_ref(); .as_ref();
parse_ast_to_type_annotation_kinds( parse_ast_to_type_annotation_kinds(
class_resolver.as_ref(), class_resolver,
temp_def_list, temp_def_list,
unifier, unifier,
primitives, primitives,
@ -1178,7 +1178,7 @@ impl TopLevelComposer {
if let Some(result) = returns { if let Some(result) = returns {
let result = result.as_ref(); let result = result.as_ref();
let annotation = parse_ast_to_type_annotation_kinds( let annotation = parse_ast_to_type_annotation_kinds(
class_resolver.as_ref(), class_resolver,
temp_def_list, temp_def_list,
unifier, unifier,
primitives, primitives,
@ -1253,8 +1253,8 @@ impl TopLevelComposer {
}; };
let annotation = parse_ast_to_type_annotation_kinds( let annotation = parse_ast_to_type_annotation_kinds(
class_resolver.as_ref(), class_resolver,
&temp_def_list, temp_def_list,
unifier, unifier,
primitives, primitives,
annotation.as_ref(), annotation.as_ref(),

View File

@ -91,7 +91,7 @@ impl TopLevelComposer {
/// when first regitering, the type_vars, fields, methods, ancestors are invalid /// when first regitering, the type_vars, fields, methods, ancestors are invalid
pub fn make_top_level_class_def( pub fn make_top_level_class_def(
index: usize, index: usize,
resolver: Option<Arc<Box<dyn SymbolResolver + Send + Sync>>>, resolver: Option<Arc<dyn SymbolResolver + Send + Sync>>,
name: StrRef, name: StrRef,
constructor: Option<Type>, constructor: Option<Type>,
) -> TopLevelDef { ) -> TopLevelDef {
@ -112,7 +112,7 @@ impl TopLevelComposer {
name: String, name: String,
simple_name: StrRef, simple_name: StrRef,
ty: Type, ty: Type,
resolver: Option<Arc<Box<dyn SymbolResolver + Send + Sync>>>, resolver: Option<Arc<dyn SymbolResolver + Send + Sync>>,
) -> TopLevelDef { ) -> TopLevelDef {
TopLevelDef::Function { TopLevelDef::Function {
name, name,

View File

@ -91,7 +91,7 @@ pub enum TopLevelDef {
// ancestor classes, including itself. // ancestor classes, including itself.
ancestors: Vec<TypeAnnotation>, ancestors: Vec<TypeAnnotation>,
// symbol resolver of the module defined the class, none if it is built-in type // symbol resolver of the module defined the class, none if it is built-in type
resolver: Option<Arc<Box<dyn SymbolResolver + Send + Sync>>>, resolver: Option<Arc<dyn SymbolResolver + Send + Sync>>,
// constructor type // constructor type
constructor: Option<Type>, constructor: Option<Type>,
}, },
@ -116,7 +116,7 @@ pub enum TopLevelDef {
/// rigid type variables that would be substituted when the function is instantiated. /// rigid type variables that would be substituted when the function is instantiated.
instance_to_stmt: HashMap<String, FunInstance>, instance_to_stmt: HashMap<String, FunInstance>,
// symbol resolver of the module defined the class // symbol resolver of the module defined the class
resolver: Option<Arc<Box<dyn SymbolResolver + Send + Sync>>>, resolver: Option<Arc<dyn SymbolResolver + Send + Sync>>,
// custom codegen callback // custom codegen callback
codegen_callback: Option<Arc<GenCall>> codegen_callback: Option<Arc<GenCall>>
}, },

View File

@ -35,7 +35,13 @@ impl ResolverInternal {
struct Resolver(Arc<ResolverInternal>); struct Resolver(Arc<ResolverInternal>);
impl SymbolResolver for Resolver { impl SymbolResolver for Resolver {
fn get_symbol_type(&self, _: &mut Unifier, _: &[Arc<RwLock<TopLevelDef>>], _: &PrimitiveStore, str: StrRef) -> Option<Type> { fn get_symbol_type(
&self,
_: &mut Unifier,
_: &[Arc<RwLock<TopLevelDef>>],
_: &PrimitiveStore,
str: StrRef,
) -> Option<Type> {
let ret = self.0.id_to_type.lock().get(&str).cloned(); let ret = self.0.id_to_type.lock().get(&str).cloned();
if ret.is_none() { if ret.is_none() {
// println!("unknown here resolver {}", str); // println!("unknown here resolver {}", str);
@ -138,9 +144,8 @@ fn test_simple_function_analyze(source: Vec<&str>, tys: Vec<&str>, names: Vec<&s
id_to_type: Default::default(), id_to_type: Default::default(),
class_names: Default::default(), class_names: Default::default(),
}); });
let resolver = Arc::new( let resolver =
Box::new(Resolver(internal_resolver.clone())) as Box<dyn SymbolResolver + Send + Sync> Arc::new(Resolver(internal_resolver.clone())) as Arc<dyn SymbolResolver + Send + Sync>;
);
for s in source { for s in source {
let ast = parse_program(s).unwrap(); let ast = parse_program(s).unwrap();
@ -148,7 +153,7 @@ fn test_simple_function_analyze(source: Vec<&str>, tys: Vec<&str>, names: Vec<&s
let (id, def_id, ty) = let (id, def_id, ty) =
composer.register_top_level(ast, Some(resolver.clone()), "".into()).unwrap(); composer.register_top_level(ast, Some(resolver.clone()), "".into()).unwrap();
internal_resolver.add_id_def(id.clone(), def_id); internal_resolver.add_id_def(id, def_id);
if let Some(ty) = ty { if let Some(ty) = ty {
internal_resolver.add_id_type(id, ty); internal_resolver.add_id_type(id, ty);
} }
@ -489,9 +494,8 @@ fn test_analyze(source: Vec<&str>, res: Vec<&str>) {
&mut composer.unifier, &mut composer.unifier,
print, print,
); );
let resolver = Arc::new( let resolver =
Box::new(Resolver(internal_resolver.clone())) as Box<dyn SymbolResolver + Send + Sync> Arc::new(Resolver(internal_resolver.clone())) as Arc<dyn SymbolResolver + Send + Sync>;
);
for s in source { for s in source {
let ast = parse_program(s).unwrap(); let ast = parse_program(s).unwrap();
@ -685,8 +689,8 @@ fn test_inference(source: Vec<&str>, res: Vec<&str>) {
print, print,
); );
let resolver = Arc::new( let resolver = Arc::new(
Box::new(Resolver(internal_resolver.clone())) as Box<dyn SymbolResolver + Send + Sync> Resolver(internal_resolver.clone())
); ) as Arc<dyn SymbolResolver + Send + Sync>;
for s in source { for s in source {
let ast = parse_program(s).unwrap(); let ast = parse_program(s).unwrap();
@ -705,7 +709,7 @@ fn test_inference(source: Vec<&str>, res: Vec<&str>) {
} }
} }
}; };
internal_resolver.add_id_def(id.clone(), def_id); internal_resolver.add_id_def(id, def_id);
if let Some(ty) = ty { if let Some(ty) = ty {
internal_resolver.add_id_type(id, ty); internal_resolver.add_id_type(id, ty);
} }
@ -754,7 +758,7 @@ fn make_internal_resolver_with_tvar(
id_to_type: tvars id_to_type: tvars
.into_iter() .into_iter()
.map(|(name, range)| { .map(|(name, range)| {
(name.clone(), { (name, {
let (ty, id) = unifier.get_fresh_var_with_range(range.as_slice()); let (ty, id) = unifier.get_fresh_var_with_range(range.as_slice());
if print { if print {
println!("{}: {:?}, tvar{}", name, ty, id); println!("{}: {:?}, tvar{}", name, ty, id);

View File

@ -38,7 +38,7 @@ pub struct PrimitiveStore {
} }
pub struct FunctionData { pub struct FunctionData {
pub resolver: Arc<Box<dyn SymbolResolver + Send + Sync>>, pub resolver: Arc<dyn SymbolResolver + Send + Sync>,
pub return_type: Option<Type>, pub return_type: Option<Type>,
pub bound_variables: Vec<Type>, pub bound_variables: Vec<Type>,
} }
@ -91,7 +91,7 @@ impl<'a> fold::Fold<()> for Inferencer<'a> {
let annotation_type = self.function_data.resolver.parse_type_annotation( let annotation_type = self.function_data.resolver.parse_type_annotation(
top_level_defs.as_slice(), top_level_defs.as_slice(),
self.unifier, self.unifier,
&self.primitives, self.primitives,
annotation.as_ref(), annotation.as_ref(),
)?; )?;
self.unify(annotation_type, target.custom.unwrap(), &node.location)?; self.unify(annotation_type, target.custom.unwrap(), &node.location)?;

View File

@ -67,11 +67,14 @@ impl TestEnvironment {
params: HashMap::new().into(), params: HashMap::new().into(),
}); });
if let TypeEnum::TObj { fields, .. } = &*unifier.get_ty(int32) { if let TypeEnum::TObj { fields, .. } = &*unifier.get_ty(int32) {
let add_ty = unifier.add_ty(TypeEnum::TFunc(FunSignature { let add_ty = unifier.add_ty(TypeEnum::TFunc(
args: vec![FuncArg { name: "other".into(), ty: int32, default_value: None }], FunSignature {
ret: int32, args: vec![FuncArg { name: "other".into(), ty: int32, default_value: None }],
vars: HashMap::new() ret: int32,
}.into())); vars: HashMap::new(),
}
.into(),
));
fields.borrow_mut().insert("__add__".into(), add_ty); fields.borrow_mut().insert("__add__".into(), add_ty);
} }
let int64 = unifier.add_ty(TypeEnum::TObj { let int64 = unifier.add_ty(TypeEnum::TObj {
@ -111,11 +114,11 @@ impl TestEnvironment {
let mut identifier_mapping = HashMap::new(); let mut identifier_mapping = HashMap::new();
identifier_mapping.insert("None".into(), none); identifier_mapping.insert("None".into(), none);
let resolver = Arc::new(Box::new(Resolver { let resolver = Arc::new(Resolver {
id_to_type: identifier_mapping.clone(), id_to_type: identifier_mapping.clone(),
id_to_def: Default::default(), id_to_def: Default::default(),
class_names: Default::default(), class_names: Default::default(),
}) as Box<dyn SymbolResolver + Send + Sync>); }) as Arc<dyn SymbolResolver + Send + Sync>;
TestEnvironment { TestEnvironment {
top_level: TopLevelContext { top_level: TopLevelContext {
@ -147,11 +150,14 @@ impl TestEnvironment {
params: HashMap::new().into(), params: HashMap::new().into(),
}); });
if let TypeEnum::TObj { fields, .. } = &*unifier.get_ty(int32) { if let TypeEnum::TObj { fields, .. } = &*unifier.get_ty(int32) {
let add_ty = unifier.add_ty(TypeEnum::TFunc(FunSignature { let add_ty = unifier.add_ty(TypeEnum::TFunc(
args: vec![FuncArg { name: "other".into(), ty: int32, default_value: None }], FunSignature {
ret: int32, args: vec![FuncArg { name: "other".into(), ty: int32, default_value: None }],
vars: HashMap::new() ret: int32,
}.into())); vars: HashMap::new(),
}
.into(),
));
fields.borrow_mut().insert("__add__".into(), add_ty); fields.borrow_mut().insert("__add__".into(), add_ty);
} }
let int64 = unifier.add_ty(TypeEnum::TObj { let int64 = unifier.add_ty(TypeEnum::TObj {
@ -308,7 +314,7 @@ impl TestEnvironment {
personality_symbol: None, personality_symbol: None,
}; };
let resolver = Arc::new(Box::new(Resolver { let resolver = Arc::new(Resolver {
id_to_type: identifier_mapping.clone(), id_to_type: identifier_mapping.clone(),
id_to_def: [ id_to_def: [
("Foo".into(), DefinitionId(5)), ("Foo".into(), DefinitionId(5)),
@ -319,7 +325,7 @@ impl TestEnvironment {
.cloned() .cloned()
.collect(), .collect(),
class_names, class_names,
}) as Box<dyn SymbolResolver + Send + Sync>); }) as Arc<dyn SymbolResolver + Send + Sync>;
TestEnvironment { TestEnvironment {
unifier, unifier,

View File

@ -1,8 +1,14 @@
use inkwell::values::BasicValueEnum; use inkwell::values::BasicValueEnum;
use nac3core::{codegen::CodeGenContext, location::Location, symbol_resolver::{SymbolResolver, SymbolValue}, toplevel::{DefinitionId, TopLevelDef}, typecheck::{ use nac3core::{
codegen::CodeGenContext,
location::Location,
symbol_resolver::SymbolResolver,
toplevel::{DefinitionId, TopLevelDef},
typecheck::{
type_inferencer::PrimitiveStore, type_inferencer::PrimitiveStore,
typedef::{Type, Unifier}, typedef::{Type, Unifier},
}}; },
};
use parking_lot::{Mutex, RwLock}; use parking_lot::{Mutex, RwLock};
use rustpython_parser::ast::StrRef; use rustpython_parser::ast::StrRef;
use std::{collections::HashMap, sync::Arc}; use std::{collections::HashMap, sync::Arc};
@ -26,7 +32,13 @@ impl ResolverInternal {
pub struct Resolver(pub Arc<ResolverInternal>); pub struct Resolver(pub Arc<ResolverInternal>);
impl SymbolResolver for Resolver { impl SymbolResolver for Resolver {
fn get_symbol_type(&self, _: &mut Unifier, _: &[Arc<RwLock<TopLevelDef>>], _: &PrimitiveStore, str: StrRef) -> Option<Type> { fn get_symbol_type(
&self,
_: &mut Unifier,
_: &[Arc<RwLock<TopLevelDef>>],
_: &PrimitiveStore,
str: StrRef,
) -> Option<Type> {
let ret = self.0.id_to_type.lock().get(&str).cloned(); let ret = self.0.id_to_type.lock().get(&str).cloned();
if ret.is_none() { if ret.is_none() {
// println!("unknown here resolver {}", str); // println!("unknown here resolver {}", str);
@ -34,7 +46,11 @@ impl SymbolResolver for Resolver {
ret ret
} }
fn get_symbol_value<'ctx, 'a>(&self, _: StrRef, _: &mut CodeGenContext<'ctx, 'a>) -> Option<BasicValueEnum<'ctx>> { fn get_symbol_value<'ctx, 'a>(
&self,
_: StrRef,
_: &mut CodeGenContext<'ctx, 'a>,
) -> Option<BasicValueEnum<'ctx>> {
unimplemented!() unimplemented!()
} }

View File

@ -40,8 +40,8 @@ fn main() {
class_names: Default::default(), class_names: Default::default(),
}.into(); }.into();
let resolver = Arc::new( let resolver = Arc::new(
Box::new(Resolver(internal_resolver.clone())) as Box<dyn SymbolResolver + Send + Sync> Resolver(internal_resolver.clone())
); ) as Arc<dyn SymbolResolver + Send + Sync>;
let setup_time = SystemTime::now(); let setup_time = SystemTime::now();
println!("setup time: {}ms", setup_time.duration_since(start).unwrap().as_millis()); println!("setup time: {}ms", setup_time.duration_since(start).unwrap().as_millis());