-
Notifications
You must be signed in to change notification settings - Fork 2
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
Cross Crate Analysis 2: An alternative approach. #163
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JustusAdam
force-pushed
the
cross-crate-v2
branch
from
July 28, 2024 23:34
a2c61fd
to
77b94bc
Compare
JustusAdam
force-pushed
the
cross-crate-v2
branch
from
July 28, 2024 23:35
77b94bc
to
7e4d821
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What Changed?
Adds the capability to load bodies and borrowcheck facts from non-local crates to facilitate analysis across the boundaries of the local crate. The design of this implementation is based on a similar mechanism in a purity analyzer by @artemagvanian.
Adds the
--include
command line argument to specify names of crates that should be loadable in addition to the analysis target.The basic mechanism is that, in every selected crate (either main target or
--include
) we run a visitor after expansion that usesget_body_with_borrowck_facts
, sanitizes that body by removing crate-local data and writes it plus relevant lifetime information to disk usingEncodable
. Downstream crates can locate the written data and load it back in usingDecodable
. A nicety of this approach is that we always do this, even or the main target crate, which means there is only one code path instead of a separate local and remote one.I the process of implementing this I realize that our points-to analysis actually doesn't need the whole
BodyWithBorrockFacts
but onlyinput_facts.subset_base
(and the body itself). I parameterized the points-to analysis, such that it can accept a reduced input, and we only store the relevant data.Also fully supports marker annotations in foreign crates.
The implicit body cache
MIR_BODIES
we used before is now replaced by an explicitBodyCache
.A large part of the changes is just changing
LocalDefId
toDefId
in call strings and the like as well as ensuring that all places that used to callrustc_utils
'get_body_with_borrowck_facts
is replaced with loading from theBodyCache
.Caveats
The statistics about how many functions were seen etc are disabled for now (always 0).
Why Does It Need To?
Analyzing only the local crate is a severe limitation of the tool which would be lifted by this PR.
There is a concurrent attempt (#153) to address the same issue. This is a simpler, but potentially less scalable approach. In addition this approach has full support for "both directions" of cross crate. The "forward direction" extends the PDG from the local crate (main analysis target) such that it also models functions in dependencies. The "backwards" direction ensures that function in the dependency, which are parameterized by traits where the impl is in the local trait, that impl composes with the function in the dependency.
Checklist
good record of what changed.
if necessary
.github/workflows/rust.yml
) either as compiler test or integration test.Or justification for their omission from CI has been provided in this PR
description.