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: refactor assembly format directives #3501

Merged
merged 2 commits into from
Nov 22, 2024

Conversation

alexarice
Copy link
Collaborator

Refactors the assembly format directives to:

  • Remove some unnecessary classes that made the system rigid
  • Separate directives that go in a type clause from format directives
    This will make it easier to add operands, results, and functional-type directives.

@alexarice alexarice self-assigned this Nov 21, 2024
@alexarice alexarice added the core xDSL core (ir, textual format, ...) label Nov 21, 2024
Copy link

codecov bot commented Nov 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.34%. Comparing base (5603904) to head (03cbad6).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3501      +/-   ##
==========================================
+ Coverage   90.32%   90.34%   +0.02%     
==========================================
  Files         464      464              
  Lines       58043    58047       +4     
  Branches     5557     5550       -7     
==========================================
+ Hits        52427    52443      +16     
+ Misses       4188     4177      -11     
+ Partials     1428     1427       -1     

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


🚨 Try these New Features:

pass
class VariadicVariable(VariableDirective, AnchorableDirective, ABC):
def is_present(self, op: IRDLOperation) -> bool:
return len(getattr(op, self.name)) > 0
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
return len(getattr(op, self.name)) > 0
return bool(getattr(op, self.name))

Copy link
Member

Choose a reason for hiding this comment

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

but then again I wonder whether we should be going via the def instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We have the index of the variable so should be able to do op.operands[self.index]. This should be more type safe too. Should I work that into this PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You couldn't do the above without more refactoring as VariadicVariable doesn't know which type of variable it is

Copy link
Member

Choose a reason for hiding this comment

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

Ah too bad, although maybe that would also be worth fixing? I'm happy to punt this side quest until someone stumbles upon it and feels motivated

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FWIW this is moved code rather than new code (I don't really see this as an excuse though)

Co-authored-by: Sasha Lopoukhine <superlopuh@gmail.com>
"A variadic region variable cannot be followed by another variadic region variable."
)
case AttrDictDirective(), RegionDirective() if not (a.with_keyword):
case VariadicOperandDirective(), VariadicOperandDirective():
Copy link
Member

Choose a reason for hiding this comment

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

seems off

Copy link
Member

Choose a reason for hiding this comment

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

ah no my bad the diff wasn't showing the input, looks good

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.

LGTM!

self.raise_error(
"An `attr-dict' directive without keyword cannot be directly followed by a region variable as it is ambiguous."
"A variadic operand variable cannot be followed by another variadic operand variable."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Glad you've cleaned this up a bit.

@alexarice alexarice merged commit 8d8feaf into main Nov 22, 2024
15 checks passed
@alexarice alexarice deleted the alexarice/simplify-directives branch November 22, 2024 11:42
EdmundGoodman pushed a commit to EdmundGoodman/xdsl that referenced this pull request Dec 6, 2024
Refactors the assembly format directives to:
- Remove some unnecessary classes that made the system rigid
- Separate directives that go in a `type` clause from format directives
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.

3 participants