Skip to content

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

Open
dcookspi wants to merge 1 commit 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 1 commit intomainfrom
index-1-package-trait-changes

Conversation

@dcookspi
Copy link
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

…nces to

internal fields. This allows alternate package implementations to use the
traits, like the forthcoming indexed based packages.

Adds ArcCompat helper for serializing and deserializing Arc<Compat> fields

Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
@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
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
Collaborator Author

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<..>.

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