mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
WIP try simplification
This commit is contained in:
parent
8b9e08bd76
commit
f1d568b848
3 changed files with 189 additions and 181 deletions
|
@ -168,7 +168,9 @@ pub fn desugar_defs_node_values<'a>(
|
||||||
// been desugared
|
// been desugared
|
||||||
if top_level_def {
|
if top_level_def {
|
||||||
for value_def in defs.value_defs.iter_mut() {
|
for value_def in defs.value_defs.iter_mut() {
|
||||||
*value_def = dbg!(desugar_value_def_suffixed(arena, *value_def));
|
// TODO REMOVE AFTER DEBUGGING
|
||||||
|
// *value_def = dbg!(desugar_value_def_suffixed(arena, *value_def));
|
||||||
|
*value_def = desugar_value_def_suffixed(arena, *value_def);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,8 +61,8 @@ pub enum EUnwrapped<'a> {
|
||||||
|
|
||||||
fn init_unwrapped_err<'a>(
|
fn init_unwrapped_err<'a>(
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
maybe_def_pat: Option<&'a Loc<Pattern<'a>>>,
|
|
||||||
unwrapped_expr: &'a Loc<Expr<'a>>,
|
unwrapped_expr: &'a Loc<Expr<'a>>,
|
||||||
|
maybe_def_pat: Option<&'a Loc<Pattern<'a>>>,
|
||||||
) -> Result<&'a Loc<Expr<'a>>, EUnwrapped<'a>> {
|
) -> Result<&'a Loc<Expr<'a>>, EUnwrapped<'a>> {
|
||||||
match maybe_def_pat {
|
match maybe_def_pat {
|
||||||
Some(..) => {
|
Some(..) => {
|
||||||
|
@ -91,16 +91,9 @@ fn init_unwrapped_err<'a>(
|
||||||
pub fn unwrap_suffixed_expression<'a>(
|
pub fn unwrap_suffixed_expression<'a>(
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
loc_expr: &'a Loc<Expr<'a>>,
|
loc_expr: &'a Loc<Expr<'a>>,
|
||||||
|
|
||||||
// passed in from the def, first may have a pattern like "x = foo!" to unwrap
|
|
||||||
//
|
|
||||||
// note be careful with calls to this function
|
|
||||||
// only those from the defs helper should pass a `Some`
|
|
||||||
// only those to helpers should forward the value
|
|
||||||
// all other calls to sub-expressions should pass `None`
|
|
||||||
maybe_def_pat: Option<&'a Loc<Pattern<'a>>>,
|
maybe_def_pat: Option<&'a Loc<Pattern<'a>>>,
|
||||||
) -> Result<&'a Loc<Expr<'a>>, EUnwrapped<'a>> {
|
) -> Result<&'a Loc<Expr<'a>>, EUnwrapped<'a>> {
|
||||||
dbg!("unwrap_suffixed_expression", &loc_expr);
|
// dbg!("unwrap_suffixed_expression", &loc_expr);
|
||||||
|
|
||||||
match loc_expr.value {
|
match loc_expr.value {
|
||||||
Expr::Var { suffixed, .. } if suffixed == 0 => Ok(loc_expr),
|
Expr::Var { suffixed, .. } if suffixed == 0 => Ok(loc_expr),
|
||||||
|
@ -119,25 +112,88 @@ pub fn unwrap_suffixed_expression<'a>(
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
|
|
||||||
init_unwrapped_err(arena, maybe_def_pat, unwrapped_var)
|
init_unwrapped_err(arena, unwrapped_var, maybe_def_pat)
|
||||||
}
|
}
|
||||||
|
|
||||||
Expr::Defs(..) => unwrap_suffixed_expression_defs_help(arena, loc_expr, maybe_def_pat),
|
Expr::Defs(..) => unwrap_suffixed_expression_defs_help(arena, loc_expr, maybe_def_pat),
|
||||||
|
|
||||||
Expr::Apply(..) => unwrap_suffixed_expression_apply_help(arena, loc_expr, maybe_def_pat),
|
Expr::Apply(..) => unwrap_suffixed_expression_apply_help(arena, loc_expr, maybe_def_pat),
|
||||||
|
|
||||||
Expr::SpaceBefore(..) | Expr::SpaceAfter(..) => {
|
|
||||||
internal_error!("unexpected SpaceBefore or SpaceAfter in unwrap_suffixed_expression, should have been removed in desugar_expr before this");
|
|
||||||
}
|
|
||||||
|
|
||||||
Expr::When(..) => unwrap_suffixed_expression_when_help(arena, loc_expr, maybe_def_pat),
|
Expr::When(..) => unwrap_suffixed_expression_when_help(arena, loc_expr, maybe_def_pat),
|
||||||
|
|
||||||
Expr::If(..) => {
|
Expr::If(..) => unwrap_suffixed_expression_if_then_else_help(arena, loc_expr, maybe_def_pat),
|
||||||
unwrap_suffixed_expression_if_then_else_help(arena, loc_expr, maybe_def_pat)
|
|
||||||
}
|
Expr::Closure(..) => unwrap_suffixed_expression_closure_help(arena, loc_expr, maybe_def_pat),
|
||||||
|
|
||||||
|
Expr::ParensAround(..) => unwrap_suffixed_expression_parens_help(arena, loc_expr, maybe_def_pat),
|
||||||
|
|
||||||
|
Expr::SpaceBefore(..) | Expr::SpaceAfter(..) => internal_error!("SpaceBefore and SpaceAfter should have been removed in desugar_expr"),
|
||||||
|
|
||||||
Expr::BinOps(..) => internal_error!("BinOps should have been desugared in desugar_expr"),
|
Expr::BinOps(..) => internal_error!("BinOps should have been desugared in desugar_expr"),
|
||||||
|
|
||||||
|
// we only need to unwrap some expressions, leave the rest alone
|
||||||
|
_ =>Ok(loc_expr),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn unwrap_suffixed_expression_parens_help<'a>(
|
||||||
|
arena: &'a Bump,
|
||||||
|
loc_expr: &'a Loc<Expr<'a>>,
|
||||||
|
maybe_def_pat: Option<&'a Loc<Pattern<'a>>>,
|
||||||
|
) -> Result<&'a Loc<Expr<'a>>, EUnwrapped<'a>> {
|
||||||
|
match loc_expr.value {
|
||||||
|
Expr::ParensAround(sub_loc_expr) => {
|
||||||
|
// dbg!(&loc_expr, &maybe_def_pat);
|
||||||
|
match unwrap_suffixed_expression(arena, arena.alloc(Loc::at_zero(*sub_loc_expr)), None)
|
||||||
|
{
|
||||||
|
Ok(new_expr) => {
|
||||||
|
let new_parens = arena.alloc(Loc::at(
|
||||||
|
loc_expr.region,
|
||||||
|
ParensAround(arena.alloc(new_expr.value)),
|
||||||
|
));
|
||||||
|
return Ok(new_parens);
|
||||||
|
}
|
||||||
|
Err(EUnwrapped::UnwrappedDefExpr(unwrapped_parens)) => {
|
||||||
|
// dbg!(&unwrapped_parens, maybe_def_pat);
|
||||||
|
if let Some(..) = maybe_def_pat {
|
||||||
|
let new_parens = arena.alloc(Loc::at(
|
||||||
|
loc_expr.region,
|
||||||
|
ParensAround(&unwrapped_parens.value),
|
||||||
|
));
|
||||||
|
return Err(EUnwrapped::UnwrappedDefExpr(new_parens));
|
||||||
|
} else {
|
||||||
|
return Err(EUnwrapped::Malformed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(EUnwrapped::UnwrappedSubExpr {
|
||||||
|
sub_arg,
|
||||||
|
sub_pat,
|
||||||
|
sub_new,
|
||||||
|
}) => {
|
||||||
|
let new_parens = arena.alloc(Loc::at(
|
||||||
|
loc_expr.region,
|
||||||
|
ParensAround(arena.alloc(sub_new.value)),
|
||||||
|
));
|
||||||
|
// dbg!(loc_expr, sub_arg, sub_pat, sub_new, &new_parens);
|
||||||
|
return Err(EUnwrapped::UnwrappedSubExpr {
|
||||||
|
sub_arg,
|
||||||
|
sub_pat,
|
||||||
|
sub_new: new_parens,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => internal_error!("unreachable, expected a ParensAround node to be passed into unwrap_suffixed_expression_parens_help"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn unwrap_suffixed_expression_closure_help<'a>(
|
||||||
|
arena: &'a Bump,
|
||||||
|
loc_expr: &'a Loc<Expr<'a>>,
|
||||||
|
maybe_def_pat: Option<&'a Loc<Pattern<'a>>>,
|
||||||
|
) -> Result<&'a Loc<Expr<'a>>, EUnwrapped<'a>> {
|
||||||
|
match loc_expr.value {
|
||||||
Expr::Closure(args, return_expr) => {
|
Expr::Closure(args, return_expr) => {
|
||||||
let count_suffixed_args = args
|
let count_suffixed_args = args
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -145,17 +201,23 @@ pub fn unwrap_suffixed_expression<'a>(
|
||||||
.count();
|
.count();
|
||||||
|
|
||||||
if count_suffixed_args > 0 {
|
if count_suffixed_args > 0 {
|
||||||
// TODO make this a nice error report
|
debug_assert!(false,"closure arguments should not be suffixed");
|
||||||
internal_error!("closure arguments should not be suffixed");
|
return Err(EUnwrapped::Malformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the return expression
|
// check the return expression
|
||||||
match unwrap_suffixed_expression(arena, return_expr, None) {
|
match unwrap_suffixed_expression(arena, return_expr, None) {
|
||||||
Ok(new_expr) => {
|
Ok(new_expr) => {
|
||||||
Ok(arena.alloc(Loc::at(loc_expr.region, Expr::Closure(args, new_expr))))
|
let new_closure = arena.alloc(Loc::at(loc_expr.region, Expr::Closure(args, new_expr)));
|
||||||
|
Ok(new_closure)
|
||||||
}
|
}
|
||||||
Err(EUnwrapped::UnwrappedDefExpr(..)) => {
|
Err(EUnwrapped::UnwrappedDefExpr(unwrapped_return)) => {
|
||||||
internal_error!("is this even possible? we aren't a Def");
|
if let Some(..) = maybe_def_pat {
|
||||||
|
let new_closure = arena.alloc(Loc::at(loc_expr.region, Expr::Closure(args, unwrapped_return)));
|
||||||
|
return Err(EUnwrapped::UnwrappedDefExpr(new_closure));
|
||||||
|
} else {
|
||||||
|
return Err(EUnwrapped::Malformed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(EUnwrapped::UnwrappedSubExpr {
|
Err(EUnwrapped::UnwrappedSubExpr {
|
||||||
sub_arg,
|
sub_arg,
|
||||||
|
@ -173,84 +235,16 @@ pub fn unwrap_suffixed_expression<'a>(
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_ => internal_error!("unreachable, expected a Closure node to be passed into unwrap_suffixed_expression_closure_help"),
|
||||||
Expr::ParensAround(sub_loc_expr) => {
|
|
||||||
match unwrap_suffixed_expression(arena, arena.alloc(Loc::at_zero(*sub_loc_expr)), None)
|
|
||||||
{
|
|
||||||
Ok(new_expr) => {
|
|
||||||
let new_parens = arena.alloc(Loc::at(
|
|
||||||
loc_expr.region,
|
|
||||||
ParensAround(arena.alloc(new_expr.value)),
|
|
||||||
));
|
|
||||||
return Ok(new_parens);
|
|
||||||
}
|
|
||||||
Err(EUnwrapped::UnwrappedDefExpr(..)) => {
|
|
||||||
internal_error!("is this even possible? we aren't a Def");
|
|
||||||
}
|
|
||||||
// // Err(EUnwrapped::UnwrappedExpr(arena.alloc(Loc::at(
|
|
||||||
// // loc_expr.region,
|
|
||||||
// // ParensAround(arena.alloc(new_expr.value)),
|
|
||||||
// // ))))
|
|
||||||
|
|
||||||
// let new_parens_expr = arena.alloc(Loc::at(
|
|
||||||
// new_expr.region,
|
|
||||||
// Expr::ParensAround(&new_expr.value),
|
|
||||||
// ));
|
|
||||||
|
|
||||||
// if called_from_def {
|
|
||||||
// return Err(EUnwrapped::UnwrappedExpr(new_parens_expr));
|
|
||||||
// } else {
|
|
||||||
// dbg!("UnwrappedSubExpr from ParensAround");
|
|
||||||
|
|
||||||
// let (answer_var, answer_pat) = next_suffixed_answer_pattern(arena);
|
|
||||||
|
|
||||||
// let sub_pat = Loc::at(new_expr.region, answer_pat);
|
|
||||||
|
|
||||||
// return Err(EUnwrapped::PassBackToDef {
|
|
||||||
// sub_arg: new_parens_expr,
|
|
||||||
// sub_pat,
|
|
||||||
// sub_new: arena.alloc(Loc::at(new_expr.region, answer_var)),
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
Err(EUnwrapped::UnwrappedSubExpr {
|
|
||||||
sub_arg,
|
|
||||||
sub_pat,
|
|
||||||
sub_new,
|
|
||||||
}) => {
|
|
||||||
let new_parens = arena.alloc(Loc::at(
|
|
||||||
loc_expr.region,
|
|
||||||
ParensAround(arena.alloc(sub_new.value)),
|
|
||||||
));
|
|
||||||
return Err(EUnwrapped::UnwrappedSubExpr {
|
|
||||||
sub_arg,
|
|
||||||
sub_pat,
|
|
||||||
sub_new: new_parens,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => {
|
|
||||||
// we only need to unwrap some expressions, leave the rest alone
|
|
||||||
Ok(loc_expr)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unwrap_suffixed_expression_apply_help<'a>(
|
pub fn unwrap_suffixed_expression_apply_help<'a>(
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
loc_expr: &'a Loc<Expr<'a>>,
|
loc_expr: &'a Loc<Expr<'a>>,
|
||||||
|
|
||||||
// passed in from the def, first may have a pattern like "x = foo!" to unwrap
|
|
||||||
//
|
|
||||||
// note be careful with calls to this function
|
|
||||||
// only those from the defs helper should pass a `Some`
|
|
||||||
// only those to helpers should forward the value
|
|
||||||
// all other calls to sub-expressions should pass `None`
|
|
||||||
maybe_def_pat: Option<&'a Loc<Pattern<'a>>>,
|
maybe_def_pat: Option<&'a Loc<Pattern<'a>>>,
|
||||||
) -> Result<&'a Loc<Expr<'a>>, EUnwrapped<'a>> {
|
) -> Result<&'a Loc<Expr<'a>>, EUnwrapped<'a>> {
|
||||||
|
// dbg!(&loc_expr, maybe_def_pat);
|
||||||
match loc_expr.value {
|
match loc_expr.value {
|
||||||
Expr::Apply(function, apply_args, called_via) => {
|
Expr::Apply(function, apply_args, called_via) => {
|
||||||
|
|
||||||
|
@ -261,41 +255,26 @@ pub fn unwrap_suffixed_expression_apply_help<'a>(
|
||||||
Ok(new_arg) => {
|
Ok(new_arg) => {
|
||||||
*arg = new_arg;
|
*arg = new_arg;
|
||||||
}
|
}
|
||||||
Err(EUnwrapped::UnwrappedDefExpr(..)) => {
|
Err(EUnwrapped::UnwrappedDefExpr(unwrapped_arg)) => {
|
||||||
internal_error!("is this even possible? we aren't a Def");
|
// dbg!(&unwrapped_arg, maybe_def_pat);
|
||||||
|
if let Some(..) = maybe_def_pat {
|
||||||
|
*arg = unwrapped_arg;
|
||||||
|
|
||||||
// let (answer_var, answer_pat) = next_suffixed_answer_pattern(arena);
|
let new_apply = arena.alloc(Loc::at(loc_expr.region, Apply(function, local_args, called_via)));
|
||||||
|
|
||||||
// let sub_pat = Loc::at(loc_expr.region, answer_pat);
|
return Err(EUnwrapped::UnwrappedDefExpr(new_apply));
|
||||||
|
} else {
|
||||||
// *arg = arena.alloc(Loc::at(loc_expr.region, answer_var));
|
return Err(EUnwrapped::Malformed);
|
||||||
|
}
|
||||||
// let new_apply = arena.alloc(Loc::at(loc_expr.region, Apply(function, local_args, called_via)));
|
|
||||||
|
|
||||||
// return Err(EUnwrapped::PassBackToDef { sub_arg: new_expr, sub_pat, sub_new: new_apply });
|
|
||||||
}
|
}
|
||||||
Err(EUnwrapped::UnwrappedSubExpr { sub_arg, sub_pat, sub_new: new_arg }) => {
|
Err(EUnwrapped::UnwrappedSubExpr { sub_arg, sub_pat, sub_new: new_arg }) => {
|
||||||
|
|
||||||
*arg = new_arg;
|
*arg = new_arg;
|
||||||
|
|
||||||
let new_apply = arena.alloc(Loc::at(loc_expr.region, Apply(function, local_args, called_via)));
|
let new_apply = arena.alloc(Loc::at(loc_expr.region, Apply(function, local_args, called_via)));
|
||||||
|
// dbg!(&loc_expr, &sub_arg, &sub_pat, &new_arg);
|
||||||
|
// return dbg!(Err(EUnwrapped::UnwrappedSubExpr { sub_arg, sub_pat, sub_new: new_apply}));
|
||||||
return Err(EUnwrapped::UnwrappedSubExpr { sub_arg, sub_pat, sub_new: new_apply});
|
return Err(EUnwrapped::UnwrappedSubExpr { sub_arg, sub_pat, sub_new: new_apply});
|
||||||
|
|
||||||
// if called_from_def {
|
|
||||||
|
|
||||||
// *arg = sub_new;
|
|
||||||
|
|
||||||
// let new_apply = arena.alloc(Loc::at(loc_expr.region, Apply(function, local_args, called_via)));
|
|
||||||
|
|
||||||
// return Err(EUnwrapped::UnwrappedSubExpr { sub_arg, sub_pat, sub_new: new_apply })
|
|
||||||
// } else {
|
|
||||||
// *arg = sub_new;
|
|
||||||
|
|
||||||
// let new_apply = arena.alloc(Loc::at(loc_expr.region, Apply(function, local_args, called_via)));
|
|
||||||
|
|
||||||
// return unwrap_suffixed_expression(arena, apply_task_await(arena, loc_expr.region, sub_arg, sub_pat, new_apply), called_from_def);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
Err(err) => return Err(err),
|
Err(err) => return Err(err),
|
||||||
}
|
}
|
||||||
|
@ -307,43 +286,19 @@ pub fn unwrap_suffixed_expression_apply_help<'a>(
|
||||||
let new_apply = arena.alloc(Loc::at(loc_expr.region, Expr::Apply(new_function, local_args, called_via)));
|
let new_apply = arena.alloc(Loc::at(loc_expr.region, Expr::Apply(new_function, local_args, called_via)));
|
||||||
return Ok(new_apply);
|
return Ok(new_apply);
|
||||||
}
|
}
|
||||||
Err(EUnwrapped::UnwrappedDefExpr(..)) => {
|
Err(EUnwrapped::UnwrappedDefExpr(unwrapped_function)) => {
|
||||||
internal_error!("is this even possible? we aren't a Def");
|
if let Some(..) = maybe_def_pat {
|
||||||
// if called_from_def {
|
let new_apply = arena.alloc(Loc::at(loc_expr.region, Expr::Apply(unwrapped_function, local_args, called_via)));
|
||||||
// let new_apply = arena.alloc(Loc::at(loc_expr.region, Expr::Apply(new_function, local_args, called_via)));
|
return Err(EUnwrapped::UnwrappedDefExpr(new_apply));
|
||||||
// return Err(EUnwrapped::UnwrappedExpr(new_apply));
|
} else {
|
||||||
// } else {
|
return Err(EUnwrapped::Malformed);
|
||||||
// let (answer_var, answer_pat) = next_suffixed_answer_pattern(arena);
|
}
|
||||||
|
|
||||||
// let sub_pat = Loc::at(loc_expr.region, answer_pat);
|
|
||||||
|
|
||||||
// let function_answer = arena.alloc(Loc::at(loc_expr.region, answer_var));
|
|
||||||
|
|
||||||
// let new_apply= arena.alloc(Loc::at(loc_expr.region, Expr::Apply(function_answer, local_args, called_via)));
|
|
||||||
|
|
||||||
// return unwrap_suffixed_expression(
|
|
||||||
// arena,
|
|
||||||
// apply_task_await(arena, loc_expr.region, new_function, sub_pat, new_apply),
|
|
||||||
// false
|
|
||||||
// );
|
|
||||||
|
|
||||||
// // return Err(EUnwrapped::UnwrappedSubExpr {
|
|
||||||
// // sub_arg: arena.alloc(Loc::at(loc_expr.region, Expr::Apply(new_function, local_args, called_via))),
|
|
||||||
// // sub_pat,
|
|
||||||
// // sub_new: arena.alloc(Loc::at(new_function.region, answer_var))
|
|
||||||
// // });
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
Err(EUnwrapped::UnwrappedSubExpr { sub_arg, sub_pat, sub_new: new_function }) => {
|
Err(EUnwrapped::UnwrappedSubExpr { sub_arg: unwrapped_function, sub_pat, sub_new }) => {
|
||||||
|
|
||||||
let new_apply = arena.alloc(Loc::at(loc_expr.region, Expr::Apply(new_function, local_args, called_via)));
|
let new_apply = arena.alloc(Loc::at(loc_expr.region, Expr::Apply(unwrapped_function, local_args, called_via)));
|
||||||
|
|
||||||
return Err(EUnwrapped::UnwrappedSubExpr { sub_arg, sub_pat, sub_new: new_apply});
|
return Err(EUnwrapped::UnwrappedSubExpr { sub_arg: new_apply, sub_pat, sub_new});
|
||||||
|
|
||||||
// let new_apply = arena.alloc(Loc::at(loc_expr.region, Expr::Apply(sub_new, local_args, called_via)));
|
|
||||||
|
|
||||||
// return unwrap_suffixed_expression(arena,
|
|
||||||
// apply_task_await(arena, loc_expr.region, sub_arg, sub_pat, new_apply), false);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Err(err) => Err(err)
|
Err(err) => Err(err)
|
||||||
|
@ -512,24 +467,14 @@ pub fn unwrap_suffixed_expression_defs_help<'a>(
|
||||||
|
|
||||||
match maybe_suffixed_value_def {
|
match maybe_suffixed_value_def {
|
||||||
None => {
|
None => {
|
||||||
// not a def that we can unwrap, move on to the next
|
// We can't unwrap this def type, continue
|
||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
Some((def_pattern, def_expr)) => {
|
Some((def_pattern, def_expr)) => {
|
||||||
match unwrap_suffixed_expression(arena, def_expr, Some(*def_pattern)) {
|
match unwrap_suffixed_expression(arena, def_expr, Some(*def_pattern)) {
|
||||||
Ok(new_def_expr) => {
|
Ok(..) => {
|
||||||
|
// Nothing further to unwrap with this def, continue
|
||||||
let new_value_def = match type_or_value_def.err() {
|
continue;
|
||||||
None | Some(Annotation(..)) | Some(Dbg{..}) | Some(Expect{..}) | Some(ExpectFx{..}) | Some(Stmt(..))=> internal_error!("unexpected ValueDef type"),
|
|
||||||
Some(AnnotatedBody{ann_pattern,ann_type,comment,..}) => ValueDef::AnnotatedBody{ann_pattern,ann_type,comment: *comment,body_pattern: def_pattern, body_expr:new_def_expr},
|
|
||||||
Some(Body ( .. )) => ValueDef::Body(def_pattern, new_def_expr),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut local_defs = defs.clone();
|
|
||||||
local_defs.replace_with_value_def(tag_index, new_value_def, loc_expr.region);
|
|
||||||
|
|
||||||
let new_defs = arena.alloc(Loc::at(def_expr.region, Defs(arena.alloc(local_defs), loc_ret)));
|
|
||||||
return unwrap_suffixed_expression(arena, new_defs, maybe_def_pat);
|
|
||||||
}
|
}
|
||||||
Err(EUnwrapped::UnwrappedDefExpr(unwrapped_expr)) => {
|
Err(EUnwrapped::UnwrappedDefExpr(unwrapped_expr)) => {
|
||||||
let local_defs = defs.clone();
|
let local_defs = defs.clone();
|
||||||
|
@ -538,22 +483,57 @@ pub fn unwrap_suffixed_expression_defs_help<'a>(
|
||||||
let after_empty = split_defs.after.is_empty();
|
let after_empty = split_defs.after.is_empty();
|
||||||
if before_empty && after_empty {
|
if before_empty && after_empty {
|
||||||
// NIL before, NIL after -> SINGLE
|
// NIL before, NIL after -> SINGLE
|
||||||
let replaced_def = apply_task_await(arena,def_expr.region,unwrapped_expr,*def_pattern,loc_ret);
|
let next_expr = match unwrap_suffixed_expression(arena,loc_ret,None) {
|
||||||
return unwrap_suffixed_expression(arena,replaced_def,maybe_def_pat);
|
Ok(next_expr) => next_expr,
|
||||||
|
Err(EUnwrapped::UnwrappedSubExpr { sub_arg, sub_pat, sub_new }) => {
|
||||||
|
apply_task_await(arena,def_expr.region,sub_arg,sub_pat,sub_new)
|
||||||
|
}
|
||||||
|
Err(EUnwrapped::UnwrappedDefExpr(..)) | Err(EUnwrapped::Malformed) => {
|
||||||
|
// TODO handle case when we have maybe_def_pat so can return an unwrapped up
|
||||||
|
return Err(EUnwrapped::Malformed);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return unwrap_suffixed_expression(arena, apply_task_await(arena,def_expr.region,unwrapped_expr,*def_pattern,next_expr), None);
|
||||||
} else if before_empty {
|
} else if before_empty {
|
||||||
// NIL before, SOME after -> FIRST
|
// NIL before, SOME after -> FIRST
|
||||||
let new_defs = arena.alloc(Loc::at(def_expr.region, Defs(arena.alloc(split_defs.after), loc_ret)));
|
let new_defs = arena.alloc(Loc::at(def_expr.region, Defs(arena.alloc(split_defs.after), loc_ret)));
|
||||||
let replaced_def = apply_task_await(arena, loc_expr.region, unwrapped_expr, *def_pattern, new_defs);
|
|
||||||
return unwrap_suffixed_expression(arena,replaced_def,maybe_def_pat);
|
let next_expr = match unwrap_suffixed_expression(arena,new_defs,None){
|
||||||
|
Ok(next_expr) => next_expr,
|
||||||
|
Err(EUnwrapped::UnwrappedSubExpr { sub_arg, sub_pat, sub_new }) => {
|
||||||
|
apply_task_await(arena, def_expr.region, sub_arg, sub_pat, sub_new)
|
||||||
|
}
|
||||||
|
Err(EUnwrapped::UnwrappedDefExpr(..)) | Err(EUnwrapped::Malformed) => {
|
||||||
|
// TODO handle case when we have maybe_def_pat so can return an unwrapped up
|
||||||
|
return Err(EUnwrapped::Malformed);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return unwrap_suffixed_expression(arena, apply_task_await(arena,def_expr.region,unwrapped_expr,*def_pattern,next_expr), None);
|
||||||
} else {
|
} else {
|
||||||
// SOME before, NIL after -> LAST
|
// SOME before, NIL after -> LAST
|
||||||
debug_assert!(after_empty);
|
debug_assert!(after_empty);
|
||||||
let new_loc_ret = apply_task_await(arena,loc_expr.region,unwrapped_expr,*def_pattern,loc_ret);
|
let new_defs = arena.alloc(Loc::at(loc_expr.region,Defs(arena.alloc(split_defs.before), loc_ret)));
|
||||||
let new_defs = arena.alloc(Loc::at(loc_expr.region,Defs(arena.alloc(split_defs.before), new_loc_ret)));
|
let next_expr = match unwrap_suffixed_expression(arena,new_defs,None){
|
||||||
return unwrap_suffixed_expression(arena,new_defs,maybe_def_pat);
|
Ok(next_expr) => next_expr,
|
||||||
|
Err(EUnwrapped::UnwrappedSubExpr { sub_arg, sub_pat, sub_new }) => {
|
||||||
|
apply_task_await(arena,def_expr.region,sub_arg,sub_pat,sub_new)
|
||||||
|
}
|
||||||
|
Err(EUnwrapped::UnwrappedDefExpr(..)) | Err(EUnwrapped::Malformed) => {
|
||||||
|
// TODO handle case when we have maybe_def_pat so can return an unwrapped up
|
||||||
|
return Err(EUnwrapped::Malformed);
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
return unwrap_suffixed_expression(arena, apply_task_await(arena,def_expr.region,unwrapped_expr,*def_pattern,next_expr), None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(EUnwrapped::UnwrappedSubExpr { sub_arg, sub_pat, sub_new }) => {
|
Err(EUnwrapped::UnwrappedSubExpr { sub_arg, sub_pat, sub_new }) => {
|
||||||
|
|
||||||
|
// dbg!(&sub_arg, &sub_pat, &sub_new);
|
||||||
|
|
||||||
let mut local_defs = defs.clone();
|
let mut local_defs = defs.clone();
|
||||||
let new_body_def = ValueDef::Body(def_pattern, sub_new);
|
let new_body_def = ValueDef::Body(def_pattern, sub_new);
|
||||||
local_defs.replace_with_value_def(tag_index,new_body_def,def_expr.region);
|
local_defs.replace_with_value_def(tag_index,new_body_def,def_expr.region);
|
||||||
|
@ -570,6 +550,9 @@ pub fn unwrap_suffixed_expression_defs_help<'a>(
|
||||||
// try to unwrap the loc_ret
|
// try to unwrap the loc_ret
|
||||||
match unwrap_suffixed_expression(arena, loc_ret, None) {
|
match unwrap_suffixed_expression(arena, loc_ret, None) {
|
||||||
Ok(new_loc_ret) => {
|
Ok(new_loc_ret) => {
|
||||||
|
|
||||||
|
// dbg!(&new_loc_ret);
|
||||||
|
|
||||||
Ok(arena.alloc(Loc::at(loc_expr.region, Defs(arena.alloc(defs), new_loc_ret))))
|
Ok(arena.alloc(Loc::at(loc_expr.region, Defs(arena.alloc(defs), new_loc_ret))))
|
||||||
}
|
}
|
||||||
Err(EUnwrapped::UnwrappedDefExpr(new_loc_ret)) => {
|
Err(EUnwrapped::UnwrappedDefExpr(new_loc_ret)) => {
|
||||||
|
|
|
@ -45,6 +45,8 @@ mod suffixed_tests {
|
||||||
|
|
||||||
let expected = r#"Defs { tags: [Index(2147483648)], regions: [@0-36], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@0-4 Identifier { ident: "main", suffixed: 0 }, @0-36 Apply(@0-36 Var { module_name: "Task", ident: "await", suffixed: 0 }, [@24-36 Apply(@24-29 Var { module_name: "", ident: "line", suffixed: 0 }, [@30-36 Str(PlainLine("Ahoy"))], Space), @0-36 Closure([@24-36 RecordDestructure([])], @58-81 Apply(@58-81 Var { module_name: "Task", ident: "await", suffixed: 0 }, [@58-81 Apply(@69-81 Var { module_name: "Stdout", ident: "line", suffixed: 0 }, [@58-65 Str(PlainLine("There"))], BinOp(Pizza)), @58-81 Closure([@53-55 RecordDestructure([])], @115-125 Apply(@115-122 Var { module_name: "Task", ident: "ok", suffixed: 0 }, [@123-125 Record([])], Space))], BangSuffix))], BangSuffix))] }"#;
|
let expected = r#"Defs { tags: [Index(2147483648)], regions: [@0-36], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@0-4 Identifier { ident: "main", suffixed: 0 }, @0-36 Apply(@0-36 Var { module_name: "Task", ident: "await", suffixed: 0 }, [@24-36 Apply(@24-29 Var { module_name: "", ident: "line", suffixed: 0 }, [@30-36 Str(PlainLine("Ahoy"))], Space), @0-36 Closure([@24-36 RecordDestructure([])], @58-81 Apply(@58-81 Var { module_name: "Task", ident: "await", suffixed: 0 }, [@58-81 Apply(@69-81 Var { module_name: "Stdout", ident: "line", suffixed: 0 }, [@58-65 Str(PlainLine("There"))], BinOp(Pizza)), @58-81 Closure([@53-55 RecordDestructure([])], @115-125 Apply(@115-122 Var { module_name: "Task", ident: "ok", suffixed: 0 }, [@123-125 Record([])], Space))], BangSuffix))], BangSuffix))] }"#;
|
||||||
|
|
||||||
|
// dbg!(&defs);
|
||||||
|
|
||||||
assert_multiline_str_eq!(format!("{:?}", &defs).as_str(), expected);
|
assert_multiline_str_eq!(format!("{:?}", &defs).as_str(), expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +81,7 @@ mod suffixed_tests {
|
||||||
|
|
||||||
let expected = r#"Defs { tags: [Index(2147483648)], regions: [@0-28], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@0-4 Identifier { ident: "main", suffixed: 0 }, @24-28 Apply(@24-28 Var { module_name: "Task", ident: "await", suffixed: 0 }, [@24-28 Var { module_name: "", ident: "foo", suffixed: 0 }, @24-28 Closure([@24-28 RecordDestructure([])], @54-59 Apply(@54-56 Var { module_name: "", ident: "ok", suffixed: 0 }, [@57-59 Record([])], Space))], BangSuffix))] }"#;
|
let expected = r#"Defs { tags: [Index(2147483648)], regions: [@0-28], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@0-4 Identifier { ident: "main", suffixed: 0 }, @24-28 Apply(@24-28 Var { module_name: "Task", ident: "await", suffixed: 0 }, [@24-28 Var { module_name: "", ident: "foo", suffixed: 0 }, @24-28 Closure([@24-28 RecordDestructure([])], @54-59 Apply(@54-56 Var { module_name: "", ident: "ok", suffixed: 0 }, [@57-59 Record([])], Space))], BangSuffix))] }"#;
|
||||||
|
|
||||||
dbg!(&defs);
|
// dbg!(&defs);
|
||||||
|
|
||||||
assert_multiline_str_eq!(format!("{:?}", &defs).as_str(), expected);
|
assert_multiline_str_eq!(format!("{:?}", &defs).as_str(), expected);
|
||||||
}
|
}
|
||||||
|
@ -96,7 +98,7 @@ mod suffixed_tests {
|
||||||
Task.ok {}
|
Task.ok {}
|
||||||
|
|
||||||
main =
|
main =
|
||||||
Task.await ("hello" |> Str.concat "world" |> line) \{} ->
|
Task.await (line (Str.concat "hello" "world")) \{} ->
|
||||||
Task.ok {}
|
Task.ok {}
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
|
@ -119,7 +121,7 @@ mod suffixed_tests {
|
||||||
|
|
||||||
let expected = r#"Defs { tags: [Index(2147483648)], regions: [@0-94], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@0-4 Identifier { ident: "main", suffixed: 0 }, @24-94 Apply(@24-94 Var { module_name: "Task", ident: "await", suffixed: 0 }, [@24-94 Apply(@89-94 Var { module_name: "", ident: "line", suffixed: 0 }, [@24-69 Apply(@51-61 Var { module_name: "Str", ident: "concat", suffixed: 0 }, [@24-31 Str(PlainLine("hello")), @62-69 Str(PlainLine("world"))], BinOp(Pizza))], BinOp(Pizza)), @24-94 Closure([@24-94 RecordDestructure([])], @120-130 Apply(@120-127 Var { module_name: "Task", ident: "ok", suffixed: 0 }, [@128-130 Record([])], Space))], BangSuffix))] }"#;
|
let expected = r#"Defs { tags: [Index(2147483648)], regions: [@0-94], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@0-4 Identifier { ident: "main", suffixed: 0 }, @24-94 Apply(@24-94 Var { module_name: "Task", ident: "await", suffixed: 0 }, [@24-94 Apply(@89-94 Var { module_name: "", ident: "line", suffixed: 0 }, [@24-69 Apply(@51-61 Var { module_name: "Str", ident: "concat", suffixed: 0 }, [@24-31 Str(PlainLine("hello")), @62-69 Str(PlainLine("world"))], BinOp(Pizza))], BinOp(Pizza)), @24-94 Closure([@24-94 RecordDestructure([])], @120-130 Apply(@120-127 Var { module_name: "Task", ident: "ok", suffixed: 0 }, [@128-130 Record([])], Space))], BangSuffix))] }"#;
|
||||||
|
|
||||||
dbg!(&defs);
|
// dbg!(&defs);
|
||||||
|
|
||||||
assert_multiline_str_eq!(format!("{:?}", &defs).as_str(), expected);
|
assert_multiline_str_eq!(format!("{:?}", &defs).as_str(), expected);
|
||||||
}
|
}
|
||||||
|
@ -154,6 +156,8 @@ mod suffixed_tests {
|
||||||
|
|
||||||
let expected = r##"Defs { tags: [Index(2147483648)], regions: [@0-66], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@0-4 Identifier { ident: "main", suffixed: 0 }, @23-66 Defs(Defs { tags: [Index(2147483649)], regions: [@23-66], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@23-25 Identifier { ident: "do", suffixed: 0 }, @28-47 Apply(@29-41 ParensAround(Var { module_name: "", ident: "sayMultiple", suffixed: 1 }), [@43-47 Str(PlainLine("hi"))], Space)), Body(@23-25 Identifier { ident: "do", suffixed: 0 }, @28-47 Apply(@28-47 Var { module_name: "Task", ident: "await", suffixed: 0 }, [ParensAround(Var { module_name: "", ident: "sayMultiple", suffixed: 0 }), @28-47 Closure([Identifier { ident: "#!a0", suffixed: 0 }], @28-47 Apply(Var { module_name: "", ident: "#!a0", suffixed: 0 }, [@43-47 Str(PlainLine("hi"))], Space))], BangSuffix))] }, @64-66 Var { module_name: "", ident: "do", suffixed: 0 }))] }"##;
|
let expected = r##"Defs { tags: [Index(2147483648)], regions: [@0-66], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@0-4 Identifier { ident: "main", suffixed: 0 }, @23-66 Defs(Defs { tags: [Index(2147483649)], regions: [@23-66], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@23-25 Identifier { ident: "do", suffixed: 0 }, @28-47 Apply(@29-41 ParensAround(Var { module_name: "", ident: "sayMultiple", suffixed: 1 }), [@43-47 Str(PlainLine("hi"))], Space)), Body(@23-25 Identifier { ident: "do", suffixed: 0 }, @28-47 Apply(@28-47 Var { module_name: "Task", ident: "await", suffixed: 0 }, [ParensAround(Var { module_name: "", ident: "sayMultiple", suffixed: 0 }), @28-47 Closure([Identifier { ident: "#!a0", suffixed: 0 }], @28-47 Apply(Var { module_name: "", ident: "#!a0", suffixed: 0 }, [@43-47 Str(PlainLine("hi"))], Space))], BangSuffix))] }, @64-66 Var { module_name: "", ident: "do", suffixed: 0 }))] }"##;
|
||||||
|
|
||||||
|
// dbg!(&defs);
|
||||||
|
|
||||||
assert_multiline_str_eq!(format!("{:?}", &defs).as_str(), expected);
|
assert_multiline_str_eq!(format!("{:?}", &defs).as_str(), expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,6 +185,17 @@ mod suffixed_tests {
|
||||||
Task.await foo \a ->
|
Task.await foo \a ->
|
||||||
Task.await bar \#!a0 ->
|
Task.await bar \#!a0 ->
|
||||||
Task.await #!a0 \b -> baz a b
|
Task.await #!a0 \b -> baz a b
|
||||||
|
|
||||||
|
```roc
|
||||||
|
main =
|
||||||
|
x = bar (foo! "hello")
|
||||||
|
baz x
|
||||||
|
|
||||||
|
main =
|
||||||
|
Task.await foo "hello" \#!a0 ->
|
||||||
|
x = bar (#!a0)
|
||||||
|
baz x
|
||||||
|
```
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -198,7 +213,9 @@ mod suffixed_tests {
|
||||||
|
|
||||||
desugar_defs_node_values(arena, &mut defs, src, &mut None, "test.roc", true);
|
desugar_defs_node_values(arena, &mut defs, src, &mut None, "test.roc", true);
|
||||||
|
|
||||||
let expected = r##"Defs { tags: [Index(2147483648)], regions: [@0-81], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@0-4 Identifier { ident: "main", suffixed: 0 }, @23-81 Apply(@23-81 Var { module_name: "Task", ident: "await", suffixed: 0 }, [@27-31 Var { module_name: "", ident: "foo", suffixed: 0 }, @23-81 Closure([@23-24 Identifier { ident: "a", suffixed: 0 }], @52-57 Apply(@52-57 Var { module_name: "Task", ident: "await", suffixed: 0 }, [@52-57 Var { module_name: "", ident: "bar", suffixed: 0 }, @52-57 Closure([@52-57 Identifier { ident: "#!a0", suffixed: 0 }], @52-57 Apply(@52-57 Var { module_name: "Task", ident: "await", suffixed: 0 }, [@52-57 Var { module_name: "", ident: "#!a0", suffixed: 0 }, @52-57 Closure([@48-49 Identifier { ident: "b", suffixed: 0 }], @74-81 Apply(@74-77 Var { module_name: "", ident: "baz", suffixed: 0 }, [@78-79 Var { module_name: "", ident: "a", suffixed: 0 }, @80-81 Var { module_name: "", ident: "b", suffixed: 0 }], Space))], BangSuffix))], BangSuffix))], BangSuffix))] }"##;
|
let expected = r##"Defs { tags: [Index(2147483648)], regions: [@0-81], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@0-4 Identifier { ident: "main", suffixed: 0 }, @27-31 Apply(@27-31 Var { module_name: "Task", ident: "await", suffixed: 0 }, [@27-31 Var { module_name: "", ident: "foo", suffixed: 0 }, @27-31 Closure([@23-24 Identifier { ident: "a", suffixed: 0 }], @27-31 Apply(@27-31 Var { module_name: "Task", ident: "await", suffixed: 0 }, [@52-57 Var { module_name: "", ident: "bar", suffixed: 0 }, @27-31 Closure([@52-57 Identifier { ident: "#!a0", suffixed: 0 }], @52-57 Apply(@52-57 Var { module_name: "Task", ident: "await", suffixed: 0 }, [@52-57 Var { module_name: "", ident: "#!a0", suffixed: 0 }, @52-57 Closure([@48-49 Identifier { ident: "b", suffixed: 0 }], @74-81 Apply(@74-77 Var { module_name: "", ident: "baz", suffixed: 0 }, [@78-79 Var { module_name: "", ident: "a", suffixed: 0 }, @80-81 Var { module_name: "", ident: "b", suffixed: 0 }], Space))], BangSuffix))], BangSuffix))], BangSuffix))] }"##;
|
||||||
|
|
||||||
|
// dbg!(&defs);
|
||||||
|
|
||||||
assert_multiline_str_eq!(format!("{:?}", &defs).as_str(), expected);
|
assert_multiline_str_eq!(format!("{:?}", &defs).as_str(), expected);
|
||||||
}
|
}
|
||||||
|
@ -240,6 +257,8 @@ mod suffixed_tests {
|
||||||
// so we have the value_def in the vec in Defs, but there is no tag pointing to it
|
// so we have the value_def in the vec in Defs, but there is no tag pointing to it
|
||||||
let expected = r##"Defs { tags: [Index(2147483648)], regions: [@0-29], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@0-4 Identifier { ident: "main", suffixed: 0 }, @24-29 Apply(@24-29 Var { module_name: "Task", ident: "await", suffixed: 0 }, [@24-29 Var { module_name: "", ident: "foo", suffixed: 0 }, @24-29 Closure([@24-29 Identifier { ident: "#!a0", suffixed: 0 }], @24-29 Apply(@24-29 Var { module_name: "Task", ident: "await", suffixed: 0 }, [@24-29 Var { module_name: "", ident: "#!a0", suffixed: 0 }, @24-29 Closure([@24-29 RecordDestructure([])], @46-49 Var { module_name: "", ident: "bar", suffixed: 0 })], BangSuffix))], BangSuffix))] }"##;
|
let expected = r##"Defs { tags: [Index(2147483648)], regions: [@0-29], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@0-4 Identifier { ident: "main", suffixed: 0 }, @24-29 Apply(@24-29 Var { module_name: "Task", ident: "await", suffixed: 0 }, [@24-29 Var { module_name: "", ident: "foo", suffixed: 0 }, @24-29 Closure([@24-29 Identifier { ident: "#!a0", suffixed: 0 }], @24-29 Apply(@24-29 Var { module_name: "Task", ident: "await", suffixed: 0 }, [@24-29 Var { module_name: "", ident: "#!a0", suffixed: 0 }, @24-29 Closure([@24-29 RecordDestructure([])], @46-49 Var { module_name: "", ident: "bar", suffixed: 0 })], BangSuffix))], BangSuffix))] }"##;
|
||||||
|
|
||||||
|
// dbg!(&defs);
|
||||||
|
|
||||||
assert_multiline_str_eq!(format!("{:?}", &defs).as_str(), expected);
|
assert_multiline_str_eq!(format!("{:?}", &defs).as_str(), expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +295,7 @@ mod suffixed_tests {
|
||||||
// so we have the value_def in the vec in Defs, but there is no tag pointing to it
|
// so we have the value_def in the vec in Defs, but there is no tag pointing to it
|
||||||
let expected = r##"Defs { tags: [Index(2147483648)], regions: [@0-70], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@0-4 Identifier { ident: "main", suffixed: 0 }, @28-48 Apply(@28-48 Var { module_name: "Task", ident: "await", suffixed: 0 }, [Apply(@29-33 Var { module_name: "", ident: "foo", suffixed: 0 }, [@34-39 Str(PlainLine("bar"))], Space), @28-48 Closure([@29-33 Identifier { ident: "#!a0", suffixed: 0 }], @28-48 Defs(Defs { tags: [Index(2147483650)], regions: [@28-48], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@24-25 Identifier { ident: "x", suffixed: 0 }, @28-48 Apply(@29-39 ParensAround(Apply(@29-33 Var { module_name: "", ident: "foo", suffixed: 1 }, [@34-39 Str(PlainLine("bar"))], Space)), [@41-48 Str(PlainLine("hello"))], Space)), Body(@24-25 Identifier { ident: "x", suffixed: 0 }, @28-48 Apply(@29-39 ParensAround(Var { module_name: "", ident: "#!a0", suffixed: 0 }), [@41-48 Str(PlainLine("hello"))], Space)), Body(@24-25 Identifier { ident: "x", suffixed: 0 }, @28-48 Apply(@29-39 ParensAround(Var { module_name: "", ident: "#!a0", suffixed: 0 }), [@41-48 Str(PlainLine("hello"))], Space))] }, @65-70 Apply(@65-68 Var { module_name: "", ident: "baz", suffixed: 0 }, [@69-70 Var { module_name: "", ident: "x", suffixed: 0 }], Space)))], BangSuffix))] }"##;
|
let expected = r##"Defs { tags: [Index(2147483648)], regions: [@0-70], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@0-4 Identifier { ident: "main", suffixed: 0 }, @28-48 Apply(@28-48 Var { module_name: "Task", ident: "await", suffixed: 0 }, [Apply(@29-33 Var { module_name: "", ident: "foo", suffixed: 0 }, [@34-39 Str(PlainLine("bar"))], Space), @28-48 Closure([@29-33 Identifier { ident: "#!a0", suffixed: 0 }], @28-48 Defs(Defs { tags: [Index(2147483650)], regions: [@28-48], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@24-25 Identifier { ident: "x", suffixed: 0 }, @28-48 Apply(@29-39 ParensAround(Apply(@29-33 Var { module_name: "", ident: "foo", suffixed: 1 }, [@34-39 Str(PlainLine("bar"))], Space)), [@41-48 Str(PlainLine("hello"))], Space)), Body(@24-25 Identifier { ident: "x", suffixed: 0 }, @28-48 Apply(@29-39 ParensAround(Var { module_name: "", ident: "#!a0", suffixed: 0 }), [@41-48 Str(PlainLine("hello"))], Space)), Body(@24-25 Identifier { ident: "x", suffixed: 0 }, @28-48 Apply(@29-39 ParensAround(Var { module_name: "", ident: "#!a0", suffixed: 0 }), [@41-48 Str(PlainLine("hello"))], Space))] }, @65-70 Apply(@65-68 Var { module_name: "", ident: "baz", suffixed: 0 }, [@69-70 Var { module_name: "", ident: "x", suffixed: 0 }], Space)))], BangSuffix))] }"##;
|
||||||
|
|
||||||
dbg!(&defs);
|
// dbg!(&defs);
|
||||||
|
|
||||||
assert_multiline_str_eq!(format!("{:?}", &defs).as_str(), expected);
|
assert_multiline_str_eq!(format!("{:?}", &defs).as_str(), expected);
|
||||||
}
|
}
|
||||||
|
@ -311,9 +330,9 @@ mod suffixed_tests {
|
||||||
// TODO fix this... the value_defs is incorrect here in a harmless way because
|
// TODO fix this... the value_defs is incorrect here in a harmless way because
|
||||||
// roc_parse::ast::Defs::split_defs_around is not completely correct
|
// roc_parse::ast::Defs::split_defs_around is not completely correct
|
||||||
// so we have the value_def in the vec in Defs, but there is no tag pointing to it
|
// so we have the value_def in the vec in Defs, but there is no tag pointing to it
|
||||||
let expected = r##"Defs { tags: [Index(2147483648)], regions: [@0-68], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@0-4 Identifier { ident: "main", suffixed: 0 }, @28-46 Apply(@28-46 Var { module_name: "Task", ident: "await", suffixed: 0 }, [Apply(@33-37 Var { module_name: "", ident: "foo", suffixed: 0 }, [@38-45 Str(PlainLine("hello"))], Space), @28-46 Closure([@33-37 Identifier { ident: "#!a0", suffixed: 0 }], @28-46 Defs(Defs { tags: [Index(2147483650)], regions: [@28-46], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@24-25 Identifier { ident: "x", suffixed: 0 }, @28-46 Apply(@28-31 Var { module_name: "", ident: "bar", suffixed: 0 }, [@33-45 ParensAround(Apply(@33-37 Var { module_name: "", ident: "foo", suffixed: 1 }, [@38-45 Str(PlainLine("hello"))], Space))], Space)), Body(@24-25 Identifier { ident: "x", suffixed: 0 }, @28-46 Apply(@28-31 Var { module_name: "", ident: "bar", suffixed: 0 }, [@33-45 ParensAround(Var { module_name: "", ident: "#!a0", suffixed: 0 })], Space)), Body(@24-25 Identifier { ident: "x", suffixed: 0 }, @28-46 Apply(@28-31 Var { module_name: "", ident: "bar", suffixed: 0 }, [@33-45 ParensAround(Var { module_name: "", ident: "#!a0", suffixed: 0 })], Space))] }, @63-68 Apply(@63-66 Var { module_name: "", ident: "baz", suffixed: 0 }, [@67-68 Var { module_name: "", ident: "x", suffixed: 0 }], Space)))], BangSuffix))] }"##;
|
let expected = r##"Defs { tags: [Index(2147483648)], regions: [@0-68], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@0-4 Identifier { ident: "main", suffixed: 0 }, @28-46 Apply(@28-46 Var { module_name: "Task", ident: "await", suffixed: 0 }, [Apply(@33-37 Var { module_name: "", ident: "foo", suffixed: 0 }, [@38-45 Str(PlainLine("hello"))], Space), @28-46 Closure([@33-37 Identifier { ident: "#!a0", suffixed: 0 }], @28-46 Defs(Defs { tags: [Index(2147483649)], regions: [@28-46], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@24-25 Identifier { ident: "x", suffixed: 0 }, @28-46 Apply(@28-31 Var { module_name: "", ident: "bar", suffixed: 0 }, [@33-45 ParensAround(Apply(@33-37 Var { module_name: "", ident: "foo", suffixed: 1 }, [@38-45 Str(PlainLine("hello"))], Space))], Space)), Body(@24-25 Identifier { ident: "x", suffixed: 0 }, @28-46 Apply(@28-31 Var { module_name: "", ident: "bar", suffixed: 0 }, [@33-45 ParensAround(Var { module_name: "", ident: "#!a0", suffixed: 0 })], Space))] }, @63-68 Apply(@63-66 Var { module_name: "", ident: "baz", suffixed: 0 }, [@67-68 Var { module_name: "", ident: "x", suffixed: 0 }], Space)))], BangSuffix))] }"##;
|
||||||
|
|
||||||
dbg!(&defs);
|
// dbg!(&defs);
|
||||||
|
|
||||||
assert_multiline_str_eq!(format!("{:?}", &defs).as_str(), expected);
|
assert_multiline_str_eq!(format!("{:?}", &defs).as_str(), expected);
|
||||||
}
|
}
|
||||||
|
@ -352,6 +371,8 @@ mod suffixed_tests {
|
||||||
// so we have the value_def in the vec in Defs, but there is no tag pointing to it
|
// so we have the value_def in the vec in Defs, but there is no tag pointing to it
|
||||||
let expected = r#"Defs { tags: [Index(2147483648)], regions: [@0-88], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@0-4 Identifier { ident: "main", suffixed: 0 }, @24-88 Defs(Defs { tags: [Index(2147483650)], regions: [@24-88, @54-66], space_before: [Slice(start = 0, length = 0), Slice(start = 0, length = 1)], space_after: [Slice(start = 0, length = 0), Slice(start = 1, length = 0)], spaces: [Newline], type_defs: [], value_defs: [Body(@24-27 Identifier { ident: "msg", suffixed: 0 }, @30-37 Str(PlainLine("hello"))), Body(@54-55 Identifier { ident: "x", suffixed: 0 }, @58-66 Apply(@58-62 Var { module_name: "", ident: "foo", suffixed: 1 }, [@63-66 Var { module_name: "", ident: "msg", suffixed: 0 }], Space)), Body(@24-27 Identifier { ident: "msg", suffixed: 0 }, @30-37 Str(PlainLine("hello")))] }, @24-88 Apply(@24-88 Var { module_name: "Task", ident: "await", suffixed: 0 }, [@58-66 Apply(@58-62 Var { module_name: "", ident: "foo", suffixed: 0 }, [@63-66 Var { module_name: "", ident: "msg", suffixed: 0 }], Space), @24-88 Closure([@54-55 Identifier { ident: "x", suffixed: 0 }], @83-88 Apply(@83-86 Var { module_name: "", ident: "bar", suffixed: 0 }, [@87-88 Var { module_name: "", ident: "x", suffixed: 0 }], Space))], BangSuffix)))] }"#;
|
let expected = r#"Defs { tags: [Index(2147483648)], regions: [@0-88], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@0-4 Identifier { ident: "main", suffixed: 0 }, @24-88 Defs(Defs { tags: [Index(2147483650)], regions: [@24-88, @54-66], space_before: [Slice(start = 0, length = 0), Slice(start = 0, length = 1)], space_after: [Slice(start = 0, length = 0), Slice(start = 1, length = 0)], spaces: [Newline], type_defs: [], value_defs: [Body(@24-27 Identifier { ident: "msg", suffixed: 0 }, @30-37 Str(PlainLine("hello"))), Body(@54-55 Identifier { ident: "x", suffixed: 0 }, @58-66 Apply(@58-62 Var { module_name: "", ident: "foo", suffixed: 1 }, [@63-66 Var { module_name: "", ident: "msg", suffixed: 0 }], Space)), Body(@24-27 Identifier { ident: "msg", suffixed: 0 }, @30-37 Str(PlainLine("hello")))] }, @24-88 Apply(@24-88 Var { module_name: "Task", ident: "await", suffixed: 0 }, [@58-66 Apply(@58-62 Var { module_name: "", ident: "foo", suffixed: 0 }, [@63-66 Var { module_name: "", ident: "msg", suffixed: 0 }], Space), @24-88 Closure([@54-55 Identifier { ident: "x", suffixed: 0 }], @83-88 Apply(@83-86 Var { module_name: "", ident: "bar", suffixed: 0 }, [@87-88 Var { module_name: "", ident: "x", suffixed: 0 }], Space))], BangSuffix)))] }"#;
|
||||||
|
|
||||||
|
// dbg!(&defs);
|
||||||
|
|
||||||
assert_multiline_str_eq!(format!("{:?}", &defs).as_str(), expected);
|
assert_multiline_str_eq!(format!("{:?}", &defs).as_str(), expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,6 +422,8 @@ mod suffixed_tests {
|
||||||
// so we have the value_def in the vec in Defs, but there is no tag pointing to it
|
// so we have the value_def in the vec in Defs, but there is no tag pointing to it
|
||||||
let expected = r#"Defs { tags: [Index(2147483648)], regions: [@0-187], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@0-4 Identifier { ident: "main", suffixed: 0 }, @24-187 Defs(Defs { tags: [Index(2147483650)], regions: [@24-187], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Annotation(@24-25 Identifier { ident: "x", suffixed: 0 }, @28-43 Function([@28-31 Apply("", "Str", [])], @35-43 Apply("", "Task", [@40-41 Inferred, @42-43 Inferred]))), AnnotatedBody { ann_pattern: @24-25 Identifier { ident: "x", suffixed: 0 }, ann_type: @28-43 Function([@28-31 Apply("", "Str", [])], @35-43 Apply("", "Task", [@40-41 Inferred, @42-43 Inferred])), comment: None, body_pattern: @60-61 Identifier { ident: "x", suffixed: 0 }, body_expr: @64-162 Closure([@65-68 Identifier { ident: "msg", suffixed: 0 }], @93-162 Defs(Defs { tags: [Index(2147483649)], regions: [@93-140], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Annotation(@93-94 Identifier { ident: "y", suffixed: 0 }, @97-106 Apply("", "Task", [@102-104 Record { fields: [], ext: None }, @105-106 Inferred])), AnnotatedBody { ann_pattern: @93-94 Identifier { ident: "y", suffixed: 0 }, ann_type: @97-106 Apply("", "Task", [@102-104 Record { fields: [], ext: None }, @105-106 Inferred]), comment: None, body_pattern: @127-128 Identifier { ident: "y", suffixed: 0 }, body_expr: @131-140 Apply(@131-136 Var { module_name: "", ident: "line", suffixed: 1 }, [@137-140 Var { module_name: "", ident: "msg", suffixed: 0 }], Space) }] }, @161-162 Var { module_name: "", ident: "y", suffixed: 0 })) }, AnnotatedBody { ann_pattern: @24-25 Identifier { ident: "x", suffixed: 0 }, ann_type: @28-43 Function([@28-31 Apply("", "Str", [])], @35-43 Apply("", "Task", [@40-41 Inferred, @42-43 Inferred])), comment: None, body_pattern: @60-61 Identifier { ident: "x", suffixed: 0 }, body_expr: @64-162 Closure([@65-68 Identifier { ident: "msg", suffixed: 0 }], @131-140 Apply(@131-140 Var { module_name: "Task", ident: "await", suffixed: 0 }, [@131-140 Apply(@131-136 Var { module_name: "", ident: "line", suffixed: 0 }, [@137-140 Var { module_name: "", ident: "msg", suffixed: 0 }], Space), @131-140 Closure([@127-128 Identifier { ident: "y", suffixed: 0 }], @161-162 Var { module_name: "", ident: "y", suffixed: 0 })], BangSuffix)) }] }, @180-187 Apply(@180-181 Var { module_name: "", ident: "x", suffixed: 0 }, [@182-187 Str(PlainLine("foo"))], Space)))] }"#;
|
let expected = r#"Defs { tags: [Index(2147483648)], regions: [@0-187], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Body(@0-4 Identifier { ident: "main", suffixed: 0 }, @24-187 Defs(Defs { tags: [Index(2147483650)], regions: [@24-187], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Annotation(@24-25 Identifier { ident: "x", suffixed: 0 }, @28-43 Function([@28-31 Apply("", "Str", [])], @35-43 Apply("", "Task", [@40-41 Inferred, @42-43 Inferred]))), AnnotatedBody { ann_pattern: @24-25 Identifier { ident: "x", suffixed: 0 }, ann_type: @28-43 Function([@28-31 Apply("", "Str", [])], @35-43 Apply("", "Task", [@40-41 Inferred, @42-43 Inferred])), comment: None, body_pattern: @60-61 Identifier { ident: "x", suffixed: 0 }, body_expr: @64-162 Closure([@65-68 Identifier { ident: "msg", suffixed: 0 }], @93-162 Defs(Defs { tags: [Index(2147483649)], regions: [@93-140], space_before: [Slice(start = 0, length = 0)], space_after: [Slice(start = 0, length = 0)], spaces: [], type_defs: [], value_defs: [Annotation(@93-94 Identifier { ident: "y", suffixed: 0 }, @97-106 Apply("", "Task", [@102-104 Record { fields: [], ext: None }, @105-106 Inferred])), AnnotatedBody { ann_pattern: @93-94 Identifier { ident: "y", suffixed: 0 }, ann_type: @97-106 Apply("", "Task", [@102-104 Record { fields: [], ext: None }, @105-106 Inferred]), comment: None, body_pattern: @127-128 Identifier { ident: "y", suffixed: 0 }, body_expr: @131-140 Apply(@131-136 Var { module_name: "", ident: "line", suffixed: 1 }, [@137-140 Var { module_name: "", ident: "msg", suffixed: 0 }], Space) }] }, @161-162 Var { module_name: "", ident: "y", suffixed: 0 })) }, AnnotatedBody { ann_pattern: @24-25 Identifier { ident: "x", suffixed: 0 }, ann_type: @28-43 Function([@28-31 Apply("", "Str", [])], @35-43 Apply("", "Task", [@40-41 Inferred, @42-43 Inferred])), comment: None, body_pattern: @60-61 Identifier { ident: "x", suffixed: 0 }, body_expr: @64-162 Closure([@65-68 Identifier { ident: "msg", suffixed: 0 }], @131-140 Apply(@131-140 Var { module_name: "Task", ident: "await", suffixed: 0 }, [@131-140 Apply(@131-136 Var { module_name: "", ident: "line", suffixed: 0 }, [@137-140 Var { module_name: "", ident: "msg", suffixed: 0 }], Space), @131-140 Closure([@127-128 Identifier { ident: "y", suffixed: 0 }], @161-162 Var { module_name: "", ident: "y", suffixed: 0 })], BangSuffix)) }] }, @180-187 Apply(@180-181 Var { module_name: "", ident: "x", suffixed: 0 }, [@182-187 Str(PlainLine("foo"))], Space)))] }"#;
|
||||||
|
|
||||||
|
// dbg!(&defs);
|
||||||
|
|
||||||
assert_multiline_str_eq!(format!("{:?}", &defs).as_str(), expected);
|
assert_multiline_str_eq!(format!("{:?}", &defs).as_str(), expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue