Closure conversion: empty tuples are OK

it's much simpler to handle down the line if they have a uniform structure;
empty tuples are easily converted into unit types when translating to OCaml.
This commit is contained in:
Louis Gesbert 2024-06-21 11:31:39 +02:00
parent 676edef101
commit dd3285bb66
2 changed files with 8 additions and 11 deletions

View File

@ -118,21 +118,17 @@ let build_closure :
~op:(Operator.ToClosureEnv, pos)
~tys:
[
( (if free_vars = [] then TLit TUnit
else TTuple free_vars_types),
( TTuple free_vars_types,
pos );
]
~args:
[
(if free_vars = [] then
Expr.elit LUnit (mark_ty (TLit TUnit, pos))
else
Expr.etuple
(List.map
(fun (extra_var, m) ->
Bindlib.box_var extra_var, Expr.with_pos pos m)
free_vars)
(mark_ty (TTuple free_vars_types, pos)));
Expr.etuple
(List.map
(fun (extra_var, m) ->
Bindlib.box_var extra_var, Expr.with_pos pos m)
free_vars)
(mark_ty (TTuple free_vars_types, pos));
]
(mark_ty (TClosureEnv, pos));
])

View File

@ -219,6 +219,7 @@ let rec format_typ (fmt : Format.formatter) (typ : typ) : unit =
in
match Mark.remove typ with
| TLit l -> Format.fprintf fmt "%a" Print.tlit l
| TTuple [] -> Format.fprintf fmt "unit"
| TTuple ts ->
Format.fprintf fmt "@[<hov 2>(%a)@]"
(Format.pp_print_list