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

dialects: (builtin) Parse @ module names #3664

Merged
merged 9 commits into from
Dec 24, 2024

Conversation

mamanain
Copy link
Collaborator

It seems that modules in xdsl already support sym_name attribute but we don't parse @-starting names.

@mamanain mamanain added the core xDSL core (ir, textual format, ...) label Dec 22, 2024
@mamanain mamanain self-assigned this Dec 22, 2024
Copy link

codecov bot commented Dec 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.29%. Comparing base (fb41de5) to head (cfa53a6).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3664      +/-   ##
==========================================
- Coverage   91.29%   91.29%   -0.01%     
==========================================
  Files         466      466              
  Lines       58354    58357       +3     
  Branches     5639     5624      -15     
==========================================
+ Hits        53276    53278       +2     
  Misses       3629     3629              
- Partials     1449     1450       +1     

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

Copy link
Member

@superlopuh superlopuh left a comment

Choose a reason for hiding this comment

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

This looks great, although this is a good opportunity to make the module name a property, and it'll simplify the format logic:

❯ echo "module @hello {}" | mlir-opt --mlir-print-op-generic
"builtin.module"() <{sym_name = "hello"}> ({
^bb0:
}) : () -> ()

@superlopuh
Copy link
Member

superlopuh commented Dec 22, 2024

Does this work?

`builtin.module` ($sym_name^)? attr-dict-with-keyword $bodyRegion

@mamanain
Copy link
Collaborator Author

mamanain commented Dec 23, 2024

Does this work?

`builtin.module` ($sym_name^)? attr-dict-with-keyword $bodyRegion

You mean does the combination of module name and attribute work? It does, added a test for it.

Copy link
Collaborator

@math-fehr math-fehr 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, I would just change a bit the init with my comment

@@ -1643,21 +1643,30 @@ def __init__(
self,
ops: list[Operation] | Region,
attributes: Mapping[str, Attribute] | None = None,
properties: dict[str, Attribute] | None = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ad properties are not extensible, and would only contain the sym_name, I would just pass a StringAttr | None instead, and create the properties dictionary in the init

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense. Done, thanks.

Comment on lines 1677 to 1680
if "sym_name" in self.properties and isinstance(
self.properties["sym_name"], StringAttr
):
printer.print(f" @{self.properties['sym_name'].data}")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if "sym_name" in self.properties and isinstance(
self.properties["sym_name"], StringAttr
):
printer.print(f" @{self.properties['sym_name'].data}")
if self.sym_name is not None:
printer.print(f" @{self.sym_name.data}")

Copy link
Member

@superlopuh superlopuh left a comment

Choose a reason for hiding this comment

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

Thank you!

@superlopuh
Copy link
Member

I meant to use the assembly_format, but there's currently a circular dependency of the assembly format parser on builtin dialect so let's not go there.

@superlopuh superlopuh changed the title core: Parse @ module names dialecgts: (builtin) Parse @ module names Dec 24, 2024
@superlopuh superlopuh added dialects Changes on the dialects and removed core xDSL core (ir, textual format, ...) labels Dec 24, 2024
@mamanain mamanain changed the title dialecgts: (builtin) Parse @ module names dialects: (builtin) Parse @ module names Dec 24, 2024
@mamanain mamanain merged commit 6411225 into xdslproject:main Dec 24, 2024
16 checks passed
@mamanain mamanain deleted the manainen/module-name-pretty branch December 24, 2024 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dialects Changes on the dialects
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants