mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 22:09:09 +00:00
WIP
This commit is contained in:
parent
646f04ef7b
commit
7d2cc3aac2
10 changed files with 91 additions and 40 deletions
|
@ -12,7 +12,7 @@ const DEFAULT_NUM_BUILTIN: Builtin<'_> = Builtin::Int64;
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum LayoutProblem {
|
||||
UnresolvedTypeVar,
|
||||
UnresolvedTypeVar(Variable),
|
||||
Erroneous,
|
||||
}
|
||||
|
||||
|
@ -284,21 +284,16 @@ impl<'a, 'b> Env<'a, 'b> {
|
|||
}
|
||||
|
||||
impl<'a> Layout<'a> {
|
||||
pub fn new(arena: &'a Bump, content: Content, subs: &Subs) -> Result<Self, LayoutProblem> {
|
||||
let mut env = Env {
|
||||
arena,
|
||||
subs,
|
||||
seen: MutSet::default(),
|
||||
};
|
||||
|
||||
Self::new_help(&mut env, content)
|
||||
}
|
||||
|
||||
fn new_help<'b>(env: &mut Env<'a, 'b>, content: Content) -> Result<Self, LayoutProblem> {
|
||||
fn new_help<'b>(
|
||||
env: &mut Env<'a, 'b>,
|
||||
var: Variable,
|
||||
content: Content,
|
||||
) -> Result<Self, LayoutProblem> {
|
||||
use roc_types::subs::Content::*;
|
||||
|
||||
match content {
|
||||
FlexVar(_) | RigidVar(_) => Err(LayoutProblem::UnresolvedTypeVar),
|
||||
FlexVar(_) | RigidVar(_) => Err(LayoutProblem::UnresolvedTypeVar(var)),
|
||||
RecursionVar(_) => todo!("recursion var"),
|
||||
Structure(flat_type) => layout_from_flat_type(env, flat_type),
|
||||
|
||||
Alias(Symbol::NUM_INT, args, _) => {
|
||||
|
@ -322,7 +317,7 @@ impl<'a> Layout<'a> {
|
|||
Ok(Layout::RecursivePointer)
|
||||
} else {
|
||||
let content = env.subs.get_without_compacting(var).content;
|
||||
Self::new_help(env, content)
|
||||
Self::new_help(env, var, content)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -752,7 +747,7 @@ fn layout_from_flat_type<'a>(
|
|||
layouts.push(layout);
|
||||
}
|
||||
}
|
||||
Err(UnresolvedTypeVar) | Err(Erroneous) => {
|
||||
Err(UnresolvedTypeVar(_)) | Err(Erroneous) => {
|
||||
// Invalid field!
|
||||
panic!("TODO gracefully handle record with invalid field.var");
|
||||
}
|
||||
|
@ -948,7 +943,7 @@ fn union_sorted_tags_help<'a>(
|
|||
layouts.push(layout);
|
||||
}
|
||||
}
|
||||
Err(LayoutProblem::UnresolvedTypeVar) => {
|
||||
Err(LayoutProblem::UnresolvedTypeVar(_)) => {
|
||||
// If we encounter an unbound type var (e.g. `Ok *`)
|
||||
// then it's zero-sized; drop the argument.
|
||||
}
|
||||
|
@ -989,7 +984,7 @@ fn union_sorted_tags_help<'a>(
|
|||
arg_layouts.push(layout);
|
||||
}
|
||||
}
|
||||
Err(LayoutProblem::UnresolvedTypeVar) => {
|
||||
Err(LayoutProblem::UnresolvedTypeVar(_)) => {
|
||||
// If we encounter an unbound type var (e.g. `Ok *`)
|
||||
// then it's zero-sized; drop the argument.
|
||||
}
|
||||
|
@ -1096,6 +1091,7 @@ fn layout_from_num_content<'a>(content: Content) -> Result<Layout<'a>, LayoutPro
|
|||
use roc_types::subs::FlatType::*;
|
||||
|
||||
match content {
|
||||
RecursionVar(_) => panic!("recursion var in num"),
|
||||
FlexVar(_) | RigidVar(_) => {
|
||||
// If a Num makes it all the way through type checking with an unbound
|
||||
// type variable, then assume it's a 64-bit integer.
|
||||
|
@ -1172,7 +1168,7 @@ pub fn list_layout_from_elem<'a>(
|
|||
Ok(Layout::Builtin(Builtin::EmptyList))
|
||||
}
|
||||
content => {
|
||||
let elem_layout = Layout::new_help(env, content)?;
|
||||
let elem_layout = Layout::new_help(env, elem_var, content)?;
|
||||
|
||||
// This is a normal list.
|
||||
Ok(Layout::Builtin(Builtin::List(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue