Indexes 2: Add new_unchecked() constructors to spk schema objects#1337
Indexes 2: Add new_unchecked() constructors to spk schema objects#1337dcookspi wants to merge 2 commits intoindex-1-package-trait-changesfrom
new_unchecked() constructors to spk schema objects#1337Conversation
| // 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. |
There was a problem hiding this comment.
This refers to something that is worked around in later Indexing changes. But it could also be something that gets addressed in future, by separating the two uses into distinct types.
There was a problem hiding this comment.
I do like the idea of there being a newtype that wraps the other and giving them their own distinct Display implementation, to get away from the "magic" alternate() mechanism.
| } | ||
|
|
||
| // Allow tests to manufacture owned instances with known good values. | ||
| // Allow tests and indexes to manufacture owned instances with known good values. |
There was a problem hiding this comment.
No new_checked() methods were added for these String based types here. But in a later indexes PRs there are several uses of unsafe { ... } around an existing method on these types. It may be we want to fold those into a new_unchecked() method for non-test cases use.
There was a problem hiding this comment.
Big picture I think we want to be able to say that values in the index were already validated before put into the index and therefore should be trusted without having to re-validate them when reading the index.
However we need a way to introduce changes to spk that may change validation rules. For example let's say we stop allowing '-' in package names. How do we want to put some kind of version number in the index metadata so at runtime the spk process can check that the index conforms to its expectations?
I'm interested in having a way to validate the whole index at once, in a sense, instead of having to validate every individual value found in the index.
There was a problem hiding this comment.
I've added unsafe's to the new_checked methods and updated the callers to use unsafe blocks around them.
Validating the index will be addressed in PR3 (#1338).
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
2f40d65 to
fb6e0dd
Compare
d83388a to
a59523b
Compare
| } | ||
|
|
||
| // Allow tests to manufacture owned instances with known good values. | ||
| // Allow tests and indexes to manufacture owned instances with known good values. |
There was a problem hiding this comment.
Big picture I think we want to be able to say that values in the index were already validated before put into the index and therefore should be trusted without having to re-validate them when reading the index.
However we need a way to introduce changes to spk that may change validation rules. For example let's say we stop allowing '-' in package names. How do we want to put some kind of version number in the index metadata so at runtime the spk process can check that the index conforms to its expectations?
I'm interested in having a way to validate the whole index at once, in a sense, instead of having to validate every individual value found in the index.
crates/spk-schema/crates/foundation/src/ident_build/build_id.rs
Outdated
Show resolved
Hide resolved
crates/spk-schema/crates/foundation/src/ident_ops/parsing/ident.rs
Outdated
Show resolved
Hide resolved
| // 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. |
There was a problem hiding this comment.
I do like the idea of there being a newtype that wraps the other and giving them their own distinct Display implementation, to get away from the "magic" alternate() mechanism.
fb6e0dd to
9bd9685
Compare
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>
a59523b to
5c8e4db
Compare
Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
5c8e4db to
33938c3
Compare
| /// # Safety | ||
| /// | ||
| /// The caller must ensure the string parses as a valid compat. | ||
| pub unsafe fn new_unchecked(compat: &str) -> Result<Self> { |
There was a problem hiding this comment.
This uses from_str and returns a Result. Is it really unsafe? It has to successfully parse so I don't think using this skips any validation.
| /// The caller must make sure the string can be parsed as a valid | ||
| /// Version. | ||
| pub unsafe fn new_unchecked(version_str: &str) -> Result<Self> { | ||
| Version::try_from(version_str) |
There was a problem hiding this comment.
Same thought here, really unsafe?
There was a problem hiding this comment.
To add to this, the followup question would be could the current users of Version::new_unchecked just switch to Version::try_from and then this constructor is not needed?
| /// The caller must make sure the pieces combine to make a valid | ||
| /// EmbeddedPackageSpec. |
There was a problem hiding this comment.
I feel the need to say that this safety message (and the others) amount to saying "you have responsibilities to use this correctly" but without giving any details on how to use it correctly. I get it that you don't necessarily know what those are. I couldn't tell you what they are right now on the spot either.
| /// | ||
| /// # Safety | ||
| /// | ||
| /// The caller must make sure the requests are valid and the they |
There was a problem hiding this comment.
| /// The caller must make sure the requests are valid and the they | |
| /// The caller must make sure the requests are valid and they |
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:
spk repo indexsubcommand for index generation and updates #1340