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: add functional-type directive #3517

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

alexarice
Copy link
Collaborator

Adds the functional-type directive, which takes two typeable directives as input.

The key difficulty here was dealing with the results, which are usually surrounded by parentheses but don't have to be if there is exactly one result.

Still a draft as this needs more tests, also stacked on #3516.

@alexarice alexarice added the core xDSL core (ir, textual format, ...) label Nov 25, 2024
@alexarice alexarice self-assigned this Nov 25, 2024
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.

Very very nice

Copy link

codecov bot commented Nov 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.39%. Comparing base (3d23c8f) to head (4b191bb).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3517      +/-   ##
==========================================
+ Coverage   90.38%   90.39%   +0.01%     
==========================================
  Files         466      466              
  Lines       58583    58709     +126     
  Branches     5585     5592       +7     
==========================================
+ Hits        52948    53068     +120     
+ Misses       4206     4205       -1     
- Partials     1429     1436       +7     

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

Base automatically changed from alexarice/assembly-parse-type to main November 27, 2024 10:41
@alexarice alexarice force-pushed the alexarice/functional-type-directive branch from c8bc6f7 to 940bc1a Compare November 27, 2024 11:23
@alexarice alexarice marked this pull request as ready for review November 27, 2024 11:35
@alexarice
Copy link
Collaborator Author

I've added an extra test to this. This also has given a way to actually trigger parse_single_type on the operands and results directives, which has revealed that they weren't quite implemented correctly. They now use the same assignment function as their many valued counterparts to be more robust.

Comment on lines +663 to +672
pos_start = parser.pos
if s := self._set_using_variadic_index(
state.operand_types, "operand types", (parser.parse_type(),)
):
parser.raise_error(s, at_position=pos_start, end_position=parser.pos)
Copy link
Member

Choose a reason for hiding this comment

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

should these then be in a separate PR? With a separate test to demonstrate the impact of the change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe, though I'm not quite sure how to test them, as the functional-type directive is the only thing that actually uses these functions

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have an idea, will cook something up

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Now separated

@alexarice alexarice force-pushed the alexarice/functional-type-directive branch from 83b2fa4 to aa4e259 Compare December 2, 2024 12:14
@alexarice
Copy link
Collaborator Author

I've stacked this on #3553 , separating out the changes mentioned in the comment above

@alexarice alexarice changed the base branch from main to alexarice/parse-single-type-fix December 2, 2024 12:14
alexarice added a commit that referenced this pull request Dec 2, 2024
Reworks the way 'parse_single_type' works for operands/results
directives, reusing the infrastructure introduced for
'parse_many_types'. This now allows 'parse_single_type' to work when
there are variadic operands, as demonstrated by the new tests.

The new tests manually make a `FormatProgram`, as the format program
parser will never generate such a program.

This currently makes no difference, as these functions are never called,
but it will be important for the functional-type directive (#3517), as
it allows a type like:
```mlir
(i32, i32) -> i32
```
to be parsed, even if the results of the operation is a variadic (the
functional type directive calls 'parse_single_type' when the results are
not wrapped in parentheses).
Base automatically changed from alexarice/parse-single-type-fix to main December 2, 2024 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core xDSL core (ir, textual format, ...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants