-
Notifications
You must be signed in to change notification settings - Fork 80
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
20cba66
to
9a30300
Compare
There was a problem hiding this 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.
xdsl/dialects/stencil.py
Outdated
BaseAttr[StencilType[Attribute]] | ||
| ParamAttrConstraint[StencilType[_FieldTypeElement]] | ||
): | ||
if bounds is None and element_type == AnyAttr(): |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perf
…ctions" This reverts commit 9a30300.
@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? |
There was a problem hiding this 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)))) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ParametrisedAttribute
s define this? perhaps with a method defined in @irdl_attr_definition
? (Perhaps not as this PR)
There was a problem hiding this comment.
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 :(
No description provided.