Skip to content

Commit 79c4f83

Browse files
davidriazatifacebook-github-bot
authored andcommitted
Include module names in recursive error stacks (#22921)
Summary: Following on to #22280, this adds module names so they're included in the call stacks of an error message (e.g. so it appears as `M.forward` instead of `forward`) ](https://our.intern.facebook.com/intern/diff/16287925/) Pull Request resolved: #22921 Pulled By: driazati Differential Revision: D16287925 fbshipit-source-id: 6f31d72caa87ba2dc527805d36f7d62eb94c0808
1 parent 7cc029c commit 79c4f83

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

test/test_jit.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13291,9 +13291,13 @@ def forward(self, x):
1329113291
checker = FileCheck()
1329213292
checker.check("Expected a value of type 'int'")
1329313293
checker.check("return d(\"hello\")")
13294+
checker.check("\'b")
1329413295
checker.check("return c(x)")
13296+
checker.check("Submodule.forward\'")
1329513297
checker.check("return b(x)")
13298+
checker.check("M.some_method\'")
1329613299
checker.check("return y + self.submodule(y)")
13300+
checker.check("M.forward\'")
1329713301
checker.check("return self.some_method(x)")
1329813302
checker.run(str(e))
1329913303

torch/csrc/jit/script/compiler.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2972,7 +2972,12 @@ std::unique_ptr<Function> CompilationUnit::define(
29722972
auto creator = [def, _resolver, self](Function& method) {
29732973
// Store the function name so that it can be referenced if there is an error
29742974
// while compiling this function
2975-
ErrorReport::CallStack::push_function(def.name().name());
2975+
if (self) {
2976+
// Include the fully qualified name if this is a method
2977+
ErrorReport::CallStack::push_function(method.qualname().qualifiedName());
2978+
} else {
2979+
ErrorReport::CallStack::push_function(method.qualname().name());
2980+
}
29762981
to_ir(def, _resolver, self, method);
29772982
// Compilation was successful, so remove the function def info
29782983
ErrorReport::CallStack::pop_function();

0 commit comments

Comments
 (0)