From 34a0efd626d30ddddf7d09f5ebfd5f0717efa42d Mon Sep 17 00:00:00 2001 From: Martino Luca Date: Tue, 23 May 2017 09:57:39 -0700 Subject: [PATCH] Add optional field in serialized output Reviewed By: jvillard Differential Revision: D4970806 fbshipit-source-id: b857003 --- Makefile.config | 2 ++ infer/.merlin | 1 + infer/lib/python/inferlib/issues.py | 1 + infer/src/IR/Localise.ml | 15 ++++++++++++++ infer/src/IR/Localise.mli | 6 ++++++ infer/src/Makefile | 25 ++++++++++++++++++++++-- infer/src/backend/InferPrint.re | 7 +++++-- infer/src/backend/InferPrint.rei | 2 ++ infer/src/backend/jsonbug.atd | 1 + infer/src/base/Config.ml | 4 ++++ infer/src/base/Config.mli | 1 + infer/src/unit/DifferentialTestsUtils.ml | 3 ++- opam | 1 + opam.lock | 1 + 14 files changed, 65 insertions(+), 5 deletions(-) diff --git a/Makefile.config b/Makefile.config index 93e9f4dd5..b0bc78982 100644 --- a/Makefile.config +++ b/Makefile.config @@ -62,6 +62,8 @@ INFER_COMMANDS = \ infer-run \ INFERTRACEBUGS_BIN = $(BIN_DIR)/inferTraceBugs +INFER_CREATE_TRACEVIEW_LINKS = InferCreateTraceViewLinks +INFER_CREATE_TRACEVIEW_LINKS_BIN = $(BIN_DIR)/$(INFER_CREATE_TRACEVIEW_LINKS) INFERTRACEBUGS_BIN_RELPATH = infer/bin/inferTraceBugs INFER_COMMAND_MANUALS = $(INFER_COMMANDS:%=$(MAN_DIR)/man1/%.1) diff --git a/infer/.merlin b/infer/.merlin index dde3cb8b9..4e27fd2da 100644 --- a/infer/.merlin +++ b/infer/.merlin @@ -6,6 +6,7 @@ PKG cmdliner PKG core PKG javalib PKG oUnit +PKG parmap PKG ppx_compare PKG ptrees PKG sawja diff --git a/infer/lib/python/inferlib/issues.py b/infer/lib/python/inferlib/issues.py index 04cc297a9..4aef00016 100644 --- a/infer/lib/python/inferlib/issues.py +++ b/infer/lib/python/inferlib/issues.py @@ -52,6 +52,7 @@ JSON_INDEX_TRACE_LEVEL = 'level' JSON_INDEX_TRACE_FILENAME = 'filename' JSON_INDEX_TRACE_LINE = 'line_number' JSON_INDEX_TRACE_DESCRIPTION = 'description' +JSON_INDEX_TRACEVIEW_ID = 'traceview_id' JSON_INDEX_VISIBILITY = 'visibility' diff --git a/infer/src/IR/Localise.ml b/infer/src/IR/Localise.ml index 197c9c808..e31440cf5 100644 --- a/infer/src/IR/Localise.ml +++ b/infer/src/IR/Localise.ml @@ -164,6 +164,21 @@ module Tags = struct let get tags tag = List.Assoc.find ~equal:String.equal tags tag let tag_value_records_of_tags tags = List.map ~f:(fun (tag, value) -> {Jsonbug_t.tag; value}) tags + + let tags_of_tag_value_records (tag_value_records: Jsonbug_t.tag_value_record list) = + List.map ~f:(fun {Jsonbug_t.tag; value} -> (tag, value)) tag_value_records + + let lines_of_tags (tags: t) = + let line_tags = String.Set.of_list [ + dereferenced_line; + call_line; + assigned_line; + alloc_line; + accessed_line; + dealloc_line; + ] in + List.filter_map ~f:(fun (tag, value) -> + if String.Set.mem line_tags tag then Some (int_of_string value) else None) tags end type error_desc = { diff --git a/infer/src/IR/Localise.mli b/infer/src/IR/Localise.mli index 04e9aa7d3..5fec3e449 100644 --- a/infer/src/IR/Localise.mli +++ b/infer/src/IR/Localise.mli @@ -107,6 +107,12 @@ module Tags : sig (** convert error description's tags to atd-serializable format *) val tag_value_records_of_tags: t -> Jsonbug_t.tag_value_record list + + (* convert atd-serializable format to error description's tags *) + val tags_of_tag_value_records: Jsonbug_t.tag_value_record list -> t + + (* collect all lines from tags *) + val lines_of_tags: t -> int list end (** description field of error messages *) diff --git a/infer/src/Makefile b/infer/src/Makefile index b3b622624..8bede3015 100644 --- a/infer/src/Makefile +++ b/infer/src/Makefile @@ -40,7 +40,7 @@ OCAMLBUILD_OPTIONS = \ -tag-line "<*{clang/clang_ast_*,backend/jsonbug_*,checkers/stacktree_*}>: warn(-27-32-34-35-39)" \ -tag-line "<*/{,*/}*.{ml,re}{,i}>: package(ppx_compare)" \ -tag thread \ - -pkgs ANSITerminal,atdgen,cmdliner,core,extlib,oUnit,str,unix,xmlm,yojson,zip + -pkgs ANSITerminal,atdgen,cmdliner,core,extlib,oUnit,parmap,str,unix,xmlm,yojson,zip ifeq ($(ENABLE_OCAML_BINANNOT),yes) OCAMLBUILD_OPTIONS += -cflags -bin-annot @@ -58,7 +58,6 @@ ifeq ($(TEST),1) OCAMLBUILD_OPTIONS += -cflags -warn-error,$(OCAML_FATAL_WARNINGS) endif - #### Backend declarations #### INFER_MAIN = backend/infer @@ -75,6 +74,12 @@ INFERPRINT_ATDGEN_STUB_BASE = backend/jsonbug INFERPRINT_ATDGEN_STUB_ATD = $(INFERPRINT_ATDGEN_STUB_BASE).atd INFERPRINT_ATDGEN_STUBS = $(addprefix $(INFERPRINT_ATDGEN_STUB_BASE), $(ATDGEN_SUFFIXES)) +#### InferCreateTraceViewLinks declarations #### + +FACEBOOK_DIR = facebook +INFER_CREATE_TRACEVIEW_LINKS_MODULE = InferCreateTraceViewLinks +INFER_CREATE_TRACEVIEW_LINKS_MAIN = $(FACEBOOK_DIR)/$(INFER_CREATE_TRACEVIEW_LINKS_MODULE) + ### InferUnit declarations ### UNIT_SOURCES = unit @@ -141,6 +146,9 @@ OCAMLBUILD_ALL = $(OCAMLBUILD_BASE) $(JAVA_OCAMLBUILD_OPTIONS) OCAMLBUILD_CONFIG = $(OCAMLBUILD_BASE) # list of ocamlbuild targets common to all build targets -- native version INFER_CONFIG_TARGETS = $(INFER_MAIN).native +ifeq ($(IS_FACEBOOK_TREE),yes) +INFER_CONFIG_TARGETS += $(INFER_CREATE_TRACEVIEW_LINKS_MAIN).native +endif ifeq ($(BUILD_JAVA_ANALYZERS),yes) OCAMLBUILD_CONFIG += $(JAVA_OCAMLBUILD_OPTIONS) @@ -194,6 +202,11 @@ $(INFER_BIN_ALIASES): Makefile $(INFER_BIN).native: $(INFER_BUILD_DIR)/$(INFER_MAIN).native $(INFER_BIN_ALIASES) $(INSTALL_PROGRAM) $(INFER_BUILD_DIR)/$(INFER_MAIN).native $(INFER_BIN) $(INSTALL_PROGRAM) $(INFER_BUILD_DIR)/$(INFER_MAIN).native $(INFER_BIN).native +ifeq ($(IS_FACEBOOK_TREE),yes) + $(INSTALL_PROGRAM) $(INFER_BUILD_DIR)/$(INFER_CREATE_TRACEVIEW_LINKS_MAIN).native \ + $(INFER_CREATE_TRACEVIEW_LINKS_BIN) +endif + .PHONY: infer infer: $(INFER_BIN).native @@ -215,6 +228,10 @@ $(INFER_BIN).byte: $(INFER_BUILD_DIR)/$(INFER_MAIN).byte $(INFER_BIN_ALIASES) ifeq ($(TEST),1) $(INSTALL_PROGRAM) $(INFER_BUILD_DIR)/$(INFERUNIT_MAIN).byte $(INFERUNIT_BIN) endif +ifeq ($(IS_FACEBOOK_TREE),yes) + $(INSTALL_PROGRAM) $(INFER_BUILD_DIR)/$(INFER_CREATE_TRACEVIEW_LINKS_MAIN).byte \ + $(INFER_CREATE_TRACEVIEW_LINKS_BIN) +endif .PHONY: byte byte: $(INFER_BIN).byte @@ -252,6 +269,9 @@ rei: $(SCRIPT_DIR)/refmt.sh -parse ml -print re $< > $*.rei roots:=Infer StatsAggregator +ifeq ($(IS_FACEBOOK_TREE),yes) +roots += $(INFER_CREATE_TRACEVIEW_LINKS_MODULE) +endif clusters:=base clang java IR ml_src_files:=$(shell find $(DEPENDENCIES) -regex '.*\.ml\(i\)*') @@ -395,5 +415,6 @@ clean: $(REMOVE) $(INFERUNIT_BIN) $(CHECKCOPYRIGHT_BIN) $(REMOVE) $(CLANG_ATDGEN_STUBS) $(REMOVE) $(INFER_CLANG_FCP_MIRRORED_FILES) + $(REMOVE) $(INFER_CREATE_TRACEVIEW_LINKS_BIN) $(REMOVE) mod_dep.dot $(REMOVE) mod_dep.pdf diff --git a/infer/src/backend/InferPrint.re b/infer/src/backend/InferPrint.re index 911ffd069..a660f17b1 100644 --- a/infer/src/backend/InferPrint.re +++ b/infer/src/backend/InferPrint.re @@ -91,6 +91,8 @@ let get_bug_hash ) }; +let exception_value = "exception"; + let loc_trace_to_jsonbug_record trace_list ekind => switch ekind { | Exceptions.Kinfo => [] @@ -102,7 +104,7 @@ let loc_trace_to_jsonbug_record trace_list ekind => {Jsonbug_j.tag: Io_infer.Xml.tag_branch, value: Printf.sprintf "%B" cond} ] | Errlog.Exception exn_name => - let res = [{Jsonbug_j.tag: Io_infer.Xml.tag_kind, value: "exception"}]; + let res = [{Jsonbug_j.tag: Io_infer.Xml.tag_kind, value: exception_value}]; let exn_str = Typ.Name.name exn_name; if (String.is_empty exn_str) { res @@ -500,7 +502,8 @@ module IssuesJson = { dotty: error_desc_to_dotty_string key.err_desc, infer_source_loc: json_ml_loc, bug_type_hum: Localise.to_human_readable_string key.err_name, - linters_def_file: err_data.linters_def_file + linters_def_file: err_data.linters_def_file, + traceview_id: None }; if (not !is_first_item) { pp "," diff --git a/infer/src/backend/InferPrint.rei b/infer/src/backend/InferPrint.rei index df7929c86..d94180fc1 100644 --- a/infer/src/backend/InferPrint.rei +++ b/infer/src/backend/InferPrint.rei @@ -8,6 +8,8 @@ */ open! IStd; +let exception_value: string; + let main: report_csv::option string => report_json::option string => unit; let main_from_config: unit => unit; diff --git a/infer/src/backend/jsonbug.atd b/infer/src/backend/jsonbug.atd index ba6fbfb41..12cd3cf22 100644 --- a/infer/src/backend/jsonbug.atd +++ b/infer/src/backend/jsonbug.atd @@ -39,6 +39,7 @@ type jsonbug = { ?infer_source_loc: loc option; bug_type_hum: string; ?linters_def_file: string option; + ?traceview_id: int option; } type report = jsonbug list diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index d7aee1602..e0c160158 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -1037,6 +1037,9 @@ and icfg_dotty_outfile = "If set, specifies path where .dot file should be written, it overrides the path for all \ other options that would generate icfg file otherwise" +and ignore_trivial_traces = CLOpt.mk_bool + ~long:"ignore-trivial-traces" ~default:true "Ignore traces whose length is at most 1" + and infer_cache = CLOpt.mk_path_opt ~deprecated:["infer_cache"; "-infer_cache"] ~long:"infer-cache" ~meta:"dir" "Select a directory to contain the infer cache (Buck and Java only)" @@ -1778,6 +1781,7 @@ and frontend_debug = !frontend_debug and frontend_stats = !frontend_stats and headers = !headers and icfg_dotty_outfile = !icfg_dotty_outfile +and ignore_trivial_traces = !ignore_trivial_traces and immutable_cast = !immutable_cast and infer_cache = !infer_cache and iphoneos_target_sdk_version = !iphoneos_target_sdk_version diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index f789a6e57..f7cacc580 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -240,6 +240,7 @@ val frontend_stats : bool val generated_classes : string option val headers : bool val icfg_dotty_outfile : string option +val ignore_trivial_traces : bool val immutable_cast : bool val infer_cache : string option val iphoneos_target_sdk_version : string option diff --git a/infer/src/unit/DifferentialTestsUtils.ml b/infer/src/unit/DifferentialTestsUtils.ml index b28785106..00bd24b4f 100644 --- a/infer/src/unit/DifferentialTestsUtils.ml +++ b/infer/src/unit/DifferentialTestsUtils.ml @@ -49,7 +49,8 @@ let create_fake_jsonbug dotty; infer_source_loc; bug_type_hum = kind; - linters_def_file + linters_def_file; + traceview_id = None; } let pp_diff_of_int_list group_name fmt (expected, actual) = diff --git a/opam b/opam index 390a81700..5aafea567 100644 --- a/opam +++ b/opam @@ -36,6 +36,7 @@ depends: [ "javalib" {>="2.3.3"} "ocamlfind" {build} "ounit" {="2.0.0"} + "parmap" {>="1.0-rc8"} "ppx_deriving" {>="4.1"} "reason" {="1.13.4"} "sawja" {>="1.5.2"} diff --git a/opam.lock b/opam.lock index e08ce54be..14d4dbf6c 100644 --- a/opam.lock +++ b/opam.lock @@ -28,6 +28,7 @@ ocaml-migrate-parsetree = 0.7 ocamlbuild = 0.11.0 ocamlfind = 1.7.1 ounit = 2.0.0 +parmap = 1.0-rc8 ppx_assert = 113.33.00 ppx_bench = 113.33.00+4.03 ppx_bin_prot = 113.33.00+4.03