-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Generic value range types #2918
Comments
I took the following notation:
A complex example: |
It seems like What about:
Also, what does it exactly mean? |
would it be possible to use global variables in these ranges? Matters such as "currentBlockNumber" and other areas that show what people would probably want to do with this in terms of defining price ranges that automatically assess risk, that being use them in ranges for proper collateralization techniques of their smart contracts. In other words, could one set these in a way where the inputs could be determined by external oracles/contracts? Or would this be/should this be explicitly disallowed? My gut tells me that it shouldn't be but that there could be interesting applications using this. |
Since in #2136 we've agreed to use
However as a start, I'd only implement support for single ranges: |
cc @ekpyron |
Yeah, this came up again, since with yul-codegen we will use overflow-checked math by default - and for that it makes almost no difference, whether the checks are against powers of two or not (apart from the fact that the constants used might be more expensive to store).
Is basically the same as
Where for the latter any other range would be valid as well at insignificant additional cost. And the question was, why to only allow this kind of logic specifically for powers of two, where ranges of real-world quantities are rarely accidentally powers of two. I actually think this is a nice direction to go - we could at some point only allow the old sized integer types in |
We're considering this for 0.7.
My first reaction to those:
Also we need to define behaviour in weird cases, e.g. If it makes things easier a first implementation could also have some restrictions, e.g. we can start with only ranges of the form Also we should write some example code to evaluate the syntax and its readability, especially wrt casting/converting. Gimmick for a future step: we could allow implicit downcasts, whenever the compiler can deduce that the actual value will be in range, i.e. |
And yeah... I just used |
Syntax-wise Regarding casting: maybe we should actually evaluate how much effort range-tracking would be:
could be much nicer than having to use
But tracking ranges well enough might be (too) tough. It might be enough to only consider constraints of the exact form |
@leonardoalt In theory, how much trust would you have into using SMT solving for the range constraints for this :-)? We probably can't do it anyways, at least as long as we can't make SMT solvers a hard dependency of the compiler, which we can't until we have emscripten builds for them... and in general it might cause loads of problems, e.g. for reproducable builds, etc., but might still be fun to think about... |
Interestingly, things like |
Another question: is dividing by a type with |
To get good answers to all these questions, we should probably take a look at a DSL that has that feature. |
This issue has been marked as stale due to inactivity for the last 90 days. |
Hi everyone! This issue has been automatically closed due to inactivity. |
Support generic types of the form
such that arithmetic operators on these types just naturally extend the ranges.
Example:
The type of the expression
a + b
isnumber<0..4000>
. Similarly, the type ofa * b
would benumber<0..4000000>
.The
precision
parameter represents the number of (decimal) digits after the radix point and we have the natural rules:The text was updated successfully, but these errors were encountered: