Draft
Conversation
Syntax:
module Foo {
option MySwitch = False;
option MyValue: uint64 = 5;
[...]
MySwitch = True;
}
Options are meant to capture a tunable parameter where a parser picks
a suitable default for something, but allows changing that value
externally. An `option` is something "in between" a global constant
and a global variable: Like a global constant, it's "semantically
constant" in the sense that it's something that's explicitly set to
some chosen value; it's not meant for dynamically collecting state.
But like a global, its value *can* change during runtime.
Access to options works through normal scoping, so that their values
can modified externally through assignments inside other modules, in
particular at initialization time through global statements. If
multiple modules change an option at init time, it's undefined which
change will win out.
This isn't fully finished yet, and up for discussion at this point.
Some notes/thoughts:
- I have tested that this works from the Zeek side to feed
script-level values back into a parser through global statements
(`Foo::MyValue = zeek::get_count("Foo:MyValue");`)
- This commit currently does not implement the equivalent of
`cxx_enable_dynamic_globals` for options. Like globals, options
aren't thread-safe by default, and we'd need to take similar
measures to make them so. In fact, at that point, options could
just be merged into the set of globals during codegen, although
we'd get similar overhead then. Alternatively, because changes
are supposed to be rare, if we'd allow only assignments to
change a value, it might be viable to use actual locks around
accesses, not sure.
- The similarity to globals on the implementation side suggests
that options are really primarily a semantic language construct,
but nothing fundamentally new. I'm kind of torn if we actually
need them, or should simply use globals for tunable parameters.
- I considered making options read-only during runtime, allowing
changes only at module initialization time (i.e., through global
statements). However, that would prevent updating them from
inside a change handler for a Zeek-side option, which would be
unfortunate.
TODO:
- Do we want this?
- More tests
- Documentation
Member
|
This seems to be practically about #765 which I just linked. |
Member
Author
|
Some notes on the plan going forward:
Next step: Write this up a bit more formally, with proposals for syntax and API. |
Member
Author
If we get a host API to change values instead, maybe we can go back to this and allow Spicy-side changes only during module initialization. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Syntax:
Options are meant to capture a tunable parameter where a parser picks
a suitable default for something, but allows changing that value
externally. An
optionis something "in between" a global constantand a global variable: Like a global constant, it's "semantically
constant" in the sense that it's something that's explicitly set to
some chosen value; it's not meant for dynamically collecting state.
But like a global, its value can change during runtime.
Access to options works through normal scoping, so that their values
can modified externally through assignments inside other modules, in
particular at initialization time through global statements. If
multiple modules change an option at init time, it's undefined which
change will win out.
This isn't fully finished yet, and up for discussion at this point.
Some notes/thoughts:
TODO:
- Do we want this?
- More tests
- Documentation