Skip to content

Commit

Permalink
show env_pipeline pass outputs if MVC_LOG=debug, show dot files if MV…
Browse files Browse the repository at this point in the history
…C_DUMP=true

also add more debug logging of Loc information
  • Loading branch information
brmataptos committed Nov 13, 2024
1 parent c57bbd6 commit a76c013
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 20 deletions.
10 changes: 5 additions & 5 deletions third_party/move/move-compiler-v2/src/env_pipeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! This module contains a set of transformers and analyzers of global environment.
//! Those can be arranged in a pipeline and executed in sequence.

use log::trace;
use log::debug;
use move_model::model::GlobalEnv;
use std::io::Write;

Expand Down Expand Up @@ -43,10 +43,10 @@ impl<'a> EnvProcessorPipeline<'a> {
/// Runs the pipeline. Running will be ended if any of the steps produces an error.
/// The function returns true if all steps succeeded without errors.
pub fn run(&self, env: &mut GlobalEnv) -> bool {
trace!("before env processor pipeline: {}", env.dump_env());
debug!("before env processor pipeline: {}", env.dump_env());
for (name, proc) in &self.processors {
proc(env);
trace!("after env processor {}", name);
debug!("after env processor {}: {}", name, env.dump_env());
if env.has_errors() {
return false;
}
Expand All @@ -58,13 +58,13 @@ impl<'a> EnvProcessorPipeline<'a> {
/// only.
pub fn run_and_record(&self, env: &mut GlobalEnv, w: &mut impl Write) -> anyhow::Result<bool> {
let msg = format!("before env processor pipeline:\n{}\n", env.dump_env());
trace!("{}", msg);
debug!("{}", msg);
writeln!(w, "// -- Model dump {}", msg)?;
for (name, proc) in &self.processors {
proc(env);
if !env.has_errors() {
let msg = format!("after env processor {}:\n{}\n", name, env.dump_env());
trace!("{}", msg);
debug!("{}", msg);
writeln!(w, "// -- Model dump {}", msg)?;
} else {
return Ok(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
livevar_analysis_processor::LiveVarAnnotation,
},
};
use log::debug;
use move_binary_format::{
file_format as FF,
file_format::{CodeOffset, FunctionDefinitionIndex},
Expand Down Expand Up @@ -209,6 +210,12 @@ impl<'a> FunctionGenerator<'a> {
for i in 0..bytecode.len() {
let code_offset = i as FF::CodeOffset;
let bc = &bytecode[i];
debug!(
"Generating code for bytecode {:?} ({}) at offset {}",
bc,
bc.display(&ctx.fun, &BTreeMap::new()),
i
);
let bytecode_ctx = BytecodeContext {
fun_ctx: ctx,
code_offset,
Expand Down Expand Up @@ -260,16 +267,17 @@ impl<'a> FunctionGenerator<'a> {
/// Generate file-format bytecode from a stackless bytecode and an optional next bytecode
/// for peephole optimizations.
fn gen_bytecode(&mut self, ctx: &BytecodeContext, bc: &Bytecode, next_bc: Option<&Bytecode>) {
let loc = ctx.fun_ctx.fun.get_bytecode_loc(ctx.attr_id);
let ir_loc = ctx.fun_ctx.module.env.to_ir_loc(&loc);
let offset = self.code.len();
let func_name = ctx.fun_ctx.fun.func_env.get_full_name_str();
debug!(
"Setting location for {}:{} with attr_id {:?} to {:?} (from {:?})",
func_name, offset, ctx.attr_id, ir_loc, loc
);
self.gen
.source_map
.add_code_mapping(
ctx.fun_ctx.def_idx,
self.code.len() as FF::CodeOffset,
ctx.fun_ctx
.module
.env
.to_ir_loc(&ctx.fun_ctx.fun.get_bytecode_loc(ctx.attr_id)),
)
.add_code_mapping(ctx.fun_ctx.def_idx, offset as FF::CodeOffset, ir_loc)
.expect(SOURCE_MAP_OK);
match bc {
Bytecode::Assign(_, dest, source, mode) => {
Expand Down
2 changes: 1 addition & 1 deletion third_party/move/move-compiler-v2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ where
&env,
&mut targets,
&dump_base_name,
false,
command_line::get_move_compiler_dump_from_env(),
&pipeline::register_formatters,
|| !env.has_errors(),
)
Expand Down
5 changes: 5 additions & 0 deletions third_party/move/move-compiler/src/command_line/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,8 @@ pub const MVC_BACKTRACE_ENV_VAR: &str = "MVC_BACKTRACE";
pub fn get_move_compiler_backtrace_from_env() -> bool {
read_bool_env_var(MOVE_COMPILER_BACKTRACE_ENV_VAR) || read_bool_env_var(MVC_BACKTRACE_ENV_VAR)
}

// Flag to dump bytecode files
pub fn get_move_compiler_dump_from_env() -> bool {
read_bool_env_var(MOVE_COMPILER_DUMP_ENV_VAR) || read_bool_env_var(MVC_DUMP_ENV_VAR)
}
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ impl<'env> FunctionTarget<'env> {

// add location
if verbose {
texts.push(format!(" # attr_id {:?}", attr_id));
texts.push(format!(
" # {}",
self.get_bytecode_loc(attr_id).display(self.global_env())
Expand Down
12 changes: 6 additions & 6 deletions third_party/move/tools/move-coverage/src/source_coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,16 @@ fn subtract_locations(locs1: BTreeSet<Loc>, locs2: &BTreeSet<Loc>) -> Vec<Loc> {
} else {
// loc2 is finished but loc1 is not,
// finish adding all loc1
result.push(current_loc1);
for loc1 in locs1_iter {
result.push(loc1);
}
return result;
break;
}
}
}
}
}
result.push(current_loc1);
for loc1 in locs1_iter {
result.push(loc1);
}
}
result
}
Expand Down Expand Up @@ -732,9 +731,10 @@ impl SourceCoverage {
TextIndicator::Explicit | TextIndicator::On => {
write!(
output_writer,
"Code coverage per line of code:\n {} indicates the line is not executable or is fully covered during execution\n {} indicates the line is executable but NOT fully covered during execution\nSource code follows:\n",
"Code coverage per line of code:\n {} indicates the line is covered during execution\n {} indicates the line is executable but NOT fully covered during execution\n {} indicates the line is either test code or is not executable\nSource code follows:\n",
"+".to_string().green(),
"-".to_string().bold().red(),
" ".to_string(),
)?;
true
},
Expand Down

0 comments on commit a76c013

Please sign in to comment.