Skip to content

Commit 58260e3

Browse files
committed
outcometree: print [@unboxed] attributes
1 parent 22c5041 commit 58260e3

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ let constructor_of_extension_constructor
502502
ocstr_name = ext.oext_name;
503503
ocstr_args = ext.oext_args;
504504
ocstr_return_type = ext.oext_ret_type;
505+
ocstr_unboxed = false;
505506
}
506507

507508
let split_anon_functor_arguments params =
@@ -716,29 +717,38 @@ and print_out_constr ppf constr =
716717
ocstr_name = name;
717718
ocstr_args = tyl;
718719
ocstr_return_type = return_type;
720+
ocstr_unboxed = unboxed;
719721
} = constr in
720722
let name =
721723
match name with
722724
| "::" -> "(::)" (* #7200 *)
723725
| s -> s
724726
in
727+
let pp_unboxed ppf = function
728+
| false -> ()
729+
| true -> fprintf ppf "@ [@unboxed]"
730+
in
725731
match return_type with
726732
| None ->
727733
begin match tyl with
728734
| [] ->
729735
pp_print_string ppf name
730736
| _ ->
731-
fprintf ppf "@[<2>%s of@ %a@]" name
737+
fprintf ppf "@[<2>%s of@ %a%a@]" name
732738
(print_typlist print_simple_out_type " *") tyl
739+
pp_unboxed unboxed
733740
end
734741
| Some ret_type ->
735742
begin match tyl with
736743
| [] ->
737-
fprintf ppf "@[<2>%s :@ %a@]" name print_simple_out_type ret_type
744+
fprintf ppf "@[<2>%s :@ %a%a@]" name
745+
print_simple_out_type ret_type
746+
pp_unboxed unboxed
738747
| _ ->
739-
fprintf ppf "@[<2>%s :@ %a -> %a@]" name
748+
fprintf ppf "@[<2>%s :@ %a -> %a%a@]" name
740749
(print_typlist print_simple_out_type " *")
741750
tyl print_simple_out_type ret_type
751+
pp_unboxed unboxed
742752
end
743753

744754
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
ocstr_name: string;
8383
ocstr_args: out_type list;
8484
ocstr_return_type: out_type option;
85+
ocstr_unboxed: bool;
8586
}
8687

8788
and out_variant =

typing/printtyp.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,11 +1420,13 @@ 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
14241425
| None -> {
14251426
ocstr_name = name;
14261427
ocstr_args = arg ();
14271428
ocstr_return_type = None;
1429+
ocstr_unboxed = unboxed;
14281430
}
14291431
| Some res ->
14301432
Names.with_local_names (fun () ->
@@ -1434,6 +1436,7 @@ and tree_of_constructor cd =
14341436
ocstr_name = name;
14351437
ocstr_args = args;
14361438
ocstr_return_type = Some ret;
1439+
ocstr_unboxed = unboxed;
14371440
})
14381441

14391442
and tree_of_label l =
@@ -1523,6 +1526,7 @@ let extension_only_constructor id ppf ext =
15231526
ocstr_name = name;
15241527
ocstr_args = args;
15251528
ocstr_return_type = ret;
1529+
ocstr_unboxed = false;
15261530
}
15271531

15281532
(* Print a value declaration *)

0 commit comments

Comments
 (0)