mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
remove optional fields destruct in mono pattern
This commit is contained in:
parent
eb501f90a2
commit
b9f92851a4
3 changed files with 32 additions and 50 deletions
|
@ -411,9 +411,6 @@ fn test_at_path<'a>(selected_path: &Path, branch: &Branch<'a>, all_tests: &mut V
|
|||
DestructType::Required => {
|
||||
arguments.push((Pattern::Underscore, destruct.layout.clone()));
|
||||
}
|
||||
DestructType::Optional(_expr) => {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -540,15 +537,10 @@ fn to_relevant_branch_help<'a>(
|
|||
..
|
||||
} => {
|
||||
debug_assert!(test_name == &TagName::Global(RECORD_TAG_NAME.into()));
|
||||
let sub_positions = destructs
|
||||
.into_iter()
|
||||
.filter(|destruct| !matches!(destruct.typ, DestructType::Optional(_)))
|
||||
.enumerate()
|
||||
.map(|(index, destruct)| {
|
||||
let sub_positions = destructs.into_iter().enumerate().map(|(index, destruct)| {
|
||||
let pattern = match destruct.typ {
|
||||
DestructType::Guard(guard) => guard.clone(),
|
||||
DestructType::Required => Pattern::Underscore,
|
||||
DestructType::Optional(_expr) => unreachable!("because of the filter"),
|
||||
};
|
||||
|
||||
(
|
||||
|
|
|
@ -67,7 +67,7 @@ fn simplify<'a>(pattern: &crate::ir::Pattern<'a>) -> Pattern {
|
|||
field_names.push(destruct.label.clone());
|
||||
|
||||
match &destruct.typ {
|
||||
DestructType::Required | DestructType::Optional(_) => patterns.push(Anything),
|
||||
DestructType::Required => patterns.push(Anything),
|
||||
DestructType::Guard(guard) => patterns.push(simplify(guard)),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4802,17 +4802,6 @@ fn store_record_destruct<'a>(
|
|||
env.arena.alloc(stmt),
|
||||
);
|
||||
}
|
||||
DestructType::Optional(expr) => {
|
||||
stmt = with_hole(
|
||||
env,
|
||||
expr.clone(),
|
||||
destruct.variable,
|
||||
procs,
|
||||
layout_cache,
|
||||
destruct.symbol,
|
||||
env.arena.alloc(stmt),
|
||||
);
|
||||
}
|
||||
DestructType::Guard(guard_pattern) => match &guard_pattern {
|
||||
Identifier(symbol) => {
|
||||
stmt = Stmt::Let(
|
||||
|
@ -5535,14 +5524,13 @@ pub struct RecordDestruct<'a> {
|
|||
pub label: Lowercase,
|
||||
pub variable: Variable,
|
||||
pub layout: Layout<'a>,
|
||||
pub symbol: Symbol,
|
||||
pub typ: DestructType<'a>,
|
||||
pub symbol: Symbol,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum DestructType<'a> {
|
||||
Required,
|
||||
Optional(roc_can::expr::Expr),
|
||||
Guard(Pattern<'a>),
|
||||
}
|
||||
|
||||
|
@ -5883,19 +5871,21 @@ fn from_can_pattern_help<'a>(
|
|||
// it must be an optional field, and we will use the default
|
||||
match &destruct.value.typ {
|
||||
roc_can::pattern::DestructType::Optional(field_var, loc_expr) => {
|
||||
let field_layout = layout_cache
|
||||
.from_var(env.arena, *field_var, env.subs)
|
||||
.unwrap_or_else(|err| {
|
||||
panic!("TODO turn fn_var into a RuntimeError {:?}", err)
|
||||
});
|
||||
|
||||
mono_destructs.push(RecordDestruct {
|
||||
label: destruct.value.label.clone(),
|
||||
symbol: destruct.value.symbol,
|
||||
variable: destruct.value.var,
|
||||
layout: field_layout,
|
||||
typ: DestructType::Optional(loc_expr.value.clone()),
|
||||
})
|
||||
// TODO these don't match up in the uniqueness inference; when we remove
|
||||
// that, reinstate this assert!
|
||||
//
|
||||
// dbg!(&env.subs.get_without_compacting(*field_var).content);
|
||||
// dbg!(&env.subs.get_without_compacting(destruct.value.var).content);
|
||||
// debug_assert_eq!(
|
||||
// env.subs.get_root_key_without_compacting(*field_var),
|
||||
// env.subs.get_root_key_without_compacting(destruct.value.var)
|
||||
// );
|
||||
assignments.push((
|
||||
destruct.value.symbol,
|
||||
// destruct.value.var,
|
||||
*field_var,
|
||||
loc_expr.value.clone(),
|
||||
));
|
||||
}
|
||||
_ => unreachable!("only optional destructs can be optional fields"),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue