Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type safe bounds #627

Merged
merged 30 commits into from
Jan 28, 2022
Merged

Type safe bounds #627

merged 30 commits into from
Jan 28, 2022

Conversation

maurolacy
Copy link
Contributor

@maurolacy maurolacy commented Jan 10, 2022

Closes #462. Implements typed range bounds, following the same approach than PrefixBound. Also introduces a couple raw variants, for flexibility and generality.

Did all the changes in this PR, except for some refactoring, that will be published separately.
Lots of changes, but mostly cosmetic. The main impls are in keys.rs, where Bound was renamed to RawBound, and a new typed Bound was introduced. All this will be moved to its own bound.rs module for clarity (in a follow-up).

There's also a new Bounder trait, to build bounds from the keys (i.e. key.inclusive_bound() syntax), but it is mostly accessory / cosmetic.

Some small follow-ups / questions from here:

  • Deprecate prefix_range? After this new syntax for bounds, prefix_range is a little redundant. It's still clearer than using composite keys with empty elements. So, I'm not sure here.
  • Deprecate / adapt raw index key helpers. We either adapt the index_key helpers to return typed keys, or deprecate them entirely.
  • Missing prefix_range_raw() impls. If we don't deprecate it, let's add these for completeness in:
    • SnapshotMap
    • IndexedSnapshotMap
    • UniqueIndex
  • Missing sub_prefix_range/_raw(). If we don't deprecate it, let's decide if we add these or not (only really useful for triple keys).
  • Simplify / consolidate trait bound definitions. There are a lot of trait bounds over these structs, and perhaps some of those can be simplified / consolidated.

Note: CI checks are failing due to the no-iterator variant. Solved in #629. (fixed / merged)

Copy link
Collaborator

@ueco-jb ueco-jb left a comment

Choose a reason for hiding this comment

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

lgtm

Being nitpicky as I am, I'd consider changing test names slightly. I'm not sure what exactly range2_... means.

Initially I wanted to point out, that bound imports in unique.rs and multi.rs are without cfg = iteration mark, but then I noticed that types that uses them have those decorators in lib.rs. Nice that you were so precise about that.

Also, iterating over prefix is neat!

@maurolacy
Copy link
Contributor Author

lgtm

Being nitpicky as I am, I'd consider changing test names slightly. I'm not sure what exactly range2_... means.

Will fix those. Thanks.

Required for `edition2021` feature
@maurolacy maurolacy merged commit 544bf59 into main Jan 28, 2022
@maurolacy maurolacy deleted the 462-type-safe-bounds branch January 28, 2022 15:45
Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

Finally got to review it. Looks very nice and impressive you got this to work without much breaking APIs.

A few comments to consider

contracts/cw1155-base/src/contract.rs Show resolved Hide resolved
contracts/cw20-base/src/enumerable.rs Show resolved Hide resolved
contracts/cw3-fixed-multisig/src/contract.rs Show resolved Hide resolved
packages/storage-plus/src/indexed_map.rs Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make Bounds type safe
3 participants