Skip to content

Commit

Permalink
Rename ~reason to ~context for annotations (only)
Browse files Browse the repository at this point in the history
  • Loading branch information
goldfirere committed Jun 14, 2023
1 parent 2e2cac3 commit 1d35034
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 33 deletions.
18 changes: 9 additions & 9 deletions ocaml/typing/layouts.ml
Original file line number Diff line number Diff line change
Expand Up @@ -379,21 +379,21 @@ module Layout = struct
| Value -> fresh_layout (Sort Sort.value) ~why
| Void -> fresh_layout (Sort Sort.void) ~why

let of_annotation ~reason Location.{ loc; txt = const } =
of_const ~why:(Annotated (reason, loc)) const
let of_annotation ~context Location.{ loc; txt = const } =
of_const ~why:(Annotated (context, loc)) const

let of_annotation_option ~reason = Option.map (of_annotation ~reason)
let of_annotation_option ~context = Option.map (of_annotation ~context)

let of_annotation_option_default ~default ~reason =
Option.fold ~none:default ~some:(of_annotation ~reason)
let of_annotation_option_default ~default ~context =
Option.fold ~none:default ~some:(of_annotation ~context)

let of_attributes ~legacy_immediate ~reason attrs =
let of_attributes ~legacy_immediate ~context attrs =
Builtin_attributes.layout ~legacy_immediate attrs |>
Result.map (of_annotation_option ~reason)
Result.map (of_annotation_option ~context)

let of_attributes_default ~legacy_immediate ~reason ~default attrs =
let of_attributes_default ~legacy_immediate ~context ~default attrs =
Builtin_attributes.layout ~legacy_immediate attrs |>
Result.map (of_annotation_option_default ~default ~reason)
Result.map (of_annotation_option_default ~default ~context)

let for_boxed_record ~all_void =
if all_void then immediate ~why:Empty_record else value ~why:Boxed_record
Expand Down
8 changes: 4 additions & 4 deletions ocaml/typing/layouts.mli
Original file line number Diff line number Diff line change
Expand Up @@ -266,24 +266,24 @@ module Layout : sig
val of_const : why:creation_reason -> const -> t

val of_annotation :
reason:annotation_context -> Asttypes.layout_annotation -> t
context:annotation_context -> Asttypes.layout_annotation -> t

val of_annotation_option_default :
default:t -> reason:annotation_context ->
default:t -> context:annotation_context ->
Asttypes.layout_annotation option -> t

(** Find a layout in attributes. Returns error if a disallowed layout is
present, but always allows immediate attributes if ~legacy_immediate is
true. See comment on [Builtin_attributes.layout]. *)
val of_attributes :
legacy_immediate:bool -> reason:annotation_context -> Parsetree.attributes ->
legacy_immediate:bool -> context:annotation_context -> Parsetree.attributes ->
(t option, const Location.loc) result

(** Find a layout in attributes, defaulting to ~default. Returns error if a
disallowed layout is present, but always allows immediate if
~legacy_immediate is true. See comment on [Builtin_attributes.layout]. *)
val of_attributes_default :
legacy_immediate:bool -> reason:annotation_context ->
legacy_immediate:bool -> context:annotation_context ->
default:t -> Parsetree.attributes ->
(t, const Location.loc) result

Expand Down
2 changes: 1 addition & 1 deletion ocaml/typing/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5383,7 +5383,7 @@ and type_expect_
| Pexp_newtype({txt=name}, sbody, lay) ->
let layout =
match Layout.of_attributes_default ~legacy_immediate:false
~reason:(Newtype_declaration name)
~context:(Newtype_declaration name)
~default:(Layout.value ~why:Univar) sexp.pexp_attributes
with
| Ok l -> l
Expand Down
24 changes: 12 additions & 12 deletions ocaml/typing/typedecl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ open Typedtree

exception Error of Location.t * error

let layout_of_attributes ~legacy_immediate ~reason attrs =
match Layout.of_attributes ~legacy_immediate ~reason attrs with
let layout_of_attributes ~legacy_immediate ~context attrs =
match Layout.of_attributes ~legacy_immediate ~context attrs with
| Ok l -> l
| Error { loc; txt } -> raise (Error (loc, Layout_not_enabled txt))

let layout_of_attributes_default ~legacy_immediate ~reason ~default attrs =
match Layout.of_attributes_default ~legacy_immediate ~reason ~default attrs with
let layout_of_attributes_default ~legacy_immediate ~context ~default attrs =
match Layout.of_attributes_default ~legacy_immediate ~context ~default attrs with
| Ok l -> l
| Error { loc; txt } -> raise (Error (loc, Layout_not_enabled txt))

