- Notifications
You must be signed in to change notification settings - Fork36
Types#154
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Types#154
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Signed-off-by: Alex Snaps <alex@wcgw.dev>
Signed-off-by: Alex Snaps <alex@wcgw.dev>
Signed-off-by: Alex Snaps <alex@wcgw.dev>
Signed-off-by: Alex Snaps <alex@wcgw.dev>
Signed-off-by: Alex Snaps <alex@wcgw.dev>
/// let expression = "foo.bar == 42"; | ||
/// | ||
/// let env = Env::Builder().add_type().add_variable("foo", "type").build(); | ||
/// let ast = env.parse(expression).unwrap(); | ||
/// let checked_ast = env.check(ast).unwrap(); | ||
/// let program = env.program(checked_ast).unwrap(); | ||
/// | ||
/// let result = program.eval(input); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This would be aligning APIs and enabling.check
phase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
let env =Env::Builder()// .add_type().add_variable("foo","type")// .add_overload().build();let ast = env.parse(expression).unwrap();
from the go impl:
e,err:=cel.NewEnv(// Variable identifiers used within this expression.cel.Variable("i",cel.StringType),cel.Variable("you",cel.StringType),// Function to generate a greeting from one person to another: i.greet(you)cel.Function("greet",cel.MemberOverload("string_greet_string", []*cel.Type{cel.StringType,cel.StringType},cel.StringType,cel.BinaryBinding(func(lhs,rhs ref.Val) ref.Val {returntypes.String(fmt.Sprintf("Hello %s! Nice to meet you, I'm %s.\n",rhs,lhs))}),),),)
@clarkmcc example given, these 2 lines become somewhat of a problem with the 2 crates. Obviously I can "hide" details from the parser by having people wanting to use the parser "only" for parsing. Now, if the point is also to use thecheck
-phase... then again it can't be done; as variable bindings, overload (functions et al) definitions need to be known.
Again, I'll keep on trying to keep things "separated", but there will inevitably be more than "just" the parser in the parser crate, as it'll need more than "just" that.
I'm also really starting to wonder whether we should consolidate the two crates into a single one, wdyt@clarkmcc ? I just find it harder to see how to lay the code into files... and mostly it feels like so much going into the parser. All that making it into the public API (pulling e.g. |
@alexsnaps the only reason to keep them separate arethese use-cases. If it's going to create a maintenance burden or technical debt in order to specifically support the parser being used in non-CEL contexts, then I am comfortable consolidating to a single crate. While it's nice to accommodate other non-CEL use-cases, those use-cases can still use the parser as part of the single interpreter crate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Pull Request Overview
This PR begins aligning the interpreter with more explicit typing and modern Rust formatting.
- Switched to inline Rust formatting (
"{v}"
, named capture) across serializers, errors, and tests. - Expanded
Val
enum and introducedget_type
mapping in the ANTLR reference. - Added placeholder
unimplemented!
for unhandledVal
conversions and updated documentation snippets.
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
interpreter/src/objects.rs | Addedunimplemented! for unhandledVal cases |
interpreter/benches/runtime.rs | Used inline formatting in benchmark names |
antlr/src/reference.rs | OverhauledVal enum and addedget_type method |
antlr/src/parser.rs | Switched to inline formatting in error messages |
interpreter/src/lib.rs | Added doc comment example and updated test messages |
(others) | Consistent switch to"{var}" formatting patterns |
Comments suppressed due to low confidence (1)
interpreter/src/lib.rs:5
- [nitpick] The code block is annotated
compile_fail
, which expects a compile error. If this is intended as a usage example, consider using```rust
so it compiles in doc tests.
/// ```compile_fail
Uh oh!
There was an error while loading.Please reload this page.
@@ -55,7 +55,7 @@ pub fn map_macro_benchmark(c: &mut Criterion) { | |||
let sizes = vec![1, 10, 100, 1000, 10000, 100000]; | |||
for size in sizes { | |||
group.bench_function(format!("map_{}", size).as_str(), |b| { | |||
group.bench_function(format!("map_{size}").as_str(), |b| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Calling.as_str()
on theformat!
result borrows a temporaryString
, causing a dangling reference. Bind theString
to a variable before borrowing, e.g.:let name = format!("map_{size}"); group.bench_function(&name, ...)
.
group.bench_function(format!("map_{size}").as_str(), |b|{ | |
let name =format!("map_{size}"); | |
group.bench_function(&name, |b|{ |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
🤔 So the borrower checker is broken, this is what this is telling us?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
IfI'm reading this right, then... you're wrong copilot, the dealloc happensafter the call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@alexsnaps sorry for the false positive. Copilot struggles with Rust lol. It's quite bold of it to assume a dangling reference in Rust haha.
No need to pay any attention to the copilot feedback, I run it through Copilot for myself to catch the easy stuff (misspellings and things) that are easy for me to miss. If there's something that needs to be fixed, I'll comment directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
No worries... I actually find it interesting to see what it comes up with. And yeah... hopefully it catches actual issues also :)
Uh oh!
There was an error while loading.Please reload this page.
I sorta get the rational, tho... possibly not. As far as I can tell, supporting these use-cases "only" requires the crate to expose whatever is needed to create an AST to be accessible to the end user. Now that remains the case either way as that's howCEL phases are defined. If we're talking requiring users of the parser to pull "too much" within the compile unit, then... possibly. Tho all they don't use would be DCE'ed anyways, but arguably that's not a free thing and will make their compilation, if only initially, slower. But that's where I fear things are going to get more obvious as I progress with this: there will be a whole lot more than "just the parser" in the Now I will try to keep the parser "as lightweight as possible" for now and see how far I can get, we can always re-evaluate later. So I'll keep all traits in the parser, along side with the literal types. Ithink I can possibly split some types out of the parser into the interpreter (thinking of container types here, but I could be wrong). I still think this is somewhat fighting the design of the other reference implementation, where these shared things are in a " |
@alexsnaps I mean I think you make a compelling case for unification. I'm comfortable with that. |
It's mostly the design that we're porting that from that makes that case. Tho, I'm also trying to avoid too many or certainly unnecessary |
This PR (based off the
clippy
one, sorry for the noise), is slowly introducing typing in a way that's more aligned with the other implementations.I'd appreciate any feedback and/or questions anyone would have already.
I'll slowly add to this, to implement stdlib's the overloads