Skip to content

Commit aba6294

Browse files
authored
Immediacy rework (#122)
* Make immediacy part of type_kind (backport PR #11841) * disable stack allocation for 32-bit CI build
1 parent cf4eeef commit aba6294

36 files changed

+441
-435
lines changed

.depend

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,6 @@ typing/persistent_env.cmi : \
11571157
file_formats/cmi_format.cmi
11581158
typing/predef.cmo : \
11591159
typing/types.cmi \
1160-
typing/type_immediacy.cmi \
11611160
typing/path.cmi \
11621161
parsing/parsetree.cmi \
11631162
parsing/location.cmi \
@@ -1168,7 +1167,6 @@ typing/predef.cmo : \
11681167
typing/predef.cmi
11691168
typing/predef.cmx : \
11701169
typing/types.cmx \
1171-
typing/type_immediacy.cmx \
11721170
typing/path.cmx \
11731171
parsing/parsetree.cmi \
11741172
parsing/location.cmx \
@@ -1513,7 +1511,6 @@ typing/typecore.cmo : \
15131511
typing/types.cmi \
15141512
typing/typedtree.cmi \
15151513
typing/typedecl.cmi \
1516-
typing/type_immediacy.cmi \
15171514
typing/subst.cmi \
15181515
typing/shape.cmi \
15191516
typing/rec_check.cmi \
@@ -1549,7 +1546,6 @@ typing/typecore.cmx : \
15491546
typing/types.cmx \
15501547
typing/typedtree.cmx \
15511548
typing/typedecl.cmx \
1552-
typing/type_immediacy.cmx \
15531549
typing/subst.cmx \
15541550
typing/shape.cmx \
15551551
typing/rec_check.cmx \
@@ -1598,9 +1594,7 @@ typing/typedecl.cmo : \
15981594
typing/types.cmi \
15991595
typing/typedtree.cmi \
16001596
typing/typedecl_variance.cmi \
1601-
typing/typedecl_unboxed.cmi \
16021597
typing/typedecl_separability.cmi \
1603-
typing/typedecl_immediacy.cmi \
16041598
typing/type_immediacy.cmi \
16051599
typing/subst.cmi \
16061600
typing/printtyp.cmi \
@@ -1633,9 +1627,7 @@ typing/typedecl.cmx : \
16331627
typing/types.cmx \
16341628
typing/typedtree.cmx \
16351629
typing/typedecl_variance.cmx \
1636-
typing/typedecl_unboxed.cmx \
16371630
typing/typedecl_separability.cmx \
1638-
typing/typedecl_immediacy.cmx \
16391631
typing/type_immediacy.cmx \
16401632
typing/subst.cmx \
16411633
typing/printtyp.cmx \
@@ -1667,7 +1659,7 @@ typing/typedecl.cmi : \
16671659
typing/typedtree.cmi \
16681660
typing/typedecl_variance.cmi \
16691661
typing/typedecl_separability.cmi \
1670-
typing/typedecl_immediacy.cmi \
1662+
typing/type_immediacy.cmi \
16711663
typing/path.cmi \
16721664
parsing/parsetree.cmi \
16731665
parsing/longident.cmi \
@@ -1677,29 +1669,6 @@ typing/typedecl.cmi : \
16771669
typing/errortrace.cmi \
16781670
typing/env.cmi \
16791671
parsing/asttypes.cmi
1680-
typing/typedecl_immediacy.cmo : \
1681-
typing/types.cmi \
1682-
typing/typedecl_unboxed.cmi \
1683-
typing/typedecl_properties.cmi \
1684-
typing/type_immediacy.cmi \
1685-
parsing/location.cmi \
1686-
typing/ctype.cmi \
1687-
typing/typedecl_immediacy.cmi
1688-
typing/typedecl_immediacy.cmx : \
1689-
typing/types.cmx \
1690-
typing/typedecl_unboxed.cmx \
1691-
typing/typedecl_properties.cmx \
1692-
typing/type_immediacy.cmx \
1693-
parsing/location.cmx \
1694-
typing/ctype.cmx \
1695-
typing/typedecl_immediacy.cmi
1696-
typing/typedecl_immediacy.cmi : \
1697-
typing/types.cmi \
1698-
typing/typedecl_properties.cmi \
1699-
typing/type_immediacy.cmi \
1700-
parsing/location.cmi \
1701-
typing/ident.cmi \
1702-
typing/env.cmi
17031672
typing/typedecl_properties.cmo : \
17041673
typing/types.cmi \
17051674
typing/ident.cmi \
@@ -1740,19 +1709,6 @@ typing/typedecl_separability.cmi : \
17401709
parsing/location.cmi \
17411710
typing/ident.cmi \
17421711
typing/env.cmi
1743-
typing/typedecl_unboxed.cmo : \
1744-
typing/types.cmi \
1745-
typing/env.cmi \
1746-
typing/ctype.cmi \
1747-
typing/typedecl_unboxed.cmi
1748-
typing/typedecl_unboxed.cmx : \
1749-
typing/types.cmx \
1750-
typing/env.cmx \
1751-
typing/ctype.cmx \
1752-
typing/typedecl_unboxed.cmi
1753-
typing/typedecl_unboxed.cmi : \
1754-
typing/types.cmi \
1755-
typing/env.cmi
17561712
typing/typedecl_variance.cmo : \
17571713
typing/types.cmi \
17581714
typing/typedtree.cmi \
@@ -1917,8 +1873,6 @@ typing/typemod.cmi : \
19171873
typing/typeopt.cmo : \
19181874
typing/types.cmi \
19191875
typing/typedtree.cmi \
1920-
typing/typedecl_unboxed.cmi \
1921-
typing/type_immediacy.cmi \
19221876
typing/predef.cmi \
19231877
typing/path.cmi \
19241878
utils/numbers.cmi \
@@ -1928,14 +1882,11 @@ typing/typeopt.cmo : \
19281882
typing/env.cmi \
19291883
typing/ctype.cmi \
19301884
utils/config.cmi \
1931-
utils/clflags.cmi \
19321885
parsing/asttypes.cmi \
19331886
typing/typeopt.cmi
19341887
typing/typeopt.cmx : \
19351888
typing/types.cmx \
19361889
typing/typedtree.cmx \
1937-
typing/typedecl_unboxed.cmx \
1938-
typing/type_immediacy.cmx \
19391890
typing/predef.cmx \
19401891
typing/path.cmx \
19411892
utils/numbers.cmx \
@@ -1945,7 +1896,6 @@ typing/typeopt.cmx : \
19451896
typing/env.cmx \
19461897
typing/ctype.cmx \
19471898
utils/config.cmx \
1948-
utils/clflags.cmx \
19491899
parsing/asttypes.cmi \
19501900
typing/typeopt.cmi
19511901
typing/typeopt.cmi : \

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
ocamlrunparam: "v=0,V=1"
2323

2424
- name: i386
25-
config: CC='cc32' AS='as --32' ASPP='gcc -m32 -c' -host i386-linux PARTIALLD='ld -r -melf_i386'
25+
config: --enable-stack-allocation=no CC='cc32' AS='as --32' ASPP='gcc -m32 -c' -host i386-linux PARTIALLD='ld -r -melf_i386'
2626
os: ubuntu-20.04
2727
ocamlparam: ''
2828
boot_config: CC='cc32' AS='as --32' ASPP='gcc -m32 -c' -host i386-linux PARTIALLD='ld -r -melf_i386'

boot/ocamlc

-1.48 KB
Binary file not shown.

boot/ocamllex

0 Bytes
Binary file not shown.

compilerlibs/Makefile.compilerlibs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ TYPING = \
115115
typing/parmatch.cmo \
116116
typing/typedecl_properties.cmo \
117117
typing/typedecl_variance.cmo \
118-
typing/typedecl_unboxed.cmo \
119-
typing/typedecl_immediacy.cmo \
120118
typing/typedecl_separability.cmo \
121119
lambda/debuginfo.cmo lambda/lambda.cmo \
122120
typing/typedecl.cmo \

configure

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,8 +2037,11 @@ AS_IF([test x"$DEFAULT_STRING" = "xunsafe"],
20372037

20382038
AS_IF([test x"$enable_stack_allocation" = "xno"],
20392039
[stack_allocation=false],
2040-
[AC_DEFINE([STACK_ALLOCATION])
2041-
stack_allocation=true])
2040+
[AS_IF([$arch64],
2041+
[AC_DEFINE([STACK_ALLOCATION])
2042+
stack_allocation=true],
2043+
[AC_MSG_ERROR([Stack allocation is only supported on 64-bit platforms. \
2044+
Please pass '--enable-stack-allocation=no'.])])])
20422045

20432046
AS_IF([test x"$enable_poll_insertion" = "xyes"],
20442047
[AC_DEFINE([POLL_INSERTION])

dune

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@
8080
includemod includemod_errorprinter
8181
typetexp patterns printpat parmatch stypes typedecl typeopt rec_check
8282
typecore
83-
typeclass typemod typedecl_variance typedecl_properties typedecl_immediacy
84-
typedecl_unboxed typedecl_separability cmt2annot
83+
typeclass typemod typedecl_variance typedecl_properties
84+
typedecl_separability cmt2annot
8585
; manual update: mli only files
8686
annot outcometree
8787

@@ -307,8 +307,6 @@
307307
(typemod.mli as compiler-libs/typemod.mli)
308308
(typedecl_variance.mli as compiler-libs/typedecl_variance.mli)
309309
(typedecl_properties.mli as compiler-libs/typedecl_properties.mli)
310-
(typedecl_immediacy.mli as compiler-libs/typedecl_immediacy.mli)
311-
(typedecl_unboxed.mli as compiler-libs/typedecl_unboxed.mli)
312310
(typedecl_separability.mli as compiler-libs/typedecl_separability.mli)
313311
(annot.mli as compiler-libs/annot.mli)
314312
(outcometree.mli as compiler-libs/outcometree.mli)

ocamldoc/odoc_sig.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ module Analyser =
371371

372372
let get_type_kind env name_comment_list type_kind =
373373
match type_kind with
374-
Types.Type_abstract ->
374+
Types.Type_abstract _ ->
375375
Odoc_type.Type_abstract
376376
| Types.Type_variant (l,_) ->
377377
let f {Types.cd_id=constructor_name;cd_args;cd_res=ret_type} =

testsuite/tests/typing-immediate/immediate.ml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ module A = struct
2424
(* Mutually recursive declarations work as well *)
2525
type p = q [@@immediate]
2626
and q = int
27+
28+
(* Variants with only constant constructors are immediate *)
29+
type o = Foo | Bar | Baz [@@immediate]
30+
31+
(* Can declare with a weaker immediacy than necessary *)
32+
type m = int [@@immediate64]
33+
34+
(* ... and yet use the stronger one by expansion later *)
35+
type n = m [@@immediate]
2736
end;;
2837
[%%expect{|
2938
module A :
@@ -33,6 +42,9 @@ module A :
3342
type r = s
3443
type p = q [@@immediate]
3544
and q = int
45+
type o = Foo | Bar | Baz
46+
type m = int [@@immediate64]
47+
type n = m [@@immediate]
3648
end
3749
|}];;
3850

@@ -60,6 +72,22 @@ module Empty_valid : S = struct type t = | end;;
6072
module Empty_valid : S
6173
|}];;
6274

75+
(* Valid when unboxed *)
76+
module Unboxed_valid = struct
77+
type t = { x : int } [@@unboxed] [@@immediate]
78+
79+
type u = { x : s } [@@unboxed] [@@immediate]
80+
and s = int
81+
end;;
82+
[%%expect{|
83+
module Unboxed_valid :
84+
sig
85+
type t = { x : int; } [@@unboxed]
86+
type u = { x : s; } [@@unboxed]
87+
and s = int
88+
end
89+
|}];;
90+
6391
(* Practical usage over modules *)
6492
module Foo : sig type t val x : t ref end = struct
6593
type t = int
@@ -119,6 +147,30 @@ Error: Types marked with the immediate attribute must be non-pointer types
119147
like int or bool.
120148
|}];;
121149