Expand Down Expand Up @@ -192,7 +192,7 @@ let enter_type rec_flag env sdecl (id, uid) =
(* We set ~legacy_immediate to true because we're looking at a declaration
that was already allowed to be [@@immediate] *)
layout_of_attributes_default
~legacy_immediate:true ~reason:(Type_declaration path)
~legacy_immediate:true ~context:(Type_declaration path)
~default:(Layout.any ~why:Initial_typedecl_env)
sdecl.ptype_attributes
in
Expand Down Expand Up @@ -227,7 +227,7 @@ let enter_type rec_flag env sdecl (id, uid) =
(fun (param, _) ->
let layout =
layout_of_attributes_default ~legacy_immediate:false
~reason:(Type_parameter (path, parameter_name param))
~context:(Type_parameter (path, parameter_name param))
~default:(Layout.value ~why:Type_argument)
param.ptyp_attributes
in
Expand Down Expand Up @@ -350,7 +350,7 @@ let make_params env path params =
try
let layout =
layout_of_attributes_default ~legacy_immediate:false
~reason:(Type_parameter (path, parameter_name sty))
~context:(Type_parameter (path, parameter_name sty))
~default:(Layout.of_new_sort_var ~why:Unannotated_type_parameter)
sty.ptyp_attributes
in
Expand Down Expand Up @@ -460,7 +460,7 @@ let make_constructor
| vs ->
Ctype.begin_def();
Some (TyVarEnv.make_poly_univars
~reason:(fun v -> Constructor_type_parameter (cstr_path, v))
~context:(fun v -> Constructor_type_parameter (cstr_path, v))
vs slays), true
in
let args, targs =
Expand Down Expand Up @@ -642,7 +642,7 @@ let transl_declaration env sdecl (id, uid) =
let layout_annotation =
(* We set legacy_immediate to true because you were already allowed to write
[@@immediate] on declarations. *)
layout_of_attributes ~legacy_immediate:true ~reason:(Type_declaration (Pident id))
layout_of_attributes ~legacy_immediate:true ~context:(Type_declaration (Pident id))
sdecl.ptype_attributes
in
let (tman, man) = match sdecl.ptype_manifest with
Expand Down Expand Up @@ -2180,7 +2180,7 @@ let transl_with_constraint id ?fixed_row_path ~sig_env ~sig_decl ~outer_env
let layout_annotation =
layout_of_attributes
~legacy_immediate:false
~reason:(With_constraint sdecl.ptype_name.txt)
~context:(With_constraint sdecl.ptype_name.txt)
sdecl.ptype_attributes
in
Ctype.end_def();
Expand Down Expand Up @@ -2235,14 +2235,14 @@ let approx_type_decl sdecl_list =
(* We set legacy_immediate to true because you were already allowed
to write [@@immediate] on declarations. *)
layout_of_attributes_default ~legacy_immediate:true
~reason:(Type_declaration (Pident id))
~context:(Type_declaration (Pident id))
~default:(Layout.value ~why:Default_type_layout)
sdecl.ptype_attributes
in
let params =
List.map (fun (styp,_) ->
layout_of_attributes_default ~legacy_immediate:false
~reason:(Type_parameter (Pident id, parameter_name styp))
~context:(Type_parameter (Pident id, parameter_name styp))
~default:(Layout.value ~why:Type_argument)
styp.ptyp_attributes)
sdecl.ptype_params
Expand Down
12 changes: 6 additions & 6 deletions ocaml/typing/typetexp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ module TyVarEnv : sig
(* evaluate with a locally extended set of univars *)

val make_poly_univars :
reason:(string -> Layout.annotation_context) ->
context:(string -> Layout.annotation_context) ->
string Location.loc list -> type_vars_layouts -> poly_univars
(* see mli file *)

Expand Down Expand Up @@ -232,12 +232,12 @@ end = struct
f
~finally:(fun () -> univars := old_univars)

let make_poly_univars ~reason vars layouts =
let make_poly_univars ~context vars layouts =
let mk_pair v l =
let name = v.txt in
let original_layout = Layout.of_annotation_option_default l
~default:(Layout.value ~why:Univar)
~reason:(reason name)
~context:(context name)
in
let layout_info = { original_layout; defaulted = Option.is_none l } in
name, newvar ~name original_layout, layout_info
Expand Down Expand Up @@ -835,7 +835,7 @@ and transl_type_aux env policy mode styp =
let typed_vars = make_typed_univars vars layouts in
begin_def();
let new_univars =
TyVarEnv.make_poly_univars ~reason:(fun v -> Univar v) vars layouts
TyVarEnv.make_poly_univars ~context:(fun v -> Univar v) vars layouts
in
let cty = TyVarEnv.with_univars new_univars begin fun () ->
transl_type env policy mode st
Expand Down Expand Up @@ -889,7 +889,7 @@ and transl_type_aux env policy mode styp =
let cty = transl_type env policy mode inner_type in
let cty_expr = cty.ctyp_type in
let layout =
Layout.of_annotation ~reason:(Type_variable "XXX layouts")
Layout.of_annotation ~context:(Type_variable "XXX layouts")
layout_annot
in
begin match constrain_type_layout env cty_expr layout with
Expand Down Expand Up @@ -1055,7 +1055,7 @@ let transl_type_scheme env styp =
let typed_vars = make_typed_univars vars layouts in
begin_def();
let univars =
TyVarEnv.make_poly_univars ~reason:(fun v -> Univar v) vars layouts
TyVarEnv.make_poly_univars ~context:(fun v -> Univar v) vars layouts
in
let typ = transl_simple_type env ~univars ~closed:true Alloc_mode.Global st in
end_def();
Expand Down
2 changes: 1 addition & 1 deletion ocaml/typing/typetexp.mli
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module TyVarEnv : sig

type poly_univars
val make_poly_univars :
reason:(string -> Layout.annotation_context) ->
context:(string -> Layout.annotation_context) ->
string Location.loc list ->
Asttypes.layout_annotation option list ->
poly_univars
Expand Down

0 comments on commit 1d35034

Please sign in to comment.