Skip to content

Conversation

@rydrman
Copy link
Collaborator

@rydrman rydrman commented Oct 11, 2022

Building on top of #529, this changeset updates the Ident type to be a generic type so that we can define different versions of it for the recipe/version-only vs package/build identifiers. The general semantics is that each identifier is composed of two types (Base/Target). The main benefit of this is that it can dereference to the Base type, meaning that the BuildIdent can also be used as a reference to a VersionIdent (it's base).

Along with VersionIdent = Ident<PkgNameBuf, Version> and BuildIdent = Ident<VersionIdent, Build> there is an AnyIdent = Ident<VersionIdent, Option<Build> which I used to replace everything in this first refactoring pass, but aim to replace where appropriate before this MR is ready.

I've also introduced the HasVersion, HasBuild, and HasLocation traits in order to have useful bounds for functions that take more than one flavor of ident.

TODO:

  • add HasLocation implemented by LocatedBuildIdent and LocatedVersionIdent
  • do not dereference ident types, instead use explicit as_ and to_ conversions for sanity checking in implementations

@rydrman rydrman added maintenance Cleanup, upgrades, etc Rust API Pertaining to the public rust API of the library labels Oct 11, 2022
@rydrman rydrman added this to the Version 1.0 milestone Oct 11, 2022
@rydrman rydrman requested a review from jrray October 11, 2022 15:16
@rydrman rydrman self-assigned this Oct 11, 2022
@rydrman rydrman mentioned this pull request Oct 12, 2022
@rydrman rydrman changed the title RFC: Separate Ident Types for Different Specificities Separate Ident Types for Different Specificities Oct 13, 2022
@rydrman
Copy link
Collaborator Author

rydrman commented Oct 13, 2022

This is all ready for review now, apologies for the larger commits, I wanted to have the tests passing on each on in case of rebasing

@codecov
Copy link

codecov bot commented Oct 13, 2022

Codecov Report

Merging #530 (3ddf334) into master (de0c1ef) will decrease coverage by 0.06%.
The diff coverage is 62.44%.

@@            Coverage Diff             @@
##           master     #530      +/-   ##
==========================================
- Coverage   58.96%   58.90%   -0.07%     
==========================================
  Files         207      213       +6     
  Lines       14696    14910     +214     
==========================================
+ Hits         8666     8783     +117     
- Misses       6030     6127      +97     
Impacted Files Coverage Δ
crates/spk-cli/cmd-install/src/cmd_install.rs 0.00% <0.00%> (ø)
crates/spk-cli/common/src/env.rs 0.00% <0.00%> (ø)
crates/spk-cli/common/src/flags.rs 29.91% <0.00%> (-0.25%) ⬇️
crates/spk-cli/group2/src/cmd_publish.rs 0.00% <ø> (ø)
crates/spk-cli/group2/src/cmd_remove.rs 0.00% <0.00%> (ø)
crates/spk-cli/group3/src/cmd_export.rs 0.00% <0.00%> (ø)
crates/spk-cli/group4/src/cmd_search.rs 0.00% <0.00%> (ø)
...a/crates/foundation/src/ident_ops/parsing/ident.rs 31.11% <ø> (ø)
...ema/crates/foundation/src/spec_ops/has_location.rs 0.00% <0.00%> (ø)
...spk-schema/crates/foundation/src/spec_ops/named.rs 66.66% <0.00%> (+16.66%) ⬆️
... and 61 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Base automatically changed from 256-recipe-separate to master October 14, 2022 03:02
@rydrman rydrman requested a review from dcookspi November 5, 2022 04:16
@rydrman rydrman force-pushed the 256-ident-types branch 2 times, most recently from 6cf13cd to ddc22f9 Compare November 15, 2022 21:22
@rydrman rydrman modified the milestones: Version 1.0, V1 Spec Nov 17, 2022
@rydrman rydrman requested a review from jrray November 19, 2022 18:39
This was referenced Dec 23, 2022
@rydrman
Copy link
Collaborator Author

rydrman commented Jan 3, 2023

@jrray this PR underpins pretty much everything that I have going and I'd like to get it in soon, if possible. Before we reach anything that diverges the code base too much...

The pattern is <base>/<target> which allows for defining different
spcificity levels as well as nice composition of different ident types.
This initial commit defines different ident types as well as an AnyIdent
with an optional build that replaces the old ident nearly everywhere.
Next steps are to use more specific identifier types where applicable

Signed-off-by: Ryan Bottriell <ryan@bottriell.ca>
This mean that the v0 spec type needed to be updated to be generic over
the internal ident type, as well as the storage interfaces using the
appropriate ident types for loading recipes vs packages.

This was largely an exercise in refactoring and separating logic that
used to be conditional on the presence of a build into distict functions
instead.

Signed-off-by: Ryan Bottriell <ryan@bottriell.ca>
Copy link
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!

Uses macros to share common 'inheritance' instead of having a deref
implementation. This works better accross types where dereferencing to
the base is not as useful as the target (eg located idents) but also
creates a safer usage where ident types are not converted silently,
instead needing an explicit conversion call by the developer.

Additionally, add a HasLocation trait to complete the set.

Signed-off-by: Ryan Bottriell <ryan@bottriell.ca>
Signed-off-by: Ryan Bottriell <ryan@bottriell.ca>
Signed-off-by: Ryan Bottriell <ryan@bottriell.ca>
@rydrman rydrman requested review from dcookspi and jrray January 5, 2023 00:00
Signed-off-by: Ryan Bottriell <ryan@bottriell.ca>
@rydrman
Copy link
Collaborator Author

rydrman commented Jan 5, 2023

Apparently, there are some new clippy lints in 1.66 - I've fixed those now, as well

@rydrman rydrman merged commit cbef31a into master Jan 5, 2023
@rydrman rydrman deleted the 256-ident-types branch January 5, 2023 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Cleanup, upgrades, etc Rust API Pertaining to the public rust API of the library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants