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

xdsl: DictionaryAttr for the builtin dialect #258

Merged
merged 8 commits into from Jan 10, 2023
Merged

Conversation

mesham
Copy link
Contributor

@mesham mesham commented Dec 7, 2022

Provides the DictionaryAttr for the builtin dialect which is required for FIR dialect

@codecov
Copy link

codecov bot commented Dec 7, 2022

Codecov Report

Base: 89.35% // Head: 89.20% // Decreases project coverage by -0.15% ⚠️

Coverage data is based on head (c324b84) compared to base (4d3491f).
Patch coverage: 76.53% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #258      +/-   ##
==========================================
- Coverage   89.35%   89.20%   -0.16%     
==========================================
  Files          49       49              
  Lines        6672     6770      +98     
  Branches     1118     1136      +18     
==========================================
+ Hits         5962     6039      +77     
- Misses        482      495      +13     
- Partials      228      236       +8     
Impacted Files Coverage Δ
xdsl/dialects/builtin.py 81.44% <57.89%> (-2.22%) ⬇️
xdsl/parser.py 83.49% <76.66%> (-0.01%) ⬇️
tests/test_parser.py 100.00% <100.00%> (ø)
tests/test_printer.py 98.07% <100.00%> (+0.07%) ⬆️
xdsl/printer.py 95.71% <100.00%> (+0.12%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@mesham mesham marked this pull request as ready for review December 7, 2022 15:06
@mesham mesham requested a review from math-fehr December 7, 2022 15:06
@georgebisbas georgebisbas added the xdsl xdsl framework specific changes label Dec 7, 2022
@georgebisbas georgebisbas changed the title DictionaryAttr for the builtin dialect xdsl: DictionaryAttr for the builtin dialect Dec 7, 2022
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.

I added some comments, but this is a good direction!

tests/test_printer.py Show resolved Hide resolved
@staticmethod
def parse_parameter(parser: Parser) -> dict[_DictionaryAttrT]:
parser.parse_char("{")
data = parser.parse_list(parser.parse_optional_attribute)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add the tests for this parsing/printing method?
Here, this should be parse_dictionary instead of parse_list, so this needs to be changed.

printer.print_string("}")

@staticmethod
def generic_constraint_coercion(args: tuple[Any]) -> AttrConstraint:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here, we either need to add the correct coercion, or raise an exception.
You can see how to do this by looking at how ArrayAttr is doing it.

f"Wrong type given to attribute {self.name}: got"
f" {type(self.data)}, but expected dictionary of"
" attributes")
for idx, val in enumerate(self.data):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here, you should check that both the types of the keys and the values.
Thus, you should use self.data.items() instead of enumerate(...)



@irdl_attr_definition
class DictionaryAttr(GenericData[dict[_DictionaryAttrT]]):
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about the key types?
I think you want this to be a dict[str, _DictionaryAttrT] instead.

xdsl/parser.py Outdated
def parse_dict_entry(self, parse_optional_one: Callable[[], T | None]):
# Limitation currently is that the key is a string
key = self.parse_str_literal()
if key is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

key should never be None here.

xdsl/parser.py Outdated
res = res | entry
return res

def parse_dict_entry(self, parse_optional_one: Callable[[], T | None]):
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 add the return type to the function?

@@ -460,6 +460,35 @@ def parse_list(self,
res.append(one)
return res

def parse_dictionary(self,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we reuse the code that we are currently using to parse the dictionary attribute?

@@ -122,6 +123,17 @@ def print_list(self,
self.print(delimiter)
print_fn(elem)

def print_dictionary(self,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, can we reuse the code we already have for the attribute dictionary in operations?

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.

Nice! Thanks!

@math-fehr math-fehr merged commit 546fda5 into main Jan 10, 2023
@math-fehr math-fehr deleted the dictionaryattr branch January 10, 2023 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
xdsl xdsl framework specific changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants