DiagnosticError when execute optimization

Hello everyone, I come across a crash when optimizing a simple computational graph.

In this script, InferType is executed twice. Each time is for the newly added function, and each function also has its type annotation. However, after making a fold constant, these type of information is lost. As a result, this error is reported because the main function cannot read the type information of the F function in the second fold constant。

I’m at a loss about this crash.

import tvm
from tvm import relay
mod = tvm.IRModule()
c = relay.const(1, dtype="float32")
f = relay.Function([], c)
mod['f'] = f
mod = relay.transform.InferType()(mod)
fc = mod.get_global_var('f')
F = relay.Function([], fc())
mod['main'] = F
mod = relay.transform.InferType()(mod)
relay.optimize(mod, target="llvm")

Traceback (most recent call last):
  File "run.py", line 12, in <module>
    relay.optimize(mod, target="llvm")
  File "/workplace/software/tvm/tvm/python/tvm/relay/build_module.py", line 565, in optimize
    mod, params = bld_mod.optimize(mod, target, params)
  File "/workplace/software/tvm/tvm/python/tvm/relay/build_module.py", line 241, in optimize
    mod = self._optimize(mod, target)
  File "/workplace/software/tvm/tvm/python/tvm/_ffi/_ctypes/packed_func.py", line 237, in __call__
    raise get_last_ffi_error()
tvm.error.DiagnosticError: Traceback (most recent call last):
  22: TVMFuncCall
  21: tvm::relay::backend::RelayBuildModule::GetFunction(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, tvm::runtime::ObjectPtr<tvm::runtime::Object> const&)::{lambda(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)#12}::operator()(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*) const
  20: tvm::relay::backend::RelayBuildModule::Optimize(tvm::IRModule, tvm::runtime::Map<tvm::Integer, tvm::Target, void, void> const&)
  19: tvm::relay::backend::RelayBuildModule::OptimizeImpl(tvm::IRModule)
  18: tvm::transform::Pass::operator()(tvm::IRModule) const
  17: tvm::transform::Pass::operator()(tvm::IRModule, tvm::transform::PassContext const&) const
  16: tvm::transform::SequentialNode::operator()(tvm::IRModule, tvm::transform::PassContext const&) const
  15: tvm::transform::Pass::operator()(tvm::IRModule, tvm::transform::PassContext const&) const
  14: tvm::relay::transform::FunctionPassNode::operator()(tvm::IRModule, tvm::transform::PassContext const&) const
  13: tvm::runtime::TVMRetValue tvm::runtime::PackedFunc::operator()<tvm::relay::Function, tvm::IRModule, tvm::transform::PassContext>(tvm::relay::Function&&, tvm::IRModule&&, tvm::transform::PassContext&&) const
  12: tvm::runtime::PackedFuncObj::Extractor<tvm::runtime::PackedFuncSubObj<tvm::runtime::TypedPackedFunc<tvm::relay::Function (tvm::relay::Function, tvm::IRModule, tvm::transform::PassContext)>::AssignTypedLambda<tvm::relay::transform::DynamicToStatic()::$_0>(tvm::relay::transform::DynamicToStatic()::$_0)::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)#1}> >::Call(tvm::runtime::PackedFuncObj const*, tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)
  11: tvm::relay::DynamicToStatic(tvm::relay::Function, tvm::IRModule)
  10: tvm::relay::DynamicToStaticMutator::PrepareInput(tvm::RelayExpr const&)
  9: tvm::transform::Pass::operator()(tvm::IRModule) const
  8: tvm::transform::Pass::operator()(tvm::IRModule, tvm::transform::PassContext const&) const
  7: tvm::relay::transform::FunctionPassNode::operator()(tvm::IRModule, tvm::transform::PassContext const&) const
  6: tvm::transform::Pass::operator()(tvm::IRModule) const
  5: tvm::transform::Pass::operator()(tvm::IRModule, tvm::transform::PassContext const&) const
  4: tvm::transform::ModulePassNode::operator()(tvm::IRModule, tvm::transform::PassContext const&) const
  3: tvm::runtime::TVMRetValue tvm::runtime::PackedFunc::operator()<tvm::IRModule, tvm::transform::PassContext>(tvm::IRModule&&, tvm::transform::PassContext&&) const
  2: _ZN3tvm7runtime13PackedFuncObj9ExtractorINS0
  1: tvm::runtime::TypedPackedFunc<tvm::IRModule (tvm::IRModule, tvm::transform::PassContext)>::AssignTypedLambda<tvm::relay::transform::InferType()::$_2>(tvm::relay::transform::InferType()::$_2)::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)#1}::operator()(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*) const
  0: tvm::DiagnosticContext::Render()
  File "/workplace/software/tvm/tvm/src/ir/diagnostic.cc", line 105
DiagnosticError: one or more error diagnostics were emitted, please check diagnostic render for output.