@@ -17,18 +17,18 @@ let rec module_type =
1717 Ast_helper.Mty. ident (Location. mknoloc (Untypeast. lident_of_path path))
1818 | Mty_alias path ->
1919 Ast_helper.Mty. alias (Location. mknoloc (Untypeast. lident_of_path path))
20- | Mty_functor (param , type_out ) ->
20+ | Mty_functor (param , type_out , ret_mode ) ->
2121 let param =
2222 match param with
2323 | Unit -> Parsetree. Unit
24- | Named (id , type_in ) ->
24+ | Named (id , type_in , param_mode ) ->
2525 Parsetree. Named
2626 ( Location. mknoloc (Option. map ~f: Ident. name id),
2727 module_type type_in,
28- [] )
28+ modes param_mode )
2929 in
3030 let out = module_type type_out in
31- Mty. functor_ param out
31+ Mty. functor_ ~ret_mode: (modes ret_mode) param out
3232 | Mty_strengthen (mty , path , _aliasability ) ->
3333 Mty. strengthen ~loc: Location. none (module_type mty)
3434 (Location. mknoloc (Untypeast. lident_of_path path))
@@ -55,16 +55,8 @@ and core_type type_expr =
5555 | Labelled l -> (Labelled l, core_type type_expr)
5656 | Optional l -> (Optional l, core_type type_expr)
5757 in
58- let snap = Btype. snapshot () in
59- let arg_modes =
60- Typemode. untransl_mode_annots
61- @@ Mode.Alloc. (Const. diff (zap_to_legacy arg_alloc_mode) Const. legacy)
62- in
63- let ret_modes =
64- Typemode. untransl_mode_annots
65- @@ Mode.Alloc. (Const. diff (zap_to_legacy ret_alloc_mode) Const. legacy)
66- in
67- Btype. backtrack snap;
58+ let arg_modes = modes arg_alloc_mode in
59+ let ret_modes = modes ret_alloc_mode in
6860 Typ. arrow label type_expr (core_type type_expr_out) arg_modes ret_modes
6961 | Ttuple type_exprs ->
7062 let labeled_type_exprs =
@@ -158,8 +150,17 @@ and extension_constructor id { ext_args; ext_ret_type; ext_attributes; _ } =
158150 ?res:(Option. map ~f: core_type ext_ret_type)
159151 (var_of_id id)
160152
161- and const_modalities modalities =
162- Typemode. untransl_modalities Immutable modalities
153+ and modes mode =
154+ let snapshot = Btype. snapshot () in
155+ let mode = Mode.Alloc. zap_to_legacy mode in
156+ Btype. backtrack snapshot;
157+ Printtyp. tree_of_modes mode
158+ |> List. map ~f: (fun mode -> Location. mknoloc (Parsetree. Mode mode))
159+
160+ and const_modalities ~mut modality =
161+ Printtyp. tree_of_modalities mut modality
162+ |> List. map ~f: (fun modality ->
163+ Location. mknoloc (Parsetree. Modality modality))
163164
164165and value_description id
165166 { val_type; val_kind = _ ; val_loc; val_attributes; val_modalities; _ } =
@@ -171,14 +172,14 @@ and value_description id
171172 pval_type = type_;
172173 pval_prim = [] ;
173174 pval_attributes = val_attributes;
174- pval_modalities = const_modalities modalities;
175+ pval_modalities = const_modalities ~mut: Immutable modalities;
175176 pval_loc = val_loc
176177 }
177178
178179and constructor_argument { ca_type; ca_loc; ca_modalities; ca_sort = _ } =
179180 { Parsetree. pca_type = core_type ca_type;
180181 pca_loc = ca_loc;
181- pca_modalities = const_modalities ca_modalities
182+ pca_modalities = const_modalities ~mut: Immutable ca_modalities
182183 }
183184
184185and label_declaration
@@ -188,7 +189,7 @@ and label_declaration
188189 (match ld_mutable with
189190 | Mutable _ -> Mutable
190191 | Immutable -> Immutable )
191- ~modalities: (Typemode. untransl_modalities ld_mutable ld_modalities)
192+ ~modalities: (const_modalities ~mut: ld_mutable ld_modalities)
192193 (var_of_id ld_id) (core_type ld_type)
193194
194195and constructor_arguments = function
0 commit comments