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

api: constr helpers for generic attributes now mostly static methods #3287

Merged
merged 5 commits into from
Oct 22, 2024

Conversation

superlopuh
Copy link
Member

No description provided.

@superlopuh superlopuh added the API Related to changes regarding API of constructs label Oct 10, 2024
@superlopuh superlopuh requested a review from math-fehr October 10, 2024 23:04
@superlopuh superlopuh self-assigned this Oct 10, 2024
Copy link

codecov bot commented Oct 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.04%. Comparing base (a6ed00e) to head (497e197).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3287      +/-   ##
==========================================
- Coverage   90.04%   90.04%   -0.01%     
==========================================
  Files         446      446              
  Lines       56239    56248       +9     
  Branches     5403     5404       +1     
==========================================
+ Hits        50639    50647       +8     
- Misses       4177     4178       +1     
  Partials     1423     1423              

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

@superlopuh superlopuh force-pushed the sasha/misc/static-constr branch from 20cba66 to 9a30300 Compare October 11, 2024 08:31
@superlopuh superlopuh marked this pull request as ready for review October 11, 2024 08:31
Copy link
Collaborator

@alexarice alexarice left a comment

Choose a reason for hiding this comment

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

I think I'd personally prefer these as @staticmethod, as it couples them more to their class and there is possibly an option of providing a default implementation in non generic cases, but this is a good improvement on what is there currently.

tests/tblgen_to_py/test_tblgen.py Outdated Show resolved Hide resolved
xdsl/dialects/builtin.py Outdated Show resolved Hide resolved
BaseAttr[StencilType[Attribute]]
| ParamAttrConstraint[StencilType[_FieldTypeElement]]
):
if bounds is None and element_type == AnyAttr():
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not specific to here, but what's the benefit to using BaseAttr over a ParamAttrConstraint?

Copy link
Member Author

Choose a reason for hiding this comment

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

Perf

xdsl/dialects/stencil.py Outdated Show resolved Hide resolved
@superlopuh superlopuh changed the title api: constr helpers for generic attributes now standalone functions api: constr helpers for generic attributes now mostly static methods Oct 14, 2024
@superlopuh
Copy link
Member Author

@math-fehr @alexarice I tried a different approach, which is not to reuse the type parameter on the class definition, seems to work quite well. The only exception is the stencil case, where they actually use type hierarchies, so that bit of the codebase can be a bit more verbose. WDYT?

Copy link
Collaborator

@alexarice alexarice left a comment

Choose a reason for hiding this comment

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

This looks nice to me, I can't see the stencil stuff you were talking about though

int_attr = prop_def(
IntegerAttr[IntegerType].constr(type=EqAttrConstraint(IntegerType(16)))
)
int_attr = prop_def(IntegerAttr.constr(type=EqAttrConstraint(IntegerType(16))))
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you wanted to simplify syntax further, you could allow this to take an attribute to be coerced into a Constraint

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'd rather not go down that route, but it can be done in a different PR

@@ -1710,23 +1710,22 @@ class ParamOne(ParametrizedAttribute, TypeAttribute, Generic[_T]):
name = "test.param_one"
p: ParameterDef[_T]

@classmethod
@staticmethod
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this looks good, much closer to what I imagined

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there any hope to have all ParametrisedAttributes define this? perhaps with a method defined in @irdl_attr_definition? (Perhaps not as this PR)

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 have a few ideas of where I would start looking for this, and no time in the foreseeable future to actually look into it :(

@superlopuh superlopuh merged commit 8522415 into main Oct 22, 2024
14 checks passed
@superlopuh superlopuh deleted the sasha/misc/static-constr branch October 22, 2024 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Related to changes regarding API of constructs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants