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

[Utility][Container] Support non-nullable types in Array::Map #17094

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions include/tvm/runtime/container/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -827,8 +827,13 @@ class Array : public ObjectRef {
// consisting of any previous elements that had mapped to
// themselves (if any), and the element that didn't map to
// itself.
//
// We cannot use `U()` as the default object, as `U` may be
// a non-nullable type. Since the default `ObjectRef()`
// will be overwritten before returning, all objects will be
// of type `U` for the calling scope.
all_identical = false;
output = ArrayNode::CreateRepeated(arr->size(), U());
output = ArrayNode::CreateRepeated(arr->size(), ObjectRef());
output->InitRange(0, arr->begin(), it);
output->SetItem(it - arr->begin(), std::move(mapped));
it++;
Expand All @@ -843,7 +848,12 @@ class Array : public ObjectRef {
// compatible types isn't strictly necessary, as the first
// mapped.same_as(*it) would return false, but we might as well
// avoid it altogether.
output = ArrayNode::CreateRepeated(arr->size(), U());
//
// We cannot use `U()` as the default object, as `U` may be a
// non-nullable type. Since the default `ObjectRef()` will be
// overwritten before returning, all objects will be of type `U`
// for the calling scope.
output = ArrayNode::CreateRepeated(arr->size(), ObjectRef());
}

// Normal path for incompatible types, or post-copy path for
Expand Down
Loading