Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

analyze: borrowck: cache results of polonius runs on disk #1056

Merged
merged 2 commits into from
Jan 19, 2024

Conversation

spernsteiner
Copy link
Collaborator

The Polonius stage of borrow checking takes a long time to run on certain functions, such as lighttpd's li_MD5Transform. Worse, we often run Polonius multiple times on the same function as the interprocedural analysis iterates to reach a fixpoint. This branch speeds up the analysis by caching Polonius results on disk.

The caching logic is fairly simple: the core Polonius analysis is effectively a pure function from input facts to output facts, so we hash the input facts before each call and check whether a file named after that hash is present in the cache directory. There's no need to factor in any details of the crate, MIR, permissions, etc. If the current Polonius query has the same input facts as a previous query, it will necessarily produce the same output facts, regardless of how those input facts were computed.

Computing the input facts still has a nontrivial cost for some functions, but this branch provides significant speedups on algo_md5 and lighttpd_rust_amalgamated once c2rust-analyze has run once to populate the cache.


// Tuples only implement `Serialize` up to length 12, so split up this 17-element tuple into
// several pieces. Note this must match the tuple format in `try_load_cached_output`.
let raw = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is a tuple needed for the serialization as opposed to serializing the struct directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The struct is defined by the polonius crate and doesn't implement Serialize. Serde has some support for deriving impls for types in "remote crates", but it requires duplicating the struct definition and generally seems like a bit of a pain. Since we don't use the struct in fields of other Serialize types, we don't need a proper Serialize impl for it, and this tuple trick is sufficient.

@spernsteiner spernsteiner merged commit d818e4d into master Jan 19, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants