Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Draft
alexsnaps wants to merge6 commits intocel-rust:master
base:master
Choose a base branch
Loading
fromalexsnaps:types
Draft

Types#154

alexsnaps wants to merge6 commits intocel-rust:masterfromalexsnaps:types

Conversation

alexsnaps
Copy link
Contributor

This PR (based off theclippy 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

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>
Signed-off-by: Alex Snaps <alex@wcgw.dev>
Comment on lines +6 to +13
/// 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);
Copy link
ContributorAuthor

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

clarkmcc reacted with hooray emoji
Copy link
ContributorAuthor

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.

@alexsnaps
Copy link
ContributorAuthor

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.usescel-parser::Value to then work with thecel-interpreter::Context for instance)

@clarkmcc
Copy link
Collaborator

@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.

@clarkmccclarkmcc requested a review fromCopilotJuly 15, 2025 17:09
Copy link
Contributor

@CopilotCopilotAI left a 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.
  • ExpandedVal enum and introducedget_type mapping in the ANTLR reference.
  • Added placeholderunimplemented! 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
FileDescription
interpreter/src/objects.rsAddedunimplemented! for unhandledVal cases
interpreter/benches/runtime.rsUsed inline formatting in benchmark names
antlr/src/reference.rsOverhauledVal enum and addedget_type method
antlr/src/parser.rsSwitched to inline formatting in error messages
interpreter/src/lib.rsAdded 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 annotatedcompile_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

@@ -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| {
Copy link
Preview

CopilotAIJul 15, 2025

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, ...).

Suggested change
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.

Copy link
ContributorAuthor

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?!

Copy link
ContributorAuthor

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.

Copy link
Collaborator

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.

Copy link
ContributorAuthor

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 :)

@alexsnaps
Copy link
ContributorAuthor

@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.

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 thecel-parser crate, as the whole type system is being pulled in. Also note, that the release and API burden does "somewhat" existtoday, as there is a hard dependency between parser & interpreter version.

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 "common" package/module/subproject, but I would really hate to add a 3rd crate. Until I'm further along, these things will then go intocel-parser::common, is that fine with you?

@clarkmcc
Copy link
Collaborator

@alexsnaps I mean I think you make a compelling case for unification. I'm comfortable with that.

@alexsnaps
Copy link
ContributorAuthor

@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 unnecessarydynamic dispatches... Which could become the case if I "hide" certain things behind atrait "just" for the sake of the dependency. I'll keep on iterating for a few days, and then we can hopefully make a call informed by actual code.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@clarkmccclarkmccclarkmcc left review comments

Copilot code reviewCopilotCopilot left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@alexsnaps@clarkmcc

[8]ページ先頭

©2009-2025 Movatter.jp