Sasha Pourcelot (she/her)
@scrabsha on {GitHub, Twitter}
CS student at Polytech Nice Sophia (France)
Software Engineer at TrustInSoft (static analysis of C programs)
Rust ecosystem contributor
Deducing properties about code without running it
Examples:
cargo-breaking
Detect breaking changes in a Rust crate
// before
pub fn knight_name(friend: &Friend) -> String;
// after
pub fn knight_name(friend: &Friend, mood: Mood) -> String;
⚠️ Breaking change: knight_name
has a new parameter
#[non_exhaustive]
attributeSend
and Sync
traitsAnd so many other very subtle things
Stability is a nice to have but not required
RUSTC_BOOTSTRAP=1
is where the fun begins
Getting information about a crate
src/lib.rs
→ AST
Parse all the Rust syntax
syn
can parse from &str
:
pub fn parse_file(content: &str) -> Result<File>;
Parse the output of cargo-expand
⚠️ Breaks hygiene
But OK here as we're not looking at function bodies
New syntax may break the parser
Fix with cargo update
No import resolution
No dependency support
Build your own path resolution algorithm
Download & parse additional dependencies from crates.io
Rewriting cargo
and rustc
is not fun
And very complex (I tried)
Getting informations about a crate
No reimplementation work
Allow for dependency handling
rustc
as a libraryInstead of rewriting rustc
, let's use it as a lib
A nightly feature: #![feature(rustc_private)]
Gives access to rustc
's public API
Documented at https://doc.rust-lang.org/nightly/nightly-rustc/
Clippy
(Linting is static analysis, after all)
Need to tell rustc
about dependencies
Cargo.toml
filerustc
Or maybe we could use cargo
cargo
integrationRUSTC_WRAPPER
env. variable
rustc
when building a dependencyrustc
Hooks defined in the Callbacks
trait
Enables:
rustc
's query engineGoal: reducing duplicate work with memoization
TyCtxt
: structure to perform queries against
Very tied to rustc
Knowledge in compiler development needed
Very steep learning curve
Constantly moving API
Your OSS project probably does not have enough bandwidth
Getting information about a crate
No reimplementation work
Allow for dependency handling
Not too tied to the compiler
rustdoc
JSON outputFreeing ourselves from the compiler internals
rustdoc --output-format json
Writes information about API in a JSON file
Datatypes defined in rustdoc_json_types
in the Rust repository
Available on crates.io as rustdoc_types
Just Use Serde™
Integrates very well with cargo:
cargo rustdoc -- --output-format json
Limited to items
No pre-expansion information
Can't be used for function body analysis
More stable than rustc
as a lib
Automated release process of rustdoc_types
Fin