| 101 | } |
| 102 | |
| 103 | void ModuleObj::ImportModule(const Module& other) { |
| 104 | std::unordered_set<const ModuleObj*> visited{other.operator->()}; |
| 105 | std::vector<const ModuleObj*> stack{other.operator->()}; |
| 106 | while (!stack.empty()) { |
| 107 | const ModuleObj* n = stack.back(); |
| 108 | stack.pop_back(); |
| 109 | for (const Any& m : n->imports_) { |
| 110 | const ModuleObj* next = m.cast<const ModuleObj*>(); |
| 111 | if (visited.count(next)) continue; |
| 112 | visited.insert(next); |
| 113 | stack.push_back(next); |
| 114 | } |
| 115 | } |
| 116 | if (visited.count(this)) { |
| 117 | TVM_FFI_THROW(RuntimeError) << "Cyclic dependency detected during import"; |
| 118 | } |
| 119 | imports_.push_back(other); |
| 120 | } |
| 121 | |
| 122 | void ModuleObj::ClearImports() { imports_.clear(); } |
| 123 | |