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

[internal] Store Values and DirectoryDigests as boxed references in the workunit store. #14749

Merged
merged 2 commits into from
Mar 9, 2022

Conversation

stuhood
Copy link
Member

@stuhood stuhood commented Mar 9, 2022

To avoid cycles between the workunit_store crate and the engine and fs crates, UserMetadataItem::PyValue and ArtifactOutput::Snapshot both used indirection.

But in #14723, ArtifactOutput::Snapshot storing a hashing::Digest will no longer be a sufficient replacement for storing a fs::DirectoryDigest, because we no longer guarantee that all (directory) Digests have actually been persisted to disk: some of them exist only in memory as DigestTries held by DirectoryDigests. And we don't want to introduce a cycle between fs and the workunit_store crate.

To fix both cases, we use a Boxed Any (technically, Arced, since we need Clone), and downcast to the underlying type at the consume side.

…ues and DirectoryDigests.

[ci skip-build-wheels]
@stuhood stuhood force-pushed the stuhood/workunit-store-refs branch from 93f3090 to b8ba625 Compare March 9, 2022 22:11
@stuhood stuhood enabled auto-merge (squash) March 9, 2022 22:14
@stuhood stuhood disabled auto-merge March 9, 2022 22:14
@stuhood stuhood enabled auto-merge (squash) March 9, 2022 22:14
Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Probably worth some more comments in the code about why we use Any, such as on the as_any methods

pub enum UserMetadataItem {
PyValue(UserMetadataPyValue),
// NB: Always stores a ...
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO?

Copy link
Member Author

@stuhood stuhood Mar 9, 2022

Choose a reason for hiding this comment

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

Oops, yep.

As to your other comment: the traits try to explain themselves:

// NB: Only implemented for `Value`, but is boxed to avoid a cycle between this crate and the
// `engine` crate.

... as does the as_any method:

  // See https://vorner.github.io/2020/08/02/fights-with-downcasting.html.
  fn as_any(&self) -> &dyn Any;

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@stuhood stuhood enabled auto-merge (squash) March 9, 2022 22:22
// is only as large as its pointers.
known_deep_size!(8 * 3; Value);
// is only as large as its pointer.
known_deep_size!(8; Value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of assuming the size is 8, maybe use std::mem::size_of<* cosnt ()> or some other pointer type?

Copy link
Member Author

Choose a reason for hiding this comment

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

Mm, yea: good idea. I think that I wasn't sure whether it would work with the macro.

@stuhood stuhood merged commit ea8cf59 into pantsbuild:main Mar 9, 2022
@stuhood stuhood deleted the stuhood/workunit-store-refs branch March 10, 2022 00:18
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