Skip to content
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

[Unity] Move VarBinding's and MatchCast's value to base class #15992

Conversation

Lunderberg
Copy link
Contributor

Prior to this commit, the VarBinding and MatchCast had equivalent Expr value fields. For use cases that need the bound value (e.g. collecting known values), this required downcasting to each subclass. This commit moves the Expr value to the base Binding class, removing the need for the downcasting.

No impact to either C++ or Python usage is expected. On the C++ side, all use of VarBindingNode::value or MatchCastNode::value will now access BindingNode::value. On the Python side, all dynamic access of binding_obj.value will access the new field.

Prior to this commit, the `VarBinding` and `MatchCast` had equivalent
`Expr value` fields.  For use cases that need the bound
value (e.g. collecting known values), this required downcasting to each
subclass.  This commit moves the `Expr value` to the base `Binding`
class, removing the need for the downcasting.

No impact to either C++ or Python usage is expected.  On the C++ side,
all use of `VarBindingNode::value` or `MatchCastNode::value` will now
access `BindingNode::value`.  On the Python side, all dynamic access
of `binding_obj.value` will access the new field.
@Lunderberg
Copy link
Contributor Author

@slyubomirsky I was thinking about the GetBoundValue utility function, and realized that there's enough locations that require the bound value that it would make sense to move the field from the VarBindingNode and MatchCastNode classes into the parent BindingNode class.

@@ -796,9 +798,6 @@ class MatchCast : public Binding {

class VarBindingNode : public BindingNode {
public:
/*! \brief The binding value. */
Expr value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We intentionally keep the value in the subclass, because in match clas there is extra set of struct info to be considered(that can populates new values), and it is important to keep reminding the users of this.

The extra dispatch is worth overall for this explicitness

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, and closing this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants