Constant flattening in math expression#3090
Conversation
There was a problem hiding this comment.
minor nit : this can be changed to single condition check,
if(eval instanceof Long)
return LongExpr(..)
else ret DoubleExpr(...)
There was a problem hiding this comment.
It's problem that we don't have type information for evaluation result. Wishfully #2836 would be included in sometime. Addressed anyway, thanks.
|
LGTM |
bb62934 to
8f47e73
Compare
There was a problem hiding this comment.
especially now that you're using getFunction() to access this, making this (and the logger) private would be cleaner. Maybe add a hasFunction() if needed for ExprListenerImpl.exitFunctionExpr()
There was a problem hiding this comment.
Should this really extend Function? What do you expect FunctionFactory.apply() to do?
There was a problem hiding this comment.
Did this not to make two classes (factory and function) for each stateful functions. if it's look that bad, I can separate these two.
There was a problem hiding this comment.
I'm okay with this for now, maybe we can revisit once you have some implementations.
There was a problem hiding this comment.
Would prefer either dynamically constructing by class name or doing else if for UnaryNotExpr() and returning original expr for unimplemented cases. Someone's going to add another UnaryExpr type and this won't work right.
There was a problem hiding this comment.
This would fail if the List object is immutable. Can we either enforce that the list is mutable or write into another list?
|
rebased on #2836 and waiting it to be committed |
8f47e73 to
30cca12
Compare
|
rebased on master |
There was a problem hiding this comment.
unnecessary parentheses around value
There was a problem hiding this comment.
unnecessary parentheses around value
There was a problem hiding this comment.
IAE("Invalid function name '%s'", name)
There was a problem hiding this comment.
Typo, fattening -> flattening I think
|
Minor cleanup, otherwise LGTM 👍 |
There was a problem hiding this comment.
Why is this not instanceof ConstantExpr? It seems like there is no point to having "ConstantExpr" as an interface if we can't use it to figure out if something is a constant or not.
There was a problem hiding this comment.
Is it feasible to add isConstant as a method on Expr?
I think it's nice to have all the logic for a particular expr together in the expr class, rather than spread around the project in methods like isConstant and flatten. That makes it easier to add new exprs without having to update a lot of different places in the code.
There was a problem hiding this comment.
replaced with instanceof ConstantExpr
There was a problem hiding this comment.
Do we expect this to happen "normally" or is this really a problem indicating a bug? If it's going to happen "normally" it shouldn't be log.info as that will be too noisy in the logs. If it indicates a bug, please bump it up to log.warn.
There was a problem hiding this comment.
I'm confused, what's going on here? It looks like this is saying that f(const) = null which doesn't seem right.
There was a problem hiding this comment.
it should be Evals.isAllConstants(fattening). fixed and added test case
30cca12 to
7182e0b
Compare
|
@navis I think there's a few remaining issues. Any chance to finish this up? |
7182e0b to
0597931
Compare
|
@fjy I think I've addressed all comments |
|
@nishantmonu51 any more comments? |
|
👍 |
* Constant flatteing in math expression * Addressed comments and fixed some bugs * Addressed comments
* Constant flatteing in math expression * Addressed comments and fixed some bugs * Addressed comments
constant expression in math-expr can be simplified in compile time when all of the arguments are constant and the function is deterministic (currently all functions and operation in math-expr is deterministic). For example, (8 + 7) * 10) now returns simply 150 not (* (+ 8 7) 10).