Skip to content

Commit

Permalink
ocaml#5809: remove hash-consing of environments, replaced by a much c…
Browse files Browse the repository at this point in the history
…heaper one-slot memoization.

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13078 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
  • Loading branch information
alainfrisch committed Nov 8, 2012
1 parent 0031d15 commit 066dce8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
22 changes: 1 addition & 21 deletions typing/cmt_format.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 [];
Expand Down
23 changes: 18 additions & 5 deletions typing/env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 066dce8

Please sign in to comment.