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

Populate liveness facts when calling get_body_with_borrowck_facts without -Z polonius #93603

Merged

Conversation

connorff
Copy link
Contributor

@connorff connorff commented Feb 2, 2022

For a new feature of Flowistry, a static-analysis tool, we need to obtain a mir::Body's liveness facts using get_body_with_borrowck_facts (added in #86977). We'd like to do this without passing -Z polonius as a compiler arg to avoid borrow checking the entire crate.

Support for doing this was added in #88983, but the Polonius input facts used for liveness analysis are empty. This happens because the liveness input facts are populated in liveness::generate depending only on the value of AllFacts::enabled (which is toggled via compiler args).

This PR propagates the use_polonius flag to liveness::generate to support populating liveness facts without requiring the -Z polonius flag.

This fix is somewhat patchy - if it'd be better to add more widely-accessible state (like AllFacts::enabled) I'd be open to ideas!

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 2, 2022
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cjgillot (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 2, 2022
@rust-log-analyzer

This comment has been minimized.

@connorff connorff force-pushed the compute-polonius-liveness-facts-flag branch from 7e58208 to 42371a5 Compare February 3, 2022 00:51
@connorff connorff marked this pull request as ready for review February 3, 2022 04:27
@connorff connorff changed the title Compute liveness facts when calling get_body_with_borrowck_facts without -Z polonius Populate liveness facts when calling get_body_with_borrowck_facts without -Z polonius Feb 3, 2022
@cjgillot
Copy link
Contributor

Sorry for the wait @connorff. I don't know this code at all.
r? @ecstatic-morse

@ecstatic-morse
Copy link
Contributor

ecstatic-morse commented Feb 25, 2022

@bors r+ rollup

I also find it strange that we pass these flags manually instead of checking some flag on tcx. I think this style predates even #86977, so no use being inconsistent here. This kind of thing can easily be fixed later.

@connorff Feel free to ping me on any future PRs that need attention. I'll try to respond in a timely fashion.

@bors
Copy link
Contributor

bors commented Feb 25, 2022

📌 Commit 42371a5 has been approved by ecstatic-morse

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 25, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 25, 2022
…facts-flag, r=ecstatic-morse

Populate liveness facts when calling `get_body_with_borrowck_facts` without `-Z polonius`

For a new feature of [Flowistry](https://github.com/willcrichton/flowistry), a static-analysis tool, we need to obtain a `mir::Body`'s liveness facts using `get_body_with_borrowck_facts` (added in rust-lang#86977). We'd like to do this without passing `-Z polonius` as a compiler arg to avoid borrow checking the entire crate.

Support for doing this was added in rust-lang#88983, but the Polonius input facts used for liveness analysis are empty. This happens because the liveness input facts are populated in `liveness::generate` depending only on the value of `AllFacts::enabled` (which is toggled via compiler args).

This PR propagates the [`use_polonius`](https://github.com/rust-lang/rust/blob/8b09ba6a5d5c644fe0f1c27c7f9c80b334241707/compiler/rustc_borrowck/src/nll.rs#L168) flag to `liveness::generate` to support populating liveness facts without requiring the `-Z polonius` flag.

This fix is somewhat patchy - if it'd be better to add more widely-accessible state (like `AllFacts::enabled`) I'd be open to ideas!
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 26, 2022
…askrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#93603 (Populate liveness facts when calling `get_body_with_borrowck_facts` without `-Z polonius`)
 - rust-lang#93870 (Fix switch on discriminant detection in a presence of coverage counters)
 - rust-lang#94355 (Add one more case to avoid ICE)
 - rust-lang#94363 (Remove needless borrows from core::fmt)
 - rust-lang#94377 (`check_used` should only look at actual `used` attributes)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3b276cb into rust-lang:master Feb 26, 2022
@rustbot rustbot added this to the 1.61.0 milestone Feb 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants