git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14452 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02master
parent
65b1193406
commit
ebd01bc49e
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue