All Projects → rescript-association → Reanalyze

rescript-association / Reanalyze

Licence: mit
Experimental analyses for OCaml/ReScript: for globally dead values/types, exception analysis, and termination analysis.

Programming Languages

ocaml
1615 projects
reason
219 projects

Labels

Projects that are alternatives of or similar to Reanalyze

Scde
R package for analyzing single-cell RNA-seq data
Stars: ✭ 147 (-18.78%)
Mutual labels:  analysis
Algorithmictrading
This repository contains three ways to obtain arbitrage which are Dual Listing, Options and Statistical Arbitrage. These are projects in collaboration with Optiver and have been peer-reviewed by staff members of Optiver.
Stars: ✭ 157 (-13.26%)
Mutual labels:  analysis
Lexical syntax analysis
编译原理词法分析器&语法分析器LR(1)实现 C++
Stars: ✭ 173 (-4.42%)
Mutual labels:  analysis
Memflow
physical memory introspection framework
Stars: ✭ 149 (-17.68%)
Mutual labels:  analysis
Pastas
🍝 Pastas is an open-source Python framework for the analysis of hydrological time series.
Stars: ✭ 155 (-14.36%)
Mutual labels:  analysis
Gitinspector
📊 The statistical analysis tool for git repositories
Stars: ✭ 2,058 (+1037.02%)
Mutual labels:  analysis
Go Ethereum Code Analysis
No description or website provided.
Stars: ✭ 2,032 (+1022.65%)
Mutual labels:  analysis
Pycbc
Core package to analyze gravitational-wave data, find signals, and study their parameters. This package was used in the first direct detection of gravitational waves (GW150914), and is used in the ongoing analysis of LIGO/Virgo data.
Stars: ✭ 177 (-2.21%)
Mutual labels:  analysis
Siem
SIEM Tactics, Techiques, and Procedures
Stars: ✭ 157 (-13.26%)
Mutual labels:  analysis
Ladybug Legacy
🐞 Ladybug is an environmental plugin for Grasshopper.
Stars: ✭ 169 (-6.63%)
Mutual labels:  analysis
Audioowl
Fast and simple music and audio analysis using RNN in Python 🕵️‍♀️ 🥁
Stars: ✭ 151 (-16.57%)
Mutual labels:  analysis
Tidyversity
🎓 Tidy tools for academics
Stars: ✭ 155 (-14.36%)
Mutual labels:  analysis
Pe Linux
Linux Privilege Escalation Tool By WazeHell
Stars: ✭ 168 (-7.18%)
Mutual labels:  analysis
Uvtools
MSLA/DLP, file analysis, calibration, repair, conversion and manipulation
Stars: ✭ 148 (-18.23%)
Mutual labels:  analysis
Sam
System Architecture Mapper
Stars: ✭ 176 (-2.76%)
Mutual labels:  analysis
Rustig
A tool to detect code paths leading to Rust's panic handler
Stars: ✭ 145 (-19.89%)
Mutual labels:  analysis
Open Synthesis
Open platform for CIA-style intelligence analysis
Stars: ✭ 158 (-12.71%)
Mutual labels:  analysis
Twitter Intelligence
Twitter Intelligence OSINT project performs tracking and analysis of the Twitter
Stars: ✭ 179 (-1.1%)
Mutual labels:  analysis
Aubio
a library for audio and music analysis
Stars: ✭ 2,601 (+1337.02%)
Mutual labels:  analysis
Angr Utils
Handy utilities for the angr binary analysis framework, most notably CFG visualization
Stars: ✭ 169 (-6.63%)
Mutual labels:  analysis

reanalyze

Program analysis for Reason and OCaml projects targeting JS (bucklescript) as well as native code (dune):

  • Globally dead values, redundant optional arguments, dead modules, dead types (records and variants).
  • Exception analysis.
  • Termination.

Status master (v3.*): Build Status

Expectations

Early release. While the core functionality is reasonably stable, the CLI and annotations are subject to change. However, this is a tiny surface at the moment.

Requirements

For correct handling of ReasonReact components in the Dead Code Analysis, bucklescript version 7.3.2 is required (fixes the location in the JSX PPX).

Use

The rest of this document describes the dead code analysis. For the Exception Analysis, build instructions are the same, and the command-line invocation is different.

Build and run on existing projects using the Build and Try instructions below. The analysis uses .cmt[i] files which are generated during compilation, so should be run after building your project. Remember to rebuild the project before running again.

CLI for bucklescript projects

# dead code analysis
reanalyze.exe -dce

# exception analysis
reanalyze.exe -exception

The requirement is that bsconfig.json can be found by walking up the current directory.

CLI for native projects

# dead code analysis
reanalyze.exe -dce-cmt root/containing/cmt/files

# exception analysis
reanalyze.exe -exception-cmt root/containing/cmt/files

Subdirectories are scanned recursively looking for .cmt[i] files.

The requirement is that the current directory is where file paths start from. So if the file path seen by the compiler is relative src/core/version.ml then the current directory should contain src as a subdirectory. The analysis only reports on existing files, so getting this wrong means no reporting.

