Skip to content

Commit

Permalink
TVMPODValue macro
Browse files Browse the repository at this point in the history
  • Loading branch information
nhynes committed Apr 5, 2019
1 parent 3441b95 commit 0257ddc
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 296 deletions.
1 change: 1 addition & 0 deletions rust/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "tvm-common"
version = "0.1.0"
authors = ["TVM Contributors"]
license = "Apache-2.0"
edition = "2018"

[features]
bindings = []
Expand Down
63 changes: 6 additions & 57 deletions rust/common/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,11 @@
use std::fmt;

static TYPE_CODE_STRS: [&str; 15] = [
"int",
"uint",
"float",
"handle",
"null",
"TVMType",
"TVMContext",
"ArrayHandle",
"NodeHandle",
"ModuleHandle",
"FuncHandle",
"str",
"bytes",
"NDArrayContainer",
"ExtBegin",
];

#[derive(Debug, Fail)]
#[fail(
display = "Could not downcast `{}` into `{}`",
expected_type, actual_type
)]
pub struct ValueDowncastError {
actual_type_code: i64,
expected_type_code: i64,
}

impl ValueDowncastError {
pub fn new(actual_type_code: i64, expected_type_code: i64) -> Self {
Self {
actual_type_code,
expected_type_code,
}
}
}

impl fmt::Display for ValueDowncastError {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(
formatter,
"Could not downcast TVMValue: expected `{}` but was {}",
TYPE_CODE_STRS[self.actual_type_code as usize],
TYPE_CODE_STRS[self.expected_type_code as usize]
)
}
pub actual_type: String,
pub expected_type: &'static str,
}

#[derive(Debug, Fail)]
Expand All @@ -62,18 +26,3 @@ impl FuncCallError {
}
}
}

// error_chain! {
// errors {
// TryFromTVMRetValueError(expected_type: String, actual_type_code: i64) {
// description("mismatched types while downcasting TVMRetValue")
// display("invalid downcast: expected `{}` but was `{}`",
// expected_type, type_code_to_string(actual_type_code))
// }
// }
// foreign_links {
// IntoString(std::ffi::IntoStringError);
// ParseInt(std::num::ParseIntError);
// Utf8(std::str::Utf8Error);
// }
// }
2 changes: 1 addition & 1 deletion rust/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This crate contains the refactored basic components required
//! for `runtime` and `frontend` TVM crates.
#![feature(box_syntax, trait_alias)]
#![feature(box_syntax, type_alias_enum_variants, trait_alias)]

#[macro_use]
extern crate failure;
Expand Down
Loading

0 comments on commit 0257ddc

Please sign in to comment.