Closed mulias closed 2 months ago
This is ready to merge, just waiting for whether @mulias agrees with my PR comments or not. Once that's resolved, we're good to go
@smores56 I added two commits to address your feedback. I think the doc comment is more helpful where it is now, but let me know what you think.
Uh oh, it looks like you didn't propagate the function arg change...
error[E0061]: this function takes 3 arguments but 4 arguments were supplied
--> crates/compiler/can/src/desugar.rs:1310:17
|
1310 | value: *desugar_dbg_stmt(env, scope, tmp_var, tmp_var),
| ^^^^^^^^^^^^^^^^ -------
| | |
| | unexpected argument of type `&mut scope::Scope`
| help: remove the extra argument
|
note: function defined here
--> crates/compiler/can/src/desugar.rs:1333:4
|
1333 | fn desugar_dbg_stmt<'a>(
| ^^^^^^^^^^^^^^^^
1334 | env: &mut Env<'a>,
| -----------------
1335 | condition: &'a Loc<Expr<'a>>,
| ----------------------------
1336 | continuation: &'a Loc<Expr<'a>>,
| -------------------------------
Never pays to rush a change!
This PR (hopefully) wraps up the work started in #7038 and continued in #7054, fully implementing https://github.com/roc-lang/roc/issues/5894,
dbg
as an expression.In the feedback I got for #7038 there was general agreement that the functions in
desugar.rs
could use some refactoring to consolidate params into a shared struct. My initial intuition was that this should be a new struct, independent of the existingcan::Env
struct. Once I started implementing the desugaring for|> dbg
I realized I would have to pass desugar specific args through the rest of canonicalization, which means the two parts essentially need the same set of args and it makes more sense to share one struct.Use a shared env for desugaring and the rest of canonicalization
This refactor simplifies the desugar pass by reducing the number of arguments threaded through each recursive function call.
Env
.line_info
toEnv
as a lazy-evaled getter function.can::Env
struct in place of a number of params. This is mostly a find-and-replace, but in a few placesVec::from_iter_in
was changed toVec::with_capacity_in
followed by afor
loop in order to avoid lifetime issues.clippy::too_many_arguments
Support passing values into dbg with the pipe operator
In order to desugar
dbg
in a pipeline we need to allow a baredbg
node in desugaring and only report it as an error if the bare node survives to the next step of canonicalization. This means we move the error code out ofdesugar_expr
and intocanonicalize_expr
. This is much simpler to do now that these functions use the sameenv
struct, since previously we would have had to pass down extra args tocanonicalize_expr
. Sharing theenv
struct means that we also don't have to worry about calculatingline_info
more than once.