Skip to content

Commit

Permalink
Last of the feedback (the part I forgot to commit)
Browse files Browse the repository at this point in the history
  • Loading branch information
gamebox committed Jan 8, 2025
1 parent 880b7ae commit 7ab2ac2
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 58 deletions.
34 changes: 0 additions & 34 deletions crates/compiler/can/src/desugar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,40 +1186,6 @@ pub fn desugar_expr<'a>(
Expr::LowLevelTry(result_expr, ResultTryKind::KeywordPrefix),
))
}
PncApply(
Loc {
value:
TrySuffix {
target: TryTarget::Result,
expr: fn_expr,
},
region: fn_region,
},
loc_args,
) => {
let loc_fn = env.arena.alloc(Loc::at(*fn_region, **fn_expr));
let function = desugar_expr(env, scope, loc_fn);

let mut desugared_args = Vec::with_capacity_in(loc_args.len(), env.arena);
for loc_arg in &loc_args.items[..] {
desugared_args.push(desugar_expr(env, scope, loc_arg));
}

let args_region = Region::span_across(
&loc_args.items[0].region,
&loc_args.items[loc_args.items.len() - 1].region,
);

let result_expr = env.arena.alloc(Loc::at(
args_region,
Expr::Apply(function, desugared_args.into_bump_slice(), CalledVia::Try),
));

env.arena.alloc(Loc::at(
loc_expr.region,
Expr::LowLevelTry(result_expr, ResultTryKind::OperatorSuffix),
))
}
PncApply(loc_fn, loc_args) => {
let mut desugared_args = Vec::with_capacity_in(loc_args.len(), env.arena);

Expand Down
3 changes: 2 additions & 1 deletion crates/compiler/fmt/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::spaces::{
use crate::Buf;
use bumpalo::collections::Vec;
use bumpalo::Bump;
use roc_module::called_via::{self, BinOp, CalledVia, UnaryOp};
use roc_module::called_via::{self, BinOp, UnaryOp};
use roc_parse::ast::{
AssignedField, Base, Collection, CommentOrNewline, Expr, ExtractSpaces, Pattern, Spaceable,
Spaces, SpacesAfter, SpacesBefore, TryTarget, WhenBranch,
Expand Down Expand Up @@ -107,6 +107,7 @@ fn format_expr_only(
if buf.flags().parens_and_commas {
fmt_pnc_apply(loc_expr, &Collection::with_items(loc_args), indent, buf);
} else if !apply_needs_parens || loc_args.is_empty() {
println!("No need parens");
fmt_apply(loc_expr, loc_args, indent, buf);
} else {
fmt_parens(item, buf, indent);
Expand Down
73 changes: 52 additions & 21 deletions crates/compiler/parse/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,25 +234,38 @@ fn loc_term<'a>() -> impl Parser<'a, Loc<Expr<'a>>, EExpr<'a>> {
zero_or_more(pnc_args()),
),
|arena,
(expr, arg_locs_vec): (
(expr, arg_locs_with_suffixes_vec): (
Loc<Expr<'a>>,
bumpalo::collections::Vec<'a, Loc<Collection<'a, &'a Loc<Expr>>>>,
bumpalo::collections::Vec<
'a,
(
Loc<Collection<'a, &'a Loc<Expr>>>,
Option<Vec<'a, Suffix<'a>>>,
),
>,
)| {
let mut e = expr;
let orig_region = e.region;
for args_loc in arg_locs_vec.iter() {
for (args_loc, maybe_suffixes) in arg_locs_with_suffixes_vec.iter() {
let value = if matches!(
e,
Loc {
value: Expr::Dbg,
..
}
) {
Expr::Apply(arena.alloc(e), args_loc.value.items, CalledVia::Space)
} else if let Some(suffixes) = maybe_suffixes {
apply_expr_access_chain(
arena,
Expr::PncApply(arena.alloc(e), args_loc.value),
suffixes.clone(),
)
} else {
Expr::PncApply(arena.alloc(e), args_loc.value)
};
e = Loc {
value: if matches!(
e,
Loc {
value: Expr::Dbg,
..
}
) {
Expr::Apply(arena.alloc(e), args_loc.value.items, CalledVia::Space)
} else {
Expr::PncApply(arena.alloc(e), args_loc.value)
},
value,
region: Region::span_across(&orig_region, &args_loc.region),
};
}
Expand All @@ -262,9 +275,16 @@ fn loc_term<'a>() -> impl Parser<'a, Loc<Expr<'a>>, EExpr<'a>> {
.trace("term")
}

fn pnc_args<'a>() -> impl Parser<'a, Loc<Collection<'a, &'a Loc<Expr<'a>>>>, EExpr<'a>> {
fn pnc_args<'a>() -> impl Parser<
'a,
(
Loc<Collection<'a, &'a Loc<Expr<'a>>>>,
Option<Vec<'a, Suffix<'a>>>,
),
EExpr<'a>,
> {
|arena: &'a Bump, state: State<'a>, min_indent: u32| {
map_with_arena(
let args_then_suffixes = and(
specialize_err(
EExpr::InParens,
loc(collection_trailing_sep_e(
Expand All @@ -275,12 +295,23 @@ fn pnc_args<'a>() -> impl Parser<'a, Loc<Collection<'a, &'a Loc<Expr<'a>>>>, EEx
Expr::SpaceBefore,
)),
),
|arena: &'a Bump, loc_args_coll: Loc<Collection<'a, Loc<Expr<'a>>>>| {
optional(record_field_access_chain()),
);
map_with_arena(
args_then_suffixes,
|arena: &'a Bump,
(loc_args_coll, maybe_suffixes): (
Loc<Collection<'a, Loc<Expr<'a>>>>,
Option<Vec<'a, Suffix<'a>>>,
)| {
let args = loc_args_coll.value.ptrify_items(arena);
Loc {
region: loc_args_coll.region,
value: args,
}
(
Loc {
region: loc_args_coll.region,
value: args,
},
maybe_suffixes,
)
},
)
.parse(arena, state, min_indent)
Expand Down
5 changes: 3 additions & 2 deletions crates/compiler/problem/src/can.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,14 @@ impl Problem {
| Problem::ReturnAtEndOfFunction { region }
| Problem::UnboundTypeVarsInAs(region)
| Problem::UnsuffixedEffectfulRecordField(region)
| Problem::SuffixedPureRecordField(region) => Some(*region),
| Problem::SuffixedPureRecordField(region)
| Problem::StmtAfterExpr(region) => Some(*region),

Problem::RuntimeError(RuntimeError::CircularDef(cycle_entries))
| Problem::BadRecursion(cycle_entries) => {
cycle_entries.first().map(|entry| entry.expr_region)
}

Problem::StmtAfterExpr(region) => Some(*region),
Problem::RuntimeError(RuntimeError::UnresolvedTypeVar)
| Problem::RuntimeError(RuntimeError::ErroneousType)
| Problem::RuntimeError(RuntimeError::NonExhaustivePattern)
Expand Down

0 comments on commit 7ab2ac2

Please sign in to comment.