Skip to content

Commit

Permalink
Fix macro scope
Browse files Browse the repository at this point in the history
  • Loading branch information
wks committed Nov 5, 2024
1 parent 42fca3d commit 7433a2a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 12 additions & 8 deletions src/util/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,33 @@
// macros such as `log::info!` from the IDE.
use the_log_crate;

pub use the_log_crate::{error, info, warn};
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.

/// The `log::debug!` macro is disabled in release build. Use the "hot_log" feature to enable.
#[cfg(not(feature = "hot_log"))]
/// The `log::debug!` macro is disabled in release build.
/// Use the "hot_log" feature to enable.
macro_rules! debug {
(target: $target:expr, $($arg:tt)+) => {};
($($arg:tt)+) => {}
}

/// The `log::trace!` macro is disabled in release build. Use the "hot_log" feature to enable.
#[cfg(not(feature = "hot_log"))]
/// The `log::trace!` macro is disabled in release build.
/// Use the "hot_log" feature to enable.
macro_rules! trace {
(target: $target:expr, $($arg:tt)+) => {};
($($arg:tt)+) => {}
}

// 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 use the_log_crate::{debug, trace};
pub(crate) use the_log_crate::{debug, trace};
}
}
4 changes: 2 additions & 2 deletions src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ pub mod heap;
pub mod is_mmtk_object;
/// Linear scan through a heap range
pub mod linear_scan;
/// Logging
pub mod log;
/// Various malloc implementations (conditionally compiled by features)
pub mod malloc;
/// Wrapper functions for memory syscalls such as mmap, mprotect, etc.
Expand All @@ -53,6 +51,8 @@ pub(crate) mod epilogue;
pub(crate) mod erase_vm;
/// Finalization implementation.
pub(crate) mod finalizable_processor;
/// Logging wrappers
pub(crate) mod log;
/// Logger initialization
pub(crate) mod logger;
pub(crate) mod object_enum;
Expand Down

0 comments on commit 7433a2a

Please sign in to comment.