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