You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by jr...@apache.org on 2020/11/06 02:11:35 UTC

[incubator-tvm] 11/21: Fix

This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 4261461974f2fb548d6b48e19fab07d34dd03a51
Author: Jared Roesch <ro...@gmail.com>
AuthorDate: Fri Oct 16 02:11:53 2020 -0700

    Fix
---
 rust/tvm/src/ir/module.rs | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/rust/tvm/src/ir/module.rs b/rust/tvm/src/ir/module.rs
index 5156e74..11d6c49 100644
--- a/rust/tvm/src/ir/module.rs
+++ b/rust/tvm/src/ir/module.rs
@@ -16,6 +16,11 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+use std::io::Result as IOResult;
+use std::path::Path;
+
+use thiserror::Error;
+use tvm_macros::Object;
 
 use crate::runtime::array::Array;
 use crate::runtime::function::Result;
@@ -27,15 +32,19 @@ use super::expr::GlobalVar;
 use super::function::BaseFunc;
 use super::source_map::SourceMap;
 
-use std::io::Result as IOResult;
-use std::path::Path;
-
-use tvm_macros::Object;
 
 // TODO(@jroesch): define type
 type TypeData = ObjectRef;
 type GlobalTypeVar = ObjectRef;
 
+#[derive(Error, Debug)]
+pub enum Error {
+    #[error("{0}")]
+    IO(#[from] std::io::Error),
+    #[error("{0}")]
+    TVM(#[from] crate::runtime::Error),
+}
+
 #[repr(C)]
 #[derive(Object)]
 #[ref_name = "IRModule"]
@@ -116,19 +125,19 @@ external! {
 //     });
 
 impl IRModule {
-    pub fn parse<N, S>(file_name: N, source: S) -> IRModule
+    pub fn parse<N, S>(file_name: N, source: S) -> Result<IRModule>
     where
         N: Into<TVMString>,
         S: Into<TVMString>,
     {
-        parse_module(file_name.into(), source.into()).expect("failed to call parser")
+        parse_module(file_name.into(), source.into())
     }
 
-    pub fn parse_file<P: 'static + AsRef<Path>>(file_path: P) -> IOResult<IRModule> {
+    pub fn parse_file<P: 'static + AsRef<Path>>(file_path: P) -> std::result::Result<IRModule, Error> {
         let file_path = file_path.as_ref();
         let file_path_as_str = file_path.to_str().unwrap().to_string();
         let source = std::fs::read_to_string(file_path)?;
-        let module = IRModule::parse(file_path_as_str, source);
+        let module = IRModule::parse(file_path_as_str, source)?;
         Ok(module)
     }