How Salsa Works (2019.01)

What is Salsa?

  • Incremental recomputation

fn foo(input1: A, input2: B) -> Output

let x1 = foo(a, b1) // reuse some of the work we did
let x2 = foo(a, b2)

  • “Automatic” 
  • “Sound / Correct” — you get the same result as if we did not re-use at all

Salsa’s actual model is richer


  • IDE:
  • Inputs:
  • manifest (Cargo.toml)
  • source files (foo.rs => "")
  • Outputs:
  • Binary executable
  • Completions at this point?
  • What should I show the user when the mouse is hovering on this line?

How does it work?


  • Identify the “base inputs” to your computation
  • Identify intermediate “derived” values
  • deterministic, “pure” function that computes them
  • Inputs:
  • manifest manifest() → Vec<Path>
  • source text source_text(x: Path) → String
  • Derived values:
  • for each source file X, we might have a derived value ast(x: Path) → AST
  • completion(path: Path, line: usize, column: usize)
  • Track:
  • in the course of computing (say) ast(Path)
  • which inputs did we access?
  • which derived values?
  • When an input changes:
  • these derived values are still valid (because none of the inputs that they touch changed)
  • these derived values may be invalid (because some of the inputs that they touch changed)

manifest() <------------------------ whole_program_ast() <-- type-checking
                                           |
source_text("a.rs") <- ast("a.rs") <-------+
                                           |
source_text("b.rs") <- ast("b.rs") <-------+

Key Salsa concepts

Query