Skip to content

Commit

Permalink
remove prefixes from inline record fields
Browse files Browse the repository at this point in the history
  • Loading branch information
rajgodse committed Aug 9, 2023
1 parent 4e8559e commit 5540121
Show file tree
Hide file tree
Showing 21 changed files with 191 additions and 197 deletions.
59 changes: 28 additions & 31 deletions ocaml/lambda/translcore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ let sort_must_not_be_void loc ty sort =
let layout_exp sort e = layout e.exp_env e.exp_loc sort e.exp_type

let layout_rhs sort = function
| Simple_rhs rhs | Boolean_guarded_rhs { bg_rhs = rhs; _ } ->
layout_exp sort rhs
| Pattern_guarded_rhs { pg_env; pg_loc; pg_type; _ } ->
layout pg_env pg_loc sort pg_type
| Simple_rhs rhs | Boolean_guarded_rhs { rhs; _ } -> layout_exp sort rhs
| Pattern_guarded_rhs { env; loc; rhs_type; _ } ->
layout env loc sort rhs_type

(* Forward declaration -- to be filled in by Translmod.transl_module *)
let transl_module =
Expand Down Expand Up @@ -258,10 +257,10 @@ let rec push_defaults loc bindings use_lhs arg_mode arg_sort cases
when bindings <> [] ->
let exp_loc, exp_extra, exp_type, exp_env, exp_attributes =
match rhs with
| Simple_rhs e | Boolean_guarded_rhs { bg_rhs = e; _ } ->
| Simple_rhs e | Boolean_guarded_rhs { rhs = e; _ } ->
e.exp_loc, e.exp_extra, e.exp_type, e.exp_env, e.exp_attributes
| Pattern_guarded_rhs { pg_loc; pg_env; pg_type; _ } ->
pg_loc, [], pg_type, pg_env, []
| Pattern_guarded_rhs { loc; env; rhs_type; _ } ->
loc, [], rhs_type, env, []
in
let mode = Value_mode.of_alloc arg_mode in
let param = Typecore.name_cases "param" cases in
Expand Down Expand Up @@ -322,10 +321,9 @@ let event_function_expr ~scopes exp lam =

let event_function_rhs ~scopes rhs lam =
match rhs with
| Simple_rhs rhs_exp | Boolean_guarded_rhs { bg_rhs = rhs_exp; _ } ->
| Simple_rhs rhs_exp | Boolean_guarded_rhs { rhs = rhs_exp; _ } ->
event_function_expr ~scopes rhs_exp lam
| Pattern_guarded_rhs { pg_loc; pg_env; _ } ->
event_function ~scopes pg_loc pg_env lam
| Pattern_guarded_rhs { loc; env; _ } -> event_function ~scopes loc env lam

(* Assertions *)

