forked from M-Labs/nac3
fix clippy warnings
This commit is contained in:
parent
34cf303e6c
commit
ffa89e9308
@ -18,12 +18,11 @@ impl TimeFns for NowPinningTimeFns {
|
||||
.unwrap_or_else(|| ctx.module.add_global(i64_type, None, "now"));
|
||||
let now_raw = ctx.builder.build_load(now.as_pointer_value(), "now");
|
||||
if let BasicValueEnum::IntValue(now_raw) = now_raw {
|
||||
let i64_32 = i64_type.const_int(32, false).into();
|
||||
let i64_32 = i64_type.const_int(32, false);
|
||||
let now_lo = ctx.builder.build_left_shift(now_raw, i64_32, "now_shl");
|
||||
let now_hi = ctx
|
||||
.builder
|
||||
.build_right_shift(now_raw, i64_32, false, "now_lshr")
|
||||
.into();
|
||||
.build_right_shift(now_raw, i64_32, false, "now_lshr");
|
||||
ctx.builder.build_or(now_lo, now_hi, "now_or").into()
|
||||
} else {
|
||||
unreachable!();
|
||||
@ -33,7 +32,7 @@ impl TimeFns for NowPinningTimeFns {
|
||||
fn emit_at_mu<'ctx, 'a>(&self, ctx: &mut CodeGenContext<'ctx, 'a>, t: BasicValueEnum<'ctx>) {
|
||||
let i32_type = ctx.ctx.i32_type();
|
||||
let i64_type = ctx.ctx.i64_type();
|
||||
let i64_32 = i64_type.const_int(32, false).into();
|
||||
let i64_32 = i64_type.const_int(32, false);
|
||||
if let BasicValueEnum::IntValue(time) = t {
|
||||
let time_hi = ctx.builder.build_int_truncate(
|
||||
ctx.builder
|
||||
@ -55,7 +54,7 @@ impl TimeFns for NowPinningTimeFns {
|
||||
let now_loptr = unsafe {
|
||||
ctx.builder.build_gep(
|
||||
now_hiptr,
|
||||
&[i32_type.const_int(1, false).into()],
|
||||
&[i32_type.const_int(1, false)],
|
||||
"now_gep",
|
||||
)
|
||||
};
|
||||
@ -78,7 +77,7 @@ impl TimeFns for NowPinningTimeFns {
|
||||
fn emit_delay_mu<'ctx, 'a>(&self, ctx: &mut CodeGenContext<'ctx, 'a>, dt: BasicValueEnum<'ctx>) {
|
||||
let i32_type = ctx.ctx.i32_type();
|
||||
let i64_type = ctx.ctx.i64_type();
|
||||
let i64_32 = i64_type.const_int(32, false).into();
|
||||
let i64_32 = i64_type.const_int(32, false);
|
||||
let now = ctx
|
||||
.module
|
||||
.get_global("now")
|
||||
@ -90,8 +89,7 @@ impl TimeFns for NowPinningTimeFns {
|
||||
let now_lo = ctx.builder.build_left_shift(now_raw, i64_32, "now_shl");
|
||||
let now_hi = ctx
|
||||
.builder
|
||||
.build_right_shift(now_raw, i64_32, false, "now_lshr")
|
||||
.into();
|
||||
.build_right_shift(now_raw, i64_32, false, "now_lshr");
|
||||
let now_val = ctx.builder.build_or(now_lo, now_hi, "now_or");
|
||||
let time = ctx.builder.build_int_add(now_val, dt, "now_add");
|
||||
let time_hi = ctx.builder.build_int_truncate(
|
||||
@ -110,7 +108,7 @@ impl TimeFns for NowPinningTimeFns {
|
||||
let now_loptr = unsafe {
|
||||
ctx.builder.build_gep(
|
||||
now_hiptr,
|
||||
&[i32_type.const_int(1, false).into()],
|
||||
&[i32_type.const_int(1, false)],
|
||||
"now_gep",
|
||||
)
|
||||
};
|
||||
|
@ -46,7 +46,7 @@ impl From<&str> for StrRef {
|
||||
LOCAL_INTERNER.with(|local| {
|
||||
let mut local = local.borrow_mut();
|
||||
local.get(s).copied().unwrap_or_else(|| {
|
||||
let r = get_str_ref(&mut get_str_ref_lock(), &s);
|
||||
let r = get_str_ref(&mut get_str_ref_lock(), s);
|
||||
local.insert(s.to_string(), r);
|
||||
r
|
||||
})
|
||||
|
@ -884,7 +884,7 @@ impl TopLevelComposer {
|
||||
vec![(*class_def_id, class_type_vars.clone())].into_iter().collect(),
|
||||
)?;
|
||||
|
||||
if let TypeAnnotation::CustomClassKind { .. } = &base_ty {
|
||||
if let TypeAnnotation::CustomClass { .. } = &base_ty {
|
||||
class_ancestors.push(base_ty);
|
||||
} else {
|
||||
return Err("class base declaration can only be custom class".into());
|
||||
@ -1096,7 +1096,7 @@ impl TopLevelComposer {
|
||||
get_type_var_contained_in_type_annotation(&type_annotation)
|
||||
.into_iter()
|
||||
.map(|x| -> Result<(u32, Type), String> {
|
||||
if let TypeAnnotation::TypeVarKind(ty) = x {
|
||||
if let TypeAnnotation::TypeVar(ty) = x {
|
||||
Ok((Self::get_var_id(ty, unifier)?, ty))
|
||||
} else {
|
||||
unreachable!("must be type var annotation kind")
|
||||
@ -1146,7 +1146,7 @@ impl TopLevelComposer {
|
||||
get_type_var_contained_in_type_annotation(&return_ty_annotation)
|
||||
.into_iter()
|
||||
.map(|x| -> Result<(u32, Type), String> {
|
||||
if let TypeAnnotation::TypeVarKind(ty) = x {
|
||||
if let TypeAnnotation::TypeVar(ty) = x {
|
||||
Ok((Self::get_var_id(ty, unifier)?, ty))
|
||||
} else {
|
||||
unreachable!("must be type var here")
|
||||
@ -1303,7 +1303,7 @@ impl TopLevelComposer {
|
||||
get_type_var_contained_in_type_annotation(&type_ann);
|
||||
// handle the class type var and the method type var
|
||||
for type_var_within in type_vars_within {
|
||||
if let TypeAnnotation::TypeVarKind(ty) = type_var_within {
|
||||
if let TypeAnnotation::TypeVar(ty) = type_var_within {
|
||||
let id = Self::get_var_id(ty, unifier)?;
|
||||
if let Some(prev_ty) = method_var_map.insert(id, ty) {
|
||||
// if already in the list, make sure they are the same?
|
||||
@ -1346,7 +1346,7 @@ impl TopLevelComposer {
|
||||
get_type_var_contained_in_type_annotation(&annotation);
|
||||
// handle the class type var and the method type var
|
||||
for type_var_within in type_vars_within {
|
||||
if let TypeAnnotation::TypeVarKind(ty) = type_var_within {
|
||||
if let TypeAnnotation::TypeVar(ty) = type_var_within {
|
||||
let id = Self::get_var_id(ty, unifier)?;
|
||||
if let Some(prev_ty) = method_var_map.insert(id, ty) {
|
||||
// if already in the list, make sure they are the same?
|
||||
@ -1365,7 +1365,7 @@ impl TopLevelComposer {
|
||||
let dummy_return_type = unifier.get_fresh_var().0;
|
||||
type_var_to_concrete_def.insert(
|
||||
dummy_return_type,
|
||||
TypeAnnotation::PrimitiveKind(primitives.none),
|
||||
TypeAnnotation::Primitive(primitives.none),
|
||||
);
|
||||
dummy_return_type
|
||||
}
|
||||
@ -1423,7 +1423,7 @@ impl TopLevelComposer {
|
||||
get_type_var_contained_in_type_annotation(&annotation);
|
||||
// handle the class type var and the method type var
|
||||
for type_var_within in type_vars_within {
|
||||
if let TypeAnnotation::TypeVarKind(t) = type_var_within {
|
||||
if let TypeAnnotation::TypeVar(t) = type_var_within {
|
||||
if !class_type_vars_def.contains(&t) {
|
||||
return Err("class fields can only use type \
|
||||
vars declared as class generic type vars"
|
||||
@ -1481,7 +1481,7 @@ impl TopLevelComposer {
|
||||
// since when this function is called, the ancestors of the direct parent
|
||||
// are supposed to be already handled, so we only need to deal with the direct parent
|
||||
let base = class_ancestor_def.get(1).unwrap();
|
||||
if let TypeAnnotation::CustomClassKind { id, params: _ } = base {
|
||||
if let TypeAnnotation::CustomClass { id, params: _ } = base {
|
||||
let base = temp_def_list.get(id.0).unwrap();
|
||||
let base = base.read();
|
||||
if let TopLevelDef::Class { methods, fields, .. } = &*base {
|
||||
|
@ -160,14 +160,14 @@ impl TopLevelComposer {
|
||||
let mut parent = Self::get_parent(child, temp_def_list);
|
||||
while let Some(p) = parent {
|
||||
parent = Self::get_parent(&p, temp_def_list);
|
||||
let p_id = if let TypeAnnotation::CustomClassKind { id, .. } = &p {
|
||||
let p_id = if let TypeAnnotation::CustomClass { id, .. } = &p {
|
||||
*id
|
||||
} else {
|
||||
unreachable!("must be class kind annotation")
|
||||
};
|
||||
// check cycle
|
||||
let no_cycle = result.iter().all(|x| {
|
||||
if let TypeAnnotation::CustomClassKind { id, .. } = x {
|
||||
if let TypeAnnotation::CustomClass { id, .. } = x {
|
||||
id.0 != p_id.0
|
||||
} else {
|
||||
unreachable!("must be class kind annotation")
|
||||
@ -187,7 +187,7 @@ impl TopLevelComposer {
|
||||
child: &TypeAnnotation,
|
||||
temp_def_list: &[Arc<RwLock<TopLevelDef>>],
|
||||
) -> Option<TypeAnnotation> {
|
||||
let child_id = if let TypeAnnotation::CustomClassKind { id, .. } = child {
|
||||
let child_id = if let TypeAnnotation::CustomClass { id, .. } = child {
|
||||
*id
|
||||
} else {
|
||||
unreachable!("should be class type annotation")
|
||||
|
@ -6,26 +6,26 @@ use super::*;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum TypeAnnotation {
|
||||
PrimitiveKind(Type),
|
||||
Primitive(Type),
|
||||
// we use type vars kind at params to represent self type
|
||||
CustomClassKind {
|
||||
CustomClass {
|
||||
id: DefinitionId,
|
||||
// params can also be type var
|
||||
params: Vec<TypeAnnotation>,
|
||||
},
|
||||
// can only be CustomClassKind
|
||||
VirtualKind(Box<TypeAnnotation>),
|
||||
TypeVarKind(Type),
|
||||
ListKind(Box<TypeAnnotation>),
|
||||
TupleKind(Vec<TypeAnnotation>),
|
||||
Virtual(Box<TypeAnnotation>),
|
||||
TypeVar(Type),
|
||||
List(Box<TypeAnnotation>),
|
||||
Tuple(Vec<TypeAnnotation>),
|
||||
}
|
||||
|
||||
impl TypeAnnotation {
|
||||
pub fn stringify(&self, unifier: &mut Unifier) -> String {
|
||||
use TypeAnnotation::*;
|
||||
match self {
|
||||
PrimitiveKind(ty) | TypeVarKind(ty) => unifier.default_stringify(*ty),
|
||||
CustomClassKind { id, params } => {
|
||||
Primitive(ty) | TypeVar(ty) => unifier.default_stringify(*ty),
|
||||
CustomClass { id, params } => {
|
||||
let class_name = match unifier.top_level {
|
||||
Some(ref top) => if let TopLevelDef::Class { name, .. } = &*top.definitions.read()[id.0].read() {
|
||||
(*name).into()
|
||||
@ -36,8 +36,8 @@ impl TypeAnnotation {
|
||||
};
|
||||
format!("{{class: {}, params: {:?}}}", class_name, params.iter().map(|p| p.stringify(unifier)).collect_vec())
|
||||
}
|
||||
VirtualKind(ty) | ListKind(ty) => ty.stringify(unifier),
|
||||
TupleKind(types) => format!("({:?})", types.iter().map(|p| p.stringify(unifier)).collect_vec()),
|
||||
Virtual(ty) | List(ty) => ty.stringify(unifier),
|
||||
Tuple(types) => format!("({:?})", types.iter().map(|p| p.stringify(unifier)).collect_vec()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -54,17 +54,17 @@ pub fn parse_ast_to_type_annotation_kinds<T>(
|
||||
match &expr.node {
|
||||
ast::ExprKind::Name { id, .. } => {
|
||||
if id == &"int32".into() {
|
||||
Ok(TypeAnnotation::PrimitiveKind(primitives.int32))
|
||||
Ok(TypeAnnotation::Primitive(primitives.int32))
|
||||
} else if id == &"int64".into() {
|
||||
Ok(TypeAnnotation::PrimitiveKind(primitives.int64))
|
||||
Ok(TypeAnnotation::Primitive(primitives.int64))
|
||||
} else if id == &"float".into() {
|
||||
Ok(TypeAnnotation::PrimitiveKind(primitives.float))
|
||||
Ok(TypeAnnotation::Primitive(primitives.float))
|
||||
} else if id == &"bool".into() {
|
||||
Ok(TypeAnnotation::PrimitiveKind(primitives.bool))
|
||||
Ok(TypeAnnotation::Primitive(primitives.bool))
|
||||
} else if id == &"None".into() {
|
||||
Ok(TypeAnnotation::PrimitiveKind(primitives.none))
|
||||
Ok(TypeAnnotation::Primitive(primitives.none))
|
||||
} else if id == &"str".into() {
|
||||
Ok(TypeAnnotation::PrimitiveKind(primitives.str))
|
||||
Ok(TypeAnnotation::Primitive(primitives.str))
|
||||
} else if let Some(obj_id) = resolver.get_identifier_def(*id) {
|
||||
let type_vars = {
|
||||
let def_read = top_level_defs[obj_id.0].try_read();
|
||||
@ -85,10 +85,10 @@ pub fn parse_ast_to_type_annotation_kinds<T>(
|
||||
type_vars.len()
|
||||
));
|
||||
}
|
||||
Ok(TypeAnnotation::CustomClassKind { id: obj_id, params: vec![] })
|
||||
Ok(TypeAnnotation::CustomClass { id: obj_id, params: vec![] })
|
||||
} else if let Some(ty) = resolver.get_symbol_type(unifier, top_level_defs, primitives, *id) {
|
||||
if let TypeEnum::TVar { .. } = unifier.get_ty(ty).as_ref() {
|
||||
Ok(TypeAnnotation::TypeVarKind(ty))
|
||||
Ok(TypeAnnotation::TypeVar(ty))
|
||||
} else {
|
||||
Err("not a type variable identifier".into())
|
||||
}
|
||||
@ -111,10 +111,10 @@ pub fn parse_ast_to_type_annotation_kinds<T>(
|
||||
slice.as_ref(),
|
||||
locked,
|
||||
)?;
|
||||
if !matches!(def, TypeAnnotation::CustomClassKind { .. }) {
|
||||
if !matches!(def, TypeAnnotation::CustomClass { .. }) {
|
||||
unreachable!("must be concretized custom class kind in the virtual")
|
||||
}
|
||||
Ok(TypeAnnotation::VirtualKind(def.into()))
|
||||
Ok(TypeAnnotation::Virtual(def.into()))
|
||||
}
|
||||
|
||||
// list
|
||||
@ -131,7 +131,7 @@ pub fn parse_ast_to_type_annotation_kinds<T>(
|
||||
slice.as_ref(),
|
||||
locked,
|
||||
)?;
|
||||
Ok(TypeAnnotation::ListKind(def_ann.into()))
|
||||
Ok(TypeAnnotation::List(def_ann.into()))
|
||||
}
|
||||
|
||||
// tuple
|
||||
@ -154,7 +154,7 @@ pub fn parse_ast_to_type_annotation_kinds<T>(
|
||||
)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
Ok(TypeAnnotation::TupleKind(type_annotations))
|
||||
Ok(TypeAnnotation::Tuple(type_annotations))
|
||||
} else {
|
||||
Err("Expect multiple elements for tuple".into())
|
||||
}
|
||||
@ -227,7 +227,7 @@ pub fn parse_ast_to_type_annotation_kinds<T>(
|
||||
}
|
||||
};
|
||||
|
||||
Ok(TypeAnnotation::CustomClassKind { id: obj_id, params: param_type_infos })
|
||||
Ok(TypeAnnotation::CustomClass { id: obj_id, params: param_type_infos })
|
||||
} else {
|
||||
Err("unsupported expression type for class name".into())
|
||||
}
|
||||
@ -247,7 +247,7 @@ pub fn get_type_from_type_annotation_kinds(
|
||||
ann: &TypeAnnotation,
|
||||
) -> Result<Type, String> {
|
||||
match ann {
|
||||
TypeAnnotation::CustomClassKind { id: obj_id, params } => {
|
||||
TypeAnnotation::CustomClass { id: obj_id, params } => {
|
||||
let def_read = top_level_defs[obj_id.0].read();
|
||||
let class_def: &TopLevelDef = def_read.deref();
|
||||
if let TopLevelDef::Class { fields, methods, type_vars, .. } = class_def {
|
||||
@ -326,8 +326,8 @@ pub fn get_type_from_type_annotation_kinds(
|
||||
unreachable!("should be class def here")
|
||||
}
|
||||
}
|
||||
TypeAnnotation::PrimitiveKind(ty) | TypeAnnotation::TypeVarKind(ty) => Ok(*ty),
|
||||
TypeAnnotation::VirtualKind(ty) => {
|
||||
TypeAnnotation::Primitive(ty) | TypeAnnotation::TypeVar(ty) => Ok(*ty),
|
||||
TypeAnnotation::Virtual(ty) => {
|
||||
let ty = get_type_from_type_annotation_kinds(
|
||||
top_level_defs,
|
||||
unifier,
|
||||
@ -336,7 +336,7 @@ pub fn get_type_from_type_annotation_kinds(
|
||||
)?;
|
||||
Ok(unifier.add_ty(TypeEnum::TVirtual { ty }))
|
||||
}
|
||||
TypeAnnotation::ListKind(ty) => {
|
||||
TypeAnnotation::List(ty) => {
|
||||
let ty = get_type_from_type_annotation_kinds(
|
||||
top_level_defs,
|
||||
unifier,
|
||||
@ -345,7 +345,7 @@ pub fn get_type_from_type_annotation_kinds(
|
||||
)?;
|
||||
Ok(unifier.add_ty(TypeEnum::TList { ty }))
|
||||
}
|
||||
TypeAnnotation::TupleKind(tys) => {
|
||||
TypeAnnotation::Tuple(tys) => {
|
||||
let tys = tys
|
||||
.iter()
|
||||
.map(|x| {
|
||||
@ -376,9 +376,9 @@ pub fn get_type_from_type_annotation_kinds(
|
||||
/// create copies of `T` and `V`, we will find them out as occured type vars in the analyze_class()
|
||||
/// and unify them with the class generic `T`, `V`
|
||||
pub fn make_self_type_annotation(type_vars: &[Type], object_id: DefinitionId) -> TypeAnnotation {
|
||||
TypeAnnotation::CustomClassKind {
|
||||
TypeAnnotation::CustomClass {
|
||||
id: object_id,
|
||||
params: type_vars.iter().map(|ty| TypeAnnotation::TypeVarKind(*ty)).collect_vec(),
|
||||
params: type_vars.iter().map(|ty| TypeAnnotation::TypeVar(*ty)).collect_vec(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -388,24 +388,24 @@ pub fn make_self_type_annotation(type_vars: &[Type], object_id: DefinitionId) ->
|
||||
pub fn get_type_var_contained_in_type_annotation(ann: &TypeAnnotation) -> Vec<TypeAnnotation> {
|
||||
let mut result: Vec<TypeAnnotation> = Vec::new();
|
||||
match ann {
|
||||
TypeAnnotation::TypeVarKind(..) => result.push(ann.clone()),
|
||||
TypeAnnotation::VirtualKind(ann) => {
|
||||
TypeAnnotation::TypeVar(..) => result.push(ann.clone()),
|
||||
TypeAnnotation::Virtual(ann) => {
|
||||
result.extend(get_type_var_contained_in_type_annotation(ann.as_ref()))
|
||||
}
|
||||
TypeAnnotation::CustomClassKind { params, .. } => {
|
||||
TypeAnnotation::CustomClass { params, .. } => {
|
||||
for p in params {
|
||||
result.extend(get_type_var_contained_in_type_annotation(p));
|
||||
}
|
||||
}
|
||||
TypeAnnotation::ListKind(ann) => {
|
||||
TypeAnnotation::List(ann) => {
|
||||
result.extend(get_type_var_contained_in_type_annotation(ann.as_ref()))
|
||||
}
|
||||
TypeAnnotation::TupleKind(anns) => {
|
||||
TypeAnnotation::Tuple(anns) => {
|
||||
for a in anns {
|
||||
result.extend(get_type_var_contained_in_type_annotation(a));
|
||||
}
|
||||
}
|
||||
TypeAnnotation::PrimitiveKind(..) => {}
|
||||
TypeAnnotation::Primitive(..) => {}
|
||||
}
|
||||
result
|
||||
}
|
||||
@ -417,8 +417,8 @@ pub fn check_overload_type_annotation_compatible(
|
||||
unifier: &mut Unifier,
|
||||
) -> bool {
|
||||
match (this, other) {
|
||||
(TypeAnnotation::PrimitiveKind(a), TypeAnnotation::PrimitiveKind(b)) => a == b,
|
||||
(TypeAnnotation::TypeVarKind(a), TypeAnnotation::TypeVarKind(b)) => {
|
||||
(TypeAnnotation::Primitive(a), TypeAnnotation::Primitive(b)) => a == b,
|
||||
(TypeAnnotation::TypeVar(a), TypeAnnotation::TypeVar(b)) => {
|
||||
let a = unifier.get_ty(*a);
|
||||
let a = a.deref();
|
||||
let b = unifier.get_ty(*b);
|
||||
@ -433,12 +433,12 @@ pub fn check_overload_type_annotation_compatible(
|
||||
unreachable!("must be type var")
|
||||
}
|
||||
}
|
||||
(TypeAnnotation::VirtualKind(a), TypeAnnotation::VirtualKind(b))
|
||||
| (TypeAnnotation::ListKind(a), TypeAnnotation::ListKind(b)) => {
|
||||
(TypeAnnotation::Virtual(a), TypeAnnotation::Virtual(b))
|
||||
| (TypeAnnotation::List(a), TypeAnnotation::List(b)) => {
|
||||
check_overload_type_annotation_compatible(a.as_ref(), b.as_ref(), unifier)
|
||||
}
|
||||
|
||||
(TypeAnnotation::TupleKind(a), TypeAnnotation::TupleKind(b)) => {
|
||||
(TypeAnnotation::Tuple(a), TypeAnnotation::Tuple(b)) => {
|
||||
a.len() == b.len() && {
|
||||
a.iter()
|
||||
.zip(b)
|
||||
@ -447,8 +447,8 @@ pub fn check_overload_type_annotation_compatible(
|
||||
}
|
||||
|
||||
(
|
||||
TypeAnnotation::CustomClassKind { id: a, params: a_p },
|
||||
TypeAnnotation::CustomClassKind { id: b, params: b_p },
|
||||
TypeAnnotation::CustomClass { id: a, params: a_p },
|
||||
TypeAnnotation::CustomClass { id: b, params: b_p },
|
||||
) => {
|
||||
a.0 == b.0 && {
|
||||
a_p.len() == b_p.len() && {
|
||||
|
Loading…
Reference in New Issue
Block a user