Indexes 2: Add new_unchecked() constructors to spk schema objects#1337
Indexes 2: Add new_unchecked() constructors to spk schema objects#1337
new_unchecked() constructors to spk schema objects#1337Conversation
| } | ||
|
|
||
| // 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.
fb6e0dd to
9bd9685
Compare
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.
There was a problem hiding this comment.
I've removed the unsafe keyword for now. I'll will come back if/when the compat representations in the index change from string to an ordered list of compat rules entries - which is a possible future extension.
| /// 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?
There was a problem hiding this comment.
It's not really unsafe here, I'll take it out.
For the followup question: Yes it could be replaced for this PR. But for one of the the later ones, or a coming improvement (I can't remember which, but one of them wull change the string in index storage to the component number pieces), the new_checked() implementation would change to directly set the fields in the Version struct. I suppose I could take it out and then put it back, but I wanted to put all the new_unchecked() methods in one PR.
There was a problem hiding this comment.
I've taken the unsafe out.
There was a problem hiding this comment.
As above, remove the safety notice and rename to something that doesn't use "unchecked".
There was a problem hiding this comment.
I've updated this.
| /// 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.
There was a problem hiding this comment.
Yes, the safety messages are a linting requirement. Looking up the specific details is very much left to the caller. I couldn't say what they are for the different cases either - other than make sure you pass valid x, y, z objects in. I suspect the actual details could be found in the parsing methods, maybe?
9bd9685 to
cebade9
Compare
f2be50a to
54465be
Compare
| /// # Safety | ||
| /// | ||
| /// The caller must ensure the string parses as a valid compat. | ||
| pub fn new_unchecked(compat: &str) -> Result<Self> { |
There was a problem hiding this comment.
You can (should) remove the safety notice for a function that is not unsafe.
IMO new or from_compat would be a better name for this, if it is even needed at all, at least up until the point where this evolves into something that is unsafe and unchecked.
There was a problem hiding this comment.
I've updated this.
| /// 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.
As above, remove the safety notice and rename to something that doesn't use "unchecked".
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>
Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
…s and compat. Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
54465be to
ae936f5
Compare
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 #1340version_filterfield in index schema #1344