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: Expose the list of dialects without using xDSLOptMain #1079

Merged
merged 3 commits into from Jun 8, 2023

Conversation

math-fehr
Copy link
Collaborator

This makes it easier for external users to get the list of existing dialects, without having to override xDSLOptMain.

@math-fehr math-fehr added the core xDSL core (ir, textual format, ...) label Jun 5, 2023
@math-fehr math-fehr requested a review from webmiche as a code owner June 5, 2023 11:30
@@ -59,6 +59,56 @@
from typing import IO, Dict, Callable, List, Sequence, Type


def get_all_dialects() -> list[Dialect]:
"""Return the list of all available dialects."""
# Please keep that list sorted alphabetically.
Copy link
Member

Choose a reason for hiding this comment

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

nit: add a test?

@codecov
Copy link

codecov bot commented Jun 5, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.02 ⚠️

Comparison is base (98f75ff) 86.92% compared to head (066bcbd) 86.90%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1079      +/-   ##
==========================================
- Coverage   86.92%   86.90%   -0.02%     
==========================================
  Files         138      138              
  Lines       20626    20600      -26     
  Branches     3115     3117       +2     
==========================================
- Hits        17929    17903      -26     
  Misses       2180     2180              
  Partials      517      517              
Impacted Files Coverage Δ
tests/xdsl_opt/test_xdsl_opt.py 98.96% <100.00%> (+0.03%) ⬆️
xdsl/xdsl_opt_main.py 96.58% <100.00%> (-0.43%) ⬇️

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



def test_dialects_and_passes():
assert len(get_all_dialects()) > 0
Copy link
Member

@superlopuh superlopuh Jun 5, 2023

Choose a reason for hiding this comment

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

sorry, I meant something like this:

Suggested change
assert len(get_all_dialects()) > 0
names = [d.__name__ for d in get_all_dialects()]
assert names == sorted(names), "Names of dialects should be in alphabetical order"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we want to enforce an invariant like that? To me, the dialects are a set of dialects, so it does not even make all that much sense to talk about order 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh no, I don't think we want to have that!
I just want it in the function definition to make it cleaner!

Copy link
Member

Choose a reason for hiding this comment

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

Why not?

Copy link
Member

Choose a reason for hiding this comment

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

It would automate this little bit of the process, I don't see the harm in it TBH

Copy link
Member

Choose a reason for hiding this comment

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

I also don't have a strong opinion, it's just that comments that say "please" in them aren't followed as closely as those that have a matching test to catch transgressors :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I would be against it to be honest.
The harm is that we are adding additional constraints on the API that we don't need, and that may change in the future. So I would prefer not introducing them in the first place.
Also, this check won't work, as dialects are object, not classes, so __name__ won't exist anyway!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I did not see the comment before, IMO, we should remove that 😅

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@webmiche, do you mean we should remove the comment about keeping them in order?
I added it only because I felt it should be sorted, both for readability and conficts.
But if this cause too much trouble I'm fine removing it

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm not sure. I would remove the comment, but I am fine with leaving it in, as long as we do not actually enforce it.



def test_dialects_and_passes():
assert len(get_all_dialects()) > 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we want to enforce an invariant like that? To me, the dialects are a set of dialects, so it does not even make all that much sense to talk about order 🤔

@math-fehr math-fehr merged commit 833c9a1 into main Jun 8, 2023
12 checks passed
@math-fehr math-fehr deleted the fehr/expose-dialect-list branch June 8, 2023 12:59
cigarichard pushed a commit to cigarichard/xdsl that referenced this pull request Jun 17, 2023
…ect#1079)

This makes it easier for external users to get the list of existing
dialects, without having to override xDSLOptMain.
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.

None yet

4 participants