Coder Social home page Coder Social logo

tomgu1991 / flowistry Goto Github PK

View Code? Open in Web Editor NEW

This project forked from willcrichton/flowistry

0.0 0.0 0.0 10.47 MB

Flowistry is a VSCode extension that helps you understand Rust programs with program analysis.

Home Page: https://marketplace.visualstudio.com/items?itemName=wcrichton.flowistry

License: MIT License

TypeScript 14.58% Rust 84.63% JavaScript 0.48% SCSS 0.16% Python 0.15%

flowistry's Introduction

Flowistry: Powerful IDE Tools for Rust

tests crates.io

Flowistry is a VSCode extension that helps you understand Rust programs. Flowistry uses dataflow analysis and pointer analysis to analyze Rust programs at a deeper level than just types can offer (e.g. as you can already find in rust-analyzer).

Flowistry is alpha software (see Limitations). I'm seeking early adopters to try it out and provide feedback! If you have questions or issues, please file a Github issue, join our Discord, or DM @wcrichton on Twitter.

Currently, Flowistry's capabilities are:

1. Backward slice: find code that influences a value

Flowistry can compute a backward static slice that identifies every piece of code that affects a value of interest. For example, let's say you're debugging an assertion failure on x. Then you could compute the backward slice of x to quickly rule out lines of code that don't influence its value, as shown here:

demo1

The green marker indicates the selected value, and the grey text indicates code with no influence on that value. Note that "influence" is a bit subtle --- for example, in the program:

if x > 0 {
  *y += 1;
}

Even though x isn't directly used to change y, we would say x influences y because a mutation to y happens conditionally based on the value of x.



2. Forward slice: find code that is influenced by a value

A forward static slice identifies every piece of code that is affected by a value of interest. For example, let's say you have a program that times a calculation, and you want to comment out all the code related to timing. You could compute a forward slice of the timer:

demo2

The timer doesn't affect the value of the computation, so run_expensive_calculation isn't part of the forward slice of start. In this example, Flowistry sets the user's selected text to the slice. Then the user can use other IDE features like bulk-commenting (⌘-/ in VSCode on macOS) on that selection.

Note that this example shows how slices are transitive: start influences elapsed, and elapsed influences println, so start influences println.



3. Function effects

A function's effects are either inputs that it mutates, or values that it returns. The function effects panel helps identify lines of code that either mutate arguments or that could return values. Selecting an effect then shows the backward slice of that effect.

demo mp4

Like before, lines that are outside of a given slice are grayed out. But for this feature, lines that are unique to a given slice are highlighted in orange. This way you can quickly focus on code that is only relevant to an effect of interest.



Installation

You can install Flowistry from the Visual Studio Marketplace or the Open VSX Registry. In VSCode:

  • Go to the Extensions pane by clicking this button in the left margin: Screen Shot 2021-09-20 at 9 30 43 AM
  • Search for "Flowistry" and then click "Install".
  • Open a Rust workspace and wait for the tool to finish installing.

Alternatively, you can install it from source:

# Install flowistry binaries
git clone https://github.com/willcrichton/flowistry
cd flowistry
cargo install --path crates/flowistry_ide

# Install vscode extension
cd ide
npm install
npm run build
ln -s $(pwd) ~/.vscode/extensions/flowistry

Usage

Flowistry has five commands:

  • Flowistry: Backward Highlight: given a selected variable, this command highlights the backward slice of the variable.
  • Flowistry: Backward Select: same as above, but this puts the slice in your selection rather than highlighting it.
  • Flowistry: Forward Highlight and Flowistry: Forward Select: same as above, but for forward slices than backward slices.
  • Flowistry: Effects: given your cursor is within a particular function, this command opens the effects panel for that function.

You can invoke these commands either through the context menu, by right-clicking and opening the "Flowistry" sub-menu. Or you can open the Command Palette (⇧⌘P on Mac) and type the name of the command.

Limitations

Flowistry is early-stage software. It inevitably has bugs in both the UI and the analysis. The UI may be unintuitive. The analysis, even if correct, may also be unintuitive.

Flowistry does not support all of Rust's features. Specifically:

  • Raw pointers: Flowistry uses lifetimes to determine what a reference can point-to. However, raw pointers can point to anything and aren't tracked by the compiler. So Flowistry cannot detect the flow of information through a raw pointer. It can, however, detect information flow through a typed wrapper around a raw pointer!
  • Some forms of interior mutability: as a corollary to above, Flowistry does not track the aliases of data wrapped in types like Rc<T>. For example, in the program:
    let x = Rc::new(RefCell::new(1));
    let y = x.clone();
    *x.borrow_mut() = 2;
    Flowistry can detect that x is modified (because borrow_mut uses lifetimes to relate the RefMut to RefCell), but not that y is modified (because nothing statically says that y aliases x).

FAQ

rustup fails on installation

If rustup fails, especially with an error like "could not rename downloaded file", this is probably because Flowistry is running rustup concurrently with another tool (like rust-analyzer). Until rustup#988 is resolved, there is unfortunately no automated way around this.

To solve the issue, go to the command line and run:

rustup toolchain install nightly-2021-11-26 -c rust-src -c rustc-dev -c llvm-tools-preview

Note: double check the value of "channel" in rust-toolchain.toml if nightly-2021-11-26 is no longer correct.

Then go back to VSCode and click "Continue" to let Flowistry continue installing.

flowistry's People

Contributors

willcrichton avatar connorff avatar vakaras avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.