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

Allow expressions with type constructors #1313

Merged
merged 23 commits into from
Jan 27, 2023

Commits on Jan 11, 2023

  1. Configuration menu
    Copy the full SHA
    480bbe4 View commit details
    Browse the repository at this point in the history
  2. 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.
    rsmmr committed Jan 11, 2023
    Configuration menu
    Copy the full SHA
    57a5682 View commit details
    Browse the repository at this point in the history
  3. 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.
    rsmmr committed Jan 11, 2023
    Configuration menu
    Copy the full SHA
    54b22f8 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    0636d23 View commit details
    Browse the repository at this point in the history
  5. Address review feedback.

    rsmmr committed Jan 11, 2023
    Configuration menu
    Copy the full SHA
    7aa2c14 View commit details
    Browse the repository at this point in the history
  6. Move negation out of parser.

    rsmmr committed Jan 11, 2023
    Configuration menu
    Copy the full SHA
    e35fa30 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    7737659 View commit details
    Browse the repository at this point in the history
  8. Add general constant folding.

    The normalizer now attempts to fold any expression through the constant
    folder.
    rsmmr committed Jan 11, 2023
    Configuration menu
    Copy the full SHA
    1829081 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    afc45a5 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    2ddb1d7 View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    38d6621 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    0e8ed00 View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    86c720d View commit details
    Browse the repository at this point in the history
  14. Suppress clang-tidy warnings.

    rsmmr committed Jan 11, 2023
    Configuration menu
    Copy the full SHA
    97484b0 View commit details
    Browse the repository at this point in the history
  15. Outsource an integer range check to SafeInt.

    Plus, a bit of cleanup.
    rsmmr committed Jan 11, 2023
    Configuration menu
    Copy the full SHA
    fa20890 View commit details
    Browse the repository at this point in the history
  16. Add boolean folding.

    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.
    rsmmr committed Jan 11, 2023
    Configuration menu
    Copy the full SHA
    4a79137 View commit details
    Browse the repository at this point in the history
  17. Fix printing of enum constants.

    I believe this path never triggered so far, but it does now with the
    new constant folding.
    rsmmr committed Jan 11, 2023
    Configuration menu
    Copy the full SHA
    5d1c311 View commit details
    Browse the repository at this point in the history
  18. Fix printing of ID scopes.

    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.
    rsmmr committed Jan 11, 2023
    Configuration menu
    Copy the full SHA
    3240fa8 View commit details
    Browse the repository at this point in the history
  19. Fix clang-tidy warnings.

    rsmmr committed Jan 11, 2023
    Configuration menu
    Copy the full SHA
    0df4162 View commit details
    Browse the repository at this point in the history
  20. Configuration menu
    Copy the full SHA
    a44ecdc View commit details
    Browse the repository at this point in the history

Commits on Jan 19, 2023

  1. Suppress GCC warnings.

    rsmmr committed Jan 19, 2023
    Configuration menu
    Copy the full SHA
    d66cc1a View commit details
    Browse the repository at this point in the history
  2. Fix issue in Bison grammar.

    rsmmr committed Jan 19, 2023
    Configuration menu
    Copy the full SHA
    10ee02c View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    78ae64b View commit details
    Browse the repository at this point in the history