-
-
Notifications
You must be signed in to change notification settings - Fork 463
feat: add disable short-circuiting option to compiler #847
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
base: master
Are you sure you want to change the base?
Conversation
5f4562f to
fd9c3f0
Compare
|
I just fix the code according to the check result. It'll be good now. |
|
Nice! Let me review this more carefully. |
|
We could implement this with less core changes if we follow your example here. My suggestion is the following (Go Playground working example): // DisableShortCircuit turns short circuiting behaviour off in `&&`, `and`, `||`, and `or` boolean operators.
func DisableShortCircuit() expr.Option {
return func(c *conf.Config) {
expr.Function("OR", func(params ...any) (any, error) {
return params[0].(bool) || params[1].(bool), nil
}, func(a, b bool) bool { return true })(c)
expr.Function("AND", func(params ...any) (any, error) {
return params[0].(bool) && params[1].(bool), nil
}, func(a, b bool) bool { return true })(c)
expr.Operator("or", "OR")(c)
expr.Operator("||", "OR")(c)
expr.Operator("and", "AND")(c)
expr.Operator("&&", "AND")(c)
}
}This way we will not need any changes to vm and compiler packages and the core language remains smaller. |
I also considered this solution at first glance. However, after spending some time investigating the implementation, I realized this more intuitive solution might potentially conflict with or be overridden by other patch/optimization features. I'm not sure if my concerns are unnecessary, so I've implemented this in the compiler & vm package, which I find easier to understand and might be more robust without bugs. On the other hand, I give it a try and find something interesting. Since I don't have much time to figure out every detail of the implementation, I'm not sure if this operator overloading solution has other hidden bugs or limitations, or we can solve this by some other tricks? What do you think about this? Looking forward to your reply. |
|
I think proposal solution in this poor request is proper. Disable short circuit should generate different bytecode. |
#831