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

Make debugging in release build a compiler error #43

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion crates/oq3_semantics/src/syntax_to_semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ use oq3_syntax::ast as synast; // Syntactic AST

use crate::with_scope;

use crate::utils::type_name_of; // for debugging
// dprintln, ddbg are defined in utils.rs
use crate::utils::type_name_of;
#[allow(unused_imports)]
#[cfg(debug_assertions)]
use crate::{ddbg, dprintln}; // for debugging

// traits
use synast::{HasArgList, HasModuleItem, HasName, HasTextName};
Expand Down
37 changes: 37 additions & 0 deletions crates/oq3_semantics/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,40 @@ macro_rules! dbg_stdout {
($(::std::dbg_stdout!($val)),+,)
};
}

/// This is the same as `dbg!`, except that it is only defined in a debug build.
/// Attempting use in a release build will result in an error
/// `error: cannot determine resolution for the macro ddbg`
#[cfg(debug_assertions)]
#[macro_export]
macro_rules! ddbg {
() => {
println!("[{}:{}:{}]", file!(), line!(), column!())
};
($val:expr $(,)?) => {
match $val {
tmp => {
eprintln!("[{}:{}:{}] {} = {:#?}",
file!(), line!(), column!(), stringify!($val), &tmp);
tmp
}
}
};
($($val:expr),+ $(,)?) => {
($(ddbg!($val)),+,)
};
}

/// This is the same as `println!`, except that it is only defined in a debug build.
/// Attempting use in a release build will result in an error
/// `error: cannot determine resolution for the macro dprintln!`
#[cfg(debug_assertions)]
#[macro_export]
macro_rules! dprintln {
() => {
print!("\n")
};
($($arg:tt)*) => {{
println!($($arg)*);
}};
}