From 4fc9dfc8b010f343ca0498ef053dbc0c6ad439e7 Mon Sep 17 00:00:00 2001 From: Eric Lunderberg Date: Mon, 11 Dec 2023 17:07:37 +0000 Subject: [PATCH] [Unity] Improved error message in ExprMutator::ReEmitBinding 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; }