This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Make ShapedTypeComponents contructible from ShapeAdaptor
ClosedPublic

Authored by Chia-hungDuan on Mar 2 2022, 1:35 PM.

Details

Summary

ValueShapeRange::getShape() returns ShapeAdaptor rather than ShapedType
and ShapeAdaptor allows implicit conversion to bool. It ends up that
ShapedTypeComponents can be constructed with ShapeAdaptor incorrectly.
The reason is that the type trait

std::is_constructible<ShapeStorageT, Arg>::value

is fulfilled because ShapeAdaptor can be converted to bool and it can be
used to construct ShapeStorageT. In the end, we won't give any warning
or error message when doing things like

inferredReturnShapes.emplace_back(valueShapeRange.getShape(0));

Diff Detail

Event Timeline

Chia-hungDuan created this revision.Mar 2 2022, 1:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2022, 1:35 PM
Chia-hungDuan requested review of this revision.Mar 2 2022, 1:35 PM

@jpienaar, this is more like a RFC CL, The target is that I want to avoid certain unexpected thing mentioned in the commit message.

jpienaar added inline comments.Mar 2 2022, 3:58 PM
mlir/include/mlir/Interfaces/InferTypeOpInterface.h
30–31

Could you show this without the move? (It's difficult to see the changes vs NFC parts)

81

What happens if we make this explicit operator?

Chia-hungDuan added inline comments.Mar 2 2022, 9:01 PM
mlir/include/mlir/Interfaces/InferTypeOpInterface.h
30–31

Sorry about that. I need to declare the ShapeAdaptor first.

I've highlighted the diff down below.

81

That will give the error.
I'm thinking it would be useful to have ShapedTypeComponent constructed with ShapeAdaptor.
How about we do both? add explicit and construct with ShapeAdaptor?

116–121

Highlight the diff part

Added explicit only.

jpienaar accepted this revision.Mar 8 2022, 9:39 AM

LGTM, thanks

This revision is now accepted and ready to land.Mar 8 2022, 9:39 AM

Rebase and check if the build is still broken