From 08c3b1780a8771124c21efa07155cd8672a13ca6 Mon Sep 17 00:00:00 2001 From: Alain Frisch Date: Fri, 12 Oct 2012 08:24:34 +0000 Subject: [PATCH] PR#5787: Bad behavior of 'Unused ...' warnings in the toplevel. git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13010 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02 --- Changes | 1 + toplevel/toploop.ml | 2 +- typing/env.ml | 18 +++++++++++++----- typing/env.mli | 4 +++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Changes b/Changes index d51958d9d..ba4255a49 100644 --- a/Changes +++ b/Changes @@ -26,6 +26,7 @@ Bug fixes: - PR#5747: 'unused open' warning not given when compiling with -annot - PR#5758: Compiler bug when matching on floats - PR#5763: ocamlbuild does not give correct flags when running menhir +- PR#5787: Bad behavior of 'Unused ...' warnings in the toplevel Internals: - Moved debugger/envaux.ml to typing/envaux.ml to publish env_of_only_summary diff --git a/toplevel/toploop.ml b/toplevel/toploop.ml index f75e27b19..821561587 100644 --- a/toplevel/toploop.ml +++ b/toplevel/toploop.ml @@ -422,7 +422,7 @@ let loop ppf = first_line := true; let phr = try !parse_toplevel_phrase lb with Exit -> raise PPerror in if !Clflags.dump_parsetree then Printast.top_phrase ppf phr; - Env.reset_missing_cmis (); + Env.reset_cache_toplevel (); ignore(execute_phrase true ppf phr) with | End_of_file -> exit 0 diff --git a/typing/env.ml b/typing/env.ml index c287e1dc6..47cd1f005 100644 --- a/typing/env.ml +++ b/typing/env.ml @@ -329,13 +329,21 @@ let reset_cache () = Hashtbl.clear persistent_structures; Consistbl.clear crc_units; Hashtbl.clear value_declarations; - Hashtbl.clear type_declarations + Hashtbl.clear type_declarations; + Hashtbl.clear used_constructors -let reset_missing_cmis () = - let l = Hashtbl.fold +let reset_cache_toplevel () = + (* Delete 'missing cmi' entries from the cache. *) + let l = + Hashtbl.fold (fun name r acc -> if r = None then name :: acc else acc) - persistent_structures [] in - List.iter (Hashtbl.remove persistent_structures) l + persistent_structures [] + in + List.iter (Hashtbl.remove persistent_structures) l; + Hashtbl.clear value_declarations; + Hashtbl.clear type_declarations; + Hashtbl.clear used_constructors + let set_unit_name name = current_unit := name diff --git a/typing/env.mli b/typing/env.mli index e6fa36542..71680ebba 100644 --- a/typing/env.mli +++ b/typing/env.mli @@ -108,7 +108,9 @@ val enter_cltype: string -> class_type_declaration -> t -> Ident.t * t (* Initialize the cache of in-core module interfaces. *) val reset_cache: unit -> unit -val reset_missing_cmis: unit -> unit + +(* To be called before each toplevel phrase. *) +val reset_cache_toplevel: unit -> unit (* Remember the name of the current compilation unit. *) val set_unit_name: string -> unit