Skip to content

Commit

Permalink
add unused assignment checker
Browse files Browse the repository at this point in the history
  • Loading branch information
Zekun Wang committed Jun 4, 2024
1 parent beab1a5 commit be23cd9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions third_party/move/move-compiler-v2/src/experiments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ pub static EXPERIMENTS: Lazy<BTreeMap<String, Experiment>> = Lazy::new(|| {
description: "Whether to check for unused struct type parameters".to_string(),
default: Inherited(Experiment::CHECKS.to_string()),
},
Experiment {
name: Experiment::UNUSED_ASSIGNMENT_CHECK.to_string(),
description: "Whether to check for unused assignments".to_string(),
default: Inherited(Experiment::CHECKS.to_string()),
},
Experiment {
name: Experiment::VARIABLE_COALESCING.to_string(),
description: "Whether to run variable coalescing".to_string(),
Expand Down Expand Up @@ -215,6 +220,7 @@ impl Experiment {
pub const SPLIT_CRITICAL_EDGES: &'static str = "split-critical-edges";
pub const UNINITIALIZED_CHECK: &'static str = "uninitialized-check";
pub const UNUSED_STRUCT_PARAMS_CHECK: &'static str = "unused-struct-params-check";
pub const UNUSED_ASSIGNMENT_CHECK: &'static str = "unused-assignment-check";
pub const USAGE_CHECK: &'static str = "usage-check";
pub const VARIABLE_COALESCING: &'static str = "variable-coalescing";
pub const VARIABLE_COALESCING_ANNOTATE: &'static str = "variable-coalescing-annotate";
Expand Down
6 changes: 6 additions & 0 deletions third_party/move/move-compiler-v2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use crate::{
uninitialized_use_checker::UninitializedUseChecker,
unreachable_code_analysis::UnreachableCodeProcessor,
unreachable_code_remover::UnreachableCodeRemover, variable_coalescing::VariableCoalescing,
unused_assignment_checker::UnusedAssignmentChecker,
},
};
use anyhow::bail;
Expand Down Expand Up @@ -391,6 +392,11 @@ pub fn bytecode_pipeline(env: &GlobalEnv) -> FunctionTargetPipeline {
pipeline.add_processor(Box::new(UninitializedUseChecker { keep_annotations }));
}

if options.experiment_on(Experiment::UNUSED_ASSIGNMENT_CHECK) {
pipeline.add_processor(Box::new(LiveVarAnalysisProcessor::new(false)));
pipeline.add_processor(Box::new(UnusedAssignmentChecker {}));
}

// Reference check is always run, but the processor decides internally
// based on `Experiment::REFERENCE_SAFETY` whether to report errors.
pipeline.add_processor(Box::new(LiveVarAnalysisProcessor::new(false)));
Expand Down
1 change: 1 addition & 0 deletions third_party/move/move-compiler-v2/src/pipeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub mod split_critical_edges_processor;
pub mod uninitialized_use_checker;
pub mod unreachable_code_analysis;
pub mod unreachable_code_remover;
pub mod unused_assignment_checker;
pub mod variable_coalescing;
pub mod visibility_checker;

Expand Down
12 changes: 12 additions & 0 deletions third_party/move/move-compiler-v2/tests/testsuite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ const TEST_CONFIGS: Lazy<BTreeMap<&str, TestConfig>> = Lazy::new(|| {
dump_bytecode: DumpLevel::None,
dump_bytecode_filter: None,
},
TestConfig {
name: "unused-assignment",
runner: |p| run_test(p, get_config_by_name("unused-assignment") ),
include: vec!["/unused-assignment/"],
exclude: vec![],
exp_suffix: None,
options: opts.clone().set_experiment(Experiment::UNUSED_ASSIGNMENT_CHECK, true),
stop_after: StopAfter::BytecodePipeline(Some("UnusedAssignmentChecker")),
dump_ast: DumpLevel::None,
dump_bytecode: DumpLevel::EndStage,
dump_bytecode_filter: None,
},
// Tests for lambda lifting
TestConfig {
name: "lambda-lifting",
Expand Down

0 comments on commit be23cd9

Please sign in to comment.