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

feat[eve]: Preserve annex in custom visitors #1874

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

tehrengruber
Copy link
Contributor

Preserve annex attributes in the NodeTranslator for nodes returned from custom visit_ methods, not only from nodes which are recreated in generic_visit. This is often desired and with this PR doesn't need to be done manually in child classes of NodeTranslator. The visit method can still decide if the node it returns should have a different annex attribute as _preserve_annex does not overwrite in case the attribute already exists.

@tehrengruber tehrengruber changed the title feat[eve]: Preserve annex on feat[eve]: Preserve annex in custom visitors Feb 20, 2025
Copy link
Contributor

@egparedes egparedes left a comment

Choose a reason for hiding this comment

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

A couple of questions only. It looks good.

if (value := getattr(old_annex, key, NOTHING)) is not NOTHING:
assert key not in new_annex_dict
new_annex_dict[key] = value
_preserve_annex(node, new_node, self.PRESERVED_ANNEX_ATTRS)
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about leaving the condition outside of the function? This is probably the hottest loop in the toolchain so I'd rather try to avoid a unnecessary function call if possible. Additionally, it would also make the function name fully correct 😄

Suggested change
_preserve_annex(node, new_node, self.PRESERVED_ANNEX_ATTRS)
if preserved_annex_attrs and hasattr(node, "__node_annex__"):
_preserve_annex(node, new_node, self.PRESERVED_ANNEX_ATTRS)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about this, but went for not duplicating the condition. Makes sense to me though, so I reverted that.

@@ -436,8 +436,12 @@ def _infer_stmt(
**kwargs: Unpack[InferenceOptions],
):
if isinstance(stmt, itir.SetAt):
# constant fold once otherwise constant folding after domain inference might create (syntactic) differences
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this change really belong to this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I initially checked that the new annex attribute is equal to the old one. That would be a desirable property of the IR and this change here is a step in that direction. This also motivated the comment above

# Note: The annex value of the new node might not be equal
# (in the sense that an equality comparison returns false),
# but in the context of the pass, they are equivalent.
# Therefore, we don't assert equality here.

However there are annex values that are equivalent, but not equal e.g. the domain annex with a value of
(domain, domain) (tuple of domains) is equivalent to domain. I therefore gave up on the assert, but kept this change here. Does that make sense?

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