facebook / infer

A static analyzer for Java, C, C++, and Objective-C
http://fbinfer.com/
MIT License
14.99k stars 2.02k forks source link

Reactive mode (run/capture/analyze) needs better documentation #1189

Open antonqiu opened 5 years ago

antonqiu commented 5 years ago
Version: 0.17.0
OS: CentOS 7

Hi Team,

I was trying to understand the effect of --reactive flag in infer run, infer capture and infer analyze, but got conflicting information from the Get Started guide and manual.

From man:

only in infer-analyze:
       --reactive,-r
           Activates: Reactive mode: the analysis starts from the files
           captured since the infer command started (Conversely:
           --no-reactive | -R)

infer-analyze:
       --changed-files-index file
           Specify the file containing the list of source files from which
           reactive analysis should start. Source files should be specified
           relative to project root or be absolute

However, in Recommended flow for CI,

  1. infer capture --reactive -- make -j 4 Apparently, one can also specify --reactive with infer capture, although man infer-capture doesn't have an entry for it.

What is its effect? Does it simply retain the infer-out folder and additively collect compiling artifacts?

  1. infer analyze --reactive --changed-files-index index.txt "Reactive mode: the analysis starts from the files captured since the infer command started."
    I do understand it in the context of infer run, but in infer analyze, there are no "files captured since the infer command started".

What's a more accurate explanation of the effect of --reactive in infer-analyze?

  1. infer analyze --changed-files-index index.txt "Specify the file containing the list of source files from which reactive analysis should start."

But it seems like --changed-files-index can be specified without --reactive.

Thanks!

micheletufano commented 4 years ago

Hi @antonqiu , I'm having similar issues in running the reactive/differential workflow.

Did you solve yours?

antonqiu commented 4 years ago

@micheletufano

Basically, there's a file infer-out/results.db that marks the staleness of captured files. Capture run with --reactive would add newly discovered files to the db and mark old files stale. Analyze run with --reactive would analyze non-stale files.

From my understanding:

infer capture

--reactive: preserve all captured procedures and source files. Otherwise, infer-out/results.db is wiped out and rebuilt. --continue: prevents previously captured files being marked as stale.

infer analyze

--reactive: analyze source files marked as fresh --changed_file_index: only analyze files specified in the index, regardless of their staleness markers. This essentially overrides --reactive, in my opinion.

Edit: about your question in another issue. Based on how Infer works through files, I don't think its results are strictly deterministic. I sort of remember they mention it somewhere in the doc.

micheletufano commented 4 years ago

Hi @antonqiu ,

This actually helped. For my purpose, I ended up removing the --reactive options (both for captureand analyze) when looping through the commits, and used only the --changed_file_index for the changed files in the commit.

In that way I have more consistent results. When using the --reactive option the bugs were sometimes double counted and accumulated (probably due to keeping the results.db file).

Overall, I do agree with the original goal of this issue that better documentation is needed.