From b2479e9de893516dab79d5c1e9817fb71b4bc49b Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 18 Oct 2023 18:36:25 -0400 Subject: [PATCH] Remove Debug from the context variables. Now that entities are stored in the settings struct, these variables are massive which makes them balloon trace sizes while being mostly unreadable. This removes Debug from them to serve as a static-analysis check that context is ALWAYS ignored in tracing calls. --- src/context/context.rs | 10 ---------- src/context/exiting.rs | 8 +------- src/context/file_access_interface.rs | 7 +++---- src/context/global_settings.rs | 4 ++-- src/parser/affiliated_keyword.rs | 5 +---- src/parser/in_buffer_settings.rs | 5 ++++- 6 files changed, 11 insertions(+), 28 deletions(-) diff --git a/src/context/context.rs b/src/context/context.rs index 3a06647..2ab029a 100644 --- a/src/context/context.rs +++ b/src/context/context.rs @@ -12,7 +12,6 @@ use crate::error::CustomError; use crate::error::Res; use crate::parser::OrgSource; -#[derive(Debug)] pub(crate) enum ContextElement<'r, 's> { /// Stores a parser that indicates that children should exit upon matching an exit matcher. ExitMatcherNode(ExitMatcherNode<'r>), @@ -34,15 +33,6 @@ pub(crate) struct ExitMatcherNode<'r> { pub(crate) class: ExitClass, } -impl<'r> std::fmt::Debug for ExitMatcherNode<'r> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let mut formatter = f.debug_struct("ExitMatcherNode"); - formatter.field("class", &self.class.to_string()); - formatter.finish() - } -} - -#[derive(Debug)] pub(crate) struct Context<'g, 'r, 's> { global_settings: &'g GlobalSettings<'g, 's>, tree: List<'r, &'r ContextElement<'r, 's>>, diff --git a/src/context/exiting.rs b/src/context/exiting.rs index d8ed86f..b1f40a8 100644 --- a/src/context/exiting.rs +++ b/src/context/exiting.rs @@ -1,13 +1,7 @@ -#[derive(Debug, Copy, Clone)] +#[derive(Copy, Clone)] pub(crate) enum ExitClass { Document = 1, Alpha = 2, Beta = 3, Gamma = 4, } - -impl std::fmt::Display for ExitClass { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{:?}", self) - } -} diff --git a/src/context/file_access_interface.rs b/src/context/file_access_interface.rs index 88ee09b..78d5bf5 100644 --- a/src/context/file_access_interface.rs +++ b/src/context/file_access_interface.rs @@ -1,17 +1,16 @@ -use std::fmt::Debug; use std::path::PathBuf; #[cfg(any(feature = "compare", feature = "foreign_document_test"))] -pub trait FileAccessInterface: Sync + Debug { +pub trait FileAccessInterface: Sync { fn read_file(&self, path: &str) -> Result; } #[cfg(not(any(feature = "compare", feature = "foreign_document_test")))] -pub trait FileAccessInterface: Debug { +pub trait FileAccessInterface { fn read_file(&self, path: &str) -> Result; } -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct LocalFileAccessInterface { pub working_directory: Option, } diff --git a/src/context/global_settings.rs b/src/context/global_settings.rs index bad04bf..8eee75c 100644 --- a/src/context/global_settings.rs +++ b/src/context/global_settings.rs @@ -10,7 +10,7 @@ use crate::types::Object; // TODO: Ultimately, I think we'll need most of this: https://orgmode.org/manual/In_002dbuffer-Settings.html -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct GlobalSettings<'g, 's> { pub radio_targets: Vec<&'g Vec>>, pub file_access: &'g dyn FileAccessInterface, @@ -98,7 +98,7 @@ impl<'g, 's> Default for GlobalSettings<'g, 's> { } } -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Clone, PartialEq, Default)] pub enum HeadlineLevelFilter { Odd, diff --git a/src/parser/affiliated_keyword.rs b/src/parser/affiliated_keyword.rs index a684ce4..b9774a9 100644 --- a/src/parser/affiliated_keyword.rs +++ b/src/parser/affiliated_keyword.rs @@ -31,10 +31,7 @@ use crate::types::AffiliatedKeywordValue; use crate::types::AffiliatedKeywords; use crate::types::Keyword; -#[cfg_attr( - feature = "tracing", - tracing::instrument(ret, level = "debug", skip(context)) -)] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub(crate) fn affiliated_keywords<'s>( input: OrgSource<'s>, ) -> Res, Vec>> { diff --git a/src/parser/in_buffer_settings.rs b/src/parser/in_buffer_settings.rs index e671940..76c3a7f 100644 --- a/src/parser/in_buffer_settings.rs +++ b/src/parser/in_buffer_settings.rs @@ -84,7 +84,10 @@ fn in_buffer_settings_key<'s>(input: OrgSource<'s>) -> Res, OrgSou ))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(level = "debug", skip(original_settings)) +)] pub(crate) fn apply_in_buffer_settings<'g, 's, 'sf>( keywords: Vec>, original_settings: &'g GlobalSettings<'g, 's>,