Commit edd4e79d authored by Kim Nguyễn's avatar Kim Nguyễn
Browse files

Add a simplification pass in the pretty-printer, to prevent generating

exponentially large types in some cases. This simplifies types of the form:
T & 'a | T \ 'a into T.
parent 8a796de7
......@@ -1936,6 +1936,26 @@ module Print = struct
) h; h'
with Not_found -> h
let tt, rm_keys =
(* Simplify types of the form 'a & T | T \'a *)
VarTable.fold (fun (v1, v2) tt1 ((acc_empty, acc_keys) as acc) ->
match Var.Set.length v1, Var.Set.length v2 with
0, 1 | 1, 0 ->
let k2 = (v2, v1) in
begin try
let tt2 = VarTable.find h k2 in
if equiv tt2 tt1 then
(cup acc_empty tt1, k2::acc_keys)
else acc
with Not_found -> acc
| _ -> acc
) h ((try VarTable.find h Key.empty with Not_found -> empty), [])
if non_empty tt then VarTable.replace h Key.empty tt;
List.iter (fun (v1, v2) -> VarTable.remove h (v1, v2);
VarTable.remove h (v2, v1)) rm_keys;
let found_any, all_descrs =
let res =
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment