You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/01/27 07:22:35 UTC

[GitHub] [tvm] junrushao1994 commented on a change in pull request #7152: [RUNTIME] Improve error messages for TypedPackedFunc

junrushao1994 commented on a change in pull request #7152:
URL: https://github.com/apache/tvm/pull/7152#discussion_r565075157



##########
File path: include/tvm/runtime/packed_func.h
##########
@@ -562,6 +597,44 @@ class TVMMovableArgValue_ : public TVMPODValue_ {
   TVMArgValue AsArgValue() const { return TVMArgValue(value_, type_code_); }
 };
 
+/*!
+ * \brief Internal auxiliary struct for TypedPackedFunc to indicate a movable argument with
+ * additional context information (function name and argument index) for better error reporting.
+ *
+ * \sa MovableArgValue_
+ * \note For internal development purpose only.
+ */
+class TVMMovableArgValueWithContext_ {
+ public:
+  /*!
+   * \brief move constructor from another return value.
+   * \param value The other return value.
+   * \param type_code The code associated with the type of the value.
+   * \param arg_index In a function call, this argument is at index arg_index (0-indexed).
+   * \param optional_name Name of the function being called. Can be nullptr if the function is not
+   * named.
+   */
+  TVMMovableArgValueWithContext_(TVMValue value, int type_code, int arg_index,
+                                 const std::string* optional_name)
+      : value_(value, type_code), arg_index_(arg_index), optional_name_(optional_name) {}
+
+  template <typename T>
+  operator T() const {
+    try {
+      return value_;  // implicit conversion happens here
+    } catch (dmlc::Error& e) {
+      LOG(FATAL) << "In function " << (optional_name_ == nullptr ? "<anonymous>" : *optional_name_)
+                 << ": error while converting argument " << arg_index_ << ": " << e.what();
+      throw "";  // never reached, LOG(FATAL) throws, but this silences a warning.

Review comment:
       Looks like we don't have to throw anything haha
   
   ```suggestion
         throw;  // never reached, LOG(FATAL) throws, but this silences a warning.
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org