Merge pull request #2982 from rtfeldman/more-debug-flags

Add more debug flags
This commit is contained in:
Ayaz 2022-05-01 14:30:33 -04:00 committed by GitHub
commit 2ab0bc1226
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 57 additions and 28 deletions

2
Cargo.lock generated
View file

@ -3366,6 +3366,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"morphic_lib", "morphic_lib",
"roc_collections", "roc_collections",
"roc_debug_flags",
"roc_module", "roc_module",
"roc_mono", "roc_mono",
] ]
@ -3683,6 +3684,7 @@ dependencies = [
"roc_alias_analysis", "roc_alias_analysis",
"roc_builtins", "roc_builtins",
"roc_collections", "roc_collections",
"roc_debug_flags",
"roc_error_macros", "roc_error_macros",
"roc_module", "roc_module",
"roc_mono", "roc_mono",

View file

@ -10,4 +10,4 @@ morphic_lib = {path = "../../vendor/morphic_lib"}
roc_collections = {path = "../collections"} roc_collections = {path = "../collections"}
roc_module = {path = "../module"} roc_module = {path = "../module"}
roc_mono = {path = "../mono"} roc_mono = {path = "../mono"}
roc_debug_flags = {path = "../debug_flags"}

View file

@ -26,8 +26,16 @@ pub fn func_name_bytes(proc: &Proc) -> [u8; SIZE] {
func_name_bytes_help(proc.name, proc.args.iter().map(|x| x.0), &proc.ret_layout) func_name_bytes_help(proc.name, proc.args.iter().map(|x| x.0), &proc.ret_layout)
} }
const DEBUG: bool = false; #[inline(always)]
const SIZE: usize = if DEBUG { 50 } else { 16 }; fn debug() -> bool {
use roc_debug_flags::{dbg_do, ROC_DEBUG_ALIAS_ANALYSIS};
dbg_do!(ROC_DEBUG_ALIAS_ANALYSIS, {
return true;
});
false
}
const SIZE: usize = 16;
#[derive(Debug, Clone, Copy, Hash)] #[derive(Debug, Clone, Copy, Hash)]
struct TagUnionId(u64); struct TagUnionId(u64);
@ -87,7 +95,7 @@ where
*target = *source; *target = *source;
} }
if DEBUG { if debug() {
for (i, c) in (format!("{:?}", symbol)).chars().take(25).enumerate() { for (i, c) in (format!("{:?}", symbol)).chars().take(25).enumerate() {
name_bytes[25 + i] = c as u8; name_bytes[25 + i] = c as u8;
} }
@ -175,7 +183,7 @@ where
} }
} }
if DEBUG { if debug() {
eprintln!( eprintln!(
"{:?}: {:?} with {:?} args", "{:?}: {:?} with {:?} args",
proc.name, proc.name,
@ -239,7 +247,7 @@ where
p.build()? p.build()?
}; };
if DEBUG { if debug() {
eprintln!("{}", program.to_source_string()); eprintln!("{}", program.to_source_string());
} }

View file

@ -34,7 +34,7 @@ macro_rules! dbg_do {
($flag:path, $expr:expr) => { ($flag:path, $expr:expr) => {
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
{ {
if std::env::var($flag).unwrap_or("0".to_string()) != "0" { if std::env::var($flag).as_ref() == Ok(&"0".to_string()) {
$expr $expr
} }
} }
@ -64,16 +64,27 @@ flags! {
// ===Mono=== // ===Mono===
/// Writes the mono IR to stderr after function specialization /// Writes a pretty-printed mono IR to stderr after function specialization.
ROC_PRINT_IR_AFTER_SPECIALIZATION ROC_PRINT_IR_AFTER_SPECIALIZATION
/// Writes the mono IR to stderr after insertion of reset/reuse instructions /// Writes a pretty-printed mono IR to stderr after insertion of reset/reuse
/// instructions.
ROC_PRINT_IR_AFTER_RESET_REUSE ROC_PRINT_IR_AFTER_RESET_REUSE
/// Writes the mono IR to stderr after insertion of refcount instructions /// Writes a pretty-printed mono IR to stderr after insertion of refcount
/// instructions.
ROC_PRINT_IR_AFTER_REFCOUNT ROC_PRINT_IR_AFTER_REFCOUNT
/// Instructs the mono IR pretty printer to dump pretty symbols and verbose /// Prints debug information during the alias analysis pass.
/// layout information ROC_DEBUG_ALIAS_ANALYSIS
ROC_PRETTY_PRINT_IR_SYMBOLS
// ===LLVM Gen===
/// Prints LLVM function verification output.
ROC_PRINT_LLVM_FN_VERIFICATION
// ===Load===
/// Print load phases as they complete.
ROC_PRINT_LOAD_LOG
} }

View file

@ -15,6 +15,7 @@ roc_error_macros = { path = "../../error_macros" }
roc_mono = { path = "../mono" } roc_mono = { path = "../mono" }
roc_target = { path = "../roc_target" } roc_target = { path = "../roc_target" }
roc_std = { path = "../../roc_std", default-features = false } roc_std = { path = "../../roc_std", default-features = false }
roc_debug_flags = { path = "../debug_flags" }
morphic_lib = { path = "../../vendor/morphic_lib" } morphic_lib = { path = "../../vendor/morphic_lib" }
bumpalo = { version = "3.8.0", features = ["collections"] } bumpalo = { version = "3.8.0", features = ["collections"] }
inkwell = { path = "../../vendor/inkwell" } inkwell = { path = "../../vendor/inkwell" }

View file

@ -56,6 +56,7 @@ use morphic_lib::{
use roc_builtins::bitcode::{self, FloatWidth, IntWidth, IntrinsicName}; use roc_builtins::bitcode::{self, FloatWidth, IntWidth, IntrinsicName};
use roc_builtins::{float_intrinsic, llvm_int_intrinsic}; use roc_builtins::{float_intrinsic, llvm_int_intrinsic};
use roc_collections::all::{ImMap, MutMap, MutSet}; use roc_collections::all::{ImMap, MutMap, MutSet};
use roc_debug_flags::{dbg_do, ROC_PRINT_LLVM_FN_VERIFICATION};
use roc_error_macros::internal_error; use roc_error_macros::internal_error;
use roc_module::low_level::LowLevel; use roc_module::low_level::LowLevel;
use roc_module::symbol::{Interns, ModuleId, Symbol}; use roc_module::symbol::{Interns, ModuleId, Symbol};
@ -67,13 +68,13 @@ use roc_mono::layout::{Builtin, LambdaSet, Layout, LayoutIds, TagIdIntType, Unio
use roc_target::{PtrWidth, TargetInfo}; use roc_target::{PtrWidth, TargetInfo};
use target_lexicon::{Architecture, OperatingSystem, Triple}; use target_lexicon::{Architecture, OperatingSystem, Triple};
/// This is for Inkwell's FunctionValue::verify - we want to know the verification #[inline(always)]
/// output in debug builds, but we don't want it to print to stdout in release builds! fn print_fn_verification_output() -> bool {
#[cfg(debug_assertions)] dbg_do!(ROC_PRINT_LLVM_FN_VERIFICATION, {
const PRINT_FN_VERIFICATION_OUTPUT: bool = true; return true;
});
#[cfg(not(debug_assertions))] false
const PRINT_FN_VERIFICATION_OUTPUT: bool = false; }
#[macro_export] #[macro_export]
macro_rules! debug_info_init { macro_rules! debug_info_init {
@ -4513,7 +4514,7 @@ pub fn build_proc<'a, 'ctx, 'env>(
} }
pub fn verify_fn(fn_val: FunctionValue<'_>) { pub fn verify_fn(fn_val: FunctionValue<'_>) {
if !fn_val.verify(PRINT_FN_VERIFICATION_OUTPUT) { if !fn_val.verify(print_fn_verification_output()) {
unsafe { unsafe {
fn_val.delete(); fn_val.delete();
} }

View file

@ -17,7 +17,7 @@ use roc_constrain::module::{
}; };
use roc_debug_flags::{ use roc_debug_flags::{
dbg_do, ROC_PRINT_IR_AFTER_REFCOUNT, ROC_PRINT_IR_AFTER_RESET_REUSE, dbg_do, ROC_PRINT_IR_AFTER_REFCOUNT, ROC_PRINT_IR_AFTER_RESET_REUSE,
ROC_PRINT_IR_AFTER_SPECIALIZATION, ROC_PRINT_IR_AFTER_SPECIALIZATION, ROC_PRINT_LOAD_LOG,
}; };
use roc_error_macros::internal_error; use roc_error_macros::internal_error;
use roc_module::ident::{Ident, ModuleName, QualifiedModuleName}; use roc_module::ident::{Ident, ModuleName, QualifiedModuleName};
@ -74,13 +74,10 @@ const PKG_CONFIG_FILE_NAME: &str = "Package-Config";
/// The . in between module names like Foo.Bar.Baz /// The . in between module names like Foo.Bar.Baz
const MODULE_SEPARATOR: char = '.'; const MODULE_SEPARATOR: char = '.';
const SHOW_MESSAGE_LOG: bool = false;
const EXPANDED_STACK_SIZE: usize = 8 * 1024 * 1024; const EXPANDED_STACK_SIZE: usize = 8 * 1024 * 1024;
macro_rules! log { macro_rules! log {
() => (if SHOW_MESSAGE_LOG { println!()} else {}); ($($arg:tt)*) => (dbg_do!(ROC_PRINT_LOAD_LOG, println!($($arg)*)))
($($arg:tt)*) => (if SHOW_MESSAGE_LOG { println!($($arg)*); } else {})
} }
/// Struct storing various intermediate stages by their ModuleId /// Struct storing various intermediate stages by their ModuleId

View file

@ -10,7 +10,10 @@ use roc_builtins::bitcode::{FloatWidth, IntWidth};
use roc_can::abilities::AbilitiesStore; use roc_can::abilities::AbilitiesStore;
use roc_can::expr::{AnnotatedMark, ClosureData, IntValue}; use roc_can::expr::{AnnotatedMark, ClosureData, IntValue};
use roc_collections::all::{default_hasher, BumpMap, BumpMapDefault, MutMap}; use roc_collections::all::{default_hasher, BumpMap, BumpMapDefault, MutMap};
use roc_debug_flags::{dbg_do, ROC_PRETTY_PRINT_IR_SYMBOLS}; use roc_debug_flags::{
dbg_do, ROC_PRINT_IR_AFTER_REFCOUNT, ROC_PRINT_IR_AFTER_RESET_REUSE,
ROC_PRINT_IR_AFTER_SPECIALIZATION,
};
use roc_exhaustive::{Ctor, CtorName, Guard, RenderAs, TagId}; use roc_exhaustive::{Ctor, CtorName, Guard, RenderAs, TagId};
use roc_module::ident::{ForeignSymbol, Lowercase, TagName}; use roc_module::ident::{ForeignSymbol, Lowercase, TagName};
use roc_module::low_level::LowLevel; use roc_module::low_level::LowLevel;
@ -28,7 +31,13 @@ use ven_pretty::{BoxAllocator, DocAllocator, DocBuilder};
#[inline(always)] #[inline(always)]
pub fn pretty_print_ir_symbols() -> bool { pub fn pretty_print_ir_symbols() -> bool {
dbg_do!(ROC_PRETTY_PRINT_IR_SYMBOLS, { dbg_do!(ROC_PRINT_IR_AFTER_SPECIALIZATION, {
return true;
});
dbg_do!(ROC_PRINT_IR_AFTER_RESET_REUSE, {
return true;
});
dbg_do!(ROC_PRINT_IR_AFTER_REFCOUNT, {
return true; return true;
}); });
false false