Skip to content

Indexes 2: Add new_unchecked() constructors to spk schema objects#1337

Open
dcookspi wants to merge 2 commits intoindex-1-package-trait-changesfrom
index-2-new-unchecked-additions
Open

Indexes 2: Add new_unchecked() constructors to spk schema objects#1337
dcookspi wants to merge 2 commits intoindex-1-package-trait-changesfrom
index-2-new-unchecked-additions

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.

This adds new_unchecked() constructor methods to various spk schema objects. These allow direct creation of those objects from other existing object pieces, e.g. from other pieces of those objects in index data. This is one of the changes that supports adding indexes and index based packages to Spk repositories. It allows indexes to avoid reparsing data from text for some objects.

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

  1. Indexes 1: Change Package and related traits to not return references to fields #1336
  2. this PR
  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

These allow for directly creating those objects from other existing
object pieces, e.g. from index data objects.

Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
@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
Comment on lines +58 to +62
// TODO: CompatRules that allow ::None are used in Compat
// structs. CompatRules that do not allow ::None are used in
// required_compat's in Requests. They should be separate types,
// perhaps one wrapping the other, to clarify where ::None is and is
// not a valid value.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This refers to something that is worked around in later Indexing changes. But it could also be something that gets addresses in future by separating the two uses into distinct types.

Comment on lines +1211 to +1216
/// Makes a VersionFilter from the given string, without checking
/// that it is valid. This is used by indexing.
pub fn new_unchecked(filter_string: &str) -> Self {
VersionFilter::from_str(filter_string).unwrap()
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This unwrap isn't good. But I've left it for now because it is likely the indexed representation of a VersionFilter, as part of an install requirement, will change to be stored as more pieces and that will mean this method is reworked entirely.

}

// Allow tests to manufacture owned instances with known good values.
// Allow tests and indexes to manufacture owned instances with known good values.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No new_checked() methods were added for these String based types here. But in a later indexes PR there are several uses of unsafe { ... } around an existing method on these types. It may be that we want to fold those into a new_unchecked() method here for the non-test cases use.

Fixing up a comment

Signed-off-by: dcookspi <92065525+dcookspi@users.noreply.github.com>
@dcookspi dcookspi added the enhancement New feature or request label Mar 19, 2026
@dcookspi dcookspi requested review from jrray and rydrman March 19, 2026 22:53
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.

1 participant