Skip to content

Commit c7ae44b

Browse files
committed
outcometree: print [@unboxed] attributes
1 parent b5fa025 commit c7ae44b

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

testsuite/tests/tool-toplevel/printval.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ type t =
6868
| Proxy of t
6969
;;
7070
[%%expect {|
71-
type t = Int of int | Str of string | Pair of t * t | Proxy of t
71+
type t =
72+
Int of int [@unboxed]
73+
| Str of string [@unboxed]
74+
| Pair of t * t
75+
| Proxy of t
7276
|}];;
7377

7478
Int 42;;

typing/oprint.ml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ let constructor_of_extension_constructor
502502
name = ext.oext_name;
503503
args = ext.oext_args;
504504
return_type = ext.oext_ret_type;
505+
unboxed = false;
505506
}
506507

507508
let split_anon_functor_arguments params =
@@ -712,29 +713,37 @@ and print_out_type_decl kwd ppf td =
712713
print_unboxed
713714

714715
and print_out_constr ppf constr =
715-
let { name; args = tyl; return_type } = constr in
716+
let { name; args = tyl; return_type; unboxed } = constr in
716717
let name =
717718
match name with
718719
| "::" -> "(::)" (* #7200 *)
719720
| s -> s
720721
in
722+
let pp_unboxed ppf = function
723+
| false -> ()
724+
| true -> fprintf ppf "@ [@unboxed]"
725+
in
721726
match return_type with
722727
| None ->
723728
begin match tyl with
724729
| [] ->
725730
pp_print_string ppf name
726731
| _ ->
727-
fprintf ppf "@[<2>%s of@ %a@]" name
732+
fprintf ppf "@[<2>%s of@ %a%a@]" name
728733
(print_typlist print_simple_out_type " *") tyl
734+
pp_unboxed unboxed
729735
end
730736
| Some ret_type ->
731737
begin match tyl with
732738
| [] ->
733-
fprintf ppf "@[<2>%s :@ %a@]" name print_simple_out_type ret_type
739+
fprintf ppf "@[<2>%s :@ %a%a@]" name
740+
print_simple_out_type ret_type
741+
pp_unboxed unboxed
734742
| _ ->
735-
fprintf ppf "@[<2>%s :@ %a -> %a@]" name
743+
fprintf ppf "@[<2>%s :@ %a -> %a%a@]" name
736744
(print_typlist print_simple_out_type " *")
737745
tyl print_simple_out_type ret_type
746+
pp_unboxed unboxed
738747
end
739748

740749
and print_out_extension_constructor ppf ext =

typing/outcometree.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ and out_constructor = {
8282
name: string;
8383
args: out_type list;
8484
return_type: out_type option;
85+
unboxed: bool;
8586
}
8687

8788
and out_variant =

typing/printtyp.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,13 +1420,14 @@ and tree_of_constructor_arguments = function
14201420
and tree_of_constructor cd =
14211421
let name = Ident.name cd.cd_id in
14221422
let arg () = tree_of_constructor_arguments cd.cd_args in
1423+
let unboxed = Builtin_attributes.has_unboxed cd.cd_attributes in
14231424
match cd.cd_res with
1424-
| None -> { name; args = arg (); return_type = None }
1425+
| None -> { name; args = arg (); return_type = None; unboxed; }
14251426
| Some res ->
14261427
Names.with_local_names (fun () ->
14271428
let ret = tree_of_typexp Type res in
14281429
let args = arg () in
1429-
{ name; args; return_type = Some ret })
1430+
{ name; args; return_type = Some ret; unboxed; })
14301431

14311432
and tree_of_label l =
14321433
(Ident.name l.ld_id, l.ld_mutable = Mutable, tree_of_typexp Type l.ld_type)
@@ -1516,6 +1517,7 @@ let extension_only_constructor id ppf ext =
15161517
name;
15171518
args;
15181519
return_type = ret;
1520+
unboxed = false;
15191521
} : out_constructor)
15201522

15211523
(* Print a value declaration *)

0 commit comments

Comments
 (0)