-
Notifications
You must be signed in to change notification settings - Fork 63
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
Support for type widening #911
Comments
An alternative proposal would be to allow type assertions to always be failable and then have the compiler turn them into a noop if the the type is known at compile time, allowing the expression to become
|
Thanks for this issue @DylanRJohnston ! I was going suggest what you have in #911 (comment) as an option too. That is: we have the type assertion functions always be fallible. I'm curious what you think @pront |
+1 on the approach described in #911 (comment) |
I believe that making them always failable is a breaking change, as any code with infailable assertions would now produce an error. So they'd need to be some kind of weird middle ground. You can simulate this right now using the dead code path trick. I guess you could argue that the infallible assertions shouldn't be there in the first place?
|
Yeah, my thought is that it'd be weird to have infallible type assertions in the first-place 🤔 I wonder if we could make this an opt-in feature to validate how much of a breaking change it would be for users. The flow would be something like:
|
Hey all, I'm currently working on a transpiler from another data processing language to VRL. Unfortunately due to a NDA I can't go into more specifics but a common problem I've encountered is VRL's strict error handling based on type information that is not possible to know at transpilation time.
For example taking a common operator from most other languages
the equivalent VRL is
however this often fails to compile due to strict error handling around types, unless both
static_query
andexpr
are known to be integers, this expression can fail, and requires error handlingHowever, you can't just use this in the transpiler as often there are times when the types are well known enough for this expression to not fail, which then causes the compiler to fail as VRL does not allow superfluous error handling. Using type assertions does not work for the same reason.
A workaround I've taken to using is using dead code paths to trick the compiler into widening the type and therefore allowing the superfluous type assertion e.g.
However
expr
can also sometimes have a known type, and sometimes not, ifexpr
is another static query into the event, it doesn't have a known type, if expr is a literal, or a reference to a variable with a known type it does. Which requires in the most general case something like.As you can see this becomes very noisy very quickly. I was wondering how you'd feel about the introduction of a type assertion that widens types, e.g.
any()
similar toint()
orstring()
, it would be infailable as it's always safe to map any type toany
and would help greatly in these cases where the transpiler is needing to output code without enough type information. e.g.What do you think?
The text was updated successfully, but these errors were encountered: