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) fix true/false printing #3555

Merged
merged 3 commits into from
Dec 2, 2024
Merged

Conversation

superlopuh
Copy link
Member

We currently don't consistently print true and false for i1 values, this PR fixes that in the cases I could find.

@superlopuh superlopuh added bug Something isn't working dialects Changes on the dialects labels Dec 2, 2024
@superlopuh superlopuh self-assigned this Dec 2, 2024
Copy link

codecov bot commented Dec 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.39%. Comparing base (e9b9297) to head (b4037bc).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3555      +/-   ##
==========================================
- Coverage   90.39%   90.39%   -0.01%     
==========================================
  Files         466      466              
  Lines       58716    58722       +6     
  Branches     5592     5593       +1     
==========================================
+ Hits        53078    53083       +5     
  Misses       4204     4204              
- Partials     1434     1435       +1     

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

@@ -513,7 +528,7 @@ def parse_with_type(
return IntegerAttr(parser.parse_integer(allow_boolean=(type == i1)), type)

def print_without_type(self, printer: Printer):
return printer.print(self.value.data)
self.type.print_value_without_type(self.value.data, printer)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The polymorphism feels unnecessary to me

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you mean?

Copy link
Collaborator

@alexarice alexarice Dec 2, 2024

Choose a reason for hiding this comment

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

It feels like this could just be

if isinstance(self.type, IntegerAttr) and self.type.bitwidth == 1:
  # print bools 
  ...
else:
  printer.print_string(str(self.value.data))

Copy link
Member Author

Choose a reason for hiding this comment

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

I considered it and then felt like doing Python runtime polymorphism is cleaner, if only because we have types like DenseArrayBase, and DenseIntOrFPAttr that will soon have a type and then lots of data, and it seems a little simpler to have the functionality available on the type directly.

@superlopuh superlopuh force-pushed the sasha/builtin/0-bitwidth-ranges branch from fc16538 to bc68c4c Compare December 2, 2024 16:12
@superlopuh superlopuh force-pushed the sasha/builtin/print-i1 branch from 035fc8a to 061e87c Compare December 2, 2024 16:14
Base automatically changed from sasha/builtin/0-bitwidth-ranges to main December 2, 2024 16:55
@superlopuh superlopuh merged commit 92101f8 into main Dec 2, 2024
15 checks passed
@superlopuh superlopuh deleted the sasha/builtin/print-i1 branch December 2, 2024 17:04
EdmundGoodman pushed a commit to EdmundGoodman/xdsl that referenced this pull request Dec 6, 2024
We currently don't consistently print true and false for i1 values, this
PR fixes that in the cases I could find.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dialects Changes on the dialects
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants