-
Notifications
You must be signed in to change notification settings - Fork 791
Refactor ExpressionRunner #2804
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
Refactor ExpressionRunner #2804
Conversation
Also note that |
// Maximum depth before giving up. | ||
Index maxDepth = NO_LIMIT; | ||
Index maxDepth; |
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.
In #2702 it has been requested to initialize both maxDepth
and maxLoopIterations
here with = NO_LIMIT
. However, the single constructor now sets these while allowing to omit either just maxLoopIterations
or both. So, C++ newbie question: Are there scenarios where a derived template may never call that constructor?
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 I don't think there can be scenarios that these are not initialized. But I also think it is good habit to initialize member variables to some default values in general, just to prevent bugs. In this case they are initialized in the constructor so the compiled code will be the same, i.e., it's not gonna initialize them twice. I'm OK with either.
Also, I broke CI again. But this time I'm not able to fix it apparently :( |
Also, I fixed CI again! |
Thank you for the quick refactoring! Sorry I still may not have the full context yet, but why are |
The precompute pass has a special mechanism that the C-API does not have, in that it computes a map of
Yep, one way to look at this is that
So, yeah, that's kinda what this is now after the refactor. Note that Does that make sense? :) |
How are the two mechanisms (
How is a class being |
See #2702 (comment) for the context of the Edit: We can always remove the |
Iiuc the GetValues-based mechanism is specialized to work with LocalGraph after its work is done, while the index-based approach observes in execution order. Would assume that there are ways to unify both, somehow, just not sure how large of a change that would be. Currently, precompute uses GetValues to establish an initial link of gets to values, and will then resort to the index-based approach on new sets and their respective gets during linear execution of the expression of interest. The challenge I faced in my PR was that one cannot easily compute the indexed variant from GetValues, since execution order is lost when that map is created, so one doesn't know which of all the values to initialize the runner with. |
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.
Thanks for the explanation. Now I think I understand things better.
It looks CExpressionRunner
is there only to be marked as final
, right? Can we delete it and use ConstantExpressionRunner
from C API instead? We can add an empty virtual destructor in ExpressionRunner
class.
// Maximum depth before giving up. | ||
Index maxDepth = NO_LIMIT; | ||
Index maxDepth; |
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 I don't think there can be scenarios that these are not initialized. But I also think it is good habit to initialize member variables to some default values in general, just to prevent bugs. In this case they are initialized in the constructor so the compiled code will be the same, i.e., it's not gonna initialize them twice. I'm OK with either.
Sure, let me see. How would you model this, considering that CExpressionRunner is a class, and ConstantExpressionRunner is its template? My intuition would be to make ConstantExpressionRunner a class, with a |
Hmm, yeah, come to think of it, it's not gonna be simple :( Making those methods virtual will break the static polymorphism this class hierarchy is using. I think the problem here stems from the fact that even though How about this hierarchy, where
Do you think this makes sense? Please let me know if you have better ideas. Thanks for your time! |
There's already a
Hmm, might work. So far I assumed that |
Yes.
I'm not sure what this paragraph means. I'm not suggesting to add any new functionality or
|
It inherits practically everything with this PR, except that it overrides
To me that looks quite reasonable already, and I have been under the impression that we are now trying to unify PrecomputeExpressionRunner/CExpressionRunner even more, but perhaps this is a misunderstanding? Like, PrecomputeExpressionRunner doesn't actually duplicate any code, which I believe you mentioned earlier? (Well, technically it is duplicating everything before optimizations by using a template, perhaps that's what you mean?) |
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.
Sorry, nevermind my last comment. I noticed that in #2702 you moved some functionalities in PrecomputeExpressionRunner
into ExpressionRunner
(now ConstantExpressionRunner
here).
Yeah, at this point I'm OK with this change. Thank you for spending time for this and explaining things for me!
Looks very nice! |
Tackles the concerns raised in #2797 directly related to #2702 by reverting merging all of
PrecomputeExpressionRunner
into the baseExpressionRunner
, instead adding a common base for both the precompute pass and the new C-API to inherit. No functional changes.Current hierarchy after #2702 is
where
ExpressionRunner
contains functionality not utilized byConstantExpressionRunner
andRuntimeExpressionRunner
.New hierarchy will be:
with the precompute pass's and the C-API's shared functionality now moved out of
ExpressionRunner
into a newConstantExpressionRunner
. Also renames the previousConstantExpressionRunner
toInitializerExpressionRunner
to better represent its uses and to make its previous name usable for the new intermediate template, where it fits perfectly. Also adds a few comments answering some of the questions that came up recently.Old hierarchy before #2702 for comparison:
cc @aheejin