-
Notifications
You must be signed in to change notification settings - Fork 72
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
dialects: (builtin) make DenseIntOrFPElementsAttr generic on element type #3492
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## alexarice/dense-typed-simple #3492 +/- ##
=============================================================
Coverage 90.34% 90.34%
=============================================================
Files 464 464
Lines 58048 58060 +12
Branches 5549 5549
=============================================================
+ Hits 52442 52453 +11
Misses 4179 4179
- Partials 1427 1428 +1 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
It would be good to get any opinions on this. I'm tempted to see what the non-generic version would look like |
AnyDenseElement: TypeAlias = IntegerType | IndexType | AnyFloat | ||
DenseElementT = TypeVar("DenseElementT", bound=AnyDenseElement, covariant=True) | ||
_DenseElementT = TypeVar("_DenseElementT", bound=AnyDenseElement) |
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 this the equivalent of sized in MLIR? Would it make sense to add this independently of the other changes?
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 doubt it is as IndexType
is not sized right? (Also IndexType
should be forbidden from DenseIntOrFPElementsAttr
but that's another matter)
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 it's quite relevant, and we should forbid it indeed, I thought we already made that change recently.
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.
Ah it was DenseArrayBase #3258
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 in any case that should be a different PR (which could happen before or after this one)
printer.print_string(">") | ||
|
||
|
||
DenseIntElementsAttr: TypeAlias = DenseIntOrFPElementsAttr[IntegerType] |
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 line feels like it could have its own PR, we could probably have a custom constraint to start with to minimise the diff
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 still feel like this could be its own 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.
You want a separate PR just for the type alias?
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.
Yeah that was the idea, it technically is its own API surface change and seems to be a large contribution to this PR's diff, independent of the other changes.
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 don't see how it makes any impact on the diff at all. Anything that is changed to a DenseIntElementAttr would have had to be changed to a DenseIntOrFPElementsAttr[IntegerType]
or at least DenseIntOrFPElementsAttr[AnyDenseElement]
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.
Sorry that's what I mean, this change in the diff of this PR could already be done in main directly, and is not dependent on the changes you make here. Or am I misunderstanding?
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 don't see how to separate the changes. I can't change DenseIntOrFPElementsAttr
to DenseIntOrFPElementsAttr[AnyDenseElement]
before this PR.
I could potentially do two steps of changing every DenseIntOrFPElementsAttr
to DenseIntOrFPElementsAttr[AnyDenseElement]
and then do a second PR specialising some of these to DenseIntElementsAttr
= DenseIntOrFPElementsAttr[IntegerType]
, but I don't think the first diff will be any smaller.
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.
Ah sorry that's not what I meant, I meant something like
DenseIntElementsAttr: TypeAlias = DenseIntOrFPElementsAttr[IntegerType] | |
DenseIntElementsAttr: TypeAlias = Annotated[DenseIntOrFPElementsAttr, ParametrizedAttrConstraint(Attribute, (BaseAttr(IntegerType),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.
Ah I get it now, I could give that a go
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 like this overall, and agree that it doesn't necessarily make sense to restrict the type to have the generic parameter. It would be nice to minimise the big diff, if possible, as somme of the changes seem like more obvious improvements than others
I think the first step is to make |
Yep that also crossed my mind, not sure whether there is a single best first step but it would be nice to have a smaller diff for sure. |
I'll split that out and see what it looks like |
2b2c93b
to
d468f99
Compare
d468f99
to
93a17b5
Compare
Reworked and stacked this PR. Still not 100% sure this is desirable |
@@ -85,7 +88,7 @@ def dense_int_or_fp_elements_value( | |||
attr: Attribute, | |||
type_attr: builtin.MemRefType[Any], | |||
) -> ShapedArray[Any]: | |||
assert isinstance(attr, builtin.DenseIntOrFPElementsAttr) | |||
assert isattr(attr, base(builtin.DenseIntOrFPElementsAttr[AnyDenseElement])) |
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 would rather have a AnyDenseIntOrFPElementsAttrConstr
TBH
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.
To expand on this thought, it's because base
does the type parsing every time this is called, whereas Constr caches that, and is a tiny bit more resilient to API changes in the future
Started trying to make
DenseIntOrFPElementsAttr
aTypedAttribute
.TypedAttribute
s force that thetype
parameter must appear as a type var generic. I am not sure why this is the case so it would be good to know what the original motivation for that was. To get this to go through I have disabled this check.I then ended up adding a typevar for the elements to
DenseIntOrFPElementsAttr
which caused a lot of follow on changes and I am unsure if the result is nicer than what I started with. I thinkDenseIntOrFPElementsAttr
can be made into aTypedAttribute
without this type var.I also imagine that extensive use of
isattr
is bad?