[inferbo] Add Preconditions.checkArgument model

Summary: It adds Preconditions.checkArgument model

Reviewed By: ezgicicek

Differential Revision: D16960199

fbshipit-source-id: 60a05a1ef
master
Sungkeun Cho 5 years ago committed by Facebook Github Bot
parent d11444f7d3
commit aaa40084c4

@ -1013,6 +1013,12 @@ module Collection = struct
{exec; check= check_index ~last_included:false coll_id index_exp}
end
module Preconditions = struct
let check_argument exp =
let exec {integer_type_widths} ~ret:_ mem = Sem.Prune.prune integer_type_widths exp mem in
{exec; check= no_check}
end
let unmodifiable _ s =
String.is_prefix ~prefix:"unmodifiable" s
&& List.exists ~f:(fun suffix -> String.is_suffix ~suffix s) ["Set"; "Collection"; "Map"; "List"]
@ -1216,6 +1222,8 @@ module Call = struct
; +PatternMatch.implements_collection
&:: "addAll" <>$ capt_var_exn $+ capt_exp $+ capt_exp $!--> Collection.addAll_at_index
; +PatternMatch.implements_collection &:: "size" <>$ capt_exp $!--> Collection.size
; +PatternMatch.implements_google "common.base.Preconditions"
&:: "checkArgument" <>$ capt_exp $--> Preconditions.check_argument
; +PatternMatch.implements_pseudo_collection &:: "size" <>$ capt_exp $!--> Collection.size
; +PatternMatch.implements_org_json "JSONArray"
&:: "length" <>$ capt_exp $!--> Collection.size

@ -9,7 +9,7 @@ import java.util.ArrayList;
class PreconditionTest {
// should be constant
public void constant_FP(ArrayList<Integer> list) {
public void constant(ArrayList<Integer> list) {
Preconditions.checkArgument(list.size() == 2);
for (int i = 0; i < list.size(); i++) {}
}

@ -167,7 +167,6 @@ codetoanalyze/java/performance/MapTest.java, MapTest.entrySet_linear(java.util.M
codetoanalyze/java/performance/MapTest.java, MapTest.keySet_linear(java.util.Map):void, 1, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 7 + 8 ⋅ map.length + 3 ⋅ (map.length + 1), O(map.length), degree = 1,{map.length + 1},Loop at line 13,{map.length},Loop at line 13]
codetoanalyze/java/performance/MapTest.java, MapTest.putAll_linear(java.util.Map):void, 3, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 13 + 8 ⋅ map.length + 3 ⋅ (map.length + 1), O(map.length), degree = 1,{map.length + 1},Loop at line 28,{map.length},Loop at line 28]
codetoanalyze/java/performance/MapTest.java, MapTest.values_linear(java.util.Map):void, 2, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 13 + 8 ⋅ (map.length + 1) + 3 ⋅ (map.length + 2), O(map.length), degree = 1,{map.length + 2},Loop at line 22,{map.length + 1},Loop at line 22]
codetoanalyze/java/performance/PreconditionTest.java, PreconditionTest.constant_FP(java.util.ArrayList):void, 2, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 13 + 5 ⋅ list.length + 3 ⋅ (list.length + 1), O(list.length), degree = 1,{list.length + 1},Loop at line 14,{list.length},Loop at line 14]
codetoanalyze/java/performance/StringTest.java, StringTest.index_substring_linear():java.lang.String, 1, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 9 + this.mId.length, O(this.mId.length), degree = 1,{this.mId.length},call to int StringTest.indexof_linear(String),Modeled call to String.indexOf]
codetoanalyze/java/performance/StringTest.java, StringTest.indexof_from_linear(java.lang.String,int):int, 1, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 3 + (-j + m.length), O((-j + m.length)), degree = 1,{-j + m.length},Modeled call to String.indexOf]
codetoanalyze/java/performance/StringTest.java, StringTest.indexof_linear(java.lang.String):int, 1, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 2 + m.length, O(m.length), degree = 1,{m.length},Modeled call to String.indexOf]

Loading…
Cancel
Save