DCE reports

The dead code analysis reports on globally dead values, redundant optional arguments, dead modules, dead types (records and variants).

A value x is dead if it is never used, or if it is used by a value which itself is dead (transitivity). At the top level, function calls such as Js.log(x), or other expressions that might cause side effects, keep value x live.

An optional argument ~argName to a function is redundant if all the calls to the function supply the argument, or if no call does.

A module is considered dead if all the elements defined it in are dead.

The type analysis repots on variant cases, and record labels.

  • A variant case | A(int) is dead if a value such as A(3) is never constructed. But it can be deconstructed via pattern matching | A(n) => ... or checked for equality x == A(3) without making the case A live.

  • A record label x in type r = {x:int, y:int} is dead if it is never read (by direct access r.x or pattern matching | {x:n, y:m} => ...). However, creating a value let r = {x:3, y:4} does not make x and y live. Note that reading a value r does not make r.x or r.y live.

While dead values can be removed automatically (see below), dead types require a bit more work. A dead variant case requires changing the type definition, and the various accesses to it. A dead record label requires changing the type definition, and removing the label from any expressions that create a value of that type.

DCE: controlling reports with Annotations

The dead code analysis supports 2 annotations:

  • @dead suppresses reporting on the value/type, but can also be used to force the analysis to consider a value as dead. Typically used to acknowledge cases of dead code you are not planning to address right now, but can be searched easily later.

  • @live tells the analysis that the value should be considered live, even though it might appear to be dead. This is typically used in case of FFI where there are indirect ways to access values. In case of bucklescript projects using genType, export annotations immediately qualify values as live, because they are potentially reachable from JS.

The main difference between @dead and @live is the transitive behaviour: @dead values don't keep alive values they use, while @live values do.

Several examples can be found in examples/deadcode/src/DeadTest.re

Unstable features

Here are several unstable features, which could change substantially over time. Ask for more information.

CLI -live-names

This automatically annotates @live all the items called foo or bar:

-live-names foo,bar

CLI -live-paths

This automatically annotates @live all the items in file Hello.re:

-live-paths Hello.re

This automatically annotates @live all the items in the src/test and tmp folders:

-live-paths src/test,tmp

CLI -debug

Print debug information during the analysis

reanalyze.exe -debug ...

Add annotations automatically

This overwrites your source files automatically with dead code annotations:

reanalyze.exe -write ...

Remove code automatically (not interactively)

There's a dead code ppx (values only, not types) in this repository. It can be used to automatically remove code annotated @dead, as if it had been commented out. Can be used after adding annotations automatically. The combination of automatic annotation and automatic elimination is a form of automatic dead code elimination. For projects that use a library, or that in general have code which is dead only temporarily. There's obviously a level of risk in doing this automatic elimination. The safety net you can rely on is that the code must still compile.

Build

No build required for bucklescript projects

npm add --save-dev reanalyze

Build for OCaml 4.06.1 using dune (for bucklescript and native projects)

opam switch 4.06.1
eval $(opam env)
opam install reason dune
dune build
# _build/default/src/Reanalyze.exe

Build for other OCaml versions (4.08, 4.09, 4.10) using dune (for native projects)

opam install reason dune
dune build
# _build/default/src/Reanalyze.exe

Try it

Bucklescript Projects (JS output)

npm run build # or whatever command to build the project
npm add --save-dev reanalyze
npx reanalyze -dce

esy Projects (native)

See for example project reanalyze-esy-example:

git clone https://github.com/cristianoc/reanalyze-esy-example
cd reanalyze-esy-example
esy
esy dce
esy check-exceptions

Single File Test (native project)

echo "let unused = 34" > test.ml
ocamlc -c -bin-annot test.ml
reanalyze.exe -dce-cmt ./test.cmt
  Warning Dead Value
  test.ml 1:1-15
  unused is never used
  <-- line 1
  let unused = 34 [@@dead "unused"]

Single Directory Test (native project)

mkdir test
echo "let unused = 34 let used = 42" > test/test.ml
echo "let _ = Test.used" > test/use.ml
cd test
ocamlc -c -bin-annot *.ml
reanalyze.exe -dce-cmt .
  Warning Dead Value
  test.ml 1:1-15
  unused is never used
  <-- line 1
  let unused = 34 [@@dead "unused"]  let used = 42
  Warning Dead Value
  use.ml 1:1-17
  _ has no side effects and can be removed
  <-- line 1
  let _ = Test.used [@@dead "_"]

Full Project Test: Infer (native project)

How to test on Infer :

--- a/infer/src/Makefile
+++ b/infer/src/Makefile
-DUNE_BUILD = dune build --profile=$(BUILD_MODE)
+DUNE_BUILD = dune build @check @all --profile=$(BUILD_MODE)
  • Build normally
make -j BUILD_MODE=dev
  • Go to the right directory from which file paths start:
% cd infer/infer
  • Run the analysis
% path/to/reanalyze.exe -dce-cmt _build/default/src/.InferModules.objs/byte/
Screen Shot 2020-04-14 at 9 28 24 AM
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].