diff --git a/third_party/move/move-compiler-v2/src/env_pipeline/mod.rs b/third_party/move/move-compiler-v2/src/env_pipeline/mod.rs index d589973479f13..5d52ecdb87048 100644 --- a/third_party/move/move-compiler-v2/src/env_pipeline/mod.rs +++ b/third_party/move/move-compiler-v2/src/env_pipeline/mod.rs @@ -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; @@ -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; } @@ -58,13 +58,13 @@ impl<'a> EnvProcessorPipeline<'a> { /// only. pub fn run_and_record(&self, env: &mut GlobalEnv, w: &mut impl Write) -> anyhow::Result { 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); diff --git a/third_party/move/move-compiler-v2/src/file_format_generator/function_generator.rs b/third_party/move/move-compiler-v2/src/file_format_generator/function_generator.rs index 9f2457f25cf3a..c2edfe4faef52 100644 --- a/third_party/move/move-compiler-v2/src/file_format_generator/function_generator.rs +++ b/third_party/move/move-compiler-v2/src/file_format_generator/function_generator.rs @@ -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}, @@ -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, @@ -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) => { diff --git a/third_party/move/move-compiler-v2/src/lib.rs b/third_party/move/move-compiler-v2/src/lib.rs index 81a63ad02e406..4e1d9a2fdbef7 100644 --- a/third_party/move/move-compiler-v2/src/lib.rs +++ b/third_party/move/move-compiler-v2/src/lib.rs @@ -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(), ) diff --git a/third_party/move/move-compiler/src/command_line/mod.rs b/third_party/move/move-compiler/src/command_line/mod.rs index c829b905d5f36..49ae3e5ff3cff 100644 --- a/third_party/move/move-compiler/src/command_line/mod.rs +++ b/third_party/move/move-compiler/src/command_line/mod.rs @@ -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) +} diff --git a/third_party/move/move-model/bytecode/src/function_target.rs b/third_party/move/move-model/bytecode/src/function_target.rs index 04ecc24bbbfa7..64d7d9ce63184 100644 --- a/third_party/move/move-model/bytecode/src/function_target.rs +++ b/third_party/move/move-model/bytecode/src/function_target.rs @@ -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()) diff --git a/third_party/move/tools/move-coverage/src/source_coverage.rs b/third_party/move/tools/move-coverage/src/source_coverage.rs index b2ab82212e1a6..db99b408e4c96 100644 --- a/third_party/move/tools/move-coverage/src/source_coverage.rs +++ b/third_party/move/tools/move-coverage/src/source_coverage.rs @@ -115,17 +115,16 @@ fn subtract_locations(locs1: BTreeSet, locs2: &BTreeSet) -> Vec { } 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 } @@ -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 },