Expand Down Expand Up @@ -1054,21 +1052,20 @@ and transl_rhs ~scopes rhs_sort rhs =
| Simple_rhs rhs ->
Matching.mk_unguarded_rhs
(event_before ~scopes rhs (transl_exp ~scopes rhs_sort rhs))
| Boolean_guarded_rhs { bg_guard; bg_rhs } ->
let guard = transl_exp ~scopes Sort.for_predef_value bg_guard in
let body =
event_before ~scopes bg_rhs (transl_exp ~scopes rhs_sort bg_rhs)
in
| Boolean_guarded_rhs { guard = typed_guard; rhs } ->
let guard = transl_exp ~scopes Sort.for_predef_value typed_guard in
let body = event_before ~scopes rhs (transl_exp ~scopes rhs_sort rhs) in
let patch_guarded ~patch =
event_before ~scopes bg_guard (Lifthenelse (guard, body, patch, layout))
event_before
~scopes typed_guard (Lifthenelse (guard, body, patch, layout))
in
let free_variables =
Ident.Set.union (free_variables guard) (free_variables body)
in
Matching.mk_boolean_guarded_rhs ~patch_guarded ~free_variables
| Pattern_guarded_rhs { pg_scrutinee; pg_scrutinee_sort; pg_cases; pg_partial;
pg_loc; pg_env; pg_type } ->
match pg_partial with
| Pattern_guarded_rhs { scrutinee; scrutinee_sort; cases; partial;
loc; env; rhs_type } ->
match partial with
| Partial ->
(* Partial pattern guards may fail to match, so we must construct a
guarded rhs from a continuation that later "patches" in the code to
Expand All @@ -1079,27 +1076,27 @@ and transl_rhs ~scopes rhs_sort rhs =
{ pat_desc = Tpat_any
; pat_loc = Location.none
; pat_extra = []
; pat_type = pg_scrutinee.exp_type
; pat_env = pg_env
; pat_type = scrutinee.exp_type
; pat_env = env
; pat_attributes = []
}
in
let extra_cases = [ any_pat, Matching.mk_unguarded_rhs patch ] in
event_before ~scopes pg_scrutinee
(transl_match ~scopes ~arg_sort:pg_scrutinee_sort
~return_sort:rhs_sort ~return_type:pg_type ~loc:pg_loc
~env:pg_env ~extra_cases pg_scrutinee pg_cases pg_partial)
event_before ~scopes scrutinee
(transl_match ~scopes ~arg_sort:scrutinee_sort
~return_sort:rhs_sort ~return_type:rhs_type ~loc ~env
~extra_cases scrutinee cases partial)
in
Matching.mk_pattern_guarded_rhs ~patch_guarded
| Total ->
(* Total pattern guards are equivalent to nested matches. *)
let nested_match =
transl_match ~scopes ~arg_sort:pg_scrutinee_sort
~return_sort:rhs_sort ~return_type:pg_type ~loc:pg_loc
~env:pg_env ~extra_cases:[] pg_scrutinee pg_cases pg_partial
transl_match ~scopes ~arg_sort:scrutinee_sort ~return_sort:rhs_sort
~return_type:rhs_type ~loc ~env ~extra_cases:[] scrutinee cases
partial
in
Matching.mk_unguarded_rhs
(event_before ~scopes pg_scrutinee nested_match)
(event_before ~scopes scrutinee nested_match)

and transl_case ~scopes rhs_sort {c_lhs; c_rhs} =
c_lhs, transl_rhs ~scopes rhs_sort c_rhs
Expand Down Expand Up @@ -1804,8 +1801,8 @@ and transl_letop ~scopes loc env let_ ands param param_sort case case_sort
let curry = More_args { partial_mode = Alloc_mode.global } in
let rhs_loc =
match case.c_rhs with
| Simple_rhs e | Boolean_guarded_rhs { bg_rhs = e; _ } -> e.exp_loc
| Pattern_guarded_rhs { pg_loc; _ } -> pg_loc
| Simple_rhs e | Boolean_guarded_rhs { rhs = e; _ } -> e.exp_loc
| Pattern_guarded_rhs { loc; _ } -> loc
in
let (kind, params, return, _region), body =
event_function_rhs ~scopes case.c_rhs
Expand Down
4 changes: 2 additions & 2 deletions ocaml/ocamldoc/odoc_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ module Analyser =
match func_body with
| Pattern_guarded_rhs _ -> parameter, None
| Simple_rhs func_body
| Boolean_guarded_rhs { bg_rhs = func_body; _ } ->
| Boolean_guarded_rhs { rhs = func_body; _ } ->
match parameter with
Simple_name { sn_name = "*opt*" } ->
(
Expand Down Expand Up @@ -450,7 +450,7 @@ module Analyser =
in
[ new_param ]
| {c_rhs=Pattern_guarded_rhs _} :: [] -> []
| {c_lhs=pattern_param; c_rhs=Simple_rhs body | Boolean_guarded_rhs {bg_rhs = body}} :: [] ->
| {c_lhs=pattern_param; c_rhs=Simple_rhs body | Boolean_guarded_rhs {rhs = body}} :: [] ->
(* if this is the first call to the function, this is the first parameter and we skip it *)
if not first then
(
Expand Down
7 changes: 3 additions & 4 deletions ocaml/parsing/ast_helper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,9 @@ end

module Case_rhs = struct
let simple e = Psimple_rhs e
let boolean_guarded ~guard pbg_rhs =
Pboolean_guarded_rhs { pbg_guard = guard; pbg_rhs }
let pattern_guarded ~loc ppg_scrutinee ppg_cases =
Ppattern_guarded_rhs { ppg_scrutinee; ppg_cases; ppg_loc = loc }
let boolean_guarded ~guard rhs = Pboolean_guarded_rhs { guard; rhs }
let pattern_guarded ~loc scrutinee cases =
Ppattern_guarded_rhs { scrutinee; cases; loc }
end

module Mty = struct
Expand Down
14 changes: 7 additions & 7 deletions ocaml/parsing/ast_iterator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -796,13 +796,13 @@ let default_iterator =
case_rhs =
(fun this -> function
| Psimple_rhs e -> this.expr this e
| Pboolean_guarded_rhs { pbg_guard; pbg_rhs } ->
this.expr this pbg_guard;
this.expr this pbg_rhs
| Ppattern_guarded_rhs { ppg_scrutinee; ppg_cases; ppg_loc } ->
this.expr this ppg_scrutinee;
this.cases this ppg_cases;
this.location this ppg_loc
| Pboolean_guarded_rhs { guard; rhs } ->
this.expr this guard;
this.expr this rhs
| Ppattern_guarded_rhs { scrutinee; cases; loc } ->
this.expr this scrutinee;
this.cases this cases;
this.location this loc
);

location = (fun _this _l -> ());
Expand Down
14 changes: 7 additions & 7 deletions ocaml/parsing/ast_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -911,16 +911,16 @@ let default_mapper =
case_rhs =
(fun this -> function
| Psimple_rhs e -> Psimple_rhs (this.expr this e)
| Pboolean_guarded_rhs { pbg_guard; pbg_rhs } ->
| Pboolean_guarded_rhs { guard; rhs } ->
Pboolean_guarded_rhs
{ pbg_guard = this.expr this pbg_guard
; pbg_rhs = this.expr this pbg_rhs
{ guard = this.expr this guard
; rhs = this.expr this rhs
}
| Ppattern_guarded_rhs { ppg_scrutinee; ppg_cases; ppg_loc } ->
| Ppattern_guarded_rhs { scrutinee; cases; loc } ->
Ppattern_guarded_rhs
{ ppg_scrutinee = this.expr this ppg_scrutinee
; ppg_cases = this.cases this ppg_cases
; ppg_loc = this.location this ppg_loc
{ scrutinee = this.expr this scrutinee
; cases = this.cases this cases
; loc = this.location this loc
}
);

Expand Down
12 changes: 6 additions & 6 deletions ocaml/parsing/depend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,12 @@ and add_case bv {pc_lhs; pc_rhs} =

and add_case_rhs bv = function
| Psimple_rhs e -> add_expr bv e
| Pboolean_guarded_rhs { pbg_guard; pbg_rhs } ->
add_expr bv pbg_guard;
add_expr bv pbg_rhs
| Ppattern_guarded_rhs { ppg_scrutinee; ppg_cases } ->
add_expr bv ppg_scrutinee;
add_cases bv ppg_cases
| Pboolean_guarded_rhs { guard; rhs } ->
add_expr bv guard;
add_expr bv rhs
| Ppattern_guarded_rhs { scrutinee; cases } ->
add_expr bv scrutinee;
add_cases bv cases

and add_bindings recf bv pel =
let bv' = List.fold_left (fun bv x -> add_pattern bv x.pvb_pat) bv pel in
Expand Down
8 changes: 4 additions & 4 deletions ocaml/parsing/parsetree.mli
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,12 @@ and case =
and case_rhs =
| Psimple_rhs of expression
(** [-> e] *)
| Pboolean_guarded_rhs of { pbg_guard : expression; pbg_rhs : expression }
| Pboolean_guarded_rhs of { guard : expression; rhs : expression }
(** [when g -> e] *)
| Ppattern_guarded_rhs of
{ ppg_scrutinee : expression
; ppg_cases : case list
; ppg_loc : Location.t
{ scrutinee : expression
; cases : case list
; loc : Location.t
}
(** [when e match (cases) ] *)

Expand Down
14 changes: 7 additions & 7 deletions ocaml/parsing/pprintast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1815,19 +1815,19 @@ and case_list ctxt f l : unit = list (case ctxt) f l ~sep:"@;" ~first:"@;"

and case_rhs ctxt f = function
| Psimple_rhs e -> pp f "->@;%a" (expression (under_pipe ctxt)) e
| Pboolean_guarded_rhs { pbg_guard; pbg_rhs } ->
pp f "when@;%a@;->@;%a" (expression ctxt) pbg_guard
(expression (under_pipe ctxt)) pbg_rhs
| Ppattern_guarded_rhs { ppg_scrutinee; ppg_cases; _ } ->
| Pboolean_guarded_rhs { guard; rhs } ->
pp f "when@;%a@;->@;%a" (expression ctxt) guard
(expression (under_pipe ctxt)) rhs
| Ppattern_guarded_rhs { scrutinee; cases; _ } ->
let singleton_case =
match ppg_cases with
match cases with
| [ _ ] -> true
| _ -> false
in
let case_list = list (case ctxt) ~sep:"@;" ~first:"@," ~last:"@," in
pp f "@[<hv0>@[<hv0>@[<2>when %a@]@ match@] %a@]"
(expression reset_ctxt) ppg_scrutinee
(paren (not singleton_case) case_list) ppg_cases
(expression reset_ctxt) scrutinee
(paren (not singleton_case) case_list) cases

and label_x_expression_param ctxt f (l,e) =
let simple_name = match e with
Expand Down
12 changes: 6 additions & 6 deletions ocaml/parsing/printast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -918,14 +918,14 @@ and case i ppf { pc_lhs; pc_rhs } =

and case_rhs i ppf = function
| Psimple_rhs e -> expression i ppf e
| Pboolean_guarded_rhs { pbg_guard; pbg_rhs } ->
| Pboolean_guarded_rhs { guard; rhs } ->
line i ppf "<when>\n";
expression (i + 1) ppf pbg_guard;
expression i ppf pbg_rhs
| Ppattern_guarded_rhs { ppg_scrutinee; ppg_cases } ->
expression (i + 1) ppf guard;
expression i ppf rhs
| Ppattern_guarded_rhs { scrutinee; cases } ->
line i ppf "<when-pattern>\n";
expression (i + 1) ppf ppg_scrutinee;
list (i + 1) case ppf ppg_cases
expression (i + 1) ppf scrutinee;
list (i + 1) case ppf cases

and value_binding i ppf x =
line i ppf "<def>\n";
Expand Down
24 changes: 12 additions & 12 deletions ocaml/tools/ocamlprof.ml
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ and rewrite_cases iflag l =
(fun pc ->
match pc.pc_rhs with
| Psimple_rhs e -> rewrite_exp iflag e
| Pboolean_guarded_rhs { pbg_guard; pbg_rhs } ->
rewrite_exp iflag pbg_guard;
rewrite_exp iflag pbg_rhs
| Ppattern_guarded_rhs { ppg_scrutinee; ppg_cases; ppg_loc = _ } ->
rewrite_exp iflag ppg_scrutinee;
rewrite_cases iflag ppg_cases
| Pboolean_guarded_rhs { guard; rhs } ->
rewrite_exp iflag guard;
rewrite_exp iflag rhs
| Ppattern_guarded_rhs { scrutinee; cases; loc = _ } ->
rewrite_exp iflag scrutinee;
rewrite_cases iflag cases
)
l

Expand Down Expand Up @@ -361,12 +361,12 @@ and rewrite_ifbody iflag ghost sifbody =
and rewrite_annotate_exp_list l =
List.iter
(function
| {pc_rhs=Pboolean_guarded_rhs { pbg_guard; pbg_rhs }} ->
rewrite_exp true pbg_guard;
insert_profile rw_exp pbg_rhs;
| {pc_rhs=Ppattern_guarded_rhs { ppg_scrutinee; ppg_cases; _ }} ->
rewrite_exp true ppg_scrutinee;
rewrite_annotate_exp_list ppg_cases
| {pc_rhs=Pboolean_guarded_rhs { guard; rhs }} ->
rewrite_exp true guard;
insert_profile rw_exp rhs;
| {pc_rhs=Ppattern_guarded_rhs { scrutinee; cases; _ }} ->
rewrite_exp true scrutinee;
rewrite_annotate_exp_list cases
| {pc_rhs=Psimple_rhs {pexp_desc = Pexp_constraint(sbody, _)}}
(* let f x : t = e *)
-> insert_profile rw_exp sbody
Expand Down
6 changes: 3 additions & 3 deletions ocaml/typing/cmt2annot.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ let bind_cases l =
let loc =
match c_rhs with
| Simple_rhs rhs -> rhs.exp_loc
| Boolean_guarded_rhs { bg_guard; bg_rhs } ->
{ bg_rhs.exp_loc with loc_start = bg_guard.exp_loc.loc_start }
| Pattern_guarded_rhs { pg_loc; _ } -> pg_loc
| Boolean_guarded_rhs { guard; rhs } ->
{ rhs.exp_loc with loc_start = guard.exp_loc.loc_start }
| Pattern_guarded_rhs { loc; _ } -> loc
in
bind_variables loc c_lhs
)
Expand Down
8 changes: 4 additions & 4 deletions ocaml/typing/parmatch.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2462,10 +2462,10 @@ let all_guard_idents c_rhs =
let iterator = {Tast_iterator.default_iterator with expr = expr_iter} in
let rec rhs_iter = function
| Simple_rhs _ -> ()
| Boolean_guarded_rhs { bg_guard; _ } -> iterator.expr iterator bg_guard
| Pattern_guarded_rhs { pg_scrutinee; pg_cases; _ } ->
iterator.expr iterator pg_scrutinee;
List.iter (fun case -> rhs_iter case.c_rhs) pg_cases
| Boolean_guarded_rhs { guard; _ } -> iterator.expr iterator guard
| Pattern_guarded_rhs { scrutinee; cases; _ } ->
iterator.expr iterator scrutinee;
List.iter (fun case -> rhs_iter case.c_rhs) cases
in
rhs_iter c_rhs;
!ids
Expand Down
14 changes: 7 additions & 7 deletions ocaml/typing/printtyped.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1039,15 +1039,15 @@ and case

and case_rhs i ppf = function
| Simple_rhs rhs -> expression i ppf rhs
| Boolean_guarded_rhs { bg_guard; bg_rhs } ->
| Boolean_guarded_rhs { guard; rhs } ->
line i ppf "<when>\n";
expression (i + 1) ppf bg_guard;
expression i ppf bg_rhs
| Pattern_guarded_rhs { pg_scrutinee; pg_scrutinee_sort; pg_cases } ->
expression (i + 1) ppf guard;
expression i ppf rhs
| Pattern_guarded_rhs { scrutinee; scrutinee_sort; cases } ->
line i ppf "<when-pattern>\n";
expression (i + 1) ppf pg_scrutinee;
line (i + 1) ppf "%a\n" Layouts.Sort.format pg_scrutinee_sort;
list (i + 1) case ppf pg_cases
expression (i + 1) ppf scrutinee;
line (i + 1) ppf "%a\n" Layouts.Sort.format scrutinee_sort;
list (i + 1) case ppf cases

and value_binding i ppf x =
line i ppf "<def>\n";
Expand Down
8 changes: 4 additions & 4 deletions ocaml/typing/rec_check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1203,8 +1203,8 @@ and case
---------------------------------------
G - p; m[mp] |- (p when g -> e) : m
*)
| Boolean_guarded_rhs { bg_guard; bg_rhs } ->
join [ expression bg_guard << Dereference; expression bg_rhs ]
| Boolean_guarded_rhs { guard; rhs } ->
join [ expression guard << Dereference; expression rhs ]
(*
G |- (match e1 with p2 -> e2) : m
p1 : mp -| G
Expand All @@ -1214,8 +1214,8 @@ and case
This judgement uses uses the one in [match_expression] as a
"subroutine."
*)
| Pattern_guarded_rhs { pg_scrutinee; pg_cases; _ } ->
match_expression pg_scrutinee pg_cases
| Pattern_guarded_rhs { scrutinee; cases; _ } ->
match_expression scrutinee cases
in
(fun m ->
let env = judg m in
Expand Down
Loading

0 comments on commit 5540121

Please sign in to comment.