[racerd] remove redundant ownership constructor/state

Reviewed By: jeremydubreil

Differential Revision: D13489018

fbshipit-source-id: b94c50664
master
Nikos Gorogiannis 6 years ago committed by Facebook Github Bot
parent e2bb049a5e
commit 9e91c9298b

@ -33,7 +33,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
| access :: access_list -> ( | access :: access_list -> (
let prefix_path' = (fst prefix_path, snd prefix_path @ [access]) in let prefix_path' = (fst prefix_path, snd prefix_path @ [access]) in
let add_field_access pre = let add_field_access pre =
let access_acc' = AccessDomain.add pre access_acc in let access_acc' = AccessDomain.add_opt pre access_acc in
add_field_accesses prefix_path' access_acc' access_list add_field_accesses prefix_path' access_acc' access_list
in in
if RacerDModels.is_safe_access access prefix_path proc_data.tenv then if RacerDModels.is_safe_access access prefix_path proc_data.tenv then
@ -49,17 +49,13 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
proc_data.pdesc proc_data.pdesc
in in
add_field_access pre add_field_access pre
| OwnershipAbstractValue.Owned ->
add_field_accesses prefix_path' access_acc access_list
| OwnershipAbstractValue.Unowned -> | OwnershipAbstractValue.Unowned ->
let pre = AccessSnapshot.make access locks threads False proc_data.pdesc in let pre = AccessSnapshot.make access locks threads False proc_data.pdesc in
add_field_access pre ) add_field_access pre )
in in
List.fold List.fold (HilExp.get_access_exprs exp) ~init:accesses ~f:(fun acc access_expr ->
~f:(fun acc access_expr ->
let base, accesses = HilExp.AccessExpression.to_access_path access_expr in let base, accesses = HilExp.AccessExpression.to_access_path access_expr in
add_field_accesses (base, []) acc accesses ) add_field_accesses (base, []) acc accesses )
~init:accesses (HilExp.get_access_exprs exp)
let make_container_access callee_pname ~is_write receiver_ap callee_loc tenv caller_pdesc let make_container_access callee_pname ~is_write receiver_ap callee_loc tenv caller_pdesc
@ -78,7 +74,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
(AccessSnapshot.OwnershipPrecondition.Conjunction (IntSet.singleton 0)) (AccessSnapshot.OwnershipPrecondition.Conjunction (IntSet.singleton 0))
caller_pdesc caller_pdesc
in in
AccessDomain.singleton snapshot AccessDomain.add_opt snapshot AccessDomain.empty
in in
(* if a container c is owned in cpp, make c[i] owned for all i *) (* if a container c is owned in cpp, make c[i] owned for all i *)
let return_ownership = let return_ownership =
@ -148,12 +144,12 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
| None -> | None ->
path path
in in
let expand_precondition (snapshot : AccessSnapshot.t) = let add snapshot acc =
let access' = TraceElem.map ~f:expand_path snapshot.access in let access' = TraceElem.map ~f:expand_path snapshot.AccessSnapshot.access in
if phys_equal snapshot.access access' then snapshot let snapshot_opt' = AccessSnapshot.make_from_snapshot access' snapshot in
else AccessSnapshot.make_from_snapshot access' snapshot AccessDomain.add_opt snapshot_opt' acc
in in
AccessDomain.map expand_precondition accesses AccessDomain.fold add accesses AccessDomain.empty
let add_callee_accesses (caller_astate : Domain.t) callee_accesses locks threads actuals let add_callee_accesses (caller_astate : Domain.t) callee_accesses locks threads actuals
@ -168,10 +164,6 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
| HilExp.AccessExpression access_expr -> ( | HilExp.AccessExpression access_expr -> (
let actual_access_path = HilExp.AccessExpression.to_access_path access_expr in let actual_access_path = HilExp.AccessExpression.to_access_path access_expr in
match OwnershipDomain.get_owned actual_access_path caller_astate.ownership with match OwnershipDomain.get_owned actual_access_path caller_astate.ownership with
| Owned ->
(* the actual passed to the current callee is owned. drop all the conditional
accesses for that actual, since they're all safe *)
Conjunction actual_indexes
| OwnedIf formal_indexes -> | OwnedIf formal_indexes ->
(* access path conditionally owned if [formal_indexes] are owned *) (* access path conditionally owned if [formal_indexes] are owned *)
Conjunction (IntSet.union formal_indexes actual_indexes) Conjunction (IntSet.union formal_indexes actual_indexes)
@ -214,8 +206,8 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
(* discard accesses to owned memory *) (* discard accesses to owned memory *)
acc acc
else else
let snapshot = AccessSnapshot.make access locks thread ownership_precondition pdesc in let snapshot_opt = AccessSnapshot.make access locks thread ownership_precondition pdesc in
AccessDomain.add snapshot acc AccessDomain.add_opt snapshot_opt acc
in in
AccessDomain.fold update_callee_access callee_accesses caller_astate.accesses AccessDomain.fold update_callee_access callee_accesses caller_astate.accesses

@ -291,14 +291,16 @@ module AccessSnapshot = struct
let make_from_snapshot access {lock; thread; ownership_precondition} = let make_from_snapshot access {lock; thread; ownership_precondition} =
(* shouldn't be creating metadata for accesses that are known to be owned; we should discard (* shouldn't be creating metadata for accesses that are known to be owned; we should discard
such accesses *) such accesses *)
assert (not (OwnershipPrecondition.is_true ownership_precondition)) ; Option.some_if
(not (OwnershipPrecondition.is_true ownership_precondition))
{access; thread; lock; ownership_precondition} {access; thread; lock; ownership_precondition}
let make access lock thread ownership_precondition pdesc = let make access lock thread ownership_precondition pdesc =
assert (not (OwnershipPrecondition.is_true ownership_precondition)) ; if not (OwnershipPrecondition.is_true ownership_precondition) then
let lock = LocksDomain.is_locked lock || Procdesc.is_java_synchronized pdesc in let lock = LocksDomain.is_locked lock || Procdesc.is_java_synchronized pdesc in
{access; lock; thread; ownership_precondition} Some {access; lock; thread; ownership_precondition}
else None
let is_unprotected {thread; lock; ownership_precondition} = let is_unprotected {thread; lock; ownership_precondition} =
@ -321,12 +323,16 @@ module AccessDomain = struct
|> Option.value_map ~default:false ~f:(fun ((v, _), _) -> should_skip_var v) |> Option.value_map ~default:false ~f:(fun ((v, _), _) -> should_skip_var v)
in in
if skip then astate else add s astate if skip then astate else add s astate
let add_opt snapshot_opt astate =
Option.fold snapshot_opt ~init:astate ~f:(fun acc s -> add s acc)
end end
module OwnershipAbstractValue = struct module OwnershipAbstractValue = struct
type t = Owned | OwnedIf of IntSet.t | Unowned [@@deriving compare] type t = OwnedIf of IntSet.t | Unowned [@@deriving compare]
let owned = Owned let owned = OwnedIf IntSet.empty
let unowned = Unowned let unowned = Unowned
@ -340,12 +346,8 @@ module OwnershipAbstractValue = struct
true (* Unowned is top *) true (* Unowned is top *)
| Unowned, _ -> | Unowned, _ ->
false false
| Owned, _ ->
true (* Owned is bottom *)
| OwnedIf s1, OwnedIf s2 -> | OwnedIf s1, OwnedIf s2 ->
IntSet.subset s1 s2 IntSet.subset s1 s2
| OwnedIf _, Owned ->
false
let join astate1 astate2 = let join astate1 astate2 =
@ -354,8 +356,6 @@ module OwnershipAbstractValue = struct
match (astate1, astate2) with match (astate1, astate2) with
| _, Unowned | Unowned, _ -> | _, Unowned | Unowned, _ ->
Unowned Unowned
| astate, Owned | Owned, astate ->
astate
| OwnedIf s1, OwnedIf s2 -> | OwnedIf s1, OwnedIf s2 ->
OwnedIf (IntSet.union s1 s2) OwnedIf (IntSet.union s1 s2)
@ -366,11 +366,11 @@ module OwnershipAbstractValue = struct
| Unowned -> | Unowned ->
F.pp_print_string fmt "Unowned" F.pp_print_string fmt "Unowned"
| OwnedIf s -> | OwnedIf s ->
if IntSet.is_empty s then F.pp_print_string fmt "Owned"
else
F.fprintf fmt "OwnedIf%a" F.fprintf fmt "OwnedIf%a"
(PrettyPrintable.pp_collection ~pp_item:Int.pp) (PrettyPrintable.pp_collection ~pp_item:Int.pp)
(IntSet.elements s) (IntSet.elements s)
| Owned ->
F.pp_print_string fmt "Owned"
end end
module OwnershipDomain = struct module OwnershipDomain = struct
@ -387,7 +387,7 @@ module OwnershipDomain = struct
OwnershipAbstractValue.Unowned OwnershipAbstractValue.Unowned
in in
match find access_path astate with match find access_path astate with
| (OwnershipAbstractValue.Owned | OwnedIf _) as v -> | OwnershipAbstractValue.OwnedIf _ as v ->
v v
| OwnershipAbstractValue.Unowned -> | OwnershipAbstractValue.Unowned ->
keep_looking access_path astate keep_looking access_path astate
@ -426,7 +426,7 @@ module OwnershipDomain = struct
in in
let ret_ownership_wrt_actuals = let ret_ownership_wrt_actuals =
match return_ownership with match return_ownership with
| OwnershipAbstractValue.Owned | Unowned -> | OwnershipAbstractValue.Unowned ->
return_ownership return_ownership
| OwnershipAbstractValue.OwnedIf formal_indexes -> | OwnershipAbstractValue.OwnedIf formal_indexes ->
IntSet.fold get_ownership formal_indexes OwnershipAbstractValue.owned IntSet.fold get_ownership formal_indexes OwnershipAbstractValue.owned
@ -595,4 +595,4 @@ let pp fmt {threads; locks; accesses; ownership; attribute_map} =
let add_unannotated_call_access pname loc pdesc (astate : t) = let add_unannotated_call_access pname loc pdesc (astate : t) =
let access = TraceElem.make_unannotated_call_access pname loc in let access = TraceElem.make_unannotated_call_access pname loc in
let snapshot = AccessSnapshot.make access astate.locks astate.threads False pdesc in let snapshot = AccessSnapshot.make access astate.locks astate.threads False pdesc in
{astate with accesses= AccessDomain.add snapshot astate.accesses} {astate with accesses= AccessDomain.add_opt snapshot astate.accesses}

@ -116,9 +116,9 @@ module AccessSnapshot : sig
-> ThreadsDomain.t -> ThreadsDomain.t
-> OwnershipPrecondition.t -> OwnershipPrecondition.t
-> Procdesc.t -> Procdesc.t
-> t -> t option
val make_from_snapshot : PathDomain.Sink.t -> t -> t val make_from_snapshot : PathDomain.Sink.t -> t -> t option
val is_unprotected : t -> bool val is_unprotected : t -> bool
(** return true if not protected by lock, thread, or ownership *) (** return true if not protected by lock, thread, or ownership *)
@ -126,12 +126,17 @@ end
(** map of access metadata |-> set of accesses. the map should hold all accesses to a (** map of access metadata |-> set of accesses. the map should hold all accesses to a
possibly-unowned access path *) possibly-unowned access path *)
module AccessDomain : AbstractDomain.FiniteSetS with type elt = AccessSnapshot.t module AccessDomain : sig
include AbstractDomain.FiniteSetS with type elt = AccessSnapshot.t
val add_opt : elt option -> t -> t
end
module OwnershipAbstractValue : sig module OwnershipAbstractValue : sig
type t = private type t = private
| Owned (** Owned value; bottom of the lattice *) | OwnedIf of IntSet.t
| OwnedIf of IntSet.t (** Owned if the formals at the given indexes are owned in the caller *) (** Owned if the formals at the given indexes are owned in the caller; unconditionally owned
if the set of formals is empty = bottom of the lattice *)
| Unowned (** Unowned value; top of the lattice *) | Unowned (** Unowned value; top of the lattice *)
[@@deriving compare] [@@deriving compare]

Loading…
Cancel
Save