Skip to content

[compiler v2] enable warnings on unused private funcs, structs, and constants#18661

Draft
junxzm1990 wants to merge 4 commits intomainfrom
jun/unused-linter
Draft

[compiler v2] enable warnings on unused private funcs, structs, and constants#18661
junxzm1990 wants to merge 4 commits intomainfrom
jun/unused-linter

Conversation

@junxzm1990
Copy link
Contributor

@junxzm1990 junxzm1990 commented Feb 9, 2026

Description

This PR

Warning Flag (-W) Propagation

Flow

aptos move compile --Wunused                                                                                                                                                                
         ↓                                                                                                                                                                                  
MovePackageOptions::warnings                                                                                                                                                                
         ↓                                                                                                                                                                                  
BuildOptions::warnings                                                                                                                                                                      
         ↓                                                                                                                                                                                  
move_compiler_v2::Options::warnings                                                                                                                                                         
         ↓                                                                                                                                                                                  
GlobalEnv (set_extension)                                                                                                                                                                   
         ↓                                                                                                                                                                                  
Checker (warning_enabled)                                                                                                                                                                   

Implementation

Layer File
CLI crates/aptos/src/common/types.rs
Aptos Tool crates/aptos/src/move_tool/mod.rs
Package third_party/move/tools/move-package/src/compilation/compiled_package.rs
Compiler third_party/move/move-compiler-v2/src/lib.rs
Checker third_party/move/move-compiler-v2/src/env_pipeline/function_checker.rs

Check logic:

pub fn warning_enabled(&self, name: &str) -> bool {                                                                                                                                         
    self.warnings.iter().any(|w| w == name || w == "all")                                                                                                                                   
}                                                                                                                                                                                           

Backward Compatibility

  • Default: warnings = vec![] (empty)
  • Activation: Explicit --Wunused or --Wall required
  • Guard: All checks wrapped in if options.warning_enabled("unused")
  • Impact: Zero breaking changes—existing builds unaffected

Close #18652

How Has This Been Tested?

  • New test cases covering both happy paths and edge paths

Type of Change

  • New feature
  • Bug fix
  • Breaking change
  • Performance improvement
  • Refactoring
  • Dependency update
  • Documentation update
  • Tests

Which Components or Systems Does This Change Impact?

  • Validator Node
  • Full Node (API, Indexer, etc.)
  • Move/Aptos Virtual Machine
  • Aptos Framework
  • Aptos CLI/SDK
  • Developer Infrastructure
  • Move Compiler
  • Other (specify)

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@junxzm1990 junxzm1990 force-pushed the jun/unused-linter branch 4 times, most recently from 515b56b to 6d71936 Compare February 9, 2026 18:07
Add comprehensive unused entity detection for private functions, structs,
and constants in Move compiler v2. This includes:

- Optimize unused linter by tracking constant/struct usage during build
  instead of lazy computation
- Add systematic type instantiation tracking to detect structs used as
  type parameters in all operations (vector<T>, helper<T>(), global storage)
- Fix Lambda/Invoke handling to safely check module existence
- Add extensive test coverage for various usage patterns

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
junxzm1990 and others added 3 commits February 9, 2026 12:55
…n 2.4

Struct visibility modifiers (public, package, friend) are only supported
in language version 2.4+. Configure the unused entity detection tests to
run with language version 2.4 and update baselines accordingly.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…tion

The is_target() check is redundant because the code is already inside an
if caller_module.is_primary_target() block, and primary targets are
always targets (is_primary_target implies is_target).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
The warning flags use double-dash --W (long option), not single-dash -W.
The reference to 'GCC style' was misleading since GCC uses -W but we use --W.

Corrected documentation to consistently show --W<name> style with examples.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[move compiler] warnings about unused funcs, structs, and consts.

1 participant