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

Migrate modes from jane syntax to the parsetree #2510

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
responding to review
  • Loading branch information
Charlie Gunn committed Apr 24, 2024
commit 524cad6a38492a04261df78c4b51c722a1309b2c
7 changes: 5 additions & 2 deletions ocaml/parsing/ast_iterator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,13 @@ module T = struct
| Ptype_record l -> List.iter (sub.label_declaration sub) l
| Ptype_open -> ()

let iter_modalities sub modalities =
List.iter (iter_loc sub) modalities

let iter_constructor_argument sub {pca_type; pca_loc; pca_modalities} =
sub.typ sub pca_type;
sub.location sub pca_loc;
List.iter (iter_loc sub) pca_modalities
iter_modalities sub pca_modalities

let iter_constructor_arguments sub = function
| Pcstr_tuple l -> List.iter (iter_constructor_argument sub) l
Expand Down Expand Up @@ -954,7 +957,7 @@ let default_iterator =
this.typ this pld_type;
this.location this pld_loc;
this.attributes this pld_attributes;
List.iter (iter_loc this) pld_modalities
T.iter_modalities this pld_modalities
);

cases = (fun this l -> List.iter (this.case this) l);
Expand Down
7 changes: 5 additions & 2 deletions ocaml/parsing/ast_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,13 @@ module T = struct
| Ptype_record l -> Ptype_record (List.map (sub.label_declaration sub) l)
| Ptype_open -> Ptype_open

let map_modalities sub modalities =
List.map (map_loc sub) modalities

let map_constructor_argument sub x =
let pca_type = sub.typ sub x.pca_type in
let pca_loc = sub.location sub x.pca_loc in
let pca_modalities = List.map (map_loc sub) x.pca_modalities in
let pca_modalities = map_modalities sub x.pca_modalities in
{ pca_type; pca_loc; pca_modalities }

let map_constructor_arguments sub = function
Expand Down Expand Up @@ -1057,7 +1060,7 @@ let default_mapper =
(map_loc this pld_name)
(this.typ this pld_type)
~mut:pld_mutable
~modalities:(List.map (map_loc this) pld_modalities)
~modalities:(T.map_modalities this pld_modalities)
~loc:(this.location this pld_loc)
~attrs:(this.attributes this pld_attributes)
);
Expand Down
8 changes: 3 additions & 5 deletions ocaml/parsing/jane_syntax.mli
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,12 @@ module Mode_expr : sig
- let local_ x = ...
- local_ exp
- local string -> string
- {global_ x : int}

Note that in the first two cases, axes other than locality are not specified;
in the second case, other axes are defaulted to legacy. In the last case, we
are specifying modalities.
in the second case, other axes are defaulted to legacy.

In the future the three annotations will be quite different, but for now they
are all lists of modes/modalities. [Typemode] has the three different
In the future the two annotations will be quite different, but for now they
are just lists of modes. [Typemode] has the two different
interpretations of the annotation.

(TODO: in the future we will have mutable(...), which is similar to the second
Expand Down
12 changes: 8 additions & 4 deletions ocaml/parsing/printast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -884,21 +884,25 @@ and constructor_decl i ppf
constructor_arguments (i+1) ppf pcd_args;
option (i+1) core_type ppf pcd_res

and modalities i ppf modalities =
list i string_loc ppf (
List.map (Location.map (fun (Modality x) -> x)) modalities
);

and constructor_argument i ppf {pca_modalities; pca_type; pca_loc} =
line i ppf "%a\n" fmt_location pca_loc;
list (i+1) string_loc ppf (
List.map (Location.map (fun (Modality x) -> x)) pca_modalities
);
modalities (i+1) ppf pca_modalities;
core_type (i+1) ppf pca_type

and constructor_arguments i ppf = function
| Pcstr_tuple l -> list i constructor_argument ppf l
| Pcstr_record l -> list i label_decl ppf l

and label_decl i ppf {pld_name; pld_mutable; pld_type; pld_loc; pld_attributes}=
and label_decl i ppf {pld_name; pld_mutable; pld_modalities; pld_type; pld_loc; pld_attributes}=
line i ppf "%a\n" fmt_location pld_loc;
attributes i ppf pld_attributes;
line (i+1) ppf "%a\n" fmt_mutable_flag pld_mutable;
modalities (i+1) ppf pld_modalities;
line (i+1) ppf "%a" fmt_string_loc pld_name;
core_type (i+1) ppf pld_type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
attribute "foo"
[]
Immutable
[]
"l" (attributes.ml[26,344+4]..[26,344+5]) core_type (attributes.ml[26,344+9]..[26,344+10])
attribute "foo"
[]
Expand Down
19 changes: 10 additions & 9 deletions ocaml/typing/predef.ml
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,16 @@ let build_initial_env add_type add_extension empty_env =
add_extension id
{ ext_type_path = path_exn;
ext_type_params = [];
ext_args = Cstr_tuple (List.map
(fun x ->
{
ca_type=x;
ca_global=Unrestricted;
ca_loc=Location.none
}
)
args);
ext_args =
Cstr_tuple
(List.map
(fun x ->
{
ca_type=x;
ca_global=Unrestricted;
ca_loc=Location.none
})
args);
ext_arg_jkinds = jkinds;
ext_constant = args = [];
ext_ret_type = None;
Expand Down
19 changes: 10 additions & 9 deletions ocaml/typing/typedecl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -422,15 +422,16 @@ let transl_constructor_arguments ~new_var_jkind env univars closed = function
{ca_global = gf; ca_type = cty; ca_loc = arg.pca_loc}
in
let flds = List.map mk l in
let flds' = List.map
(fun ca ->
{
Types.ca_global = ca.ca_global.txt;
ca_loc = ca.ca_loc;
ca_type = ca.ca_type.ctyp_type;
}
)
flds in
let flds' =
List.map
(fun ca ->
{
Types.ca_global = ca.ca_global.txt;
ca_loc = ca.ca_loc;
ca_type = ca.ca_type.ctyp_type;
})
flds
in
Types.Cstr_tuple flds',
Cstr_tuple flds
| Pcstr_record l ->
Expand Down
Loading