From 25476d1cea07fa96874dbdfafaf30c2c4e9d1b3a Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 27 Sep 2022 08:52:39 +0800 Subject: [PATCH] Mark debug functions cold. --- src/ast/ast.rs | 2 ++ src/ast/expr.rs | 9 ++++++++- src/ast/ident.rs | 2 ++ src/ast/namespace.rs | 2 ++ src/ast/stmt.rs | 7 ++++++- src/engine.rs | 3 ++- src/eval/global_state.rs | 3 ++- src/func/callable_function.rs | 2 ++ src/module/mod.rs | 2 ++ src/packages/iter_basic.rs | 2 ++ src/tokenizer.rs | 5 ++++- src/types/custom_types.rs | 2 ++ src/types/dynamic.rs | 2 ++ src/types/fn_ptr.rs | 2 ++ src/types/immutable_string.rs | 3 ++- src/types/scope.rs | 1 - 16 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/ast/ast.rs b/src/ast/ast.rs index 902a6856..f6ebb50c 100644 --- a/src/ast/ast.rs +++ b/src/ast/ast.rs @@ -42,6 +42,8 @@ impl Default for AST { } impl fmt::Debug for AST { + #[cold] + #[inline(never)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut fp = f.debug_struct("AST"); diff --git a/src/ast/expr.rs b/src/ast/expr.rs index e29745a7..037079e8 100644 --- a/src/ast/expr.rs +++ b/src/ast/expr.rs @@ -117,6 +117,8 @@ pub struct FnCallHashes { } impl fmt::Debug for FnCallHashes { + #[cold] + #[inline(never)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { #[cfg(not(feature = "no_function"))] if self.script != 0 { @@ -199,6 +201,8 @@ pub struct FnCallExpr { } impl fmt::Debug for FnCallExpr { + #[cold] + #[inline(never)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ff = f.debug_struct("FnCallExpr"); #[cfg(not(feature = "no_module"))] @@ -294,7 +298,8 @@ impl DerefMut for FloatWrapper { #[cfg(not(feature = "no_float"))] impl fmt::Debug for FloatWrapper { - #[inline(always)] + #[cold] + #[inline(never)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&self.0, f) } @@ -448,6 +453,8 @@ impl Default for Expr { } impl fmt::Debug for Expr { + #[cold] + #[inline(never)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut display_pos = format!(" @ {:?}", self.start_position()); diff --git a/src/ast/ident.rs b/src/ast/ident.rs index 8a6d98aa..eb84c432 100644 --- a/src/ast/ident.rs +++ b/src/ast/ident.rs @@ -20,6 +20,8 @@ pub struct Ident { } impl fmt::Debug for Ident { + #[cold] + #[inline(never)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}", self.name)?; self.pos.debug_print(f) diff --git a/src/ast/namespace.rs b/src/ast/namespace.rs index 9dba5b18..ee36d3bd 100644 --- a/src/ast/namespace.rs +++ b/src/ast/namespace.rs @@ -29,6 +29,8 @@ pub struct Namespace { } impl fmt::Debug for Namespace { + #[cold] + #[inline(never)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if self.is_empty() { return f.write_str("NONE"); diff --git a/src/ast/stmt.rs b/src/ast/stmt.rs index 3bbb0177..ba6f0821 100644 --- a/src/ast/stmt.rs +++ b/src/ast/stmt.rs @@ -106,6 +106,8 @@ impl OpAssignment { } impl fmt::Debug for OpAssignment { + #[cold] + #[inline(never)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if self.is_op_assignment() { f.debug_struct("OpAssignment") @@ -178,7 +180,8 @@ pub enum RangeCase { } impl fmt::Debug for RangeCase { - #[inline] + #[cold] + #[inline(never)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::ExclusiveInt(r, n) => write!(f, "{}..{} => {}", r.start, r.end, n), @@ -454,6 +457,8 @@ impl AsMut<[Stmt]> for StmtBlock { } impl fmt::Debug for StmtBlock { + #[cold] + #[inline(never)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("Block")?; fmt::Debug::fmt(&self.block, f)?; diff --git a/src/engine.rs b/src/engine.rs index 72f95c6b..fb905cde 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -150,7 +150,8 @@ pub struct Engine { } impl fmt::Debug for Engine { - #[inline] + #[cold] + #[inline(never)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut f = f.debug_struct("Engine"); diff --git a/src/eval/global_state.rs b/src/eval/global_state.rs index 775fdda0..20ee2614 100644 --- a/src/eval/global_state.rs +++ b/src/eval/global_state.rs @@ -354,7 +354,8 @@ impl, M: Into>> Ext } impl fmt::Debug for GlobalRuntimeState<'_> { - #[inline] + #[cold] + #[inline(never)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut f = f.debug_struct("GlobalRuntimeState"); diff --git a/src/func/callable_function.rs b/src/func/callable_function.rs index babf1ebf..3973b1b1 100644 --- a/src/func/callable_function.rs +++ b/src/func/callable_function.rs @@ -27,6 +27,8 @@ pub enum CallableFunction { } impl fmt::Debug for CallableFunction { + #[cold] + #[inline(never)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Pure(..) => write!(f, "NativePureFunction"), diff --git a/src/module/mod.rs b/src/module/mod.rs index a07a82d3..fb94e590 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -202,6 +202,8 @@ impl Default for Module { } impl fmt::Debug for Module { + #[cold] + #[inline(never)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut d = f.debug_struct("Module"); diff --git a/src/packages/iter_basic.rs b/src/packages/iter_basic.rs index b9c849fe..4473cfbb 100644 --- a/src/packages/iter_basic.rs +++ b/src/packages/iter_basic.rs @@ -47,6 +47,8 @@ pub struct StepRange { } impl Debug for StepRange { + #[cold] + #[inline(never)] fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_tuple(&format!("StepRange<{}>", type_name::())) .field(&self.from) diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 7cea143e..81893066 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -241,6 +241,8 @@ impl fmt::Display for Position { } impl fmt::Debug for Position { + #[cold] + #[inline(never)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if self.is_none() { f.write_str("none") @@ -333,7 +335,6 @@ impl Span { } impl fmt::Display for Span { - #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let _f = f; @@ -360,6 +361,8 @@ impl fmt::Display for Span { } impl fmt::Debug for Span { + #[cold] + #[inline(never)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(self, f) } diff --git a/src/types/custom_types.rs b/src/types/custom_types.rs index 3b759edc..ca43e1e8 100644 --- a/src/types/custom_types.rs +++ b/src/types/custom_types.rs @@ -17,6 +17,8 @@ pub struct CustomTypeInfo { pub struct CustomTypesCollection(BTreeMap); impl fmt::Debug for CustomTypesCollection { + #[cold] + #[inline(never)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("CustomTypesCollection ")?; f.debug_map().entries(self.0.iter()).finish() diff --git a/src/types/dynamic.rs b/src/types/dynamic.rs index db88b9fa..79e63abf 100644 --- a/src/types/dynamic.rs +++ b/src/types/dynamic.rs @@ -507,6 +507,8 @@ impl fmt::Display for Dynamic { } impl fmt::Debug for Dynamic { + #[cold] + #[inline(never)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.0 { Union::Unit(ref v, ..) => fmt::Debug::fmt(v, f), diff --git a/src/types/fn_ptr.rs b/src/types/fn_ptr.rs index 3ac75077..ab39e9b9 100644 --- a/src/types/fn_ptr.rs +++ b/src/types/fn_ptr.rs @@ -23,6 +23,8 @@ pub struct FnPtr { } impl fmt::Debug for FnPtr { + #[cold] + #[inline(never)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if self.is_curried() { self.curry diff --git a/src/types/immutable_string.rs b/src/types/immutable_string.rs index 507c33d6..7353f151 100644 --- a/src/types/immutable_string.rs +++ b/src/types/immutable_string.rs @@ -197,7 +197,8 @@ impl fmt::Display for ImmutableString { } impl fmt::Debug for ImmutableString { - #[inline(always)] + #[cold] + #[inline(never)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(self.as_str(), f) } diff --git a/src/types/scope.rs b/src/types/scope.rs index 4cc5a91c..169830b4 100644 --- a/src/types/scope.rs +++ b/src/types/scope.rs @@ -81,7 +81,6 @@ pub struct Scope<'a, const N: usize = SCOPE_ENTRIES_INLINED> { } impl fmt::Display for Scope<'_> { - #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { for (i, (name, constant, value)) in self.iter_raw().enumerate() { #[cfg(not(feature = "no_closure"))]