-
Notifications
You must be signed in to change notification settings - Fork 79
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -438,27 +438,41 @@ def parse(self, parser: Parser, state: ParsingState) -> None: | |||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
def print(self, printer: Printer, state: PrintingState, op: IRDLOperation) -> None: | ||||||||||||||||||||||||||||||||
if self.print_properties: | ||||||||||||||||||||||||||||||||
if ( | ||||||||||||||||||||||||||||||||
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" | ||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||
op_def = op.get_irdl_definition() | ||||||||||||||||||||||||||||||||
dictionary = op.attributes | op.properties | ||||||||||||||||||||||||||||||||
default_names = set( | ||||||||||||||||||||||||||||||||
name | ||||||||||||||||||||||||||||||||
for name, d in (op_def.properties | op_def.attributes).items() | ||||||||||||||||||||||||||||||||
if d.default_value is not None | ||||||||||||||||||||||||||||||||
and dictionary.get(name) == d.default_value | ||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||
reserved_or_default = self.reserved_attr_names | default_names | ||||||||||||||||||||||||||||||||
if not (set(dictionary.keys())) - reserved_or_default: | ||||||||||||||||||||||||||||||||
return | ||||||||||||||||||||||||||||||||
printer.print_op_attributes( | ||||||||||||||||||||||||||||||||
op.attributes | op.properties, | ||||||||||||||||||||||||||||||||
reserved_attr_names=self.reserved_attr_names, | ||||||||||||||||||||||||||||||||
dictionary, | ||||||||||||||||||||||||||||||||
reserved_attr_names=reserved_or_default, | ||||||||||||||||||||||||||||||||
print_keyword=self.with_keyword, | ||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||
if not set(op.attributes.keys()) - self.reserved_attr_names: | ||||||||||||||||||||||||||||||||
op_def = op.get_irdl_definition() | ||||||||||||||||||||||||||||||||
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: | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
Two proposals, each of which avoids a set construction, seems a tiny bit cleaner There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My bad, I meant |
||||||||||||||||||||||||||||||||
return | ||||||||||||||||||||||||||||||||
printer.print_op_attributes( | ||||||||||||||||||||||||||||||||
op.attributes, | ||||||||||||||||||||||||||||||||
reserved_attr_names=self.reserved_attr_names, | ||||||||||||||||||||||||||||||||
reserved_attr_names=reserved_or_default, | ||||||||||||||||||||||||||||||||
print_keyword=self.with_keyword, | ||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
|
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.
Can you fix this typo while you're at it? 🙃