|
18 | 18 |
|
19 | 19 | open Typedtree
|
20 | 20 |
|
21 |
| -type error = Conflicting_inline_attributes | Fragile_pattern_in_toplevel |
| 21 | +type error = Fragile_pattern_in_toplevel |
22 | 22 |
|
23 | 23 | exception Error of Location.t * error
|
24 | 24 |
|
@@ -78,37 +78,30 @@ let rec apply_coercion loc strict (restr : Typedtree.module_coercion) arg =
|
78 | 78 | | Tcoerce_functor (cc_arg, cc_res) ->
|
79 | 79 | let param = Ident.create "funarg" in
|
80 | 80 | let carg = apply_coercion loc Alias cc_arg (Lvar param) in
|
81 |
| - apply_coercion_result loc strict arg [param] [carg] cc_res |
| 81 | + apply_coercion_result loc strict arg param carg cc_res |
82 | 82 | | Tcoerce_primitive {pc_loc; pc_desc; pc_env; pc_type} ->
|
83 | 83 | Translcore.transl_primitive pc_loc pc_desc pc_env pc_type
|
84 | 84 | | Tcoerce_alias (path, cc) ->
|
85 | 85 | Lambda.name_lambda strict arg (fun _ ->
|
86 | 86 | apply_coercion loc Alias cc (Lambda.transl_normal_path path))
|
87 | 87 |
|
88 |
| -and apply_coercion_result loc strict funct params args cc_res = |
89 |
| - match cc_res with |
90 |
| - (* | Tcoerce_functor (cc_arg, cc_res) -> |
91 |
| - let param = Ident.create "funarg" in |
92 |
| - let arg = apply_coercion loc Alias cc_arg (Lvar param) in |
93 |
| - apply_coercion_result loc strict funct (param :: params) (arg :: args) |
94 |
| - cc_res *) |
95 |
| - | _ -> |
96 |
| - Lambda.name_lambda strict funct (fun id -> |
97 |
| - Lfunction |
98 |
| - { |
99 |
| - params = List.rev params; |
100 |
| - attr = {Lambda.default_function_attribute with is_a_functor = true}; |
101 |
| - loc; |
102 |
| - body = |
103 |
| - apply_coercion loc Strict cc_res |
104 |
| - (Lapply |
105 |
| - { |
106 |
| - ap_loc = loc; |
107 |
| - ap_func = Lvar id; |
108 |
| - ap_args = List.rev args; |
109 |
| - ap_inlined = Default_inline; |
110 |
| - }); |
111 |
| - }) |
| 88 | +and apply_coercion_result loc strict funct param arg cc_res = |
| 89 | + Lambda.name_lambda strict funct (fun id -> |
| 90 | + Lfunction |
| 91 | + { |
| 92 | + params = [param]; |
| 93 | + attr = {Lambda.default_function_attribute with is_a_functor = true}; |
| 94 | + loc; |
| 95 | + body = |
| 96 | + apply_coercion loc Strict cc_res |
| 97 | + (Lapply |
| 98 | + { |
| 99 | + ap_loc = loc; |
| 100 | + ap_func = Lvar id; |
| 101 | + ap_args = [arg]; |
| 102 | + ap_inlined = Default_inline; |
| 103 | + }); |
| 104 | + }) |
112 | 105 |
|
113 | 106 | and wrap_id_pos_list loc id_pos_list get_field lam =
|
114 | 107 | let fv = Lambda.free_variables lam in
|
@@ -210,74 +203,41 @@ let rec bound_value_identifiers : Types.signature_item list -> Ident.t list =
|
210 | 203 | functor(s) being merged with. Such an attribute will be placed on the
|
211 | 204 | resulting merged functor. *)
|
212 | 205 |
|
213 |
| -let merge_inline_attributes (attr1 : Lambda.inline_attribute) |
214 |
| - (attr2 : Lambda.inline_attribute) loc = |
215 |
| - match (attr1, attr2) with |
216 |
| - | Lambda.Default_inline, _ -> attr2 |
217 |
| - | _, Lambda.Default_inline -> attr1 |
218 |
| - | _, _ -> |
219 |
| - if attr1 = attr2 then attr1 |
220 |
| - else raise (Error (loc, Conflicting_inline_attributes)) |
221 |
| - |
222 |
| -let merge_functors mexp coercion root_path = |
223 |
| - let merge mexp coercion path acc inline_attribute = |
224 |
| - let finished = (acc, mexp, path, coercion, inline_attribute) in |
225 |
| - match mexp.mod_desc with |
226 |
| - | Tmod_functor (param, _, _, body) -> |
227 |
| - let inline_attribute' = |
228 |
| - Translattribute.get_inline_attribute mexp.mod_attributes |
229 |
| - in |
230 |
| - let arg_coercion, res_coercion = |
231 |
| - match coercion with |
232 |
| - | Tcoerce_none -> (Tcoerce_none, Tcoerce_none) |
233 |
| - | Tcoerce_functor (arg_coercion, res_coercion) -> |
234 |
| - (arg_coercion, res_coercion) |
235 |
| - | _ -> Misc.fatal_error "Translmod.merge_functors: bad coercion" |
236 |
| - in |
237 |
| - let loc = mexp.mod_loc in |
238 |
| - let path = functor_path path param in |
239 |
| - let inline_attribute = |
240 |
| - merge_inline_attributes inline_attribute inline_attribute' loc |
241 |
| - in |
242 |
| - let r = |
243 |
| - ( (param, loc, arg_coercion) :: acc, |
244 |
| - body, |
245 |
| - path, |
246 |
| - res_coercion, |
247 |
| - inline_attribute ) |
248 |
| - in |
249 |
| - (* let _ = |
250 |
| - merge body res_coercion path |
251 |
| - ((param, loc, arg_coercion) :: acc) |
252 |
| - inline_attribute |
253 |
| - in *) |
254 |
| - r |
255 |
| - | _ -> finished |
256 |
| - in |
257 |
| - merge mexp coercion root_path [] Default_inline |
| 206 | +let get_functor_params mexp coercion root_path = |
| 207 | + match mexp.mod_desc with |
| 208 | + | Tmod_functor (param, _, _, body) -> |
| 209 | + let inline_attribute = |
| 210 | + Translattribute.get_inline_attribute mexp.mod_attributes |
| 211 | + in |
| 212 | + let arg_coercion, res_coercion = |
| 213 | + match coercion with |
| 214 | + | Tcoerce_none -> (Tcoerce_none, Tcoerce_none) |
| 215 | + | Tcoerce_functor (arg_coercion, res_coercion) -> |
| 216 | + (arg_coercion, res_coercion) |
| 217 | + | _ -> Misc.fatal_error "Translmod.get_functor_params: bad coercion" |
| 218 | + in |
| 219 | + let loc = mexp.mod_loc in |
| 220 | + let path = functor_path root_path param in |
| 221 | + ((param, loc, arg_coercion), body, path, res_coercion, inline_attribute) |
| 222 | + | _ -> assert false |
258 | 223 |
|
259 | 224 | let export_identifiers : Ident.t list ref = ref []
|
260 | 225 |
|
261 | 226 | let rec compile_functor mexp coercion root_path loc =
|
262 |
| - let functor_params_rev, body, body_path, res_coercion, inline_attribute = |
263 |
| - merge_functors mexp coercion root_path |
| 227 | + let functor_param, body, body_path, res_coercion, inline_attribute = |
| 228 | + get_functor_params mexp coercion root_path |
264 | 229 | in
|
265 |
| - assert (functor_params_rev <> []); |
266 | 230 | (* cf. [transl_module] *)
|
267 |
| - let params, body = |
268 |
| - List.fold_left |
269 |
| - (fun (params, body) (param, loc, arg_coercion) -> |
270 |
| - let param' = Ident.rename param in |
271 |
| - let arg = apply_coercion loc Alias arg_coercion (Lvar param') in |
272 |
| - let params = param' :: params in |
273 |
| - let body = Lambda.Llet (Alias, Pgenval, param, arg, body) in |
274 |
| - (params, body)) |
275 |
| - ([], transl_module res_coercion body_path body) |
276 |
| - functor_params_rev |
| 231 | + let param, loc_, arg_coercion = functor_param in |
| 232 | + let param' = Ident.rename param in |
| 233 | + let arg = apply_coercion loc_ Alias arg_coercion (Lvar param') in |
| 234 | + let body = |
| 235 | + Lambda.Llet |
| 236 | + (Alias, Pgenval, param, arg, transl_module res_coercion body_path body) |
277 | 237 | in
|
278 | 238 | Lambda.Lfunction
|
279 | 239 | {
|
280 |
| - params; |
| 240 | + params = [param']; |
281 | 241 | attr =
|
282 | 242 | {
|
283 | 243 | inline = inline_attribute;
|
@@ -523,8 +483,6 @@ let transl_implementation module_name (str, cc) =
|
523 | 483 | (* Error report *)
|
524 | 484 |
|
525 | 485 | let report_error ppf = function
|
526 |
| - | Conflicting_inline_attributes -> |
527 |
| - Format.fprintf ppf "@[Conflicting ``inline'' attributes@]" |
528 | 486 | | Fragile_pattern_in_toplevel ->
|
529 | 487 | Format.fprintf ppf "@[Such fragile pattern not allowed in the toplevel@]"
|
530 | 488 |
|
|
0 commit comments