diff --git a/src/api/mod.rs b/src/api/mod.rs index 7f128243..e9e03854 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -170,11 +170,8 @@ impl Engine { keyword: impl AsRef, precedence: u8, ) -> Result<&mut Self, String> { - let precedence = Precedence::new(precedence); - - if precedence.is_none() { - return Err("precedence cannot be zero".into()); - } + let precedence = + Precedence::new(precedence).ok_or_else(|| "precedence cannot be zero".to_string())?; let keyword = keyword.as_ref(); @@ -213,7 +210,8 @@ impl Engine { } // Add to custom keywords - self.custom_keywords.insert(keyword.into(), precedence); + self.custom_keywords + .insert(keyword.into(), Some(precedence)); Ok(self) } diff --git a/src/api/type_names.rs b/src/api/type_names.rs index 495916ed..f426154b 100644 --- a/src/api/type_names.rs +++ b/src/api/type_names.rs @@ -238,6 +238,7 @@ impl Engine { } /// Make a `Box<`[`EvalAltResult`][ERR::ErrorMismatchDataType]`>`. + #[cold] #[inline(never)] #[must_use] pub(crate) fn make_type_mismatch_err(&self, typ: &str, pos: Position) -> RhaiError { diff --git a/src/eval/cache.rs b/src/eval/cache.rs index 34a6941a..cf96dc24 100644 --- a/src/eval/cache.rs +++ b/src/eval/cache.rs @@ -79,7 +79,6 @@ impl Caches<'_> { self.stack.last_mut().unwrap() } /// Push an empty function resolution cache onto the stack and make it current. - #[allow(dead_code)] #[inline(always)] pub fn push_fn_resolution_cache(&mut self) { self.stack.push(Default::default()); diff --git a/src/func/script.rs b/src/func/script.rs index 968b2309..8309c6ba 100644 --- a/src/func/script.rs +++ b/src/func/script.rs @@ -35,6 +35,7 @@ impl Engine { pos: Position, level: usize, ) -> RhaiResult { + #[cold] #[inline(never)] fn make_error( name: String, diff --git a/src/packages/arithmetic.rs b/src/packages/arithmetic.rs index d1181889..34615564 100644 --- a/src/packages/arithmetic.rs +++ b/src/packages/arithmetic.rs @@ -9,7 +9,8 @@ use std::prelude::v1::*; #[cfg(not(feature = "no_float"))] use num_traits::Float; -#[inline] +#[cold] +#[inline(never)] pub fn make_err(msg: impl Into) -> RhaiError { ERR::ErrorArithmetic(msg.into(), Position::NONE).into() } diff --git a/src/packages/mod.rs b/src/packages/mod.rs index 8a7e1dbc..6337a0b1 100644 --- a/src/packages/mod.rs +++ b/src/packages/mod.rs @@ -120,11 +120,9 @@ pub trait Package { /// /// def_package! { /// /// My super-duper package. -/// pub MyPackage(module @ 10) { +/// pub MyPackage(module) { /// // Load a native Rust function. /// module.set_native_fn("my_add", add); -/// } |> |engine| { -/// engine.register_custom_operator("@", 160).unwrap(); /// } /// } /// ``` diff --git a/src/types/error.rs b/src/types/error.rs index 6e9814cd..d426d5ed 100644 --- a/src/types/error.rs +++ b/src/types/error.rs @@ -249,6 +249,7 @@ impl fmt::Display for EvalAltResult { } impl> From for EvalAltResult { + #[cold] #[inline(never)] fn from(err: T) -> Self { Self::ErrorRuntime(err.as_ref().to_string().into(), Position::NONE) @@ -256,6 +257,7 @@ impl> From for EvalAltResult { } impl> From for Box { + #[cold] #[inline(never)] fn from(err: T) -> Self { EvalAltResult::ErrorRuntime(err.as_ref().to_string().into(), Position::NONE).into() @@ -266,6 +268,8 @@ impl EvalAltResult { /// Is this a pseudo error? A pseudo error is one that does not occur naturally. /// /// [`LoopBreak`][EvalAltResult::LoopBreak] and [`Return`][EvalAltResult::Return] are pseudo errors. + #[cold] + #[inline(never)] #[must_use] pub const fn is_pseudo_error(&self) -> bool { match self { @@ -274,6 +278,8 @@ impl EvalAltResult { } } /// Can this error be caught? + #[cold] + #[inline(never)] #[must_use] pub const fn is_catchable(&self) -> bool { match self { @@ -319,6 +325,8 @@ impl EvalAltResult { } } /// Is this error a system exception? + #[cold] + #[inline(never)] #[must_use] pub const fn is_system_exception(&self) -> bool { match self { @@ -338,6 +346,8 @@ impl EvalAltResult { } /// Get the [position][Position] of this error. #[cfg(not(feature = "no_object"))] + #[cold] + #[inline(never)] pub(crate) fn dump_fields(&self, map: &mut crate::Map) { map.insert( "error".into(), @@ -419,6 +429,8 @@ impl EvalAltResult { }; } /// Unwrap this error and get the very base error. + #[cold] + #[inline(never)] #[must_use] pub fn unwrap_inner(&self) -> &Self { match self { @@ -429,6 +441,8 @@ impl EvalAltResult { } } /// Get the [position][Position] of this error. + #[cold] + #[inline(never)] #[must_use] pub const fn position(&self) -> Position { match self { @@ -470,18 +484,24 @@ impl EvalAltResult { /// Remove the [position][Position] information from this error. /// /// The [position][Position] of this error is set to [`NONE`][Position::NONE] afterwards. + #[cold] + #[inline(never)] pub fn clear_position(&mut self) -> &mut Self { self.set_position(Position::NONE) } /// Remove the [position][Position] information from this error and return it. /// /// The [position][Position] of this error is set to [`NONE`][Position::NONE] afterwards. + #[cold] + #[inline(never)] pub fn take_position(&mut self) -> Position { let pos = self.position(); self.set_position(Position::NONE); pos } /// Override the [position][Position] of this error. + #[cold] + #[inline(never)] pub fn set_position(&mut self, new_position: Position) -> &mut Self { match self { Self::ErrorSystem(..) => (), @@ -522,6 +542,7 @@ impl EvalAltResult { } /// Consume the current [`EvalAltResult`] and return a new one with the specified [`Position`] /// if the current position is [`Position::NONE`]. + #[cold] #[inline(never)] #[must_use] pub(crate) fn fill_position(mut self: Box, new_position: Position) -> Box { diff --git a/src/types/parse_error.rs b/src/types/parse_error.rs index 47e3589a..5cbdcb5d 100644 --- a/src/types/parse_error.rs +++ b/src/types/parse_error.rs @@ -263,6 +263,7 @@ impl fmt::Display for ParseErrorType { } impl From for ParseErrorType { + #[cold] #[inline(never)] fn from(err: LexError) -> Self { match err { @@ -300,13 +301,15 @@ impl fmt::Display for ParseError { impl ParseError { /// Get the [type][ParseErrorType] of this parse error. - #[inline(always)] + #[cold] + #[inline(never)] #[must_use] pub const fn err_type(&self) -> &ParseErrorType { &self.0 } /// Get the [position][Position] of this parse error. - #[inline(always)] + #[cold] + #[inline(never)] #[must_use] pub const fn position(&self) -> Position { self.1 @@ -314,28 +317,32 @@ impl ParseError { } impl From for RhaiError { - #[inline(always)] + #[cold] + #[inline(never)] fn from(err: ParseErrorType) -> Self { Box::new(err.into()) } } impl From for ERR { - #[inline(always)] + #[cold] + #[inline(never)] fn from(err: ParseErrorType) -> Self { Self::ErrorParsing(err, Position::NONE) } } impl From for RhaiError { - #[inline(always)] + #[cold] + #[inline(never)] fn from(err: ParseError) -> Self { Box::new(err.into()) } } impl From for ERR { - #[inline(always)] + #[cold] + #[inline(never)] fn from(err: ParseError) -> Self { Self::ErrorParsing(*err.0, err.1) }