#6343, #5537, #5573: improving access to values in nested modules.

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14452 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Alain Frisch 2014-03-10 10:02:31 +00:00
parent 65b1193406
commit ebd01bc49e
4 changed files with 19 additions and 3 deletions

View File

@ -82,3 +82,4 @@ type value_approximation =
| Value_tuple of value_approximation array
| Value_unknown
| Value_const of uconstant
| Value_global_field of string * int

View File

@ -82,3 +82,4 @@ type value_approximation =
| Value_tuple of value_approximation array
| Value_unknown
| Value_const of uconstant
| Value_global_field of string * int

View File

@ -465,6 +465,15 @@ let strengthen_approx appl approx =
let check_constant_result lam ulam approx =
match approx with
Value_const c when is_pure lam -> make_const c
| Value_global_field (id, i) when is_pure lam ->
begin match ulam with
| Uprim(Pfield _, [Uprim(Pgetglobal _, _, _)], _) -> (ulam, approx)
| _ ->
let glb =
Uprim(Pgetglobal (Ident.create_persistent id), [], Debuginfo.none)
in
Uprim(Pfield i, [glb], Debuginfo.none), approx
end
| _ -> (ulam, approx)
(* Evaluate an expression with known value for its side effects only,
@ -679,7 +688,8 @@ let rec close fenv cenv = function
fieldapprox
| Lprim(Psetfield(n, _), [Lprim(Pgetglobal id, []); lam]) ->
let (ulam, approx) = close fenv cenv lam in
(!global_approx).(n) <- approx;
if approx <> Value_unknown then
(!global_approx).(n) <- approx;
(Uprim(Psetfield(n, false), [getglobal id; ulam], Debuginfo.none),
Value_unknown)
| Lprim(Praise k, [Levent(arg, ev)]) ->
@ -910,7 +920,7 @@ let collect_exported_structured_constants a =
end
| Value_tuple a -> Array.iter approx a
| Value_const c -> const c
| Value_unknown -> ()
| Value_unknown | Value_global_field _ -> ()
and const = function
| Uconst_ref (s, c) ->
Compilenv.add_exported_constant s;
@ -953,7 +963,8 @@ let collect_exported_structured_constants a =
let intro size lam =
function_nesting_depth := 0;
global_approx := Array.create size Value_unknown;
let id = Compilenv.make_symbol None in
global_approx := Array.init size (fun i -> Value_global_field (id, i));
Compilenv.set_global_approx(Value_tuple !global_approx);
let (ulam, approx) = close Tbl.empty Tbl.empty lam in
collect_exported_structured_constants (Value_tuple !global_approx);

View File

@ -171,3 +171,6 @@ let rec approx ppf = function
Format.fprintf ppf "_"
| Value_const c ->
fprintf ppf "@[const(%a)@]" uconstant c
| Value_global_field (s, i) ->
fprintf ppf "@[global(%s,%i)@]" s i