From 330a6dff72e700bd669808bbffbac3c51844b8a4 Mon Sep 17 00:00:00 2001 From: Anand Krishnamoorthi <35780660+anakrish@users.noreply.github.com> Date: Sun, 24 Mar 2024 18:37:24 +0530 Subject: [PATCH] Remove cruft. (#184) Logging wasn't implemented fully nor getting used much. Signed-off-by: Anand Krishnamoorthi --- Cargo.toml | 2 -- examples/regorus.rs | 4 --- src/interpreter.rs | 28 +----------------- src/utils.rs | 72 --------------------------------------------- 4 files changed, 1 insertion(+), 105 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c33408e..50237ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -72,8 +72,6 @@ anyhow = {version = "1.0.66", features = ["backtrace"] } serde = {version = "1.0.150", features = ["derive", "rc"] } serde_json = {version = "1.0.89", features = ["arbitrary_precision"] } serde_yaml = {version = "0.9.16", optional = true } -log = "0.4.17" -env_logger="0.11.1" lazy_static = "1.4.0" rand = "0.8.5" num = "0.4.1" diff --git a/examples/regorus.rs b/examples/regorus.rs index 8d6b4be..f805c17 100644 --- a/examples/regorus.rs +++ b/examples/regorus.rs @@ -184,10 +184,6 @@ struct Cli { fn main() -> Result<()> { use clap::Parser; - env_logger::builder() - .format_level(false) - .format_timestamp(None) - .init(); // Parse and dispatch command. let cli = Cli::parse(); diff --git a/src/interpreter.rs b/src/interpreter.rs index 3e9434e..136fe84 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -13,7 +13,6 @@ use crate::Rc; use crate::{Expression, Extension, Location, QueryResult, QueryResults}; use anyhow::{anyhow, bail, Result}; -use log::info; use std::collections::btree_map::Entry as BTreeMapEntry; use std::collections::{hash_map::Entry, BTreeMap, BTreeSet, HashMap}; use std::ops::Bound::*; @@ -236,7 +235,6 @@ impl Interpreter { pub fn set_input(&mut self, input: Value) { self.input = input; - info!("input: {:#?}", self.input); } pub fn init_with_document(&mut self) -> Result<()> { @@ -731,11 +729,6 @@ impl Interpreter { // TODO: optimize this self.variables_assignment(&name, &value)?; - info!( - "eval_assign_expr before, op: {:?}, lhs: {:?}, rhs: {:?}", - op, lhs, rhs - ); - Ok(Value::Bool(true)) } @@ -1323,13 +1316,6 @@ impl Interpreter { } fn eval_stmt(&mut self, stmt: &LiteralStmt, stmts: &[&LiteralStmt]) -> Result { - debug_new_group!( - "eval_stmt {}:{} {}", - stmt.span.line, - stmt.span.col, - stmt.span.text() - ); - let (saved_state, skip_exec) = self.apply_with_modifiers(stmt)?; let r = if !skip_exec { self.eval_stmt_impl(stmt, stmts) @@ -2543,7 +2529,6 @@ impl Interpreter { fn lookup_var(&mut self, span: &Span, fields: &[&str], no_error: bool) -> Result { let name = span.source_str(); - debug_new_group!("lookup_var: name={name}, fields={fields:?}, no_error={no_error}"); // Return local variable/argument. if let Some(v) = self.lookup_local_var(&name) { @@ -2648,13 +2633,6 @@ impl Interpreter { } fn eval_expr(&mut self, expr: &ExprRef) -> Result { - debug_new_group!( - "eval_expr: {}:{} {}", - expr.span().line, - expr.span().col, - expr.span().text() - ); - #[cfg(feature = "coverage")] if self.enable_coverage { let span = expr.span(); @@ -3402,12 +3380,8 @@ impl Interpreter { } pub fn create_rule_prefixes(&mut self) -> Result<()> { - debug_new_group!("create_rule_prefixes"); - debug!("data before: {}", self.data); - for module in self.modules.clone() { let module_path = Self::get_rule_path_components(&module.package.refr)?; - debug!("processing module {module_path:?}"); for rule in &module.policy { let rule_refr = Self::get_rule_refr(rule); @@ -3443,7 +3417,7 @@ impl Interpreter { } } } - debug!("data after: {}", self.data); + Ok(()) } diff --git a/src/utils.rs b/src/utils.rs index 45deb89..ef12eca 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -8,78 +8,6 @@ use crate::lexer::*; use std::collections::BTreeMap; use anyhow::{bail, Result}; - -#[cfg(debug_assertions)] -macro_rules! debug { - ($($arg:tt)+) => { - { - if log::log_enabled!(log::Level::Debug) { - print!("{}:{}:", file!(), line!()); - crate::utils::NESTING.with(|f| { - print!("{}", " ".repeat(*f.borrow() as usize)); - }); - println!($($arg)+); - } - } - } - -} - -#[cfg(not(debug_assertions))] -macro_rules! debug { - ($($arg:tt)+) => {}; -} - -#[allow(unused)] -pub(crate) use debug; - -#[cfg(debug_assertions)] -#[allow(unused)] -macro_rules! debug_new_group { - ($($arg:tt)+) => { - debug!($($arg)+); - let _group = DebugNesting::new(); - }; -} - -#[cfg(not(debug_assertions))] -macro_rules! debug_new_group { - ($($arg:tt)+) => {}; -} - -#[allow(unused)] -pub(crate) use debug_new_group; - -#[allow(unused)] -pub struct DebugNesting {} - -#[cfg(debug_assertions)] -thread_local!(pub static NESTING: std::cell::RefCell = std::cell::RefCell::new(1)); - -impl DebugNesting { - #[cfg(debug_assertions)] - #[allow(unused)] - pub fn new() -> DebugNesting { - NESTING.with(|f| { - *f.borrow_mut() += 1; - }); - DebugNesting {} - } -} - -#[allow(unused)] -impl Drop for DebugNesting { - #[cfg(debug_assertions)] - fn drop(&mut self) { - NESTING.with(|f| { - *f.borrow_mut() -= 1; - }); - } - - #[cfg(not(debug_assertions))] - fn drop(&mut self) {} -} - pub fn get_path_string(refr: &Expr, document: Option<&str>) -> Result { let mut comps: Vec<&str> = vec![]; let mut expr = Some(refr);