150+
(* Cannot directly declare a non-immediate type as immediate (variant) *)
151+
module B = struct
152+
type t = Foo of int | Bar [@@immediate]
153+
end;;
154+
[%%expect{|
155+
Line 2, characters 2-41:
156+
2 | type t = Foo of int | Bar [@@immediate]
157+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
158+
Error: Types marked with the immediate attribute must be non-pointer types
159+
like int or bool.
160+
|}];;
161+
162+
(* Cannot directly declare a non-immediate type as immediate (record) *)
163+
module B = struct
164+
type t = { foo : int } [@@immediate]
165+
end;;
166+
[%%expect{|
167+
Line 2, characters 2-38:
168+
2 | type t = { foo : int } [@@immediate]
169+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
170+
Error: Types marked with the immediate attribute must be non-pointer types
171+
like int or bool.
172+
|}];;
173+
122174
(* Not guaranteed that t is immediate, so this is an invalid declaration *)
123175
module C = struct
124176
type t
@@ -181,3 +233,53 @@ Line 2, characters 2-26:
181233
Error: Types marked with the immediate attribute must be non-pointer types
182234
like int or bool.
183235
|}];;
236+
237+
238+
(* Aliases should be expanded to check immediacy *)
239+
type 'a id = 'a
240+
type s = int id [@@immediate]
241+
[%%expect{|
242+
type 'a id = 'a
243+
type s = int id [@@immediate]
244+
|}];;
245+
module F (X : sig type t end) = X
246+
module I = struct type t = int end
247+
type t = F(I).t [@@immediate]
248+
[%%expect{|
249+
module F : functor (X : sig type t end) -> sig type t = X.t end
250+
module I : sig type t = int end
251+
type t = F(I).t [@@immediate]
252+
|}];;
253+
module F (X : sig type t end) = X
254+
module I : sig type t = private int end = struct type t = int end
255+
type t = F(I).t [@@immediate]
256+
[%%expect{|
257+
module F : functor (X : sig type t end) -> sig type t = X.t end
258+
module I : sig type t = private int end
259+
type t = F(I).t [@@immediate]
260+
|}];;
261+
module type T = sig type t type s = t end
262+
module F (X : T with type t = int) = struct
263+
type t = X.s [@@immediate]
264+
end
265+
[%%expect{|
266+
module type T = sig type t type s = t end
267+
module F :
268+
functor (X : sig type t = int type s = t end) ->
269+
sig type t = X.s [@@immediate] end
270+
|}];;
271+
module type T = sig type t type s = t end
272+
module F (X : T with type t = private int) = struct
273+
type t = X.s [@@immediate]
274+
end
275+
[%%expect{|
276+
module type T = sig type t type s = t end
277+
module F :
278+
functor (X : sig type t = private int type s = t end) ->
279+
sig type t = X.s [@@immediate] end
280+
|}];;
281+
type t = int s [@@immediate] and 'a s = 'a
282+
[%%expect{|
283+
type t = int s [@@immediate]
284+
and 'a s = 'a
285+
|}];;

toplevel/genprintval.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,9 @@ module Make(O : OBJ)(EVP : EVALPATH with type valu = O.t) = struct
366366
try
367367
let decl = Env.find_type path env in
368368
match decl with
369-
| {type_kind = Type_abstract; type_manifest = None} ->
369+
| {type_kind = Type_abstract _; type_manifest = None} ->
370370
Oval_stuff "<abstr>"
371-
| {type_kind = Type_abstract; type_manifest = Some body} ->
371+
| {type_kind = Type_abstract _; type_manifest = Some body} ->
372372
tree_of_val depth obj
373373
(instantiate_type env decl.type_params ty_list body)
374374
| {type_kind = Type_variant (constr_list,rep)} ->

typing/btype.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ let map_type_expr_cstr_args f = function
324324
Cstr_record (List.map (fun d -> {d with ld_type=f d.ld_type}) lbls)
325325

326326
let iter_type_expr_kind f = function
327-
| Type_abstract -> ()
327+
| Type_abstract _ -> ()
328328
| Type_variant (cstrs, _) ->
329329
List.iter
330330
(fun cd ->

0 commit comments

Comments
 (0)