[racerd] fix unknown-returns-owned option to true and remove

Summary: Specialise the above option to `true` and remove resulting dead code.

Reviewed By: dulmarod

Differential Revision: D21177041

fbshipit-source-id: 4a1c65850
master
Nikos Gorogiannis 5 years ago committed by Facebook GitHub Bot
parent 07175f163c
commit 581af4856e

@ -431,8 +431,7 @@ RACERD CHECKER OPTIONS
--no-racerd-guardedby) --no-racerd-guardedby)
--no-racerd-unknown-returns-owned --no-racerd-unknown-returns-owned
Deactivates: Assume that all methods without a CFG (including Deactivates: DEPRECATED, does nothing. (Conversely:
abstract methods) return owned objects (Conversely:
--racerd-unknown-returns-owned) --racerd-unknown-returns-owned)
--threadsafe-aliases json --threadsafe-aliases json

@ -911,8 +911,7 @@ OPTIONS
(Conversely: --no-racerd-only) See also infer-analyze(1). (Conversely: --no-racerd-only) See also infer-analyze(1).
--no-racerd-unknown-returns-owned --no-racerd-unknown-returns-owned
Deactivates: Assume that all methods without a CFG (including Deactivates: DEPRECATED, does nothing. (Conversely:
abstract methods) return owned objects (Conversely:
--racerd-unknown-returns-owned) See also infer-analyze(1). --racerd-unknown-returns-owned) See also infer-analyze(1).
--reactive,-r --reactive,-r

@ -911,8 +911,7 @@ OPTIONS
(Conversely: --no-racerd-only) See also infer-analyze(1). (Conversely: --no-racerd-only) See also infer-analyze(1).
--no-racerd-unknown-returns-owned --no-racerd-unknown-returns-owned
Deactivates: Assume that all methods without a CFG (including Deactivates: DEPRECATED, does nothing. (Conversely:
abstract methods) return owned objects (Conversely:
--racerd-unknown-returns-owned) See also infer-analyze(1). --racerd-unknown-returns-owned) See also infer-analyze(1).
--reactive,-r --reactive,-r

@ -1829,10 +1829,11 @@ and racerd_guardedby =
"Check @GuardedBy annotations with RacerD" "Check @GuardedBy annotations with RacerD"
and racerd_unknown_returns_owned = and[@warning "-32"] racerd_unknown_returns_owned =
CLOpt.mk_bool ~long:"racerd-unknown-returns-owned" ~default:true CLOpt.mk_bool ~deprecated:["racerd-unknown-returns-owned"] ~long:"racerd-unknown-returns-owned"
~default:true
~in_help:InferCommand.[(Analyze, manual_racerd)] ~in_help:InferCommand.[(Analyze, manual_racerd)]
"Assume that all methods without a CFG (including abstract methods) return owned objects" "DEPRECATED, does nothing."
and reactive = and reactive =
@ -2879,8 +2880,6 @@ and quiet = !quiet
and racerd_guardedby = !racerd_guardedby and racerd_guardedby = !racerd_guardedby
and racerd_unknown_returns_owned = !racerd_unknown_returns_owned
and reactive_mode = !reactive and reactive_mode = !reactive
and reactive_capture = !reactive_capture and reactive_capture = !reactive_capture

@ -469,8 +469,6 @@ val quiet : bool
val racerd_guardedby : bool val racerd_guardedby : bool
val racerd_unknown_returns_owned : bool
val reactive_capture : bool val reactive_capture : bool
val reactive_mode : bool val reactive_mode : bool

