-
Notifications
You must be signed in to change notification settings - Fork 37
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
Allow expressions with type constructors #1313
Merged
Merged
Commits on Jan 11, 2023
-
Configuration menu - View commit details
-
Copy full SHA for 480bbe4 - Browse repository at this point
Copy the full SHA 480bbe4View commit details -
Support arbitrary expression as argument to
interval(...)
and `inte……rval_ns(...)`. So far we used constructor expressions like `interval(...)` to create *constants* of the given type, and for that we required that the argument was a single atomic value. The result was that these constructor expressions were really more like literals for the corresponding types than "normal" expressions. While that's useful internally, it's confusing for the user. This commits is beginning to change that, using `interval`/`interval_NS` as the first instances that now supports arbitrary expressions as its argument. In follow-up commits, we'll port other constructor expressions over to that new syntax. (This also unifies HILTI & Spicy to each provide both of those interval constructors.) To make this change without loosing a way to create actual constants (which we need at some places), we implement this in two stages: the parser initially turns such `interval(...)` expressions into call operators[1] that the types now define for each desired constructor. We then extend the normalizer to look at all the relevant call operators: if they are just receiving a constant value as their argument, then it substitutes them with a plain ``Ctor`` node (``ctor::Interval`` in our cases here). That check for "if they just receive a constant value" isn't quite trivial in general. In our case, where we just want to go back to what we had, it's not that difficult, but more generally it would be nice if we had a constant folder that could compute results even for more complex, but constant, expressions. As that's a piece that our AST infrastructure is still missing, this commit starts going that route by adding a new "constant folder" visitor. Right now, it's covers only the simple cases we need here, but it's something we can extend going forward. Addresses #1123. [1] These call operators are a bit special because they actually don't have anything to call: in `interval(42)` the `interval` isn't any kind of actual value; we just need it for overload resolution. To make that work, we use a `expression::Member` as the first operand, which models a predefined ID. Normally `Member` is just for field lookups in, e.g., structs, but it works just as well elsewhere.
Configuration menu - View commit details
-
Copy full SHA for 57a5682 - Browse repository at this point
Copy the full SHA 57a5682View commit details -
Port more type constructors to new call operators.
This moves `time/time_ns/stream/error/intN/uintN` over to the new call operator model that we introduced for `interval`. One HILTI-side syntax change: HILTI now also uses `intN(x)` and `uintN(x)` instead of `int<N>`/`uint<N>`. This is to avoid having to introduce two separate set of operators. This change slightly changes timing for when exactly some errors are caught, which required tweaking a couple of tests a bit.
Configuration menu - View commit details
-
Copy full SHA for 54b22f8 - Browse repository at this point
Copy the full SHA 54b22f8View commit details -
Configuration menu - View commit details
-
Copy full SHA for 0636d23 - Browse repository at this point
Copy the full SHA 0636d23View commit details -
Configuration menu - View commit details
-
Copy full SHA for 7aa2c14 - Browse repository at this point
Copy the full SHA 7aa2c14View commit details -
Configuration menu - View commit details
-
Copy full SHA for e35fa30 - Browse repository at this point
Copy the full SHA e35fa30View commit details -
Configuration menu - View commit details
-
Copy full SHA for 7737659 - Browse repository at this point
Copy the full SHA 7737659View commit details -
The normalizer now attempts to fold any expression through the constant folder.
Configuration menu - View commit details
-
Copy full SHA for 1829081 - Browse repository at this point
Copy the full SHA 1829081View commit details -
Configuration menu - View commit details
-
Copy full SHA for afc45a5 - Browse repository at this point
Copy the full SHA afc45a5View commit details -
Configuration menu - View commit details
-
Copy full SHA for 2ddb1d7 - Browse repository at this point
Copy the full SHA 2ddb1d7View commit details -
Configuration menu - View commit details
-
Copy full SHA for 38d6621 - Browse repository at this point
Copy the full SHA 38d6621View commit details -
Configuration menu - View commit details
-
Copy full SHA for 0e8ed00 - Browse repository at this point
Copy the full SHA 0e8ed00View commit details -
Configuration menu - View commit details
-
Copy full SHA for 86c720d - Browse repository at this point
Copy the full SHA 86c720dView commit details -
Configuration menu - View commit details
-
Copy full SHA for 97484b0 - Browse repository at this point
Copy the full SHA 97484b0View commit details -
Configuration menu - View commit details
-
Copy full SHA for fa20890 - Browse repository at this point
Copy the full SHA fa20890View commit details -
Note: The original plan was to have this fully replace the optimizer's boolean folding. However, it turns out that that doesn't quite work because it would mess up the optimizer's tracking of feature usage. For now, we special-case the feature constants in the folder and don't touch them.
Configuration menu - View commit details
-
Copy full SHA for 4a79137 - Browse repository at this point
Copy the full SHA 4a79137View commit details -
Fix printing of enum constants.
I believe this path never triggered so far, but it does now with the new constant folding.
Configuration menu - View commit details
-
Copy full SHA for 5d1c311 - Browse repository at this point
Copy the full SHA 5d1c311View commit details -
The intent has always been to normalize ID scopes so that they aren't prefixed with the current module. However, that wasn't always working because we lost the state of the current scope. Now moving that into a global to retain it across different printing streams.
Configuration menu - View commit details
-
Copy full SHA for 3240fa8 - Browse repository at this point
Copy the full SHA 3240fa8View commit details -
Configuration menu - View commit details
-
Copy full SHA for 0df4162 - Browse repository at this point
Copy the full SHA 0df4162View commit details -
Configuration menu - View commit details
-
Copy full SHA for a44ecdc - Browse repository at this point
Copy the full SHA a44ecdcView commit details
Commits on Jan 19, 2023
-
Configuration menu - View commit details
-
Copy full SHA for d66cc1a - Browse repository at this point
Copy the full SHA d66cc1aView commit details -
Configuration menu - View commit details
-
Copy full SHA for 10ee02c - Browse repository at this point
Copy the full SHA 10ee02cView commit details -
Configuration menu - View commit details
-
Copy full SHA for 78ae64b - Browse repository at this point
Copy the full SHA 78ae64bView commit details
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.