[Loop-hoisting] Add a new model for Javax's Provider.get() and make it invariant only

Reviewed By: mbouaziz, ddino

Differential Revision: D9748162

fbshipit-source-id: bedd2300e
master
Ezgi Çiçek 6 years ago committed by Facebook Github Bot
parent e5b38a42d8
commit 15bdcca119

@ -66,6 +66,8 @@ let implements_pseudo_collection t s =
let implements_enumeration = implements "java.util.Enumeration" let implements_enumeration = implements "java.util.Enumeration"
let implements_inject class_name = implements ("javax.inject." ^ class_name)
let implements_io class_name = implements ("java.io." ^ class_name) let implements_io class_name = implements ("java.io." ^ class_name)
let implements_map = implements "java.util.Map" let implements_map = implements "java.util.Map"

@ -43,6 +43,9 @@ val implements_pseudo_collection : Tenv.t -> string -> bool
val implements_enumeration : Tenv.t -> string -> bool val implements_enumeration : Tenv.t -> string -> bool
(** Check whether class implements a Java's Enumeration *) (** Check whether class implements a Java's Enumeration *)
val implements_inject : string -> Tenv.t -> string -> bool
(** Check whether class implements a Javax Inject *)
val implements_io : string -> Tenv.t -> string -> bool val implements_io : string -> Tenv.t -> string -> bool
(** Check whether class implements a Java IO *) (** Check whether class implements a Java IO *)

@ -55,7 +55,7 @@ let get_hoist_inv_map tenv reaching_defs_invariant_map loop_head_to_source_nodes
let loop_nodes = Loop_control.get_all_nodes_upwards_until loop_head source_nodes in let loop_nodes = Loop_control.get_all_nodes_upwards_until loop_head source_nodes in
let inv_vars_in_loop = let inv_vars_in_loop =
LoopInvariant.get_inv_vars_in_loop tenv reaching_defs_invariant_map loop_head loop_nodes LoopInvariant.get_inv_vars_in_loop tenv reaching_defs_invariant_map loop_head loop_nodes
~is_inv_by_default:true ~is_inv_by_default:Config.cost_invariant_by_default
in in
let hoist_instrs = get_hoistable_calls inv_vars_in_loop loop_nodes source_nodes idom in let hoist_instrs = get_hoistable_calls inv_vars_in_loop loop_nodes source_nodes idom in
LoopHeadToHoistInstrs.add loop_head hoist_instrs inv_map ) LoopHeadToHoistInstrs.add loop_head hoist_instrs inv_map )

@ -7,12 +7,19 @@
open! IStd open! IStd
type model = Variant | VariantForHoisting type model = Invariant | Variant | VariantForHoisting
(* Even though functions marked with VariantForHoisting are pure, we (* Even though functions marked with VariantForHoisting are pure, we
don't want to report them in hoisting. Hence, we model them as don't want to report them in hoisting. Hence, we model them as
Variant. *) Variant. *)
let is_invariant = function VariantForHoisting -> not Config.loop_hoisting | Variant -> false let is_invariant = function
| Invariant ->
true
| VariantForHoisting ->
not Config.loop_hoisting
| Variant ->
false
module Call = struct module Call = struct
let dispatch : (Tenv.t, model) ProcnameDispatcher.Call.dispatcher = let dispatch : (Tenv.t, model) ProcnameDispatcher.Call.dispatcher =
@ -55,6 +62,7 @@ module Call = struct
; +PatternMatch.implements_io "PrintStream" &:: "println" <>--> Variant ; +PatternMatch.implements_io "PrintStream" &:: "println" <>--> Variant
; +PatternMatch.implements_io "Reader" &:: "read" <>--> Variant ; +PatternMatch.implements_io "Reader" &:: "read" <>--> Variant
; +PatternMatch.implements_io "BufferedReader" &:: "readLine" <>--> Variant ; +PatternMatch.implements_io "BufferedReader" &:: "readLine" <>--> Variant
; +PatternMatch.implements_inject "Provider" &:: "get" <>--> Invariant
; -"__new" <>--> Variant ; -"__new" <>--> Variant
; +(fun _ name -> BuiltinDecl.is_declared (Typ.Procname.from_string_c_fun name)) ; +(fun _ name -> BuiltinDecl.is_declared (Typ.Procname.from_string_c_fun name))
<>--> VariantForHoisting ] <>--> VariantForHoisting ]

@ -6,7 +6,7 @@
TESTS_DIR = ../../.. TESTS_DIR = ../../..
ANALYZER = checkers ANALYZER = checkers
INFER_OPTIONS = --loop-hoisting-only --debug-exceptions INFER_OPTIONS = --loop-hoisting-only --invariant-by-default --debug-exceptions
INFERPRINT_OPTIONS = --issues-tests INFERPRINT_OPTIONS = --issues-tests
SOURCES = $(wildcard *.java) SOURCES = $(wildcard *.java)

Loading…
Cancel
Save