@ -149,22 +149,9 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
AccessDomain.fold update_callee_access callee_accesses caller_astate.accesses AccessDomain.fold update_callee_access callee_accesses caller_astate.accesses
let call_without_summary tenv callee_pname ret_base call_flags actuals astate = let call_without_summary tenv callee_pname ret_base actuals astate =
let open RacerDModels in let open RacerDModels in
let open RacerDDomain in let open RacerDDomain in
let should_assume_returns_ownership callee_pname (call_flags : CallFlags.t) actuals =
Config.racerd_unknown_returns_owned
(* non-interface methods with no summary and no parameters *)
|| ((not call_flags.cf_interface) && List.is_empty actuals)
|| (* static [$Builder] creation methods *)
creates_builder callee_pname
in
let should_assume_returns_conditional_ownership callee_pname =
(* non-interface methods with no parameters *)
is_abstract_getthis_like callee_pname
|| (* non-static [$Builder] methods with same return type as receiver type *)
is_builder_passthrough callee_pname
in
if RacerDModels.is_synchronized_container_constructor tenv callee_pname actuals then if RacerDModels.is_synchronized_container_constructor tenv callee_pname actuals then
List.hd actuals |> Option.bind ~f:get_access_exp List.hd actuals |> Option.bind ~f:get_access_exp
|> Option.value_map ~default:astate ~f:(fun receiver -> |> Option.value_map ~default:astate ~f:(fun receiver ->
@ -188,22 +175,12 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
{astate with attribute_map} {astate with attribute_map}
| _ -> | _ ->
astate astate
else if should_assume_returns_ownership callee_pname call_flags actuals then else
let ownership = let ownership =
OwnershipDomain.add (AccessExpression.base ret_base) OwnershipAbstractValue.owned OwnershipDomain.add (AccessExpression.base ret_base) OwnershipAbstractValue.owned
astate.ownership astate.ownership
in in
{astate with ownership} {astate with ownership}
else if should_assume_returns_conditional_ownership callee_pname then
(* assume abstract, single-parameter methods whose return type is equal to that of the first
formal return conditional ownership -- an example is getThis in Litho *)
let ownership =
OwnershipDomain.add (AccessExpression.base ret_base)
(OwnershipAbstractValue.make_owned_if 0)
astate.ownership
in
{astate with ownership}
else astate
let treat_call_acquiring_ownership ret_base procname actuals loc let treat_call_acquiring_ownership ret_base procname actuals loc
@ -321,7 +298,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
in in
{locks; threads; accesses; ownership; attribute_map} {locks; threads; accesses; ownership; attribute_map}
| None -> | None ->
call_without_summary tenv callee_pname ret_base call_flags actuals astate ) call_without_summary tenv callee_pname ret_base actuals astate )
in in
let add_if_annotated predicate attribute attribute_map = let add_if_annotated predicate attribute attribute_map =
if PatternMatch.override_exists predicate tenv callee_pname then if PatternMatch.override_exists predicate tenv callee_pname then

@ -513,47 +513,5 @@ let is_synchronized_container callee_pname (access_exp : HilExp.AccessExpression
false false
(** check that callee is abstract and accepts one argument. In addition, its argument type must be
equal to its return type. *)
let is_abstract_getthis_like callee =
attrs_of_pname callee
|> Option.exists ~f:(fun (attrs : ProcAttributes.t) ->
attrs.is_abstract
&&
match attrs.formals with
| [(_, typ)] when Typ.equal typ attrs.ret_type ->
true
| _ ->
false )
let creates_builder callee =
(match callee with Procname.Java jpname -> Procname.Java.is_static jpname | _ -> false)
&& String.equal "create" (Procname.get_method callee)
&& attrs_of_pname callee
|> Option.exists ~f:(fun (attrs : ProcAttributes.t) ->
match attrs.ret_type with
| Typ.{desc= Tptr ({desc= Tstruct ret_class}, _)} ->
is_builder_class ret_class
| _ ->
false )
let is_builder_passthrough callee =
match callee with
| Procname.Java java_pname ->
(not (Procname.Java.is_static java_pname))
&& is_builder_method java_pname
&& attrs_of_pname callee
|> Option.exists ~f:(fun (attrs : ProcAttributes.t) ->
match attrs.formals with
| (_, typ) :: _ when Typ.equal typ attrs.ret_type ->
true
| _ ->
false )
| _ ->
false
let is_initializer tenv proc_name = let is_initializer tenv proc_name =
Procname.is_constructor proc_name || FbThreadSafety.is_custom_init tenv proc_name Procname.is_constructor proc_name || FbThreadSafety.is_custom_init tenv proc_name

@ -53,15 +53,6 @@ val should_flag_interface_call : Tenv.t -> HilExp.t list -> CallFlags.t -> Procn
val is_synchronized_container : Procname.t -> HilExp.AccessExpression.t -> Tenv.t -> bool val is_synchronized_container : Procname.t -> HilExp.AccessExpression.t -> Tenv.t -> bool
(** is a call on an access expression to a method of a synchronized container? *) (** is a call on an access expression to a method of a synchronized container? *)
val is_abstract_getthis_like : Procname.t -> bool
(** is the callee an abstract method with one argument where argument type is equal to return type *)
val creates_builder : Procname.t -> bool
(** is the callee a static java method returning a [Builder] object? *)
val is_builder_passthrough : Procname.t -> bool
(** is the callee a non-static [Builder] method returning the same type as its receiver *)
val is_initializer : Tenv.t -> Procname.t -> bool val is_initializer : Tenv.t -> Procname.t -> bool
(** should the given procedure be treated as a constructor/initializer? *) (** should the given procedure be treated as a constructor/initializer? *)

Loading…
Cancel
Save