From b22aa0f7c74a7f0a11461fd19b2bb82893780f25 Mon Sep 17 00:00:00 2001 From: Eric Lunderberg Date: Mon, 8 Jan 2024 16:05:53 -0600 Subject: [PATCH] [Unity] Improved error message in ExprMutator::ReEmitBinding (#16307) Prior to this commit, an error message would occur in `ExprMutator::ReEmitBinding` if the struct info is missing from the generated value. However, because this error was generated from inside `GetStructInfo`, it didn't include sufficient context for debugging. This commit checks the struct info explicitly, and includes the context of the updated variable in the error message. --- src/relax/ir/expr_functor.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/relax/ir/expr_functor.cc b/src/relax/ir/expr_functor.cc index 14a704d729e3..26ce952626ef 100644 --- a/src/relax/ir/expr_functor.cc +++ b/src/relax/ir/expr_functor.cc @@ -670,7 +670,15 @@ void ExprMutator::ReEmitBinding(const VarBindingNode* binding, Expr new_value) { return; } - Var temp = WithStructInfo(new_var, GetStructInfo(new_value)); + auto new_sinfo = new_value->struct_info_.as(); + + ICHECK(new_sinfo) + << "InternalError: " + << "In binding of variable " << binding->var << ", the value " << new_value + << " does not have StructInfo. " + << "This typically occurs when ReEmitBinding is called without first calling Normalize."; + + Var temp = WithStructInfo(new_var, new_sinfo.value()); if (!temp.same_as(new_var)) { new_var = temp; }