[racerd] `Precondition` -> `OwnershipPrecondition`

Reviewed By: jeremydubreil

Differential Revision: D7718403

fbshipit-source-id: 73c5cee
master
Sam Blackshear 7 years ago committed by Facebook Github Bot
parent 4fc0ecd86b
commit cfd9802d89

@ -170,7 +170,8 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
| OwnershipAbstractValue.OwnedIf formal_indexes -> | OwnershipAbstractValue.OwnedIf formal_indexes ->
let pre = let pre =
AccessSnapshot.make locks threads AccessSnapshot.make locks threads
(AccessSnapshot.Precondition.Conjunction formal_indexes) proc_data.pdesc (AccessSnapshot.OwnershipPrecondition.Conjunction formal_indexes)
proc_data.pdesc
in in
add_field_access pre add_field_access pre
| OwnershipAbstractValue.Owned -> | OwnershipAbstractValue.Owned ->
@ -227,7 +228,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
in in
let pre = let pre =
AccessSnapshot.make astate.locks astate.threads AccessSnapshot.make astate.locks astate.threads
(AccessSnapshot.Precondition.Conjunction (IntSet.singleton 0)) caller_pdesc (AccessSnapshot.OwnershipPrecondition.Conjunction (IntSet.singleton 0)) caller_pdesc
in in
AccessDomain.add_access pre container_access AccessDomain.empty AccessDomain.add_access pre container_access AccessDomain.empty
in in
@ -328,7 +329,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
in in
AccessDomain.add pre combined_accesses caller_accesses AccessDomain.add pre combined_accesses caller_accesses
in in
let conjoin_ownership_pre actual_exp actual_indexes : AccessSnapshot.Precondition.t = let conjoin_ownership_pre actual_exp actual_indexes : AccessSnapshot.OwnershipPrecondition.t =
match actual_exp with match actual_exp with
| HilExp.Constant _ -> | HilExp.Constant _ ->
(* the actual is a constant, so it's owned in the caller. *) (* the actual is a constant, so it's owned in the caller. *)
@ -360,7 +361,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
(* couldn't find access path, don't know if it's owned. assume not *) (* couldn't find access path, don't know if it's owned. assume not *)
False False
in in
let update_ownership_pre actual_index (acc: AccessSnapshot.Precondition.t) = let update_ownership_pre actual_index (acc: AccessSnapshot.OwnershipPrecondition.t) =
match acc with match acc with
| False -> | False ->
(* precondition can't be satisfied *) (* precondition can't be satisfied *)
@ -379,12 +380,12 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
let ownership_precondition' = let ownership_precondition' =
match pre.ownership_precondition with match pre.ownership_precondition with
| Conjunction indexes -> | Conjunction indexes ->
let empty_pre = AccessSnapshot.Precondition.Conjunction IntSet.empty in let empty_pre = AccessSnapshot.OwnershipPrecondition.Conjunction IntSet.empty in
IntSet.fold update_ownership_pre indexes empty_pre IntSet.fold update_ownership_pre indexes empty_pre
| False -> | False ->
pre.ownership_precondition pre.ownership_precondition
in in
if AccessSnapshot.Precondition.is_true ownership_precondition' then accesses_acc if AccessSnapshot.OwnershipPrecondition.is_true ownership_precondition' then accesses_acc
else else
let locks' = if pre.lock then LocksDomain.add_lock locks else locks in let locks' = if pre.lock then LocksDomain.add_lock locks else locks in
(* if the access occurred on a main thread in the callee, we should remember this when (* if the access occurred on a main thread in the callee, we should remember this when

@ -404,7 +404,7 @@ module AttributeMapDomain = struct
end end
module AccessSnapshot = struct module AccessSnapshot = struct
module Precondition = struct module OwnershipPrecondition = struct
type t = Conjunction of IntSet.t | False [@@deriving compare] type t = Conjunction of IntSet.t | False [@@deriving compare]
(* precondition is true if the conjunction of owned indexes is empty *) (* precondition is true if the conjunction of owned indexes is empty *)
@ -420,25 +420,25 @@ module AccessSnapshot = struct
end end
type t = type t =
{thread: ThreadsDomain.astate; lock: bool; ownership_precondition: Precondition.t} {thread: ThreadsDomain.astate; lock: bool; ownership_precondition: OwnershipPrecondition.t}
[@@deriving compare] [@@deriving compare]
let make lock thread ownership_precondition pdesc = let make lock thread ownership_precondition pdesc =
(* 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 (Precondition.is_true ownership_precondition)) ; assert (not (OwnershipPrecondition.is_true ownership_precondition)) ;
let lock = LocksDomain.is_locked lock || Procdesc.is_java_synchronized pdesc in let lock = LocksDomain.is_locked lock || Procdesc.is_java_synchronized pdesc in
{thread; lock; ownership_precondition} {thread; lock; ownership_precondition}
let is_unprotected {thread; lock; ownership_precondition} = let is_unprotected {thread; lock; ownership_precondition} =
not (ThreadsDomain.is_any_but_self thread) && not lock not (ThreadsDomain.is_any_but_self thread) && not lock
&& not (Precondition.is_true ownership_precondition) && not (OwnershipPrecondition.is_true ownership_precondition)
let pp fmt {thread; lock; ownership_precondition} = let pp fmt {thread; lock; ownership_precondition} =
F.fprintf fmt "Thread: %a Lock: %b Pre: %a" ThreadsDomain.pp thread lock Precondition.pp F.fprintf fmt "Thread: %a Lock: %b Pre: %a" ThreadsDomain.pp thread lock
ownership_precondition OwnershipPrecondition.pp ownership_precondition
end end
module AccessDomain = struct module AccessDomain = struct

@ -78,11 +78,11 @@ module ThreadsDomain : sig
assume this by default unless we see evidence to the contrary (annotations, use of locks, assume this by default unless we see evidence to the contrary (annotations, use of locks,
etc.) *) etc.) *)
| AnyThreadButSelf | AnyThreadButSelf
(** Current thread can run in parallel with other threads, but not with itself. (** Current thread can run in parallel with other threads, but not with a copy of itself.
(concretization : { t | t \in TIDs ^ t != t_cur } ) *) (concretization : { t | t \in TIDs ^ t != t_cur } ) *)
| AnyThread | AnyThread
(** Current thread can run in parallel with any thread, including itself (concretization: set (** Current thread can run in parallel with any thread, including itself (concretization:
of all TIDs ) *) set of all TIDs ) *)
include AbstractDomain.WithBottom with type astate := astate include AbstractDomain.WithBottom with type astate := astate
@ -158,10 +158,10 @@ module AttributeMapDomain : sig
val add_attribute : AccessPath.t -> Attribute.t -> astate -> astate val add_attribute : AccessPath.t -> Attribute.t -> astate -> astate
end end
(** Data shared among a set of accesses: current thread, lock(s) held, ownership precondition *) (** snapshot of the relevant state at the time of a heap access: concurrent thread(s), lock(s) held, ownership precondition *)
module AccessSnapshot : sig module AccessSnapshot : sig
(** Precondition for owned access; access is owned if it evaluates to ture *) (** precondition for owned access; access is owned if it evaluates to true *)
module Precondition : sig module OwnershipPrecondition : sig
type t = type t =
| Conjunction of IntSet.t | Conjunction of IntSet.t
(** Conjunction of "formal index must be owned" predicates. (** Conjunction of "formal index must be owned" predicates.
@ -176,10 +176,11 @@ module AccessSnapshot : sig
end end
type t = private type t = private
{thread: ThreadsDomain.astate; lock: bool; ownership_precondition: Precondition.t} {thread: ThreadsDomain.astate; lock: bool; ownership_precondition: OwnershipPrecondition.t}
[@@deriving compare] [@@deriving compare]
val make : LocksDomain.astate -> ThreadsDomain.astate -> Precondition.t -> Procdesc.t -> t val make :
LocksDomain.astate -> ThreadsDomain.astate -> OwnershipPrecondition.t -> Procdesc.t -> t
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 *)

Loading…
Cancel
Save