-
Notifications
You must be signed in to change notification settings - Fork 81
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
Experimental: Strongly typed types of time #1907
Draft
lemunozm
wants to merge
4
commits into
main
Choose a base branch
from
exp/time-safety-types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lemunozm
added
Q5-hard
Can be done by an experienced coder with a good knowledge of the codebase.
P2-nice-to-have
Issue is worth doing.
I6-refactoring
Code needs refactoring.
labels
Jul 11, 2024
lemunozm
force-pushed
the
exp/time-safety-types
branch
from
July 11, 2024 15:19
f18650a
to
19a3acd
Compare
lemunozm
commented
Jul 11, 2024
libs/utils/src/num_wrapper.rs
Outdated
Comment on lines
24
to
29
/// ``` | ||
/// # use crate::num_wrapper::NumWrapper; | ||
/// | ||
/// struct Id1; | ||
/// struct Id2; | ||
/// | ||
/// type FooU64 = NumWrapper<u64, Id1>; | ||
/// type BarU64 = NumWrapper<u64, Id2>; | ||
/// ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FooU64
and BarU64
are different types for the compiler, and you can implement different traits to them. In memory and for serde
and codec
there are just plain u64
lemunozm
force-pushed
the
exp/time-safety-types
branch
2 times, most recently
from
August 2, 2024 07:23
babfbbe
to
09cda36
Compare
lemunozm
commented
Aug 2, 2024
lemunozm
force-pushed
the
exp/time-safety-types
branch
3 times, most recently
from
August 5, 2024 14:33
fb6d6f5
to
6a790fa
Compare
lemunozm
force-pushed
the
exp/time-safety-types
branch
from
August 19, 2024 08:04
431c9dc
to
7dfc4a4
Compare
lemunozm
force-pushed
the
exp/time-safety-types
branch
from
August 19, 2024 08:16
7dfc4a4
to
73a732f
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
I6-refactoring
Code needs refactoring.
P2-nice-to-have
Issue is worth doing.
Q5-hard
Can be done by an experienced coder with a good knowledge of the codebase.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The idea of this PR is to have
Millis
andSeconds
as different types for the compiler. This helps to never mix by error different duration units and improve the readability of some parts of the codebase.To achieve this, we need:
num_wrapper.rs
file).BaseArithmetic
to be able to use this types as normalu64
(i.e. give topallet_timestamp
'sMoment
the newMillis
type.How times should be used now in the code base?
Moment
(probably most of the times a<<T as Config>::Time as Time>::Moment
), as usual. You can use the traitTimeUnit
to get the time as the unit you want.cfg_primitives::{Millis, Seconds, Days, ..}
. There is no need for an associated type in the pallet.Blockers
It seems likeparity_scale_codec
doesn't allow to implementHasCompact
trait required byBasicArithmetic
:Custom types withHasCompact
paritytech/parity-scale-codec#613unlock this work if they allow us to implementHasCompact
RemoveHasCompact
fromBaseArithmetic
paritytech/polkadot-sdk#5004unlock this work if they do not force us to useHasCompact
Found a solution: last message of Custom types with
HasCompact
paritytech/parity-scale-codec#613Remainders
Requirement::DelayTime
uses au32
to hold seconds when it should be au64
wrapped intoSeconds
type. Nevertheless, this requires a migration in an storage of pool-system.