Skip to content

Commit

Permalink
comments from the meeting
Browse files Browse the repository at this point in the history
  • Loading branch information
riaqn committed Jun 17, 2024
1 parent 2c7f08a commit 168da42
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ocaml/typing/env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -877,12 +877,15 @@ let md md_type =

(** The caller is not interested in modes, and thus [val_modalities] is
invalidated. *)
(* CR zqian: this is not needed *)
let vda_description vda =
let vda_description = vda.vda_description in
{vda_description with val_modalities = Mode.Modality.Value.undefined}

(** The caller wants the mode of the [value_data] *)
(* CR zqian: call this [normalize_vda_mode] *)
let apply_val_modalities vda =
(* CR zqian: either inline this, or move to [types.ml] *)
let decouple_val_modalities (vd : Subst.Lazy.value_description) =
let modalities = vd.val_modalities in
let vd = {vd with val_modalities = Mode.Modality.Value.id |> Mode.Modality.Value.internalize} in
Expand Down Expand Up @@ -1295,6 +1298,8 @@ let find_cltype path env =
(NameMap.find s sc.comp_cltypes).cltda_declaration
| Papply _ | Pextra_ty _ -> raise Not_found

(* Have two versions, one takes path, one takes identity. The first doesn't run
locks, the second does. *)
let find_value path env =
let data, locks = find_value_full path env in
let data = apply_val_modalities data in
Expand Down Expand Up @@ -1823,6 +1828,7 @@ let rec components_of_module_maker
Lazy_backtrack.create addr
in
(* structures are always legacy *)
(* CR zqian: rename this to [module_mode] *)
let mmode = Mode.Value.legacy |> Mode.Value.disallow_right in
List.iter (fun ((item : Subst.Lazy.signature_item), path) ->
match item with
Expand Down Expand Up @@ -3429,6 +3435,7 @@ let lookup_value ~errors ~use ~loc lid env =
let path, locks, vda =
lookup_value_lazy ~errors ~use ~loc lid env
in
(* CR zqian: add comments about the ordering the applying modality and walk_locks *)
let vda = apply_val_modalities vda in
let vd = Subst.Lazy.force_value_description vda.vda_description in
let vmode =
Expand Down Expand Up @@ -3774,6 +3781,7 @@ let fold_modules f lid env acc =
acc
end

(* CR zqian: also passes mode in additional vda_description *)
let fold_values f =
find_all wrap_value (fun env -> env.values) (fun sc -> sc.comp_values)
(fun k p ve acc ->
Expand Down
5 changes: 5 additions & 0 deletions ocaml/typing/mode_intf.mli
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ module type S = sig
val value_to_alloc_r2g : ('l * 'r) Value.t -> ('l * 'r) Alloc.t

module Modality : sig
(* CR zqian: have [const] and [var], and an injection from [const] to [var]. *)
type _user = private User

type _internal = private Internal
Expand Down Expand Up @@ -498,13 +499,15 @@ module type S = sig
val apply_left : 'd t -> (allowed * 'r) Value.t -> Value.l

(** [cons m t] returns the modality that is [m] after [t]. *)
(* CR zqian: call this [compose]. *)
val cons : atom -> user -> user

(** [singleton m] returns the modality containing only [m]. *)
val singleton : atom -> user

(** Returns the list of [atom] in the given modality. The list is
commutative. *)
(* CR zqian: return record, then we don't need [Exist.t]. *)
val to_list : user -> atom list

type error =
Expand All @@ -528,6 +531,7 @@ module type S = sig
(** Printing for debugging. *)
val print : Format.formatter -> 'd t -> unit

(* CR zqian: consider spliting the [lr]. Also, label the arguments. *)
val infer : Value.lr -> Value.l -> internal

(** Returns a user modality weaker than the given modality. The returned
Expand All @@ -544,6 +548,7 @@ module type S = sig

(** Returns a user modality by asserting the given modality is already
user modality and returning it. *)
(* CR zqian: rename to [to_const_exn]. *)
val zap_assert : 'd t -> user

(** The top modality; [sub x max] succeeds for any [x]. *)
Expand Down
1 change: 1 addition & 0 deletions ocaml/typing/typemod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2875,6 +2875,7 @@ and type_structure ?(toplevel = None) funct_body anchor env sstr =
let vd, mode = Env.find_value (Pident id) newenv in
let vd = Subst.Lazy.force_value_description vd in
(* structures are always legacy *)
(* CR zqian: rename this to [module_mode] *)
let mmode = Mode.Value.legacy in
begin match Mode.Value.Comonadic.submode
mode.Mode.comonadic
Expand Down

0 comments on commit 168da42

Please sign in to comment.