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

+1-1
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

+1-1
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

+4-2
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

+2-2
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+2-2
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

+5-6
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

parsing/jane_syntax.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ module Jkind : sig
199199

200200
type t =
201201
| Default
202-
| Primitive_layout_or_abbreviation of Const.t
202+
| Abbreviation of Const.t
203203
| Mod of t * Mode_expr.t
204204
| With of t * Parsetree.core_type
205205
| Kind_of of Parsetree.core_type

parsing/parser.mly

+1-2
Original file line numberDiff line numberDiff line change
@@ -3879,8 +3879,7 @@ jkind:
38793879
}
38803880
| mkrhs(ident) {
38813881
let {txt; loc} = $1 in
3882-
Jane_syntax.Jkind.(Primitive_layout_or_abbreviation
3883-
(Const.mk txt loc))
3882+
Jane_syntax.Jkind.(Abbreviation (Const.mk txt loc))
38843883
}
38853884
| KIND_OF ty=core_type {
38863885
Jane_syntax.Jkind.Kind_of ty

parsing/pprintast.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ and type_with_label ctxt f (label, c) =
377377

378378
and jkind ctxt f k = match (k : Jane_syntax.Jkind.t) with
379379
| Default -> pp f "_"
380-
| Primitive_layout_or_abbreviation s ->
380+
| Abbreviation s ->
381381
pp f "%s" (s : Jane_syntax.Jkind.Const.t :> _ loc).txt
382382
| Mod (t, { txt = mode_list }) ->
383383
begin match mode_list with

parsing/pprintast.mli

+1
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ val tyvar: Format.formatter -> string -> unit
5959
position, or for keywords by escaping them with \#. No-op on "_". *)
6060

6161
val jkind : Format.formatter -> Jane_syntax.Jkind.t -> unit
62+
val mode : Format.formatter -> Jane_syntax.Mode_expr.Const.t -> unit

testsuite/tests/language-extensions/pprintast_unconditional.ml

+4-1
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,12 @@ module Example = struct
120120
let tyvar = "no_tyvars_require_extensions"
121121
let jkind = Jane_syntax.Jkind.(
122122
With (
123-
Primitive_layout_or_abbreviation
123+
Abbreviation
124124
(Const.mk "value" loc),
125125
core_type
126126
))
127+
128+
let mode = Jane_syntax.Mode_expr.Const.mk "global" loc
127129
end
128130

129131
let print_test_header name =
@@ -205,6 +207,7 @@ end = struct
205207

206208
let tyvar = test "tyvar" tyvar Example.tyvar
207209
let jkind = test "jkind" jkind Example.jkind
210+
let mode = test "mode" mode Example.mode
208211
end
209212

210213

testsuite/tests/language-extensions/pprintast_unconditional.reference

+4
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ tyvar: 'no_tyvars_require_extensions
9595

9696
jkind: value with local_ ('a : value) -> unit
9797

98+
mode: global
99+
98100
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
99101

100102
##### Extensions disallowed
@@ -194,6 +196,8 @@ tyvar: 'no_tyvars_require_extensions
194196

195197
jkind: value with local_ ('a : value) -> unit
196198

199+
mode: global
200+
197201
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
198202

199203
##### Calling [Language_extension.For_pprintast.make_printer_exporter ()]

testsuite/tests/typing-layouts-arrays/basics.ml

+2
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ module M6_2 = struct
274274
let f2 idx : int32# = get arr idx
275275
end
276276

277+
(* CR layouts v2.8: The jkind in the error message is wrong. It should really be
278+
('a : layout float64) *)
277279
[%%expect{|
278280
Line 9, characters 24-35:
279281
9 | let f2 idx : int32# = get arr idx

0 commit comments

Comments
 (0)