#5809: remove hash-consing of environments, replaced by a much cheaper one-slot memoization.

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13078 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Alain Frisch 2012-11-08 10:31:58 +00:00
parent 0031d158f9
commit 066dce8c20
2 changed files with 19 additions and 26 deletions

View File

@ -62,30 +62,11 @@ type cmt_infos = {
type error =
Not_a_typedtree of string
(*
Keeping all the environments in the typedtree can result in
huge typedtrees.
*)
let need_to_clear_env =
try ignore (Sys.getenv "OCAML_BINANNOT_WITHENV"); false
with Not_found -> true
(* Re-introduce sharing after clearing environments *)
let env_hcons = Hashtbl.create 133
let keep_only_summary env =
let new_env = Env.keep_only_summary env in
try
Hashtbl.find env_hcons new_env
with Not_found ->
Hashtbl.add env_hcons new_env new_env;
new_env
let clear_env_hcons () = Hashtbl.clear env_hcons
let keep_only_summary = Env.keep_only_summary
module ClearEnv = TypedtreeMap.MakeMap (struct
open TypedtreeMap
@ -242,7 +223,6 @@ let save_cmt filename modname binary_annots sourcefile initial_env sg =
cmt_interface_digest = this_crc;
cmt_use_summaries = need_to_clear_env;
} in
clear_env_hcons ();
output_cmt oc cmt;
close_out oc;
set_saved_types [];

View File

@ -1313,12 +1313,25 @@ let initial = Predef.build_initial_env add_type add_exception empty
let summary env = env.summary
let last_env = ref empty
let last_reduced_env = ref empty
let keep_only_summary env =
{ empty with
summary = env.summary;
local_constraints = env.local_constraints;
in_signature = env.in_signature;
}
if !last_env == env then !last_reduced_env
else begin
let new_env =
{
empty with
summary = env.summary;
local_constraints = env.local_constraints;
in_signature = env.in_signature;
}
in
last_env := env;
last_reduced_env := new_env;
new_env
end
let env_of_only_summary env_from_summary env =
let new_env = env_from_summary env.summary Subst.identity in