Skip to content

Commit 3f6d004

Browse files
committed
Clarify object row strengthening contracts
Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
1 parent d27d93b commit 3f6d004

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

compiler/ml/ctype.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2707,9 +2707,9 @@ let filter_object_field_for_write env name ty :
27072707
| Tobject f -> write_field ~can_promote:(is_Tvar (object_row ty)) f
27082708
| _ -> Error Owrite_missing
27092709

2710-
(* Require a readable [name] field and return its type. An open object row can
2711-
acquire the missing field; a closed row cannot. This operation does not
2712-
require or introduce write capability. *)
2710+
(* Require a readable [name] field and return its type. If lookup reaches a
2711+
[Tvar] row terminator, it can acquire the missing field. Rigid and closed
2712+
rows cannot. This operation does not require or introduce write capability. *)
27132713
let filter_method env name ty =
27142714
let ty = expand_head_trace env ty in
27152715
match ty.desc with

compiler/ml/ctype.mli

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,20 +243,23 @@ val filter_arrow_n :
243243

244244
val filter_method : Env.t -> string -> type_expr -> type_expr
245245
(** Constrain a type to have the named readable object field and return the
246-
field's stored type. A missing field extends an open row as [Immutable].
247-
A closed row without the field, or a non-object type which cannot be
248-
constrained to an object, raises [Unify]. *)
246+
field's stored type. If lookup reaches a [Tvar] row terminator, a missing
247+
field extends that inferred row as [Immutable]. A row ending in [Tunivar],
248+
[Tconstr], or [Tnil] cannot acquire a missing field. A non-object type which
249+
cannot be constrained to an object also raises [Unify]. *)
249250

250251
type object_field_write_error = Owrite_missing | Owrite_not_mutable
251252

252253
val filter_object_field_for_write :
253254
Env.t -> string -> type_expr -> (type_expr, object_field_write_error) Result.t
254255
(** Constrain a type for assignment to the named object field.
255256
256-
A mutable field returns its stored type. On an open row, an immutable field
257-
is promoted without changing its type, and a missing field is added as
258-
mutable. On a closed row, these cases return [Owrite_not_mutable] and
259-
[Owrite_missing], respectively. *)
257+
A mutable field returns its stored type. When the object row ends in a
258+
[Tvar], an immutable field is promoted without changing its type, and a
259+
missing field is added as mutable. [Tunivar] and private-row [Tconstr]
260+
terminators are structurally open but cannot be strengthened. With either
261+
of those terminators, or with [Tnil], an immutable field returns
262+
[Owrite_not_mutable] and a missing field returns [Owrite_missing]. *)
260263

261264
val occur_in : Env.t -> type_expr -> type_expr -> bool
262265
val deep_occur : type_expr -> type_expr -> bool

0 commit comments

Comments
 (0)