Skip to content

Expand VisitMachineValues to cover more pointers in the interpreter #2566

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

Merged
merged 7 commits into from
Oct 4, 2022

Conversation

saethlin
Copy link
Member

Follow-on to #2559

This is making me want to write a proc macro 🤔

r? @RalfJung

@saethlin saethlin marked this pull request as ready for review September 26, 2022 01:49
@saethlin saethlin added the S-waiting-on-review Status: Waiting for a review to complete label Sep 26, 2022
@saethlin saethlin added S-waiting-on-author Status: Waiting for the PR author to address review comments S-waiting-on-review Status: Waiting for a review to complete and removed S-waiting-on-review Status: Waiting for a review to complete S-waiting-on-author Status: Waiting for the PR author to address review comments labels Sep 26, 2022
@@ -3,30 +3,120 @@ use rustc_data_structures::fx::FxHashSet;
use crate::*;

pub trait VisitMachineValues {
fn visit_machine_values(&self, visit: &mut impl FnMut(&Operand<Provenance>));
fn visit_machine_values(&self, visit: &mut ProvenanceVisitor);
}
Copy link
Member

@RalfJung RalfJung Sep 27, 2022

Choose a reason for hiding this comment

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

Hm okay this is less general than what I started out with, but I guess for now visiting all provenance is sufficient.

But then it should probably be called VisitProvenance.
And why did you change the visit argument?

Copy link
Member Author

Choose a reason for hiding this comment

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

We need to visit a number of different things. It's possible to contort them all into an Operand, but that adds a lot of repetitive glue code at the call sites. If each use of the visitor can take a different type, we can do the dispatch inside this module, instead of spread across the codebase. So we need to shift the generic parameter to each call to the visitor, which means we need a new type with the generic parameter on the method, not FnMut.

Copy link
Member

@RalfJung RalfJung Sep 27, 2022

Choose a reason for hiding this comment

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

But it seems you solved this by completely re-structuring the visitor to (a) to longer be lazy (it now hard-codes the use of a hash map -- ProvenanceVisitor is a somewhat misleading name for a newtyped HashMap) and (b) hard-code that only provenance matters.

If we want to hard-code that only provenance matters (which I am fine with for now), we should have

pub trait VisitProvenance {
 fn visit_provenance(&self, visit: &mut impl FnMut(Provenance));
}

Then you can impl VisitProvenance for {Operand,Immediate,Pointer} and you can now do x.visit_provenance(visit) for x ∈ {Operand,Immediate,Pointer}.

If we don't want to hard-code hat only provenance matters we need something else, but your approach does not achieve that.

Copy link
Member

Choose a reason for hiding this comment

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

That said, some places only have SbTag, not a full Provenance... not sure what the best way is to handle them. We could make the visitor focus only on SbTag I guess; then it should be called VisitProvenanceTags or so.

Copy link
Member

Choose a reason for hiding this comment

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

I pushed to this branch a version of these traits (or rather, just a single trait) demonstrating what I meant.

@saethlin saethlin added S-waiting-on-author Status: Waiting for the PR author to address review comments and removed S-waiting-on-review Status: Waiting for a review to complete labels Sep 28, 2022
@RalfJung RalfJung force-pushed the gc-cleanup branch 3 times, most recently from b30d3a9 to 1776178 Compare October 2, 2022 14:34
@RalfJung
Copy link
Member

RalfJung commented Oct 2, 2022

I went over all the visitors and made sure the discarded parts with _ have a type that doesn't need visit.

But yeah some kind of macro would be great.^^ Even a regular macro where one lists all the fields and that does the pattern expansion and calling the visitor. rustc used to have something like that but then later it got turned into a proper proc macro.

@RalfJung
Copy link
Member

RalfJung commented Oct 2, 2022

Ah, CI already merges with master. We can't rebase due to the subtree sync situation.

@RalfJung
Copy link
Member

RalfJung commented Oct 4, 2022

@bors r=oli-obk

@bors
Copy link
Contributor

bors commented Oct 4, 2022

📌 Commit 0790a41 has been approved by oli-obk

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Oct 4, 2022

⌛ Testing commit 0790a41 with merge da0ae33...

bors added a commit that referenced this pull request Oct 4, 2022
Expand VisitMachineValues to cover more pointers in the interpreter

Follow-on to #2559

This is making me want to write a proc macro 🤔

r? `@RalfJung`
@bors
Copy link
Contributor

bors commented Oct 4, 2022

💔 Test failed - checks-actions

@RalfJung
Copy link
Member

RalfJung commented Oct 4, 2022

@bors r=oli-obk

@bors
Copy link
Contributor

bors commented Oct 4, 2022

📌 Commit d2552d2 has been approved by oli-obk

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Oct 4, 2022

⌛ Testing commit d2552d2 with merge 2093184...

@bors
Copy link
Contributor

bors commented Oct 4, 2022

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 2093184 to master...

@bors bors merged commit 2093184 into rust-lang:master Oct 4, 2022
@saethlin saethlin deleted the gc-cleanup branch January 15, 2023 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: Waiting for the PR author to address review comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants