Skip to content

Conversation

@Lunderberg
Copy link
Contributor

@Lunderberg Lunderberg commented Jul 1, 2024

Prior to this commit, the TVM_DEFINE_OBJECT_REF_COW_METHOD could be used in any ObjectRef subclass to provide a CopyOnWrite method. However, the implementation of this method method was invalid if the object's ContainerType could itself be subclassed. In that case, using obj.CopyOnWrite() when the object contains a subclass, and when a copy is required, would silently convert obj to instead contain a base class.

This commit adds a static_assert, to the TVM_DEFINE_OBJECT_REF_COW_METHOD macro, preventing the macro from being used in classes that would have incorrect usage.

Compilation with this change found two classes, relax::Var and relax::BindingBlock, that were susceptible to this error, and the macro has been removed from these classes. For backwards-compatibility, the CopyOnWrite function for these two classes is provided explicitly.

Prior to this commit, the `TVM_DEFINE_OBJECT_REF_COW_METHOD` could be
used in any `ObjectRef` subclass to provide a `CopyOnWrite` method.
However, the implementation of this method method was invalid if the
object's `ContainerType` could itself be subclassed.  In that case,
using `obj.CopyOnWrite()` when the object contains a subclass, and
when a copy is required, would silently convert `obj` to instead
contain a base class.

This commit adds a `static_assert`, to the
`TVM_DEFINE_OBJECT_REF_COW_METHOD` macro, preventing the macro from being
used in classes that would have incorrect usage.

Compilation with this change found two classes, `relax::Var` and
`relax::BindingBlock` that were susceptible to this error, and the macro
has been removed from these classes.  For backwards-compatibility, the
`CopyOnWrite` function for these two classes is provided explicitly.
@Lunderberg Lunderberg requested a review from tqchen July 1, 2024 19:32
@tqchen tqchen merged commit 0df4103 into apache:main Jul 2, 2024
@Lunderberg Lunderberg deleted the bugfix_copy_on_write_requires_final branch July 3, 2024 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants