pytorch/torch/csrc/jit/function.cpp
Michael Suo 3b2844eeea Make CompilationUnit own Functions (#22202)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/22202
ghimport-source-id: de6c963af1df76d2d6357155e64a5913ab879f76

Test Plan: Imported from OSS

Differential Revision: D15998761

Pulled By: suo

fbshipit-source-id: 5414a6424953738d823b265d20dc67dde6e5b2d8
2019-07-04 17:12:00 -07:00

32 lines
895 B
C++

#include <torch/csrc/jit/function.h>
#include <torch/csrc/jit/script/error_report.h>
namespace torch {
namespace jit {
struct RecursiveMethodCallError : public std::exception {};
void placeholderCreator(Function&) {
throw RecursiveMethodCallError();
}
void Function::ensure_defined() {
try {
if (function_creator_) {
auto creator = function_creator_;
function_creator_ = placeholderCreator;
creator(*this);
function_creator_ = nullptr;
}
} catch (RecursiveMethodCallError&) {
throw script::ErrorReport() // TODO: once lower_first_class methods is
// removed re-establish callsite info for
// debugging
<< " method '" << name() << "' is called recursively. "
<< "Recursive calls are not supported";
}
check_single_output();
}
} // namespace jit
} // namespace torch