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: Move MLContext out of ir, move get_all_dialects to dialects. #2749

Merged
merged 6 commits into from
Jun 19, 2024

Conversation

PapyChacal
Copy link
Collaborator

Just some refactoring to decouple a few things.

@PapyChacal PapyChacal added the core xDSL core (ir, textual format, ...) label Jun 18, 2024
@PapyChacal PapyChacal self-assigned this Jun 18, 2024
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@PapyChacal PapyChacal marked this pull request as ready for review June 18, 2024 14:14
Copy link

codecov bot commented Jun 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.77%. Comparing base (9503983) to head (5dcf83e).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2749   +/-   ##
=======================================
  Coverage   89.77%   89.77%           
=======================================
  Files         369      371    +2     
  Lines       47545    47608   +63     
  Branches     7291     7292    +1     
=======================================
+ Hits        42684    42742   +58     
- Misses       3725     3728    +3     
- Partials     1136     1138    +2     

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

Copy link
Collaborator

@AntonLydike AntonLydike left a comment

Choose a reason for hiding this comment

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

Nice to see this refactored!

Copy link
Collaborator

@AntonLydike AntonLydike left a comment

Choose a reason for hiding this comment

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

oops

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.

Really nice!
I would just have a question relative to MLContext.register_all_dialects.
To me, this is a bit weird, as we do not really want users to overload MLContext I think? Or at least this is not how I was currently seeing it, and should change my view.

But to me, having the register_all_dialects in the command line tool made sense as it was a tool that was meant to be inherited for each use case. However, for the MLContext, I don't see why we would overload this for each tool besides to add these dialects (which we can add in another way?).

But maybe I'm just missing a use case you have on this?

Otherwise, thanks a lot for moving the get_all_dialects!!!!

@@ -0,0 +1,310 @@
from collections.abc import Callable
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, I would not have thought about adding this to the __init__.py directly, but that's a really good idea!

xdsl/context.py Outdated
Comment on lines 28 to 35
def register_all_dialects(self):
"""
Register all dialects that can be used.

Add other/additional dialects by overloading this function.
"""
for dialect_name, dialect_factory in get_all_dialects().items():
self.register_dialect(dialect_name, dialect_factory)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not entirely sure that anyone should inherit MLContext, so I would drop this comment.
Which is also why I'm not sure we should add this method here? Maybe we should just have register_dialects to make this simpler and just have context.register_dialects(get_all_dialects())? Or keep what we had before.

At least, I would prefer keep this a conscious decision for the user to add all dialects or not, and for that asking them to call get_all_dialects make sense to me if that makes sense? I don't know, what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I think this gets especially weird for users of xDSL that want to add their own dialects, it seems a little cleaner to let them do their own combinations of different dialects rather than strongly encouraging inheritance in this way.

Comment on lines 729 to 743
def register_all_dialects(self):
"""
Register all dialects that can be used.

Add other/additional dialects by overloading this function.
"""
for dialect_name, dialect_factory in get_all_dialects().items():
self.ctx.register_dialect(dialect_name, dialect_factory)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would still keep this here actually, and remove it from MLContext, what do you think?
This class is supposed to be overloaded for each tool, so adding the dialects here would make sense to me. While MLContext is not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, I missed the comment stating that people should override it.

Problem is, to parse and interpret irdl dialects, I need the dependent (i.e., at least irdl?) dialexts to be available.
Our lazy loading mechanism is perfect for this, as it will only load actually needed dialects.

Now, without moving register_all_dialects, I would have to create an xDSLOptMain for this purpose, which can be wanted completely out of a tool's context.

I guess a compromise would be to keep a register_all_dialects method on xDSLOptMain, of which the default implementation is to just call MLContext's one? WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not 100% sure what the answer is to this but I would propose changing the mechanism in a different PR

@PapyChacal PapyChacal merged commit 29182e2 into main Jun 19, 2024
9 checks passed
@PapyChacal PapyChacal deleted the emilien/context branch June 19, 2024 11:58
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.

5 participants