Skip to content

Commit

Permalink
Sort modes and modalities (#90)
Browse files Browse the repository at this point in the history
* Sort modes and modalities

x @ mode1 mode2 and x @ mode2 mode1 are equivalent, as are things like `value
mod mode1 mode2` and `value mod mode2 mode1`. It'll be nice to have a canonical
order on these to avoid thrashing and inconsistency in code with modalities and
mode annotations. I decided to just go with sorting by String.compare for now,
rather than trying to impose any opinions on the order.

Signed-off-by: Aspen Smith <aspsmith@janestreet.com>

* normalize mode order in the extended parser

the current state of the PR leaves the extended parse tree
unnormalized, but this is hidden by the wonderful bug in the
round-trip check

this commit sorts the modes while parsing the extended ast as we are
wont; now we don't need to handle them specially from `Fmt_ast.ml` or
do a separate normalization

Signed-off-by: David Vulakh <dvulakh@janestreet.com>

---------

Signed-off-by: Aspen Smith <aspsmith@janestreet.com>
Signed-off-by: David Vulakh <dvulakh@janestreet.com>
Co-authored-by: David Vulakh <dvulakh@janestreet.com>
  • Loading branch information
glittershark and dvulakh authored Dec 3, 2024
1 parent efd15ae commit c39d773
Show file tree
Hide file tree
Showing 12 changed files with 1,300 additions and 1,239 deletions.
18 changes: 16 additions & 2 deletions lib/Normalize_std_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,25 @@ let make_mapper conf ~ignore_doc_comments ~erase_jane_syntax =
Ast_mapper.default_mapper.type_declaration m {decl with ptype_attributes}
in
let modes (m : Ast_mapper.mapper) ms =
Ast_mapper.default_mapper.modes m (if erase_jane_syntax then [] else ms)
Ast_mapper.default_mapper.modes m
( if erase_jane_syntax then []
else
List.sort
~compare:(fun
{Location.txt= Mode m1; _} {Location.txt= Mode m2; _} ->
String.compare m1 m2 )
ms )
in
let modalities (m : Ast_mapper.mapper) ms =
Ast_mapper.default_mapper.modalities m
(if erase_jane_syntax then [] else ms)
( if erase_jane_syntax then []
else
List.sort
~compare:(fun
{Location.txt= Modality m1; _}
{Location.txt= Modality m2; _}
-> String.compare m1 m2 )
ms )
in
let value_binding (m : Ast_mapper.mapper) vb =
let vb =
Expand Down
Loading

0 comments on commit c39d773

Please sign in to comment.