Skip to content

Indexes 1: Change Package and related traits to not return references to fields#1336

Open
dcookspi wants to merge 2 commits intomainfrom
index-1-package-trait-changes
Open

Indexes 1: Change Package and related traits to not return references to fields#1336
dcookspi wants to merge 2 commits intomainfrom
index-1-package-trait-changes

Conversation

@dcookspi
Copy link
Copy Markdown
Collaborator

@dcookspi dcookspi commented Mar 19, 2026

Note: for info on benefits of indexing for spk solves see #1340 (5 of 5). Maybe start there and work back down to this PR if you prefer to review PRs top down.

Changes various Package traits' methods to return Arc's instead of references to internal fields. This allows other package implementations, without matching fields, to use the traits. This is one of the changes that supports adding indexes and index based packages to Spk repositories.

This also adds the ArcCompat object as helper for serializing and deserializing Arc<Compat> fields.

This is 1 of 5 chained PRs for adding indexes to spk solves:

  1. this PR
  2. Indexes 2: Add new_unchecked() constructors to spk schema objects #1337
  3. Indexes 3: Adds flatbuffers schema and SolverPackageSpec for indexes to spk #1338
  4. Indexes 4: Adds Indexes for SPK repositories #1339
  5. Indexes 5: Adds spk repo index subcommand for index generation and updates #1340

@dcookspi dcookspi requested review from jrray and rydrman March 19, 2026 21:52
@dcookspi dcookspi self-assigned this Mar 19, 2026
@dcookspi dcookspi added SPI AOI Area of interest for SPI pr-chain This PR doesn't target the main branch, don't merge! labels Mar 19, 2026
@dcookspi dcookspi changed the title Changes Package and related traits to not return references to fields Indexing 1: Change Package and related traits to not return references to fields Mar 19, 2026
@dcookspi dcookspi changed the title Indexing 1: Change Package and related traits to not return references to fields Indexes 1: Change Package and related traits to not return references to fields Mar 19, 2026
@dcookspi dcookspi added the enhancement New feature or request label Mar 19, 2026
Comment on lines +360 to +361
fn compat(&self) -> Arc<Compat> {
self.compat.clone()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We've discussed this elsewhere already, but for the record the suggestion is to use Cow instead of Arc to provide a way for some implementations to be able to return an owned value without sacrificing some places (like this one) from being able to return a cheap reference instead of cloning.

A perhaps even better alternative would be to change this method to return impl SomeNewTrait where that trait contains methods to access whatever is needed from whatever is currently calling this compat() method. Then implementers of Versioned are free to return anything that conforms to that trait.

Copy link
Copy Markdown
Collaborator Author

@dcookspi dcookspi Mar 23, 2026

Choose a reason for hiding this comment

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

Todo:

  • Swap the updated Arc<..> return values out for Cow<..>.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I've switched the methods over to return Cows, and updated the rest of the PRs in the chain as well.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Turned the alternative into an issue for discussion: #1346

@dcookspi dcookspi force-pushed the index-1-package-trait-changes branch from 2f40d65 to fb6e0dd Compare March 25, 2026 00:42
@dcookspi dcookspi requested a review from jrray March 25, 2026 16:25
Copy link
Copy Markdown
Collaborator

@jrray jrray left a comment

Choose a reason for hiding this comment

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

Minor nits.

/// The expanded list of components selected for this resolved item
pub fn selected_components(&self) -> BTreeSet<&Component> {
let mut installed_components: BTreeSet<_> = self.request.pkg.components.iter().collect();
pub fn selected_components(&self) -> BTreeSet<Component> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think there could be a case for using Cow here too to allow this method to continue borrowing and avoid cloning but looking at where this method is used it doesn't seem like it is a critical path for the overhead to matter.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I wondered about that too, but the method didn't show up in the solve profiling before, or after, the change.

…nces to

internal fields.

This allows alternate package implementations to use the traits, such
as the forthcoming indexed based packages.

Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request pr-chain This PR doesn't target the main branch, don't merge! SPI AOI Area of interest for SPI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants