Skip to content

Commit 74e6758

Browse files
liam923goldfirere
andauthored
flambda-backend: Support for mod syntax - unclean (#2717)
* Apply changes from PR 2676 as on 6/21/24 * Fix printing of unrepresentable jkinds * Resolve memoization issue in jkind.ml * Fix memoization in subst * Add crs for bad error messages * Mode crossing tests * Add more tests for soundness checks * Add more inference tests * Add tests for intersection behavior * Add test for modality annotations * Add gadt tests * Add tests for objects * Test externality axis interaction with mixed blocks * Add test for mutable record field * Fix memoization in sort * Hoist builtins in subst * Update incorrect CRs * Some tweaks in jkind tests during review --------- Co-authored-by: Richard Eisenberg <reisenberg@janestreet.com>
1 parent 8a2b699 commit 74e6758

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3929
-816
lines changed

debugger/loadprinter.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ let eval_value_path env path =
9393

9494
let match_printer_type desc make_printer_type =
9595
Ctype.with_local_level ~post:Ctype.generalize begin fun () ->
96-
let ty_arg = Ctype.newvar Jkind.(value ~why:Debug_printer_argument) in
96+
let ty_arg = Ctype.newvar (Jkind.Primitive.value ~why:Debug_printer_argument) in
9797
Ctype.unify (Lazy.force Env.initial)
9898
(make_printer_type ty_arg)
9999
(Ctype.instance desc.val_type);

debugger4/loadprinter.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ let eval_value_path env path =
9393

9494
let match_printer_type desc make_printer_type =
9595
Ctype.with_local_level ~post:Ctype.generalize begin fun () ->
96-
let ty_arg = Ctype.newvar Jkind.(value ~why:Debug_printer_argument) in
96+
let ty_arg = Ctype.newvar Jkind.Primitive.(value ~why:Debug_printer_argument) in
9797
Ctype.unify (Lazy.force Env.initial)
9898
(make_printer_type ty_arg)
9999
(Ctype.instance desc.val_type);

lambda/matching.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,10 @@ exception Error of Location.t * error
106106
let dbg = false
107107

108108
let jkind_layout_default_to_value_and_check_not_void loc jkind =
109-
match Jkind.get_default_value jkind with
110-
| Void -> raise (Error (loc, Void_layout))
109+
let const = Jkind.default_to_value_and_get jkind in
110+
let layout = Jkind.Const.get_layout const in
111+
match layout with
112+
| Sort Void -> raise (Error (loc, Void_layout))
111113
| _ -> ()
112114
;;
113115

lambda/translcore.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ let layout_exp sort e = layout e.exp_env e.exp_loc sort e.exp_type
5454
let layout_pat sort p = layout p.pat_env p.pat_loc sort p.pat_type
5555

5656
let check_record_field_sort loc sort =
57-
match Jkind.Sort.get_default_value sort with
57+
match Jkind.Sort.default_to_value_and_get sort with
5858
| Value | Float64 | Float32 | Bits32 | Bits64 | Word -> ()
5959
| Void -> raise (Error (loc, Illegal_void_record_field))
6060

@@ -1022,7 +1022,7 @@ and transl_exp0 ~in_new_scope ~scopes sort e =
10221022
match
10231023
Ctype.check_type_jkind
10241024
e.exp_env (Ctype.correct_levels val_type)
1025-
(Jkind.value ~why:Probe)
1025+
(Jkind.Primitive.value ~why:Probe)
10261026
with
10271027
| Ok _ -> ()
10281028
| Error _ -> raise (Error (e.exp_loc, Bad_probe_layout id))

lambda/translmod.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ let init_shape id modl =
300300
Tarrow(_,ty_arg,_,_) -> begin
301301
(* CR layouts: We should allow any representable layout here. It
302302
will require reworking [camlinternalMod.init_mod]. *)
303-
let jkind = Jkind.value ~why:Recmod_fun_arg in
303+
let jkind = Jkind.Primitive.value ~why:Recmod_fun_arg in
304304
let ty_arg = Ctype.correct_levels ty_arg in
305305
match Ctype.check_type_jkind env ty_arg jkind with
306306
| Ok _ -> const_int 0 (* camlinternalMod.Function *)

lambda/translprim.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ let to_modify_mode ~poly = function
143143
let extern_repr_of_native_repr:
144144
poly_sort:Jkind.Sort.t option -> Primitive.native_repr -> Lambda.extern_repr
145145
= fun ~poly_sort r -> match r, poly_sort with
146-
| Repr_poly, Some s -> Same_as_ocaml_repr (Jkind.Sort.get_default_value s)
146+
| Repr_poly, Some s -> Same_as_ocaml_repr (Jkind.Sort.default_to_value_and_get s)
147147
| Repr_poly, None -> Misc.fatal_error "Unexpected Repr_poly"
148148
| Same_as_ocaml_repr s, _ -> Same_as_ocaml_repr s
149149
| Unboxed_float f, _ -> Unboxed_float f

ocamldoc/odoc_sig.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ module Analyser =
493493
{ Typedtree.ld_id; ld_mutable; ld_type; ld_loc; ld_attributes } =
494494
get_field env comments @@
495495
{Types.ld_id; ld_mutable; ld_modalities = Mode.Modality.Value.id;
496-
ld_jkind=Jkind.any ~why:Dummy_jkind (* ignored *);
496+
ld_jkind=Jkind.Primitive.any ~why:Dummy_jkind (* ignored *);
497497
ld_type=ld_type.Typedtree.ctyp_type;
498498
ld_loc; ld_attributes; ld_uid=Types.Uid.internal_not_actually_unique} in
499499
let open Typedtree in

parsing/ast_iterator.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ let default_iterator =
10051005
jkind_annotation =
10061006
(fun this -> function
10071007
| Default -> ()
1008-
| Primitive_layout_or_abbreviation s ->
1008+
| Abbreviation s ->
10091009
iter_loc this (s : Jane_syntax.Jkind.Const.t :> _ loc)
10101010
| Mod (t, mode_list) ->
10111011
this.jkind_annotation this t;

parsing/ast_mapper.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,11 +1130,11 @@ let default_mapper =
11301130
let open Jane_syntax in
11311131
function
11321132
| Default -> Default
1133-
| Primitive_layout_or_abbreviation s ->
1133+
| Abbreviation s ->
11341134
let {txt; loc} =
11351135
map_loc this (s : Jkind.Const.t :> _ loc)
11361136
in
1137-
Primitive_layout_or_abbreviation (Jkind.Const.mk txt loc)
1137+
Abbreviation (Jkind.Const.mk txt loc)
11381138
| Mod (t, mode_list) ->
11391139
Mod (this.jkind_annotation this t, this.modes this mode_list)
11401140
| With (t, ty) ->

parsing/jane_syntax.ml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ module Jkind = struct
514514

515515
type t =
516516
| Default
517-
| Primitive_layout_or_abbreviation of Const.t
517+
| Abbreviation of Const.t
518518
| Mod of t * Mode_expr.t
519519
| With of t * core_type
520520
| Kind_of of core_type
@@ -571,8 +571,8 @@ module Jkind = struct
571571
let to_structure_item t = to_structure_item (Location.mknoloc t) in
572572
match t_loc.txt with
573573
| Default -> struct_item_of_list "default" [] t_loc.loc
574-
| Primitive_layout_or_abbreviation c ->
575-
struct_item_of_list "prim" [Const.to_structure_item c] t_loc.loc
574+
| Abbreviation c ->
575+
struct_item_of_list "abbrev" [Const.to_structure_item c] t_loc.loc
576576
| Mod (t, mode_list) ->
577577
let mode_list_item =
578578
struct_item_of_attr
@@ -607,9 +607,8 @@ module Jkind = struct
607607
ret loc (With (t, ty))))
608608
| Some ("kind_of", [item_of_ty], loc) ->
609609
bind (struct_item_to_type item_of_ty) (fun ty -> ret loc (Kind_of ty))
610-
| Some ("prim", [item], loc) ->
611-
bind (Const.of_structure_item item) (fun c ->
612-
ret loc (Primitive_layout_or_abbreviation c))
610+
| Some ("abbrev", [item], loc) ->
611+
bind (Const.of_structure_item item) (fun c -> ret loc (Abbreviation c))
613612
| Some _ | None -> None
614613
end
615614

0 commit comments

Comments
 (0)