Skip to content

Commit 3360a23

Browse files
[mlir][SparseTensor] Fix type conversion rule (#140350)
A type conversion rule cannot make any assumptions about the number of pre-existing types in the `results` vector. This commit fixes a failed assertion in a SparseTensor type conversion rule. This is only reproducible when type conversion caching is deactivated. There's no way to do this at the moment. This commit is in preparation of adding context-aware type conversions, which will deactivate type caching in such cases.
1 parent 751e6c0 commit 3360a23

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

mlir/lib/Dialect/SparseTensor/Transforms/Utils/SparseTensorDescriptor.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ convertSparseTensorType(RankedTensorType rtp, SmallVectorImpl<Type> &fields) {
3838
if (!stt.hasEncoding())
3939
return std::nullopt;
4040

41+
unsigned numFields = fields.size();
4142
foreachFieldAndTypeInSparseTensor(
4243
stt,
43-
[&fields](Type fieldType, FieldIndex fieldIdx,
44-
SparseTensorFieldKind /*fieldKind*/, Level /*lvl*/,
45-
LevelType /*lt*/) -> bool {
46-
assert(fieldIdx == fields.size());
44+
[&](Type fieldType, FieldIndex fieldIdx,
45+
SparseTensorFieldKind /*fieldKind*/, Level /*lvl*/,
46+
LevelType /*lt*/) -> bool {
47+
assert(numFields + fieldIdx == fields.size());
4748
fields.push_back(fieldType);
4849
return true;
4950
});

0 commit comments

Comments
 (0)