nac3core: fix clippy warnings
This commit is contained in:
parent
97f5b7c324
commit
105d605e6d
|
@ -14,7 +14,7 @@ use inkwell::{
|
||||||
use itertools::{chain, izip, zip, Itertools};
|
use itertools::{chain, izip, zip, Itertools};
|
||||||
use rustpython_parser::ast::{self, Boolop, Constant, Expr, ExprKind, Operator, StrRef};
|
use rustpython_parser::ast::{self, Boolop, Constant, Expr, ExprKind, Operator, StrRef};
|
||||||
|
|
||||||
pub fn assert_int_val<'ctx>(val: BasicValueEnum<'ctx>) -> IntValue<'ctx> {
|
pub fn assert_int_val(val: BasicValueEnum<'_>) -> IntValue<'_> {
|
||||||
if let BasicValueEnum::IntValue(v) = val {
|
if let BasicValueEnum::IntValue(v) = val {
|
||||||
v
|
v
|
||||||
} else {
|
} else {
|
||||||
|
@ -22,7 +22,7 @@ pub fn assert_int_val<'ctx>(val: BasicValueEnum<'ctx>) -> IntValue<'ctx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn assert_pointer_val<'ctx>(val: BasicValueEnum<'ctx>) -> PointerValue<'ctx> {
|
pub fn assert_pointer_val(val: BasicValueEnum<'_>) -> PointerValue<'_> {
|
||||||
if let BasicValueEnum::PointerValue(v) = val {
|
if let BasicValueEnum::PointerValue(v) = val {
|
||||||
v
|
v
|
||||||
} else {
|
} else {
|
||||||
|
@ -189,7 +189,7 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
|
||||||
.args
|
.args
|
||||||
.iter()
|
.iter()
|
||||||
.map(|arg| FuncArg {
|
.map(|arg| FuncArg {
|
||||||
name: arg.name.clone(),
|
name: arg.name,
|
||||||
ty: unifier.copy_from(&mut self.unifier, arg.ty, &mut type_cache),
|
ty: unifier.copy_from(&mut self.unifier, arg.ty, &mut type_cache),
|
||||||
default_value: arg.default_value.clone(),
|
default_value: arg.default_value.clone(),
|
||||||
})
|
})
|
||||||
|
@ -645,7 +645,7 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
|
||||||
args.iter().map(|arg| (None, self.gen_expr(arg).unwrap())).collect_vec();
|
args.iter().map(|arg| (None, self.gen_expr(arg).unwrap())).collect_vec();
|
||||||
let kw_iter = keywords.iter().map(|kw| {
|
let kw_iter = keywords.iter().map(|kw| {
|
||||||
(
|
(
|
||||||
Some(kw.node.arg.as_ref().unwrap().clone()),
|
Some(*kw.node.arg.as_ref().unwrap()),
|
||||||
self.gen_expr(&kw.node.value).unwrap(),
|
self.gen_expr(&kw.node.value).unwrap(),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
|
@ -320,7 +320,7 @@ pub fn gen_func<'ctx>(
|
||||||
&arg.name.to_string(),
|
&arg.name.to_string(),
|
||||||
);
|
);
|
||||||
builder.build_store(alloca, param);
|
builder.build_store(alloca, param);
|
||||||
var_assignment.insert(arg.name.clone(), alloca);
|
var_assignment.insert(arg.name, alloca);
|
||||||
}
|
}
|
||||||
builder.build_unconditional_branch(body_bb);
|
builder.build_unconditional_branch(body_bb);
|
||||||
builder.position_at_end(body_bb);
|
builder.position_at_end(body_bb);
|
||||||
|
|
|
@ -25,7 +25,7 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
|
||||||
ExprKind::Name { id, .. } => {
|
ExprKind::Name { id, .. } => {
|
||||||
self.var_assignment.get(id).cloned().unwrap_or_else(|| {
|
self.var_assignment.get(id).cloned().unwrap_or_else(|| {
|
||||||
let ptr = self.gen_var(pattern.custom.unwrap());
|
let ptr = self.gen_var(pattern.custom.unwrap());
|
||||||
self.var_assignment.insert(id.clone(), ptr);
|
self.var_assignment.insert(*id, ptr);
|
||||||
ptr
|
ptr
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,15 +10,12 @@ pub enum Location {
|
||||||
Builtin,
|
Builtin,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct FileRegistry {
|
pub struct FileRegistry {
|
||||||
files: Vec<String>,
|
files: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileRegistry {
|
impl FileRegistry {
|
||||||
pub fn new() -> FileRegistry {
|
|
||||||
FileRegistry { files: Vec::new() }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn add_file(&mut self, path: &str) -> FileID {
|
pub fn add_file(&mut self, path: &str) -> FileID {
|
||||||
let index = self.files.len() as u32;
|
let index = self.files.len() as u32;
|
||||||
self.files.push(path.to_owned());
|
self.files.push(path.to_owned());
|
||||||
|
|
|
@ -89,8 +89,8 @@ impl TopLevelComposer {
|
||||||
|
|
||||||
for (name, sig) in builtins {
|
for (name, sig) in builtins {
|
||||||
let fun_sig = unifier.add_ty(TypeEnum::TFunc(RefCell::new(sig)));
|
let fun_sig = unifier.add_ty(TypeEnum::TFunc(RefCell::new(sig)));
|
||||||
built_in_ty.insert(name.clone(), fun_sig);
|
built_in_ty.insert(name, fun_sig);
|
||||||
built_in_id.insert(name.clone(), DefinitionId(definition_ast_list.len()));
|
built_in_id.insert(name, DefinitionId(definition_ast_list.len()));
|
||||||
definition_ast_list.push((
|
definition_ast_list.push((
|
||||||
Arc::new(RwLock::new(TopLevelDef::Function {
|
Arc::new(RwLock::new(TopLevelDef::Function {
|
||||||
name: name.into(),
|
name: name.into(),
|
||||||
|
@ -161,7 +161,7 @@ impl TopLevelComposer {
|
||||||
return Err("duplicate definition of class".into());
|
return Err("duplicate definition of class".into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let class_name = class_name.clone();
|
let class_name = *class_name;
|
||||||
let class_def_id = self.definition_ast_list.len();
|
let class_def_id = self.definition_ast_list.len();
|
||||||
|
|
||||||
// since later when registering class method, ast will still be used,
|
// since later when registering class method, ast will still be used,
|
||||||
|
@ -221,10 +221,10 @@ impl TopLevelComposer {
|
||||||
// dummy method define here
|
// dummy method define here
|
||||||
let dummy_method_type = self.unifier.get_fresh_var();
|
let dummy_method_type = self.unifier.get_fresh_var();
|
||||||
class_method_name_def_ids.push((
|
class_method_name_def_ids.push((
|
||||||
method_name.clone(),
|
*method_name,
|
||||||
RwLock::new(Self::make_top_level_function_def(
|
RwLock::new(Self::make_top_level_function_def(
|
||||||
global_class_method_name,
|
global_class_method_name,
|
||||||
method_name.clone(),
|
*method_name,
|
||||||
// later unify with parsed type
|
// later unify with parsed type
|
||||||
dummy_method_type.0,
|
dummy_method_type.0,
|
||||||
resolver.clone(),
|
resolver.clone(),
|
||||||
|
@ -246,7 +246,7 @@ impl TopLevelComposer {
|
||||||
for (name, _, id, ty, ..) in &class_method_name_def_ids {
|
for (name, _, id, ty, ..) in &class_method_name_def_ids {
|
||||||
let mut class_def = class_def_ast.0.write();
|
let mut class_def = class_def_ast.0.write();
|
||||||
if let TopLevelDef::Class { methods, .. } = class_def.deref_mut() {
|
if let TopLevelDef::Class { methods, .. } = class_def.deref_mut() {
|
||||||
methods.push((name.clone(), *ty, *id));
|
methods.push((*name, *ty, *id));
|
||||||
self.method_class.insert(*id, DefinitionId(class_def_id));
|
self.method_class.insert(*id, DefinitionId(class_def_id));
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
|
@ -705,7 +705,7 @@ impl TopLevelComposer {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(FuncArg {
|
Ok(FuncArg {
|
||||||
name: x.node.arg.clone(),
|
name: x.node.arg,
|
||||||
ty,
|
ty,
|
||||||
default_value: Default::default(),
|
default_value: Default::default(),
|
||||||
})
|
})
|
||||||
|
@ -809,7 +809,7 @@ impl TopLevelComposer {
|
||||||
if let ast::StmtKind::ClassDef { name, bases, body, .. } = &class_ast {
|
if let ast::StmtKind::ClassDef { name, bases, body, .. } = &class_ast {
|
||||||
(
|
(
|
||||||
*object_id,
|
*object_id,
|
||||||
name.clone(),
|
*name,
|
||||||
bases,
|
bases,
|
||||||
body,
|
body,
|
||||||
ancestors,
|
ancestors,
|
||||||
|
@ -851,7 +851,7 @@ impl TopLevelComposer {
|
||||||
let mut defined_paramter_name: HashSet<_> = HashSet::new();
|
let mut defined_paramter_name: HashSet<_> = HashSet::new();
|
||||||
let zelf: StrRef = "self".into();
|
let zelf: StrRef = "self".into();
|
||||||
let have_unique_fuction_parameter_name = args.args.iter().all(|x| {
|
let have_unique_fuction_parameter_name = args.args.iter().all(|x| {
|
||||||
defined_paramter_name.insert(x.node.arg.clone())
|
defined_paramter_name.insert(x.node.arg)
|
||||||
&& (!keyword_list.contains(&x.node.arg) || x.node.arg == zelf)
|
&& (!keyword_list.contains(&x.node.arg) || x.node.arg == zelf)
|
||||||
});
|
});
|
||||||
if !have_unique_fuction_parameter_name {
|
if !have_unique_fuction_parameter_name {
|
||||||
|
@ -1310,7 +1310,7 @@ impl TopLevelComposer {
|
||||||
let unifier = &mut self.unifier;
|
let unifier = &mut self.unifier;
|
||||||
args.iter()
|
args.iter()
|
||||||
.map(|a| FuncArg {
|
.map(|a| FuncArg {
|
||||||
name: a.name.clone(),
|
name: a.name,
|
||||||
ty: unifier.subst(a.ty, &subst).unwrap_or(a.ty),
|
ty: unifier.subst(a.ty, &subst).unwrap_or(a.ty),
|
||||||
default_value: a.default_value.clone(),
|
default_value: a.default_value.clone(),
|
||||||
})
|
})
|
||||||
|
@ -1328,7 +1328,7 @@ impl TopLevelComposer {
|
||||||
if self_type.is_some() {
|
if self_type.is_some() {
|
||||||
result.insert("self".into());
|
result.insert("self".into());
|
||||||
}
|
}
|
||||||
result.extend(inst_args.iter().map(|x| x.name.clone()));
|
result.extend(inst_args.iter().map(|x| x.name));
|
||||||
result
|
result
|
||||||
};
|
};
|
||||||
let mut calls: HashMap<CodeLocation, CallId> = HashMap::new();
|
let mut calls: HashMap<CodeLocation, CallId> = HashMap::new();
|
||||||
|
@ -1356,7 +1356,7 @@ impl TopLevelComposer {
|
||||||
if let Some(self_ty) = self_type {
|
if let Some(self_ty) = self_type {
|
||||||
result.insert("self".into(), self_ty);
|
result.insert("self".into(), self_ty);
|
||||||
}
|
}
|
||||||
result.extend(inst_args.iter().map(|x| (x.name.clone(), x.ty)));
|
result.extend(inst_args.iter().map(|x| (x.name, x.ty)));
|
||||||
result
|
result
|
||||||
},
|
},
|
||||||
primitives: &self.primitives_ty,
|
primitives: &self.primitives_ty,
|
||||||
|
|
|
@ -296,7 +296,7 @@ impl TopLevelComposer {
|
||||||
if let ast::ExprKind::Attribute { value, attr, .. } = &t.node {
|
if let ast::ExprKind::Attribute { value, attr, .. } = &t.node {
|
||||||
if let ast::ExprKind::Name { id, .. } = &value.node {
|
if let ast::ExprKind::Name { id, .. } = &value.node {
|
||||||
if id == &"self".into() {
|
if id == &"self".into() {
|
||||||
result.insert(attr.clone());
|
result.insert(*attr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ impl<'a> Inferencer<'a> {
|
||||||
match &pattern.node {
|
match &pattern.node {
|
||||||
ExprKind::Name { id, .. } => {
|
ExprKind::Name { id, .. } => {
|
||||||
if !defined_identifiers.contains(id) {
|
if !defined_identifiers.contains(id) {
|
||||||
defined_identifiers.insert(id.clone());
|
defined_identifiers.insert(*id);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ impl<'a> Inferencer<'a> {
|
||||||
ExprKind::Name { id, .. } => {
|
ExprKind::Name { id, .. } => {
|
||||||
if !defined_identifiers.contains(id) {
|
if !defined_identifiers.contains(id) {
|
||||||
if self.function_data.resolver.get_identifier_def(*id).is_some() {
|
if self.function_data.resolver.get_identifier_def(*id).is_some() {
|
||||||
defined_identifiers.insert(id.clone());
|
defined_identifiers.insert(*id);
|
||||||
} else {
|
} else {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
"unknown identifier {} (use before def?) at {}",
|
"unknown identifier {} (use before def?) at {}",
|
||||||
|
@ -107,7 +107,7 @@ impl<'a> Inferencer<'a> {
|
||||||
let mut defined_identifiers = defined_identifiers.clone();
|
let mut defined_identifiers = defined_identifiers.clone();
|
||||||
for arg in args.args.iter() {
|
for arg in args.args.iter() {
|
||||||
if !defined_identifiers.contains(&arg.node.arg) {
|
if !defined_identifiers.contains(&arg.node.arg) {
|
||||||
defined_identifiers.insert(arg.node.arg.clone());
|
defined_identifiers.insert(arg.node.arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.check_expr(body, &mut defined_identifiers)?;
|
self.check_expr(body, &mut defined_identifiers)?;
|
||||||
|
@ -167,7 +167,7 @@ impl<'a> Inferencer<'a> {
|
||||||
|
|
||||||
for ident in body_identifiers.iter() {
|
for ident in body_identifiers.iter() {
|
||||||
if !defined_identifiers.contains(ident) && orelse_identifiers.contains(ident) {
|
if !defined_identifiers.contains(ident) && orelse_identifiers.contains(ident) {
|
||||||
defined_identifiers.insert(ident.clone());
|
defined_identifiers.insert(*ident);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(body_returned && orelse_returned)
|
Ok(body_returned && orelse_returned)
|
||||||
|
|
|
@ -164,7 +164,7 @@ impl<'a> fold::Fold<()> for Inferencer<'a> {
|
||||||
ast::ExprKind::Name { id, .. } => {
|
ast::ExprKind::Name { id, .. } => {
|
||||||
if !self.defined_identifiers.contains(id) {
|
if !self.defined_identifiers.contains(id) {
|
||||||
if self.function_data.resolver.get_identifier_def(*id).is_some() {
|
if self.function_data.resolver.get_identifier_def(*id).is_some() {
|
||||||
self.defined_identifiers.insert(id.clone());
|
self.defined_identifiers.insert(*id);
|
||||||
} else {
|
} else {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
"unknown identifier {} (use before def?) at {}",
|
"unknown identifier {} (use before def?) at {}",
|
||||||
|
@ -220,7 +220,7 @@ impl<'a> Inferencer<'a> {
|
||||||
match &pattern.node {
|
match &pattern.node {
|
||||||
ExprKind::Name { id, .. } => {
|
ExprKind::Name { id, .. } => {
|
||||||
if !self.defined_identifiers.contains(id) {
|
if !self.defined_identifiers.contains(id) {
|
||||||
self.defined_identifiers.insert(id.clone());
|
self.defined_identifiers.insert(*id);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -312,13 +312,13 @@ impl<'a> Inferencer<'a> {
|
||||||
for arg in args.args.iter() {
|
for arg in args.args.iter() {
|
||||||
let name = &arg.node.arg;
|
let name = &arg.node.arg;
|
||||||
if !defined_identifiers.contains(name) {
|
if !defined_identifiers.contains(name) {
|
||||||
defined_identifiers.insert(name.clone());
|
defined_identifiers.insert(*name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let fn_args: Vec<_> = args
|
let fn_args: Vec<_> = args
|
||||||
.args
|
.args
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| (v.node.arg.clone(), self.unifier.get_fresh_var().0))
|
.map(|v| (v.node.arg, self.unifier.get_fresh_var().0))
|
||||||
.collect();
|
.collect();
|
||||||
let mut variable_mapping = self.variable_mapping.clone();
|
let mut variable_mapping = self.variable_mapping.clone();
|
||||||
variable_mapping.extend(fn_args.iter().cloned());
|
variable_mapping.extend(fn_args.iter().cloned());
|
||||||
|
@ -337,7 +337,7 @@ impl<'a> Inferencer<'a> {
|
||||||
let fun = FunSignature {
|
let fun = FunSignature {
|
||||||
args: fn_args
|
args: fn_args
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(k, ty)| FuncArg { name: k.clone(), ty: *ty, default_value: None })
|
.map(|(k, ty)| FuncArg { name: *k, ty: *ty, default_value: None })
|
||||||
.collect(),
|
.collect(),
|
||||||
ret,
|
ret,
|
||||||
vars: Default::default(),
|
vars: Default::default(),
|
||||||
|
@ -503,7 +503,7 @@ impl<'a> Inferencer<'a> {
|
||||||
posargs: args.iter().map(|v| v.custom.unwrap()).collect(),
|
posargs: args.iter().map(|v| v.custom.unwrap()).collect(),
|
||||||
kwargs: keywords
|
kwargs: keywords
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| (v.node.arg.as_ref().unwrap().clone(), v.custom.unwrap()))
|
.map(|v| (*v.node.arg.as_ref().unwrap(), v.custom.unwrap()))
|
||||||
.collect(),
|
.collect(),
|
||||||
fun: RefCell::new(None),
|
fun: RefCell::new(None),
|
||||||
ret: sign.ret,
|
ret: sign.ret,
|
||||||
|
@ -531,7 +531,7 @@ impl<'a> Inferencer<'a> {
|
||||||
posargs: args.iter().map(|v| v.custom.unwrap()).collect(),
|
posargs: args.iter().map(|v| v.custom.unwrap()).collect(),
|
||||||
kwargs: keywords
|
kwargs: keywords
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| (v.node.arg.as_ref().unwrap().clone(), v.custom.unwrap()))
|
.map(|v| (*v.node.arg.as_ref().unwrap(), v.custom.unwrap()))
|
||||||
.collect(),
|
.collect(),
|
||||||
fun: RefCell::new(None),
|
fun: RefCell::new(None),
|
||||||
ret,
|
ret,
|
||||||
|
|
|
@ -107,6 +107,12 @@ pub struct Unifier {
|
||||||
var_id: u32,
|
var_id: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Unifier {
|
||||||
|
fn default() -> Self {
|
||||||
|
Unifier::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Unifier {
|
impl Unifier {
|
||||||
/// Get an empty unifier
|
/// Get an empty unifier
|
||||||
pub fn new() -> Unifier {
|
pub fn new() -> Unifier {
|
||||||
|
@ -454,7 +460,7 @@ impl Unifier {
|
||||||
if let Some(ty) = fields2.get(key) {
|
if let Some(ty) = fields2.get(key) {
|
||||||
self.unify(*ty, *value)?;
|
self.unify(*ty, *value)?;
|
||||||
} else {
|
} else {
|
||||||
fields2.insert(key.clone(), *value);
|
fields2.insert(*key, *value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,12 @@ pub struct UnificationTable<V> {
|
||||||
values: Vec<Option<V>>,
|
values: Vec<Option<V>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<V> Default for UnificationTable<V> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<V> UnificationTable<V> {
|
impl<V> UnificationTable<V> {
|
||||||
pub fn new() -> UnificationTable<V> {
|
pub fn new() -> UnificationTable<V> {
|
||||||
UnificationTable { parents: Vec::new(), ranks: Vec::new(), values: Vec::new() }
|
UnificationTable { parents: Vec::new(), ranks: Vec::new(), values: Vec::new() }
|
||||||
|
|
|
@ -78,7 +78,7 @@ fn main() {
|
||||||
"__main__".into(),
|
"__main__".into(),
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
internal_resolver.add_id_def(name.clone(), def_id);
|
internal_resolver.add_id_def(name, def_id);
|
||||||
if let Some(ty) = ty {
|
if let Some(ty) = ty {
|
||||||
internal_resolver.add_id_type(name, ty);
|
internal_resolver.add_id_type(name, ty);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue