Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not generalize the type of every sub-pattern, only of variables #1745

Merged
merged 2 commits into from May 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changes
Expand Up @@ -40,6 +40,9 @@ Working version

### Internal/compiler-libs changes:

- GPR#1745: do not generalize the type of every sub-pattern, only of variables
(Thomas Refis, review by Leo White)

- GPR#1747: type_cases: always propagate
(Thomas Refis, review by Jacques Garrigue)

Expand Down
14 changes: 10 additions & 4 deletions typing/typecore.ml
Expand Up @@ -1490,6 +1490,9 @@ let check_unused ?(lev=get_current_level ()) env expected_ty cases =
| r -> r)
cases

let iter_pattern_variables_type f : pattern_variable list -> unit =
List.iter (fun (_, t, _, _, _) -> f t)

let add_pattern_variables ?check ?check_as env pv =
List.fold_right
(fun (id, ty, _name, loc, as_var) env ->
Expand Down Expand Up @@ -4723,7 +4726,7 @@ and type_cases ?in_function env ty_arg ty_res partial_flag loc caselist =
let pat =
if !Clflags.principal then begin
end_def ();
iter_pattern (fun {pat_type=t} -> generalize_structure t) pat;
iter_pattern_variables_type generalize_structure pvs;
{ pat with pat_type = instance pat.pat_type }
end else pat
in
Expand Down Expand Up @@ -4764,11 +4767,14 @@ and type_cases ?in_function env ty_arg ty_res partial_flag loc caselist =
List.iter (fun f -> f()) !pattern_force;
(* Post-processing and generalization *)
if take_partial_instance <> None then unify_pats (instance ty_arg);
List.iter
(iter_pattern (fun {pat_type=t} -> unify_var env (newvar()) t)) patl;
List.iter (fun { pat_vars; _ } ->
iter_pattern_variables_type (fun t -> unify_var env (newvar()) t) pat_vars
) half_typed_cases;
end_def ();
generalize ty_arg';
List.iter (iter_pattern (fun {pat_type=t} -> generalize t)) patl;
List.iter (fun { pat_vars; _ } ->
iter_pattern_variables_type generalize pat_vars
) half_typed_cases;
(* type bodies *)
let in_function = if List.length caselist = 1 then in_function else None in
let cases =
Expand Down