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

ast/simplify: Remove in_lvalue/in_param simplify() parameters #3813

Merged
merged 3 commits into from
Sep 28, 2023

Conversation

povik
Copy link
Member

@povik povik commented Jun 21, 2023

Split off from PR #3722, but it's still on top of the other PR's commits to save on rebase work. So, only the last three commits, starting with "ast/simplify: Make tweaks in advance of big in_lvalue/in_param change" should be the subject of this PR.

As is, the change might be objectionable since it requires the code to be sprinkled with calls to fixup_hierarchy_flags and set_attribute (new methods). That may not be as bad if we (1) don't require the in_param/in_lvalue values of the old code to be perfectly reproduced (which the change here does reproduce, at least as exercised by make test); (2) move to a coding style in the simplify code that doesn't rely on explicitly modifying the children list of an existing node as much. See the commits and let me know what you think.

This should be passing make test at each commit.

@povik povik requested a review from zachjs as a code owner June 21, 2023 15:58
@povik
Copy link
Member Author

povik commented Jun 21, 2023

(It doesn't make much sense to separate these three commits, so it's one PR.)

@povik povik force-pushed the ast-simplify-work-vol2 branch from c9bafd9 to d6284f1 Compare July 25, 2023 09:52
@povik
Copy link
Member Author

povik commented Jul 25, 2023

Rebased, shaked off the commits that were merged in PR #3722

Copy link
Member

@clairexen clairexen left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@zachjs zachjs left a comment

Choose a reason for hiding this comment

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

I like this change. The only downside I see is that one might easily forget to call fixup_hierarchy_flags() when working on new code that modifies children, but I think this overhead will be small compared to the benefit. Thank you!

@povik povik force-pushed the ast-simplify-work-vol2 branch from d6284f1 to 75225e1 Compare September 25, 2023 13:53
@povik
Copy link
Member Author

povik commented Sep 25, 2023

Rebased, but as it is now those old way/new way equivalence asserts between the second and third commit fail at some point in the test suite. Maybe I will investigate. (Those asserts are removed in the final commit so it's an option to merge this as is.)

The following commit will replace the way in_lvalue/in_param is being
tracked in the simplify code. Make tweaks in advance so that it will
be easier to make the old way and the new way agree.

These changes all should be innocuous.
Instead of passing around in_lvalue/in_param flags to simplify, we make
the flags into properties of the AST nodes themselves. After the tree
is first parsed, we once do

  ast->fixup_hierarchy_flags(true)

to walk the full hierarchy and set the flags to their initial correct
values. Then as long as one is using ->clone(), ->cloneInto() and the
AstNode constructor (with children passed to it) to modify the tree, the
flags will be kept in sync automatically. On the other hand if we are
modifying the children list of an existing node, we may need to call

  node->fixup_hierarchy_flags()

to do a localized fixup. That fixup will update the flags on the node's
children, and will propagate the change down the tree if necessary.

clone() doesn't always retain the flags of the subtree being cloned. It
will produce a tree with a consistent setting of the flags, but the
root doesn't have in_param/in_lvalue set unless it's intrinsic to the
type of node being cloned (e.g. AST_PARAMETER). cloneInto() will make
sure the cloned subtree has the flags consistent with the new placement
in a hierarchy.

Add asserts to make sure the old and new way of determining the flags
agree.
@povik povik force-pushed the ast-simplify-work-vol2 branch from 75225e1 to a511976 Compare September 26, 2023 11:42
@povik
Copy link
Member Author

povik commented Sep 26, 2023

Rebased, but as it is now those old way/new way equivalence asserts between the second and third commit fail at some point in the test suite.

Should be resolved now (as expected, it was due to interaction with other AST changes in the meantime).

Copy link
Collaborator

@zachjs zachjs left a comment

Choose a reason for hiding this comment

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

Thanks for fixing the semantic conflicts in the intermediate commit! This still looks good to me.

@povik
Copy link
Member Author

povik commented Sep 28, 2023

If that's the case, let's do it.

@povik povik merged commit 2002490 into YosysHQ:master Sep 28, 2023
@povik povik deleted the ast-simplify-work-vol2 branch October 9, 2023 09:54
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.

3 participants