Skip to content

Commit

Permalink
change name to create_row_field and put back comment
Browse files Browse the repository at this point in the history
  • Loading branch information
garrigue committed Sep 30, 2021
1 parent c871bd6 commit d28a862
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 38 deletions.
8 changes: 4 additions & 4 deletions typing/btype.ml
Expand Up @@ -424,13 +424,13 @@ let copy_row f fixed row keep more =
let fields = List.map
(fun (l, fi) -> l,
match row_field_repr fi with
| Rpresent(Some ty) -> inj_row_field (Rpresent(Some(f ty)))
| Rpresent(Some ty) -> create_row_field (Rpresent(Some(f ty)))
| Reither(c, tl, m) ->
let with_ext_of = if keep then Some fi else None in
let use_ext_of = if keep then Some fi else None in
let m = if is_fixed row then fixed else m in
let tl = List.map f tl in
inj_row_field ?with_ext_of (Reither(c, tl, m))
| view -> inj_row_field view)
create_row_field ?use_ext_of (Reither(c, tl, m))
| view -> create_row_field view)
orig_fields in
let name =
match orig_name with
Expand Down
18 changes: 9 additions & 9 deletions typing/ctype.ml
Expand Up @@ -411,7 +411,7 @@ let rec filter_row_fields erase = function
match row_field_repr f with
Rabsent -> fi
| Reither(_,_,false) when erase ->
link_row_field_ext ~inside:f (inj_row_field Rabsent); fi
link_row_field_ext ~inside:f (create_row_field Rabsent); fi
| _ -> p :: fi

(**************************************)
Expand Down Expand Up @@ -3038,7 +3038,7 @@ and unify_row_field env fixed1 fixed2 rm1 rm2 l f1 f2 =
if either_fixed && not (c1 || c2)
&& List.length tl1 = List.length tl2 then begin
(* PR#7496 *)
let f = inj_row_field (Reither (c1 || c2, [], m1 || m2)) in
let f = create_row_field (Reither (c1 || c2, [], m1 || m2)) in
link_row_field_ext ~inside:f1 f; link_row_field_ext ~inside:f2 f;
List.iter2 (unify env) tl1 tl2
end
Expand Down Expand Up @@ -3075,9 +3075,9 @@ and unify_row_field env fixed1 fixed2 rm1 rm2 l f1 f2 =
in
update_levels rm2 tl1';
update_levels rm1 tl2';
let f1' = inj_row_field (Reither(c1 || c2, tl2', m1 || m2)) in
let f1' = create_row_field (Reither(c1 || c2, tl2', m1 || m2)) in
let f2' =
inj_row_field ~with_ext_of:f1' (Reither(c1 || c2, tl1', m1 || m2)) in
create_row_field ~use_ext_of:f1' (Reither(c1 || c2, tl1', m1 || m2)) in
link_row_field_ext ~inside:f1 f1'; link_row_field_ext ~inside:f2 f2';
| Reither(_, _, false), Rabsent ->
if_not_fixed first (fun () -> link_row_field_ext ~inside:f1 f2)
Expand Down Expand Up @@ -3754,7 +3754,7 @@ and moregen_row inst_nongen type_pairs env row1 row2 =
if not (eq_row_field_ext f1 f2) then begin
if c1 && not c2 then raise_unexplained_for Moregen;
let f2' =
inj_row_field ~with_ext_of:f2 (Reither (c2, [], m2)) in
create_row_field ~use_ext_of:f2 (Reither (c2, [], m2)) in
link_row_field_ext ~inside:f1 f2';
if List.length tl1 = List.length tl2 then
List.iter2 (moregen inst_nongen type_pairs env) tl1 tl2
Expand Down Expand Up @@ -4596,15 +4596,15 @@ let rec build_subtype env (visited : transient_expr list)
(fun (l,f as orig) -> match row_field_repr f with
Rpresent None ->
if posi then
(l, inj_row_field (Reither(true, [], false))), Unchanged
(l, create_row_field (Reither(true, [], false))), Unchanged
else
orig, Unchanged
| Rpresent(Some t) ->
let (t', c) = build_subtype env visited loops posi level' t in
let f =
if posi && level > 0
then inj_row_field (Reither(false, [t'], false))
else inj_row_field (Rpresent(Some t'))
then create_row_field (Reither(false, [t'], false))
else create_row_field (Rpresent(Some t'))
in (l, f), c
| _ -> assert false)
fields
Expand Down Expand Up @@ -5062,7 +5062,7 @@ let rec normalize_type_rec visited ty =
[ty] tyl
in
if List.length tyl' <= List.length tyl then
inj_row_field ~with_ext_of:f (Reither(b, List.rev tyl', m))
create_row_field ~use_ext_of:f (Reither(b, List.rev tyl', m))
else f
| _ -> f)
orig_fields in
Expand Down
2 changes: 1 addition & 1 deletion typing/parmatch.ml
Expand Up @@ -724,7 +724,7 @@ let close_variant env row =
match row_field_repr f with
| Reither(_, _, false) ->
(* fixed=false means that this tag is not explicitly matched *)
link_row_field_ext ~inside:f (inj_row_field Rabsent);
link_row_field_ext ~inside:f (create_row_field Rabsent);
(None, static)
| Reither (_, _, true) -> (nm, false)
| Rabsent | Rpresent _ -> (nm, static))
Expand Down
18 changes: 9 additions & 9 deletions typing/typecore.ml
Expand Up @@ -401,15 +401,15 @@ let finalize_variant pat tag opat r =
begin match row_field_repr f with
| Rabsent -> () (* assert false *)
| Reither (true, [], _) when not (row_closed row) ->
link_row_field_ext ~inside:f (inj_row_field (Rpresent None))
link_row_field_ext ~inside:f (create_row_field (Rpresent None))
| Reither (false, ty::tl, _) when not (row_closed row) ->
link_row_field_ext ~inside:f (inj_row_field (Rpresent (Some ty)));
link_row_field_ext ~inside:f (create_row_field (Rpresent (Some ty)));
begin match opat with None -> assert false
| Some pat ->
let env = ref pat.pat_env in List.iter (unify_pat env pat) (ty::tl)
end
| Reither (c, _l, true) when not (has_fixed_explanation row) ->
link_row_field_ext ~inside:f (inj_row_field (Reither (c, [], false)))
link_row_field_ext ~inside:f (create_row_field (Reither (c, [], false)))
| _ -> ()
end
(* Force check of well-formedness WHY? *)
Expand Down Expand Up @@ -564,7 +564,7 @@ and build_as_type_aux env p =
ty_res
| Tpat_variant(l, p', _) ->
let ty = Option.map (build_as_type env) p' in
let fields = [l, inj_row_field (Rpresent ty)] in
let fields = [l, create_row_field (Rpresent ty)] in
newty (Tvariant (create_row ~fields ~more:(newvar())
~name:None ~fixed:None ~closed:false))
| Tpat_record (lpl,_) ->
Expand Down Expand Up @@ -780,7 +780,7 @@ let solve_Ppat_constraint ~refine loc env sty expected_ty =

let solve_Ppat_variant ~refine loc env tag constant expected_ty =
let arg_type = if constant then [] else [newgenvar()] in
let fields = [tag, inj_row_field (Reither(constant, arg_type, true))] in
let fields = [tag, create_row_field (Reither(constant, arg_type, true))] in
let make_row more =
create_row ~fields ~closed:false ~more ~fixed:None ~name:None
in
Expand All @@ -807,11 +807,11 @@ let build_or_pat env loc lid =
(fun (pats,fields) (l,f) ->
match row_field_repr f with
Rpresent None ->
let f = inj_row_field (Reither(true, [], true)) in
let f = create_row_field (Reither(true, [], true)) in
(l,None) :: pats,
(l, f) :: fields
| Rpresent (Some ty) ->
let f = inj_row_field (Reither(false, [ty], true)) in
let f = create_row_field (Reither(false, [ty], true)) in
(l, Some {pat_desc=Tpat_any; pat_loc=Location.none; pat_env=env;
pat_type=ty; pat_extra=[]; pat_attributes=[]})
:: pats,
Expand Down Expand Up @@ -2715,7 +2715,7 @@ let check_absent_variant env =
then () else
let ty_arg =
match arg with None -> [] | Some p -> [correct_levels p.pat_type] in
let fields = [s, inj_row_field (Reither(arg=None,ty_arg,true))] in
let fields = [s, create_row_field (Reither(arg=None,ty_arg,true))] in
let row' =
create_row ~fields
~more:(newvar ()) ~closed:false ~fixed:None ~name:None in
Expand Down Expand Up @@ -3111,7 +3111,7 @@ and type_expect_
let arg_type = Option.map (fun arg -> arg.exp_type) arg in
let row =
create_row
~fields: [l, inj_row_field(Rpresent arg_type)]
~fields: [l, create_row_field (Rpresent arg_type)]
~more: (newvar ())
~closed: false
~fixed: None
Expand Down
4 changes: 2 additions & 2 deletions typing/types.ml
Expand Up @@ -646,13 +646,13 @@ let rec row_field_ext fi =
if !ext = RFnone then ext else row_field_ext !ext
| _ -> Misc.fatal_error "Types.row_field_ext "

let inj_row_field ?with_ext_of view =
let create_row_field ?use_ext_of view =
match view with
| Rabsent -> RFabsent
| Rpresent t -> RFpresent t
| Reither (const, arg_type, fixed) ->
let ext =
match with_ext_of with
match use_ext_of with
Some rf -> row_field_ext rf
| None -> ref RFnone
in
Expand Down
14 changes: 9 additions & 5 deletions typing/types.mli
Expand Up @@ -302,21 +302,25 @@ val get_row_field: label -> row_desc -> row_field
(** get all fields at once; different from the old [row_repr] *)
type row_desc_repr =
Row of { fields: (label * row_field) list;
more:type_expr;
closed:bool;
fixed:fixed_explanation option;
name:(Path.t * type_expr list) option }
more: type_expr;
closed: bool;
fixed: fixed_explanation option;
name: (Path.t * type_expr list) option }

val row_repr: row_desc -> row_desc_repr

(** Current contents of a row field *)
type row_field_view =
Rpresent of type_expr option
| Reither of bool * type_expr list * bool
(* 1st true denotes a constant constructor *)
(* 2nd true denotes a tag in a pattern matching, and
is erased later *)
| Rabsent

val create_row_field: ?use_ext_of:row_field -> row_field_view -> row_field
val row_field_repr: row_field -> row_field_view
val inj_row_field: ?with_ext_of:row_field -> row_field_view -> row_field

val eq_row_field_ext: row_field -> row_field -> bool
val match_row_field:
present:(type_expr option -> 'a) ->
Expand Down
16 changes: 8 additions & 8 deletions typing/typetexp.ml
Expand Up @@ -324,9 +324,9 @@ and transl_type_aux env policy styp =
(fun (l,f) -> l,
match row_field_repr f with
| Rpresent (Some ty) ->
inj_row_field (Reither(false, [ty], false))
create_row_field (Reither(false, [ty], false))
| Rpresent None ->
inj_row_field (Reither(true, [], false))
create_row_field (Reither(true, [], false))
| _ -> f)
(row_fields row)
in
Expand Down Expand Up @@ -416,14 +416,14 @@ and transl_type_aux env policy styp =
let f = match present with
Some present when not (List.mem l.txt present) ->
let ty_tl = List.map (fun cty -> cty.ctyp_type) tl in
inj_row_field (Reither(c, ty_tl, false))
create_row_field (Reither(c, ty_tl, false))
| _ ->
if List.length stl > 1 || c && stl <> [] then
raise(Error(styp.ptyp_loc, env,
Present_has_conjunction l.txt));
match tl with [] -> inj_row_field (Rpresent None)
match tl with [] -> create_row_field (Rpresent None)
| st :: _ ->
inj_row_field (Rpresent (Some st.ctyp_type))
create_row_field (Rpresent (Some st.ctyp_type))
in
add_typed_field styp.ptyp_loc l.txt f;
Ttag (l,c,tl)
Expand All @@ -450,9 +450,9 @@ and transl_type_aux env policy styp =
Some present when not (List.mem l present) ->
begin match row_field_repr f with
Rpresent(Some ty) ->
inj_row_field (Reither(false, [ty], false))
create_row_field (Reither(false, [ty], false))
| Rpresent None ->
inj_row_field (Reither(true, [], false))
create_row_field (Reither(true, [], false))
| _ ->
assert false
end
Expand Down Expand Up @@ -597,7 +597,7 @@ let rec make_fixed_univars ty =
List.map
(fun (s,f as p) -> match row_field_repr f with
Reither (c, tl, _m) ->
s, inj_row_field ~with_ext_of:f (Reither (c, tl, true))
s, create_row_field ~use_ext_of:f (Reither (c, tl, true))
| _ -> p)
fields
in
Expand Down

0 comments on commit d28a862

Please sign in to comment.