Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic import in expression #6310

Merged
merged 19 commits into from
Jun 26, 2023
Merged

Dynamic import in expression #6310

merged 19 commits into from
Jun 26, 2023

Conversation

mununki
Copy link
Member

@mununki mununki commented Jun 25, 2023

Fixes #6300

This PR fixes the issue #6300 that is formatting removes await keyword. This is not just a formatting issue, it's an issue because there is no transformation for when dynamic imports are used in expressions in addition to one of the structure_items, Pstr_module.

This PR add the transformation for Pstr_eval and Pstr_value.

  • keep the await in the expression

@mununki
Copy link
Member Author

mununki commented Jun 25, 2023

Side note: I have to go now, I'll fix the formatting part couple of hours later 😓

@mununki
Copy link
Member Author

mununki commented Jun 26, 2023

Not to handle the case of Pstr_eval.

// no need
await Belt.List

Copy link
Collaborator

@cristianoc cristianoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks!
Just some code style comments.
Remember to add a changelog before merging.

@@ -214,6 +221,19 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
the attribute to the whole expression, in general, when shuffuling the ast
it is very hard to place attributes correctly
*)
| Pexp_letmodule
(lid, ({pmod_desc = Pmod_ident {txt}; pmod_attributes} as me), expr)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this too, or are the use cases of this kind more rare?

  | Pmod_constraint of module_expr * module_type
        (* (ME : MT) *)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, correct! I'll add it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

da381ba

I've added the case of Pmod_constraint ({pmod_desc = Pmod_ident _}, {pmty_desc = Pmty_ident mtyp_lid}) additionally, e.g. ME: MT. In other cases, for example, I don't think Pmty_alias or Pmty_with are applicable for dynamic import. Any thought?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

match has_local_module_name with
| Some _ -> None
| None ->
let open Ast_helper in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove the open, just makes the code more indirect

Copy link
Member Author

@mununki mununki Jun 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand what the indirect means correctly:
1ed974f

(* [ module __Belt_List__ = module type of Belt.List ] *)
let module_type_decls =
module_exprs
|> List.filter_map (fun ({pmod_desc} as me : Parsetree.module_expr) ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: instead of filter-map twice and compose, why not compose the functions inside directly, and do only 1 filter-map.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@cristianoc cristianoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last changes look good.
How about adding 1 more example whith 2 module awaits in the same function.

@@ -214,6 +221,19 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
the attribute to the whole expression, in general, when shuffuling the ast
it is very hard to place attributes correctly
*)
| Pexp_letmodule
(lid, ({pmod_desc = Pmod_ident {txt}; pmod_attributes} as me), expr)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

@mununki
Copy link
Member Author

mununki commented Jun 26, 2023

The last changes look good. How about adding 1 more example whith 2 module awaits in the same function.

Good catch, thanks. There an issue in that case. I'll fix it.

@mununki
Copy link
Member Author

mununki commented Jun 26, 2023

The last changes look good. How about adding 1 more example whith 2 module awaits in the same function.

Added the test and fixes the issue 606a1cb 5070930

~module_type_lid:safe_module_type_lid me,
expr );
}
self.expr self
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little dangerous.
One never applies the recursion to the whole expression, but to the subparts.
The danger is to create infinite loops.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, agree.

Copy link
Collaborator

@cristianoc cristianoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final comments

me,
expr );
}
self.expr self
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@cristianoc
Copy link
Collaborator

Left comments for some final changes before merging.

@mununki
Copy link
Member Author

mununki commented Jun 26, 2023

Left comments for some final changes before merging.

Thanks! f3ebaff

@cristianoc
Copy link
Collaborator

Ready to merge?

@mununki mununki merged commit de9b806 into master Jun 26, 2023
14 checks passed
@mununki mununki deleted the fix-import-letmodule branch June 26, 2023 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Formatter formats away await on module
2 participants