mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 07:41:12 +00:00
groundwork for RoseTree
This commit is contained in:
parent
a4d7e809d2
commit
513d7cd78f
9 changed files with 304 additions and 29 deletions
|
@ -834,6 +834,8 @@ impl Wrapped {
|
|||
},
|
||||
_ => Some(Wrapped::MultiTagUnion),
|
||||
},
|
||||
NonNullableUnwrapped(_) => Some(Wrapped::RecordOrSingleTagUnion),
|
||||
|
||||
NullableWrapped { .. } | NullableUnwrapped { .. } => {
|
||||
Some(Wrapped::MultiTagUnion)
|
||||
}
|
||||
|
@ -1127,9 +1129,11 @@ impl<'a> Stmt<'a> {
|
|||
use Stmt::*;
|
||||
|
||||
match self {
|
||||
Let(symbol, expr, _, cont) => alloc
|
||||
Let(symbol, expr, _layout, cont) => alloc
|
||||
.text("let ")
|
||||
.append(symbol_to_doc(alloc, *symbol))
|
||||
//.append(" : ")
|
||||
//.append(alloc.text(format!("{:?}", layout)))
|
||||
.append(" = ")
|
||||
.append(expr.to_doc(alloc))
|
||||
.append(";")
|
||||
|
@ -2731,6 +2735,7 @@ pub fn with_hole<'a>(
|
|||
use WrappedVariant::*;
|
||||
let (tag, layout) = match variant {
|
||||
Recursive { sorted_tag_layouts } => {
|
||||
debug_assert!(sorted_tag_layouts.len() > 1);
|
||||
let tag_id_symbol = env.unique_symbol();
|
||||
opt_tag_id_symbol = Some(tag_id_symbol);
|
||||
|
||||
|
@ -2751,6 +2756,7 @@ pub fn with_hole<'a>(
|
|||
layouts.push(arg_layouts);
|
||||
}
|
||||
|
||||
debug_assert!(layouts.len() > 1);
|
||||
let layout =
|
||||
Layout::Union(UnionLayout::Recursive(layouts.into_bump_slice()));
|
||||
|
||||
|
@ -2764,6 +2770,35 @@ pub fn with_hole<'a>(
|
|||
|
||||
(tag, layout)
|
||||
}
|
||||
NonNullableUnwrapped {
|
||||
fields,
|
||||
tag_name: wrapped_tag_name,
|
||||
} => {
|
||||
debug_assert_eq!(tag_name, wrapped_tag_name);
|
||||
|
||||
opt_tag_id_symbol = None;
|
||||
|
||||
field_symbols = {
|
||||
let mut temp =
|
||||
Vec::with_capacity_in(field_symbols_temp.len(), arena);
|
||||
|
||||
temp.extend(field_symbols_temp.iter().map(|r| r.1));
|
||||
|
||||
temp.into_bump_slice()
|
||||
};
|
||||
|
||||
let layout = Layout::Union(UnionLayout::NonNullableUnwrapped(fields));
|
||||
|
||||
let tag = Expr::Tag {
|
||||
tag_layout: layout.clone(),
|
||||
tag_name,
|
||||
tag_id: tag_id as u8,
|
||||
union_size,
|
||||
arguments: field_symbols,
|
||||
};
|
||||
|
||||
(tag, layout)
|
||||
}
|
||||
NonRecursive { sorted_tag_layouts } => {
|
||||
let tag_id_symbol = env.unique_symbol();
|
||||
opt_tag_id_symbol = Some(tag_id_symbol);
|
||||
|
@ -6118,6 +6153,7 @@ fn from_can_pattern_help<'a>(
|
|||
temp
|
||||
};
|
||||
|
||||
debug_assert!(layouts.len() > 1);
|
||||
let layout =
|
||||
Layout::Union(UnionLayout::Recursive(layouts.into_bump_slice()));
|
||||
|
||||
|
@ -6130,6 +6166,51 @@ fn from_can_pattern_help<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
NonNullableUnwrapped {
|
||||
tag_name: w_tag_name,
|
||||
fields,
|
||||
} => {
|
||||
debug_assert_eq!(&w_tag_name, tag_name);
|
||||
|
||||
ctors.push(Ctor {
|
||||
tag_id: TagId(0_u8),
|
||||
name: tag_name.clone(),
|
||||
arity: fields.len(),
|
||||
});
|
||||
|
||||
let union = crate::exhaustive::Union {
|
||||
render_as: RenderAs::Tag,
|
||||
alternatives: ctors,
|
||||
};
|
||||
|
||||
let mut mono_args = Vec::with_capacity_in(arguments.len(), env.arena);
|
||||
|
||||
debug_assert_eq!(arguments.len(), argument_layouts.len());
|
||||
let it = argument_layouts.iter();
|
||||
|
||||
for ((_, loc_pat), layout) in arguments.iter().zip(it) {
|
||||
mono_args.push((
|
||||
from_can_pattern_help(
|
||||
env,
|
||||
layout_cache,
|
||||
&loc_pat.value,
|
||||
assignments,
|
||||
)?,
|
||||
layout.clone(),
|
||||
));
|
||||
}
|
||||
|
||||
let layout = Layout::Union(UnionLayout::NonNullableUnwrapped(fields));
|
||||
|
||||
Pattern::AppliedTag {
|
||||
tag_name: tag_name.clone(),
|
||||
tag_id: tag_id as u8,
|
||||
arguments: mono_args,
|
||||
union,
|
||||
layout,
|
||||
}
|
||||
}
|
||||
|
||||
NullableWrapped {
|
||||
sorted_tag_layouts: ref tags,
|
||||
nullable_id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue