-
Notifications
You must be signed in to change notification settings - Fork 51
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
global meta fields #517
base: master
Are you sure you want to change the base?
global meta fields #517
Conversation
Since I will be offline for a while, I merged in the code that's ready to go (namely, the local compiler now supports meta fields #521) and rebased this branch. This addresses feature-request #511. Global compilation is a little more involved (and less important), so I will address this once I'm back. |
I found some weird behavior. As of right now, when matching on or modifying meta fields, we have to use vanilla integers (maybe that will change eventually, especially to allow matching with masks). But there is an issue when using an integer that's at least 2^31 (IP >= 128.0.0.0) Here is some code that complains because my integer 0x80000000 is too big for int32 due to sign issues.
Error message:
But the weirder part is that under some circumstances, there is no error:
|
Thanks for the bug report. This must be a fat-fingered numeric operation somewhere. -N On Tue, Aug 2, 2016 at 10:42 AM, Caleb Voss notifications@github.com
|
The problem occurs because OCaml's builtin integers ( I'm actually not sure what the best way to go about this is, because OCaml doesn't come with native support for unsigned integers. Any ideas, @jnfoster / @arjunguha / @basus ? I would expect this sort of problem would have come up before? Update: |
Ctypes seems to have an |
@basus: It doesn't seem to have an usigned conversion function (see my updated post). |
By the way, I checked and the parser suffers from the same bug. It uses |
Perhaps this? |
@calebvoss: You can now assign ip addresses and mac addresses directly to meta fields, see https://github.com/frenetic-lang/frenetic/blob/master/ppx/test/main.ml#L17-L18. We still need to fix the bug you mentioned (see #536), but this should do as a workaround. |
Update: Most of this PR has already been merged (#521). The remaining bits are low priority.
This implements a feature suggested and discussed in #511. It introduces "meta fields" (or "logical fields"). They behave like other fields, but are erased during compilation.
They come in 4 versions: mutable or immutable, and initialized with a constant or initialized with the value of another field:
let <meta> := <int64> in p
let <meta> := <field> in p
var <meta> := <int64> in p
var <meta> := <field> in p
Here is a typical use case:
It compiles to the following table:
Note how the
ingress
field has been erased.A more detailed discussion of the motivation for this feature can be found in #511. More examples can be found in examples/meta-fields/
Note that this feature is just syntax sugar, i.e. it does not increase the expressivity of the language: any program with meta fields can be rewritten to an equivalent program without meta fields (in fact, that's what the compiler does). However, meta fields are a useful language abstraction that sometimes allow for more modular, more concise, and more readable programs. The virtual compiler (with meta fields
vswitch
andvport
) is a powerful examples of this.TODO:
vswitch
andvport
fields with meta fieldsLet
constructor (see Support inline records of OCaml 4.03? janestreet/ppx_sexp_conv#9 (comment))