Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use wrapper for logging. #1225

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix compiler warnings
wks committed Nov 5, 2024
commit 6c946aeec25e6be3a817acb4e851745428fde06c
1 change: 1 addition & 0 deletions src/plan/tracing.rs
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@

use crate::scheduler::gc_work::{ProcessEdgesWork, SlotOf};
use crate::scheduler::{GCWorker, WorkBucketStage};
#[cfg(debug_assertions)]
use crate::util::log;
use crate::util::ObjectReference;
use crate::vm::SlotVisitor;
1 change: 1 addition & 0 deletions src/util/copy/mod.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ use crate::policy::copyspace::CopySpaceCopyContext;
use crate::policy::immix::ImmixSpace;
use crate::policy::immix::{ImmixCopyContext, ImmixHybridCopyContext};
use crate::policy::space::Space;
#[cfg(debug_assertions)]
use crate::util::log;
use crate::util::object_forwarding;
use crate::util::opaque_pointer::VMWorkerThread;
56 changes: 34 additions & 22 deletions src/util/log.rs
Original file line number Diff line number Diff line change
@@ -13,31 +13,43 @@ use the_log_crate;

pub(crate) use the_log_crate::{error, info, warn};

cfg_if::cfg_if! {
if #[cfg(all(not(debug_assertions), not(feature = "hot_log")))] {
// If it is release build and the feature "hot_log" is not enabled,
// then we define verbose logs as no-op in release build.
/// Whether logs of DEBUG and TRACE levels are enabled.
/// In debug build, they are always enabled.
/// In release build, they are not enabled unless the "hot_log" Cargo feature is enabled.
pub(crate) const HOT_LOG_ENABLED: bool = cfg!(any(not(debug_assertions), feature = "hot_log"));

/// The `log::debug!` macro is disabled in release build.
/// Use the "hot_log" feature to enable.
macro_rules! debug {
($($arg:tt)+) => {}
/// A wrapper of the `debug!` macro in the `log` crate.
/// Does nothing if [`HOT_LOG_ENABLED`] is false.
macro_rules! debug {
(target: $target:expr, $($arg:tt)+) => {
if $crate::util::log::HOT_LOG_ENABLED {
the_log_crate::debug!(target: $target, $($arg)+)
}

/// The `log::trace!` macro is disabled in release build.
/// Use the "hot_log" feature to enable.
macro_rules! trace {
($($arg:tt)+) => {}
};
($($arg:tt)+) => {
if $crate::util::log::HOT_LOG_ENABLED {
the_log_crate::debug!($($arg)+)
}
}
}

// By default, a macro has no path-based scope.
// The following allows other modules to access the macros with `crate::util::log::debug`
// and `crate::util::log::trace`.
pub(crate) use debug;
pub(crate) use trace;

} else {
// Otherwise simply import the macros from the `log` crate.
pub(crate) use the_log_crate::{debug, trace};
/// A wrapper of the `trace!` macro in the `log` crate.
/// Does nothing if [`HOT_LOG_ENABLED`] is false.
macro_rules! trace {
(target: $target:expr, $($arg:tt)+) => {
if $crate::util::log::HOT_LOG_ENABLED {
the_log_crate::trace!(target: $target, $($arg)+)
}
};
($($arg:tt)+) => {
if $crate::util::log::HOT_LOG_ENABLED {
the_log_crate::trace!($($arg)+)
}
}
}

// By default, a macro has no path-based scope.
// The following allows other modules to access the macros with `crate::util::log::debug`
// and `crate::util::log::trace`.
pub(crate) use debug;
pub(crate) use trace;
1 change: 0 additions & 1 deletion src/vm/scanning.rs
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@ pub trait SlotVisitor<SL: Slot> {
/// This lets us use closures as SlotVisitor.
impl<SL: Slot, F: FnMut(SL)> SlotVisitor<SL> for F {
fn visit_slot(&mut self, slot: SL) {
#[cfg(debug_assertions)]
log::trace!(
"(FunctionClosure) Visit slot {:?} (pointing to {:?})",
slot,