mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
implement can crate
This commit is contained in:
parent
4545e76b76
commit
34e566965d
3 changed files with 19 additions and 10 deletions
|
@ -7,7 +7,7 @@ use roc_module::symbol::{IdentIds, ModuleId, Symbol};
|
||||||
use roc_parse::ast::{AssignedField, Pattern, Tag, TypeAnnotation, TypeHeader};
|
use roc_parse::ast::{AssignedField, Pattern, Tag, TypeAnnotation, TypeHeader};
|
||||||
use roc_region::all::{Loc, Region};
|
use roc_region::all::{Loc, Region};
|
||||||
use roc_types::subs::{VarStore, Variable};
|
use roc_types::subs::{VarStore, Variable};
|
||||||
use roc_types::types::{Alias, AliasKind, LambdaSet, Problem, RecordField, Type};
|
use roc_types::types::{Alias, AliasKind, LambdaSet, Problem, RecordField, Type, TypeExtension};
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct Annotation {
|
pub struct Annotation {
|
||||||
|
@ -542,7 +542,7 @@ fn can_annotation_help(
|
||||||
// just `a` does not mean the same as `{}a`, so even
|
// just `a` does not mean the same as `{}a`, so even
|
||||||
// if there are no fields, still make this a `Record`,
|
// if there are no fields, still make this a `Record`,
|
||||||
// not an EmptyRec
|
// not an EmptyRec
|
||||||
Type::Record(Default::default(), Box::new(ext_type))
|
Type::Record(Default::default(), TypeExtension::from_type(ext_type))
|
||||||
}
|
}
|
||||||
|
|
||||||
None => Type::EmptyRec,
|
None => Type::EmptyRec,
|
||||||
|
@ -559,7 +559,7 @@ fn can_annotation_help(
|
||||||
references,
|
references,
|
||||||
);
|
);
|
||||||
|
|
||||||
Type::Record(field_types, Box::new(ext_type))
|
Type::Record(field_types, TypeExtension::from_type(ext_type))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TagUnion { tags, ext, .. } => {
|
TagUnion { tags, ext, .. } => {
|
||||||
|
@ -580,7 +580,7 @@ fn can_annotation_help(
|
||||||
// just `a` does not mean the same as `{}a`, so even
|
// just `a` does not mean the same as `{}a`, so even
|
||||||
// if there are no fields, still make this a `Record`,
|
// if there are no fields, still make this a `Record`,
|
||||||
// not an EmptyRec
|
// not an EmptyRec
|
||||||
Type::TagUnion(Default::default(), Box::new(ext_type))
|
Type::TagUnion(Default::default(), TypeExtension::from_type(ext_type))
|
||||||
}
|
}
|
||||||
|
|
||||||
None => Type::EmptyTagUnion,
|
None => Type::EmptyTagUnion,
|
||||||
|
@ -602,7 +602,7 @@ fn can_annotation_help(
|
||||||
// in theory we save a lot of time by sorting once here
|
// in theory we save a lot of time by sorting once here
|
||||||
insertion_sort_by(&mut tag_types, |a, b| a.0.cmp(&b.0));
|
insertion_sort_by(&mut tag_types, |a, b| a.0.cmp(&b.0));
|
||||||
|
|
||||||
Type::TagUnion(tag_types, Box::new(ext_type))
|
Type::TagUnion(tag_types, TypeExtension::from_type(ext_type))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SpaceBefore(nested, _) | SpaceAfter(nested, _) => can_annotation_help(
|
SpaceBefore(nested, _) | SpaceAfter(nested, _) => can_annotation_help(
|
||||||
|
|
|
@ -10,7 +10,7 @@ use roc_module::ident::TagName;
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_region::all::{Loc, Region};
|
use roc_region::all::{Loc, Region};
|
||||||
use roc_types::subs::{VarStore, Variable};
|
use roc_types::subs::{VarStore, Variable};
|
||||||
use roc_types::types::{AliasKind, Type};
|
use roc_types::types::{AliasKind, Type, TypeExtension};
|
||||||
|
|
||||||
#[derive(Default, Clone, Copy)]
|
#[derive(Default, Clone, Copy)]
|
||||||
pub(crate) struct HostedGeneratedFunctions {
|
pub(crate) struct HostedGeneratedFunctions {
|
||||||
|
@ -1111,7 +1111,7 @@ fn build_effect_loop(
|
||||||
(step_tag_name, vec![Type::Variable(var_a)]),
|
(step_tag_name, vec![Type::Variable(var_a)]),
|
||||||
(done_tag_name, vec![Type::Variable(var_b)]),
|
(done_tag_name, vec![Type::Variable(var_b)]),
|
||||||
],
|
],
|
||||||
Box::new(Type::EmptyTagUnion),
|
TypeExtension::Closed,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1129,7 +1129,7 @@ fn build_effect_loop(
|
||||||
Box::new(state_type.clone()),
|
Box::new(state_type.clone()),
|
||||||
)],
|
)],
|
||||||
)],
|
)],
|
||||||
Box::new(Type::EmptyTagUnion),
|
TypeExtension::Closed,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1571,7 +1571,7 @@ fn build_effect_alias(
|
||||||
Box::new(a_type),
|
Box::new(a_type),
|
||||||
)],
|
)],
|
||||||
)],
|
)],
|
||||||
Box::new(Type::EmptyTagUnion),
|
TypeExtension::Closed,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1600,7 +1600,7 @@ pub fn build_effect_actual(
|
||||||
Box::new(a_type),
|
Box::new(a_type),
|
||||||
)],
|
)],
|
||||||
)],
|
)],
|
||||||
Box::new(Type::EmptyTagUnion),
|
TypeExtension::Closed,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -219,6 +219,15 @@ pub enum TypeExtension {
|
||||||
Closed,
|
Closed,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TypeExtension {
|
||||||
|
pub fn from_type(typ: Type) -> Self {
|
||||||
|
match typ {
|
||||||
|
Type::EmptyTagUnion | Type::EmptyRec => Self::Closed,
|
||||||
|
_ => Self::Open(Box::new(typ)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl IntoIterator for TypeExtension {
|
impl IntoIterator for TypeExtension {
|
||||||
type Item = Box<Type>;
|
type Item = Box<Type>;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue