Skip to content

Commit 6806a00

Browse files
authored
flambda-backend: Support for mod syntax (#2676)
* Promote tests that remove redundant kind from error message history * Rename Primitive to Builtin * Remove Const.Sort and Const.Layout aliases * Remove pointless const definition * Remove stale crs about eg layout_float64 * Remove legacy layout usage in printing * Remove legacy layout usage in extension universe check * Rename has_imported_history to is_imported * Remove Legacy module * Remove unused builtins * Move const_of_user_written_annotation into Const module * Update comment * Remove redundant layout definition * Remove unnecessary layout aliases * Document jkind printing * Rename ModeParser to Mode_parser * Fix cr formatting * Remove stale cr * Remove incorrect CRs * Replace any with abstract layout in error message * Assert layout is value in value_kind_of_value_jkind * Don't print : value * Add CRs to remove annotation * Improve debug printing * Share parsing logic between modes and jkinds * Simplify parsing * Add tests * Create test for not calling caml_modify * Reformat files * Add comments to caml_modify test * Rename external_record to internal_record * Hide external_variant's immediacy * Add inlining test for caml_modify * Add copyright header * Clean up typemodifier * Fix prining typo * Add CR to Builtin * Stop calling crossing of nullability mode-crossing * Improve warning 211 message * Restore PRs about incorrect error messages * Cleanup typemodifier more * Fix bug in required maturity level for modes * Fix floatarray kind and promote tests
1 parent e3ea46b commit 6806a00

Some content is hidden

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

71 files changed

+1296
-1184
lines changed

boot/menhir/parser.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41625,7 +41625,7 @@ module Tables = struct
4162541625
>>>>>>> origin/main
4162641626
(
4162741627
let {txt; loc} = _1 in
41628-
Jane_syntax.Jkind.(Primitive_layout_or_abbreviation
41628+
Jane_syntax.Jkind.(Builtin_layout_or_abbreviation
4162941629
(Const.mk txt loc))
4163041630
)
4163141631
<<<<<<< HEAD

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.Primitive.value ~why:Debug_printer_argument) in
96+
let ty_arg = Ctype.newvar (Jkind.Builtin.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.Primitive.(value ~why:Debug_printer_argument) in
96+
let ty_arg = Ctype.newvar Jkind.Builtin.(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);

dune

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
typedtree printtyped ctype printtyp includeclass mtype envaux includecore
109109
tast_iterator tast_mapper signature_group cmt_format cms_format untypeast
110110
includemod includemod_errorprinter
111-
typemode typetexp patterns printpat parmatch stypes typedecl typeopt
111+
typemode typemodifier typetexp patterns printpat parmatch stypes typedecl typeopt
112112
value_rec_check typecore solver_intf solver mode_intf mode uniqueness_analysis
113113
typeclass typemod typedecl_variance typedecl_properties
114114
typedecl_separability cmt2annot
@@ -334,6 +334,7 @@
334334
(untypeast.mli as compiler-libs/untypeast.mli)
335335
(includemod.mli as compiler-libs/includemod.mli)
336336
(typemode.mli as compiler-libs/typemode.mli)
337+
(typemodifier.mli as compiler-libs/typemodifier.mli)
337338
(typetexp.mli as compiler-libs/typetexp.mli)
338339
(printpat.mli as compiler-libs/printpat.mli)
339340
(parmatch.mli as compiler-libs/parmatch.mli)

lambda/translcore.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ and transl_exp0 ~in_new_scope ~scopes sort e =
10861086
(* CR layouts v3: here we allow [value_or_null] because this check
10871087
happens too late for the typecheker to infer [non_null]. Test that
10881088
nothing breaks once we have null pointers. *)
1089-
(Jkind.Primitive.value_or_null ~why:Probe)
1089+
(Jkind.Builtin.value_or_null ~why:Probe)
10901090
with
10911091
| Ok _ -> ()
10921092
| 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.Primitive.value ~why:Recmod_fun_arg in
303+
let jkind = Jkind.Builtin.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 *)

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.Const.id;
496-
ld_jkind=Jkind.Primitive.any ~why:Dummy_jkind (* ignored *);
496+
ld_jkind=Jkind.Builtin.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

otherlibs/dynlink/dune

+5
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
zero_alloc
9898
types
9999
oprint
100+
typemodifier
100101
jkind
101102
value_rec_types
102103
btype
@@ -195,6 +196,7 @@
195196
(copy_files ../../typing/jkind.ml)
196197
(copy_files ../../typing/jkind_intf.ml)
197198
(copy_files ../../typing/jkind_types.ml)
199+
(copy_files ../../typing/typemodifier.ml)
198200
(copy_files ../../typing/oprint.ml)
199201
(copy_files ../../typing/primitive.ml)
200202
(copy_files ../../typing/shape.ml)
@@ -266,6 +268,7 @@
266268
(copy_files ../../typing/jkind.mli)
267269
(copy_files ../../typing/jkind_intf.mli)
268270
(copy_files ../../typing/jkind_types.mli)
271+
(copy_files ../../typing/typemodifier.mli)
269272
(copy_files ../../typing/oprint.mli)
270273
(copy_files ../../typing/primitive.mli)
271274
(copy_files ../../typing/shape.mli)
@@ -390,6 +393,7 @@
390393
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Attr_helper.cmo
391394
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Primitive.cmo
392395
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Oprint.cmo
396+
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Typemodifier.cmo
393397
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Jkind.cmo
394398
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Btype.cmo
395399
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Subst.cmo
@@ -475,6 +479,7 @@
475479
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Attr_helper.cmx
476480
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Primitive.cmx
477481
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Oprint.cmx
482+
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Typemodifier.cmx
478483
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Jkind.cmx
479484
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Btype.cmx
480485
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Subst.cmx

testsuite/tests/typing-immediate/immediate.ml

+5-5
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Line 2, characters 2-31:
144144
2 | type t = string [@@immediate]
145145
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
146146
Error: The kind of type string is immutable_data
147-
because it is the primitive immutable_data type string.
147+
because it is the primitive type string.
148148
But the kind of type string must be a subkind of immediate
149149
because of the definition of t at line 2, characters 2-31.
150150
|}];;
@@ -214,7 +214,7 @@ Error: Signature mismatch:
214214
is not included in
215215
type t : immediate
216216
The kind of the first is immutable_data
217-
because it is the primitive immutable_data type string.
217+
because it is the primitive type string.
218218
But the kind of the first must be a subkind of immediate
219219
because of the definition of t at line 1, characters 15-35.
220220
|}];;
@@ -232,7 +232,7 @@ Error: Signature mismatch:
232232
is not included in
233233
type t : immediate
234234
The kind of the first is immutable_data
235-
because it is the primitive immutable_data type string.
235+
because it is the primitive type string.
236236
But the kind of the first must be a subkind of immediate
237237
because of the definition of t at line 1, characters 20-40.
238238
|}];;
@@ -249,7 +249,7 @@ Error: Modules do not match: sig type t = string end is not included in
249249
is not included in
250250
type t : immediate
251251
The kind of the first is immutable_data
252-
because it is the primitive immutable_data type string.
252+
because it is the primitive type string.
253253
But the kind of the first must be a subkind of immediate
254254
because of the definition of t at line 1, characters 20-40.
255255
|}];;
@@ -264,7 +264,7 @@ Line 2, characters 2-26:
264264
2 | type t = s [@@immediate]
265265
^^^^^^^^^^^^^^^^^^^^^^^^
266266
Error: The kind of type s is immutable_data
267-
because it is the primitive immutable_data type string.
267+
because it is the primitive type string.
268268
But the kind of type s must be a subkind of immediate
269269
because of the definition of t at line 2, characters 2-26.
270270
|}];;

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Line 1, characters 27-28:
8989
Error: This expression has type float# array
9090
but an expression was expected of type 'a array
9191
The layout of float# is float64
92-
because it is the primitive float64 type float#.
92+
because it is the primitive type float#.
9393
But the layout of float# must be a sublayout of value
9494
because of layout requirements from an imported definition.
9595
|}];;
@@ -102,7 +102,7 @@ Line 1, characters 40-41:
102102
Error: This expression has type float# array
103103
but an expression was expected of type 'a array
104104
The layout of float# is float64
105-
because it is the primitive float64 type float#.
105+
because it is the primitive type float#.
106106
But the layout of float# must be a sublayout of value
107107
because of layout requirements from an imported definition.
108108
|}];;
@@ -255,7 +255,7 @@ Line 11, characters 79-82:
255255
Error: This expression has type int64# but an expression was expected of type
256256
('a : bits32)
257257
The layout of int64# is bits64
258-
because it is the primitive bits64 type int64#.
258+
because it is the primitive type int64#.
259259
But the layout of int64# must be a sublayout of bits32
260260
because of the definition of get_third at lines 4-7, characters 16-23.
261261
|}]
@@ -280,7 +280,7 @@ Line 9, characters 24-35:
280280
Error: This expression has type ('a : float64)
281281
but an expression was expected of type int32#
282282
The layout of int32# is bits32
283-
because it is the primitive bits32 type int32#.
283+
because it is the primitive type int32#.
284284
But the layout of int32# must be a sublayout of float64
285285
because of the definition of arr at line 6, characters 12-16.
286286
|}]

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Line 1, characters 27-28:
8686
Error: This expression has type float# array
8787
but an expression was expected of type 'a array
8888
The layout of float# is float64
89-
because it is the primitive float64 type float#.
89+
because it is the primitive type float#.
9090
But the layout of float# must be a sublayout of value
9191
because of layout requirements from an imported definition.
9292
|}];;
@@ -99,7 +99,7 @@ Line 1, characters 40-41:
9999
Error: This expression has type float# array
100100
but an expression was expected of type 'a array
101101
The layout of float# is float64
102-
because it is the primitive float64 type float#.
102+
because it is the primitive type float#.
103103
But the layout of float# must be a sublayout of value
104104
because of layout requirements from an imported definition.
105105
|}];;
@@ -253,7 +253,7 @@ Line 11, characters 79-82:
253253
Error: This expression has type int64# but an expression was expected of type
254254
('a : bits32)
255255
The layout of int64# is bits64
256-
because it is the primitive bits64 type int64#.
256+
because it is the primitive type int64#.
257257
But the layout of int64# must be a sublayout of bits32
258258
because of the definition of get_third at lines 4-7, characters 16-23.
259259
|}]
@@ -278,7 +278,7 @@ Line 9, characters 24-35:
278278
Error: This expression has type ('a : float64)
279279
but an expression was expected of type int32#
280280
The layout of int32# is bits32
281-
because it is the primitive bits32 type int32#.
281+
because it is the primitive type int32#.
282282
But the layout of int32# must be a sublayout of float64
283283
because of the definition of arr at line 6, characters 12-16.
284284
|}]

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Line 25, characters 13-29:
5353
Error: This expression has type Float_u.t = float#
5454
but an expression was expected of type ('a : value)
5555
The layout of Float_u.t is float64
56-
because it is the primitive float64 type float#.
56+
because it is the primitive type float#.
5757
But the layout of Float_u.t must be a sublayout of value
5858
because it's the element type of array comprehension.
5959
|}];;

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Line 1, characters 24-25:
142142
Error: This expression has type int32# but an expression was expected of type
143143
('a : value)
144144
The layout of int32# is bits32
145-
because it is the primitive bits32 type int32#.
145+
because it is the primitive type int32#.
146146
But the layout of int32# must be a sublayout of value
147147
because it's the type of a tuple element.
148148
|}];;
@@ -166,7 +166,7 @@ Line 1, characters 18-24:
166166
^^^^^^
167167
Error: Tuple element types must have layout value.
168168
The layout of int32# is bits32
169-
because it is the primitive bits32 type int32#.
169+
because it is the primitive type int32#.
170170
But the layout of int32# must be a sublayout of value
171171
because it's the type of a tuple element.
172172
|}];;
@@ -306,7 +306,7 @@ Line 1, characters 31-37:
306306
^^^^^^
307307
Error: This type signature for x is not a value type.
308308
The layout of type int32# is bits32
309-
because it is the primitive bits32 type int32#.
309+
because it is the primitive type int32#.
310310
But the layout of type int32# must be a sublayout of value
311311
because it's the type of something stored in a module structure.
312312
|}];;
@@ -348,7 +348,7 @@ Line 1, characters 27-28:
348348
Error: This expression has type int32# but an expression was expected of type
349349
('a : value)
350350
The layout of int32# is bits32
351-
because it is the primitive bits32 type int32#.
351+
because it is the primitive type int32#.
352352
But the layout of int32# must be a sublayout of value
353353
because it's the type of the field of a polymorphic variant.
354354
|}];;
@@ -426,7 +426,7 @@ Line 1, characters 20-36:
426426
Error: This expression has type int32# but an expression was expected of type
427427
('a : value)
428428
The layout of int32# is bits32
429-
because it is the primitive bits32 type int32#.
429+
because it is the primitive type int32#.
430430
But the layout of int32# must be a sublayout of value
431431
because of the definition of id_value at line 5, characters 13-18.
432432
|}];;
@@ -631,7 +631,7 @@ Line 1, characters 26-43:
631631
^^^^^^^^^^^^^^^^^
632632
Error: The method x has type int32# but is expected to have type ('a : value)
633633
The layout of int32# is bits32
634-
because it is the primitive bits32 type int32#.
634+
because it is the primitive type int32#.
635635
But the layout of int32# must be a sublayout of value
636636
because it's the type of an object field.
637637
|}];;
@@ -643,7 +643,7 @@ Line 1, characters 26-40:
643643
^^^^^^^^^^^^^^
644644
Error: Variables bound in a class must have layout value.
645645
The layout of x is bits32
646-
because it is the primitive bits32 type int32#.
646+
because it is the primitive type int32#.
647647
But the layout of x must be a sublayout of value
648648
because it's the type of an instance variable.
649649
|}];;

testsuite/tests/typing-layouts-bits32/basics_alpha.ml

+7-7
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Line 1, characters 24-25:
140140
Error: This expression has type int32# but an expression was expected of type
141141
('a : value_or_null)
142142
The layout of int32# is bits32
143-
because it is the primitive bits32 type int32#.
143+
because it is the primitive type int32#.
144144
But the layout of int32# must be a sublayout of value
145145
because it's the type of a tuple element.
146146
|}];;
@@ -164,7 +164,7 @@ Line 1, characters 18-24:
164164
^^^^^^
165165
Error: Tuple element types must have layout value.
166166
The layout of int32# is bits32
167-
because it is the primitive bits32 type int32#.
167+
because it is the primitive type int32#.
168168
But the layout of int32# must be a sublayout of value
169169
because it's the type of a tuple element.
170170
|}];;
@@ -295,7 +295,7 @@ Line 1, characters 31-37:
295295
^^^^^^
296296
Error: This type signature for x is not a value type.
297297
The layout of type int32# is bits32
298-
because it is the primitive bits32 type int32#.
298+
because it is the primitive type int32#.
299299
But the layout of type int32# must be a sublayout of value
300300
because it's the type of something stored in a module structure.
301301
|}];;
@@ -337,7 +337,7 @@ Line 1, characters 27-28:
337337
Error: This expression has type int32# but an expression was expected of type
338338
('a : value_or_null)
339339
The layout of int32# is bits32
340-
because it is the primitive bits32 type int32#.
340+
because it is the primitive type int32#.
341341
But the layout of int32# must be a sublayout of value
342342
because it's the type of the field of a polymorphic variant.
343343
|}];;
@@ -415,7 +415,7 @@ Line 1, characters 20-36:
415415
Error: This expression has type int32# but an expression was expected of type
416416
('a : value_or_null)
417417
The layout of int32# is bits32
418-
because it is the primitive bits32 type int32#.
418+
because it is the primitive type int32#.
419419
But the layout of int32# must be a sublayout of value
420420
because of the definition of id_value at line 5, characters 13-18.
421421
|}];;
@@ -620,7 +620,7 @@ Line 1, characters 26-43:
620620
^^^^^^^^^^^^^^^^^
621621
Error: The method x has type int32# but is expected to have type ('a : value)
622622
The layout of int32# is bits32
623-
because it is the primitive bits32 type int32#.
623+
because it is the primitive type int32#.
624624
But the layout of int32# must be a sublayout of value
625625
because it's the type of an object field.
626626
|}];;
@@ -632,7 +632,7 @@ Line 1, characters 26-40:
632632
^^^^^^^^^^^^^^
633633
Error: Variables bound in a class must have layout value.
634634
The layout of x is bits32
635-
because it is the primitive bits32 type int32#.
635+
because it is the primitive type int32#.
636636
But the layout of x must be a sublayout of value
637637
because it's the type of an instance variable.
638638
|}];;

0 commit comments

Comments
 (0)