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

core: (assembly-format) omit default attributes/properties from attr-dict directive #3783

Merged
merged 3 commits into from
Jan 24, 2025

Conversation

alexarice
Copy link
Collaborator

The attr-dict directive currently prints attributes/properties which are set to the default value, which is not the correct behaviour.

@alexarice alexarice added bug Something isn't working core xDSL core (ir, textual format, ...) labels Jan 23, 2025
@alexarice alexarice self-assigned this Jan 23, 2025
Copy link

codecov bot commented Jan 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.25%. Comparing base (cafe3c5) to head (ad87012).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3783      +/-   ##
==========================================
- Coverage   91.25%   91.25%   -0.01%     
==========================================
  Files         461      461              
  Lines       57490    57519      +29     
  Branches     5543     5543              
==========================================
+ Hits        52465    52491      +26     
- Misses       3603     3604       +1     
- Partials     1422     1424       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@AntonLydike AntonLydike left a comment

Choose a reason for hiding this comment

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

Looks good, minor nit request 🙃

not (set(op.attributes.keys()) | set(op.properties.keys()))
- self.reserved_attr_names
):
return
if any(name in op.attributes for name in op.properties):
raise ValueError(
"Cannot print attributes and properties with the same name "
"in a signle dictionary"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you fix this typo while you're at it? 🙃

Suggested change
"in a signle dictionary"
"in a single dictionary"

Comment on lines 464 to 471
default_names = set(
name
for name, d in op_def.attributes.items()
if d.default_value is not None
and op.attributes.get(name) == d.default_value
)
reserved_or_default = self.reserved_attr_names | default_names
if not set(op.attributes.keys()) - reserved_or_default:
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
default_names = set(
name
for name, d in op_def.attributes.items()
if d.default_value is not None
and op.attributes.get(name) == d.default_value
)
reserved_or_default = self.reserved_attr_names | default_names
if not set(op.attributes.keys()) - reserved_or_default:
reserved_or_default = self.reserved_attr_names.update(
name
for name, d in op_def.attributes.items()
if d.default_value is not None
and op.attributes.get(name) == d.default_value
)
if not reserved_or_default.is_superset(op.attributes.keys()):

Two proposals, each of which avoids a set construction, seems a tiny bit cleaner

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

update is a mutating function right? (I can't mutate self.reserved_attr_names)

Copy link
Member

Choose a reason for hiding this comment

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

My bad, I meant union

@alexarice
Copy link
Collaborator Author

Should I still refactor to use union?

@superlopuh
Copy link
Member

It's a bit of a nit, and it's unlikely to be a perf bottleneck, but it seems like a good opportunity to do so, sets aren't free :)

@alexarice
Copy link
Collaborator Author

Great, will wait for CI then merge

@alexarice alexarice merged commit 2d39e73 into main Jan 24, 2025
16 checks passed
@alexarice alexarice deleted the alexarice/default-prop-in-dict branch January 24, 2025 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core xDSL core (ir, textual format, ...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants