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

GC: factor out visiting all machine values #2559

Merged
merged 1 commit into from
Sep 23, 2022

Conversation

RalfJung
Copy link
Member

@saethlin that is roughly what I had in mind.

I think some parts of the state are skipped by the visitor. I listed the ones that I found in FIXMEs but I am not sure if that list is complete.

@RalfJung
Copy link
Member Author

More bits of machine state that are not visited:

  • last_error
  • catch_unwind

@RalfJung
Copy link
Member Author

We will probably want a VisitMachineValues trait that is implemented for Machine and recursively for all the non-trivial types it has as fields. That'll be quite a bit of work, but the current approach clearly misses too many bits of the state.

trait VisitMachineValues {
  fn visit_machine_values(&self, impl FnMut(&Operand<Provenance>));
}

@saethlin
Copy link
Member

I can read what you changed, but I don't understand how this helps with missing pieces of state in the interpreter?

@RalfJung
Copy link
Member Author

I think separating the visiting from the remaining GC logic makes it easier to check that nothing was forgotten. Also using the visitor pattern with exhaustive field lists in the let bindings (see my latest commit) means we get errors when a field was skipped.

@RalfJung
Copy link
Member Author

I am happy with the structure of this PR now. @saethlin do you want to take over and complete the PR by implementing all the missing things in the visitor? Or should we land this and you hopefully can do that in a future PR?

src/concurrency/thread.rs Outdated Show resolved Hide resolved
@@ -628,6 +624,34 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> {
}
}

impl VisitMachineValues for ThreadManager<'_, '_> {
fn visit_machine_values(&self, visit: &mut impl FnMut(&Operand<Provenance>)) {
// FIXME some other fields also contain machine values
Copy link
Member

Choose a reason for hiding this comment

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

I see there are other fields with machine values, but it's not clear to me that for example thread_local_alloc_ids is keeping pointers live. Are there other fields?

Copy link
Member Author

Choose a reason for hiding this comment

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

Isn't that the only way you will reach the current value of thread-local variables? And a thread-local variable can store a pointer to somewhere else.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's similar, I think, to the global base tag map in Stacked Borrows -- I don't know how your GC is not failing left and right due to removing the base tags.

Copy link
Member

@saethlin saethlin Sep 24, 2022

Choose a reason for hiding this comment

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

Stack::retain never removes the bottom-most tag. (I forgot about this until just now)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah. Yeah that would help but needs to be carefully documented.

@saethlin
Copy link
Member

saethlin commented Sep 22, 2022

I'd prefer to do a second PR. r=me with or without addressing the formatting nit (I think we have other formatting jank which will snap into place when the style team gets off the ground).

@RalfJung
Copy link
Member Author

@bors r=saethlin

@bors
Copy link
Contributor

bors commented Sep 23, 2022

📌 Commit 8dc4893 has been approved by saethlin

It is now in the queue for this repository.

@RalfJung
Copy link
Member Author

@bors ping

@bors
Copy link
Contributor

bors commented Sep 23, 2022

😪 I'm awake I'm awake

@RalfJung
Copy link
Member Author

@bors retry

@RalfJung RalfJung closed this Sep 23, 2022
@RalfJung RalfJung reopened this Sep 23, 2022
@RalfJung
Copy link
Member Author

@bors r=saethlin

@bors
Copy link
Contributor

bors commented Sep 23, 2022

💡 This pull request was already approved, no need to approve it again.

@bors
Copy link
Contributor

bors commented Sep 23, 2022

📌 Commit 8dc4893 has been approved by saethlin

It is now in the queue for this repository.

@RalfJung
Copy link
Member Author

@bors r-

@RalfJung
Copy link
Member Author

@bors r=saethlin

@bors
Copy link
Contributor

bors commented Sep 23, 2022

📌 Commit 8dc4893 has been approved by saethlin

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Sep 23, 2022

⌛ Testing commit 8dc4893 with merge 9a9bbc9...

@bors
Copy link
Contributor

bors commented Sep 23, 2022

☀️ Test successful - checks-actions
Approved by: saethlin
Pushing 9a9bbc9 to master...

@bors bors merged commit 9a9bbc9 into rust-lang:master Sep 23, 2022
@RalfJung RalfJung deleted the gc-refactor branch September 24, 2022 07:53
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 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`
RalfJung pushed a commit to RalfJung/rust that referenced this pull request Oct 4, 2022
Expand VisitMachineValues to cover more pointers in the interpreter

Follow-on to rust-lang/miri#2559

This is making me want to write a proc macro 🤔

r? `@RalfJung`
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.

3 participants