From 5f1ae26f106ea72ddaf940e525f198eb2d592a4b Mon Sep 17 00:00:00 2001 From: Tianqi Chen Date: Tue, 29 Jun 2021 17:54:04 -0400 Subject: [PATCH] [TIR] Tighten up invariance of CopyOnWrite in recursive stmt visitor (#8358) --- include/tvm/tir/stmt_functor.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/tvm/tir/stmt_functor.h b/include/tvm/tir/stmt_functor.h index a6681f0b9941..24773a5a471f 100644 --- a/include/tvm/tir/stmt_functor.h +++ b/include/tvm/tir/stmt_functor.h @@ -209,6 +209,12 @@ class TVM_DLL StmtMutator : protected StmtFunctor { */ template ObjectPtr CopyOnWrite(const TNode* node) { + static_assert(std::is_base_of::value, + "StmtMutator:: CopyOnWrite requires us to track uniqueness of all parent " + "nodes during the recursion. Because the child classes do not necessarily " + "check the Array, Expr and other structures during the visit, it is only safe to " + "call this function with StmtNodes for now. " + "Please create a new node directly in other cases."); if (allow_copy_on_write_) { // return the old node. return runtime::GetObjectPtr(const_cast(node));