Skip to content

Commit 01d586e

Browse files
authored
Better comment for unboxed version typechecking (#3809)
1 parent 1661e74 commit 01d586e

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

typing/typedecl.ml

+23-3
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,25 @@ let transl_declaration env sdecl (id, uid) =
10961096
decl, typ_shape
10971097
end
10981098

1099+
(* Note [Typechecking unboxed versions of types]
1100+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1101+
Unboxed versions are computed in three steps:
1102+
1103+
1. In the temporary environment computed by [enter_type], all types get an
1104+
unboxed version.
1105+
1106+
2. After translating declarations, [derive_unboxed_versions] gives the
1107+
[Record_boxed] records unboxed versions.
1108+
1109+
3. But some of these [Record_boxed]s are a lie, and become
1110+
[Record_float]/[Record_ufloat]/[Record_mixed] after [update_decls_jkind].
1111+
As float records should not end up with unboxed versions, we then remove
1112+
theirs in [remove_unboxed_versions].
1113+
1114+
After steps 2 and 3, the set of unboxed versions decreases, so we check for
1115+
newly-unbound unboxed paths with [check_unboxed_paths].
1116+
*)
1117+
10991118
(* Record declarations with representation [Record_boxed] get an implicit
11001119
unboxed record stored in [type_unboxed_version]. If that record is also an
11011120
alias, so is its stored unboxed version. E.g. [type t = r = { i : int }]'s
@@ -1215,9 +1234,9 @@ let derive_unboxed_versions decls env =
12151234
id, { d with type_unboxed_version })
12161235
decls
12171236

1218-
(* Float and [@@unboxed] records are typechecked as boxed records until
1219-
[update_decls_jkind], so their unboxed versions need to be removed
1220-
afterwards.
1237+
(* Removes unboxed versions from type declarations not satisfying
1238+
[gets_unboxed_version]. In practice, it is float records that lose their
1239+
unboxed versions. See Note [Typechecking unboxed versions of types].
12211240
12221241
Returns new decls and paths whose unboxed versions got removed. *)
12231242
let remove_unboxed_versions decls =
@@ -2056,6 +2075,7 @@ let update_decls_jkind env decls =
20562075
(id, decl, allow_any_crossing, update_decl_jkind env (Pident id) decl))
20572076
decls
20582077

2078+
(* See Note [Typechecking unboxed versions of types]. *)
20592079
let check_unboxed_paths decls ~unboxed_version_banned =
20602080
(* We iterate on all subexpressions of the declaration to check "in depth"
20612081
that no non-existent unboxed version is used. *)

0 commit comments

Comments
 (0)