pytorch/torch/csrc/jit/function.cpp
Michael Suo cab3e726df Split out Function into its own file (#21539)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/21539
ghimport-source-id: f1e4396a0bec6e30d3179f926ec4da68807942f7

Differential Revision: D15741979

Pulled By: suo

fbshipit-source-id: 4cd0ed36bcbf8db0b36a101dda6f58975f806889
2019-06-10 16:37:58 -07:00

31 lines
894 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