diff --git a/third_party/move/move-compiler-v2/src/lib.rs b/third_party/move/move-compiler-v2/src/lib.rs index d46eab6916f7e..2ee3067e492d7 100644 --- a/third_party/move/move-compiler-v2/src/lib.rs +++ b/third_party/move/move-compiler-v2/src/lib.rs @@ -185,7 +185,10 @@ pub fn run_checker(options: Options) -> anyhow::Result { &options.known_attributes }, options.language_version.unwrap_or_default(), + options.warn_deprecated, + options.warn_of_deprecation_use_in_aptos_libs, options.compile_test_code, + options.compile_verify_code, )?; // Store address aliases let map = addrs diff --git a/third_party/move/move-compiler-v2/src/options.rs b/third_party/move/move-compiler-v2/src/options.rs index bb8933ad163c9..60bc379f7211f 100644 --- a/third_party/move/move-compiler-v2/src/options.rs +++ b/third_party/move/move-compiler-v2/src/options.rs @@ -6,8 +6,14 @@ use crate::experiments::{DefaultValue, EXPERIMENTS}; use clap::Parser; use codespan_reporting::diagnostic::Severity; use itertools::Itertools; -use move_command_line_common::env::read_env_var; -use move_compiler::command_line as cli; +use move_command_line_common::env::{bool_to_str, read_env_var}; +use move_compiler::{ + command_line as cli, + shared::{ + move_compiler_warn_of_deprecation_use_env_var, + warn_of_deprecation_use_in_aptos_libs_env_var, + }, +}; use move_model::metadata::LanguageVersion; use once_cell::sync::Lazy; use std::{ @@ -25,29 +31,36 @@ pub struct Options { num_args = 0.. )] pub dependencies: Vec, + /// Named address mapping. #[clap( short, num_args = 0.. )] pub named_address_mapping: Vec, + /// Output directory. #[clap(short, long, default_value = "")] pub output_dir: String, + /// The language version to use. #[clap(long, value_parser = clap::value_parser!(LanguageVersion))] pub language_version: Option, + /// Do not complain about unknown attributes in Move code. #[clap(long, default_value = "false")] pub skip_attribute_checks: bool, + /// Known attributes for this dialect of move; if empty, assumes third-party Move. /// Only used if skip_attribute_checks is false. #[clap(skip)] pub known_attributes: BTreeSet, + /// Whether we generate code for tests. This specifically guarantees stable output /// for baseline testing. #[clap(long)] pub testing: bool, + /// Active experiments. Experiments alter default behavior of the compiler. /// See `Experiment` struct. #[clap(short)] @@ -56,31 +69,52 @@ pub struct Options { num_args = 0.. )] pub experiments: Vec, + /// A transient cache for memoization of experiment checks. #[clap(skip)] pub experiment_cache: RefCell>, + /// Sources to compile (positional arg, therefore last). /// Each source should be a path to either (1) a Move file or (2) a directory containing Move /// files, all to be compiled (e.g., not the root directory of a package---which contains /// Move.toml---but a specific subdirectorysuch as `sources`, `scripts`, and/or `tests`, /// depending on compilation mode). pub sources: Vec, + /// Dependencies to compile but not treat as a test/docgen/warning/prover target. /// Each source_dep should be a path to either (1) a Move file or (2) a directory containing /// Move files, all to be compiled (e.g., not the root directory of a package---which contains /// Move.toml---but a specific subdirectorysuch as `sources`). #[clap(skip)] pub sources_deps: Vec, + + #[clap(long = cli::MOVE_COMPILER_WARN_OF_DEPRECATION_USE_FLAG, + default_value=bool_to_str(move_compiler_warn_of_deprecation_use_env_var()))] + pub warn_deprecated: bool, + + /// Show warnings about use of deprecated usage in the Aptos libraries, + /// which we should generally not bother users with. + /// Note that current value of this constant is "Wdeprecation-aptos" + #[clap(long = cli::WARN_OF_DEPRECATION_USE_IN_APTOS_LIBS_FLAG, + default_value=bool_to_str(warn_of_deprecation_use_in_aptos_libs_env_var()))] + pub warn_of_deprecation_use_in_aptos_libs: bool, + /// Show warnings about unused functions, fields, constants, etc. /// Note that the current value of this constant is "Wunused" #[clap(long = cli::WARN_UNUSED_FLAG, default_value="false")] pub warn_unused: bool, + /// Whether to compile everything, including dependencies. #[clap(long)] pub whole_program: bool, + /// Whether to compile #[test] and #[test_only] code #[clap(skip)] pub compile_test_code: bool, + + /// Whether to compile #[verify_only] code + #[clap(skip)] + pub compile_verify_code: bool, } impl Default for Options { @@ -169,6 +203,34 @@ impl Options { ..self } } + + pub fn set_compile_verify_code(self, value: bool) -> Self { + Self { + compile_verify_code: value, + ..self + } + } + + pub fn set_warn_deprecated(self, value: bool) -> Self { + Self { + warn_deprecated: value, + ..self + } + } + + pub fn set_warn_of_deprecation_use_in_aptos_libs(self, value: bool) -> Self { + Self { + warn_of_deprecation_use_in_aptos_libs: value, + ..self + } + } + + pub fn set_warn_unused(self, value: bool) -> Self { + Self { + warn_unused: value, + ..self + } + } } /// Finds the experiment in the list of definitions. A definition diff --git a/third_party/move/move-compiler-v2/tests/deprecated/deprecated_constant_duplicated_struct.exp b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_constant_duplicated_struct.exp new file mode 100644 index 0000000000000..a30fe67df07d0 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_constant_duplicated_struct.exp @@ -0,0 +1,27 @@ + +Diagnostics: +error: duplicate declaration, item, or annotation + ┌─ tests/deprecated/deprecated_constant_duplicated_struct.move:5:11 + │ +4 │ struct C { } + │ - Alias previously defined here +5 │ const C: u64 = 0; + │ ^ Duplicate module member or alias 'C'. Top level names in a namespace must be unique + +warning: unused alias + ┌─ tests/deprecated/deprecated_constant_duplicated_struct.move:12:15 + │ +12 │ use 0x42::mod1; + │ ^^^^ Unused 'use' of alias 'mod1'. Consider removing it + +warning: unused alias + ┌─ tests/deprecated/deprecated_constant_duplicated_struct.move:31:15 + │ +31 │ use 0x42::mod1; + │ ^^^^ Unused 'use' of alias 'mod1'. Consider removing it + +error: invalid name + ┌─ tests/deprecated/deprecated_constant_duplicated_struct.move:32:26 + │ +32 │ use 0x42::mod1::C as mod1; + │ ^^^^ Invalid constant alias name 'mod1'. Constant alias names must start with 'A'..'Z' diff --git a/third_party/move/move-compiler-v2/tests/deprecated/deprecated_constant_duplicated_struct.move b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_constant_duplicated_struct.move new file mode 100644 index 0000000000000..e700dd74e7aec --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_constant_duplicated_struct.move @@ -0,0 +1,44 @@ +address 0x42 { +module mod1 { + #[deprecated] + struct C { } + const C: u64 = 0; + public fun mod1() {} +} +} + +address 0x41 { +module N { + use 0x42::mod1; + use 0x42::mod1::C as D; + use 0x42::mod1::C as C; + use 0x42::mod1::mod1; + + fun f1(): 0x42::mod1::C { + mod1(); + C; + { + use 0x42::mod1::C; + C + }; + D + } +} +} + + +script { + use 0x42::mod1; + use 0x42::mod1::C as mod1; + use 0x42::mod1::C as C; + use 0x42::mod1::mod1; + + fun f1(): 0x42::mod1::C { + mod1(); + C; + { + use 0x42::mod1::C; + C + } + } +} diff --git a/third_party/move/move-compiler-v2/tests/deprecated/deprecated_constant_duplicated_struct2.exp b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_constant_duplicated_struct2.exp new file mode 100644 index 0000000000000..9f0348c6e4d2e --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_constant_duplicated_struct2.exp @@ -0,0 +1,145 @@ + +Diagnostics: +error: duplicate declaration, item, or annotation + ┌─ tests/deprecated/deprecated_constant_duplicated_struct2.move:5:11 + │ +3 │ struct C { } + │ - Alias previously defined here +4 │ #[deprecated] +5 │ const C: u64 = 0; + │ ^ Duplicate module member or alias 'C'. Top level names in a namespace must be unique + +warning: unused alias + ┌─ tests/deprecated/deprecated_constant_duplicated_struct2.move:12:15 + │ +12 │ use 0x42::mod1; + │ ^^^^ Unused 'use' of alias 'mod1'. Consider removing it + +warning: Use of deprecated constant + ┌─ tests/deprecated/deprecated_constant_duplicated_struct2.move:13:21 + │ + 4 │ #[deprecated] + │ ---------- Constant 'C' in module '0x42::mod1' deprecated here + · +13 │ use 0x42::mod1::C as D; + │ ^ Use of deprecated constant 'C' from module '0x42::mod1' + +warning: Use of deprecated constant + ┌─ tests/deprecated/deprecated_constant_duplicated_struct2.move:14:21 + │ + 4 │ #[deprecated] + │ ---------- Constant 'C' in module '0x42::mod1' deprecated here + · +14 │ use 0x42::mod1::C as C; + │ ^ Use of deprecated constant 'C' from module '0x42::mod1' + +warning: Use of deprecated struct + ┌─ tests/deprecated/deprecated_constant_duplicated_struct2.move:17:27 + │ + 4 │ #[deprecated] + │ ---------- Struct 'C' in module '0x42::mod1' deprecated here + · +17 │ fun f1(): 0x42::mod1::C { + │ ^ Use of deprecated struct 'C' from module '0x42::mod1' + +warning: Use of deprecated member + ┌─ tests/deprecated/deprecated_constant_duplicated_struct2.move:19:2 + │ + 4 │ #[deprecated] + │ ---------- Member 'C' in module '0x42::mod1' deprecated here + · +19 │ C; + │ ^ Use of deprecated member 'C' from module '0x42::mod1' + +warning: Use of deprecated constant + ┌─ tests/deprecated/deprecated_constant_duplicated_struct2.move:21:22 + │ + 4 │ #[deprecated] + │ ---------- Constant 'C' in module '0x42::mod1' deprecated here + · +21 │ use 0x42::mod1::C; + │ ^ Use of deprecated constant 'C' from module '0x42::mod1' + +warning: Use of deprecated member + ┌─ tests/deprecated/deprecated_constant_duplicated_struct2.move:22:6 + │ + 4 │ #[deprecated] + │ ---------- Member 'C' in module '0x42::mod1' deprecated here + · +22 │ C + │ ^ Use of deprecated member 'C' from module '0x42::mod1' + +warning: Use of deprecated member + ┌─ tests/deprecated/deprecated_constant_duplicated_struct2.move:24:2 + │ + 4 │ #[deprecated] + │ ---------- Member 'C' in module '0x42::mod1' deprecated here + · +24 │ D + │ ^ Use of deprecated member 'C' from module '0x42::mod1' + +warning: unused alias + ┌─ tests/deprecated/deprecated_constant_duplicated_struct2.move:31:15 + │ +31 │ use 0x42::mod1; + │ ^^^^ Unused 'use' of alias 'mod1'. Consider removing it + +warning: Use of deprecated constant + ┌─ tests/deprecated/deprecated_constant_duplicated_struct2.move:32:21 + │ + 4 │ #[deprecated] + │ ---------- Constant 'C' in module '0x42::mod1' deprecated here + · +32 │ use 0x42::mod1::C as mod1; + │ ^ Use of deprecated constant 'C' from module '0x42::mod1' + +error: invalid name + ┌─ tests/deprecated/deprecated_constant_duplicated_struct2.move:32:26 + │ +32 │ use 0x42::mod1::C as mod1; + │ ^^^^ Invalid constant alias name 'mod1'. Constant alias names must start with 'A'..'Z' + +warning: Use of deprecated constant + ┌─ tests/deprecated/deprecated_constant_duplicated_struct2.move:33:21 + │ + 4 │ #[deprecated] + │ ---------- Constant 'C' in module '0x42::mod1' deprecated here + · +33 │ use 0x42::mod1::C as C; + │ ^ Use of deprecated constant 'C' from module '0x42::mod1' + +warning: Use of deprecated struct + ┌─ tests/deprecated/deprecated_constant_duplicated_struct2.move:36:27 + │ + 4 │ #[deprecated] + │ ---------- Struct 'C' in module '0x42::mod1' deprecated here + · +36 │ fun f1(): 0x42::mod1::C { + │ ^ Use of deprecated struct 'C' from module '0x42::mod1' + +warning: Use of deprecated member + ┌─ tests/deprecated/deprecated_constant_duplicated_struct2.move:38:2 + │ + 4 │ #[deprecated] + │ ---------- Member 'C' in module '0x42::mod1' deprecated here + · +38 │ C; + │ ^ Use of deprecated member 'C' from module '0x42::mod1' + +warning: Use of deprecated constant + ┌─ tests/deprecated/deprecated_constant_duplicated_struct2.move:40:22 + │ + 4 │ #[deprecated] + │ ---------- Constant 'C' in module '0x42::mod1' deprecated here + · +40 │ use 0x42::mod1::C; + │ ^ Use of deprecated constant 'C' from module '0x42::mod1' + +warning: Use of deprecated member + ┌─ tests/deprecated/deprecated_constant_duplicated_struct2.move:41:6 + │ + 4 │ #[deprecated] + │ ---------- Member 'C' in module '0x42::mod1' deprecated here + · +41 │ C + │ ^ Use of deprecated member 'C' from module '0x42::mod1' diff --git a/third_party/move/move-compiler-v2/tests/deprecated/deprecated_constant_duplicated_struct2.move b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_constant_duplicated_struct2.move new file mode 100644 index 0000000000000..faf1c9ff4b518 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_constant_duplicated_struct2.move @@ -0,0 +1,44 @@ +address 0x42 { +module mod1 { + struct C { } + #[deprecated] + const C: u64 = 0; + public fun mod1() {} +} +} + +address 0x41 { +module N { + use 0x42::mod1; + use 0x42::mod1::C as D; + use 0x42::mod1::C as C; + use 0x42::mod1::mod1; + + fun f1(): 0x42::mod1::C { + mod1(); + C; + { + use 0x42::mod1::C; + C + }; + D + } +} +} + + +script { + use 0x42::mod1; + use 0x42::mod1::C as mod1; + use 0x42::mod1::C as C; + use 0x42::mod1::mod1; + + fun f1(): 0x42::mod1::C { + mod1(); + C; + { + use 0x42::mod1::C; + C + } + } +} diff --git a/third_party/move/move-compiler-v2/tests/deprecated/deprecated_field_type.exp b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_field_type.exp new file mode 100644 index 0000000000000..9b2175d2d571a --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_field_type.exp @@ -0,0 +1,31 @@ + +Diagnostics: +warning: Use of deprecated struct + ┌─ tests/deprecated/deprecated_field_type.move:17:22 + │ + 3 │ #[deprecated] + │ ---------- Struct 'EventHandle' in module '0x42::event' deprecated here + · +17 │ use 0x42::event::EventHandle; + │ ^^^^^^^^^^^ Use of deprecated struct 'EventHandle' from module '0x42::event' + +warning: Use of deprecated struct + ┌─ tests/deprecated/deprecated_field_type.move:27:25 + │ + 3 │ #[deprecated] + │ ---------- Struct 'EventHandle' in module '0x42::event' deprecated here + · +27 │ deposit_events: EventHandle, + │ ^^^^^^^^^^^ Use of deprecated struct 'EventHandle' from module '0x42::event' + +warning: Use of deprecated struct + ┌─ tests/deprecated/deprecated_field_type.move:28:26 + │ + 3 │ #[deprecated] + │ ---------- Struct 'EventHandle' in module '0x42::event' deprecated here + · +28 │ withdraw_events: EventHandle, + │ ^^^^^^^^^^^ Use of deprecated struct 'EventHandle' from module '0x42::event' + + +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/deprecated/deprecated_field_type.move b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_field_type.move new file mode 100644 index 0000000000000..7b8603579e617 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_field_type.move @@ -0,0 +1,30 @@ +module 0x42::event { + + #[deprecated] + /// A handle for an event such that: + /// 1. Other modules can emit events to this handle. + /// 2. Storage can use this handle to prove the total number of events that happened in the past. + struct EventHandle has store { + /// Total number of events emitted to this event stream. + counter: u64, + /// A globally unique ID for this event stream. + guid: u64, + } + +} + +module 0x41::coin { + use 0x42::event::EventHandle; + + struct Coin has store { } + struct CoinType has key {} + struct DepositEvent has drop, store {} + struct WithdrawEvent has drop, store {} + + struct CoinStore has key { + coin: Coin, + frozen: bool, + deposit_events: EventHandle, + withdraw_events: EventHandle, + } +} diff --git a/third_party/move/move-compiler-v2/tests/deprecated/deprecated_field_type2.exp b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_field_type2.exp new file mode 100644 index 0000000000000..9fd7327c3f1ee --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_field_type2.exp @@ -0,0 +1,13 @@ + +Diagnostics: +warning: Use of deprecated struct + ┌─ tests/deprecated/deprecated_field_type2.move:29:38 + │ +22 │ #[deprecated] + │ ---------- Struct 'WithdrawEvent' in module '0x41::coin' deprecated here + · +29 │ withdraw_events: EventHandle, + │ ^^^^^^^^^^^^^ Use of deprecated struct 'WithdrawEvent' from module '0x41::coin' + + +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/deprecated/deprecated_field_type2.move b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_field_type2.move new file mode 100644 index 0000000000000..f21a61fedec9a --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_field_type2.move @@ -0,0 +1,31 @@ +module 0x42::event { + + /// A handle for an event such that: + /// 1. Other modules can emit events to this handle. + /// 2. Storage can use this handle to prove the total number of events that happened in the past. + struct EventHandle has store { + /// Total number of events emitted to this event stream. + counter: u64, + /// A globally unique ID for this event stream. + guid: u64, + } + +} + +module 0x41::coin { + use 0x42::event::EventHandle; + + struct Coin has store { } + struct CoinType has key {} + struct DepositEvent has drop, store {} + + #[deprecated] + struct WithdrawEvent has drop, store {} + + struct CoinStore has key { + coin: Coin, + frozen: bool, + deposit_events: EventHandle, + withdraw_events: EventHandle, + } +} diff --git a/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_address.exp b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_address.exp new file mode 100644 index 0000000000000..c492663d4fe27 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_address.exp @@ -0,0 +1,22 @@ + +Diagnostics: +warning: Use of deprecated module + ┌─ tests/deprecated/deprecated_placement_address.move:25:9 + │ + 1 │ #[deprecated] + │ ---------- Module '0x42::M' deprecated here + · +25 │ use 0x42::M; + │ ^^^^^^^ Use of deprecated module '0x42::M' + +warning: Use of deprecated module + ┌─ tests/deprecated/deprecated_placement_address.move:29:15 + │ + 1 │ #[deprecated] + │ ---------- Module '0x42::M' deprecated here + · +29 │ let foo: S = M::foo(); + │ ^ Use of deprecated module '0x42::M' + + +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_address.move b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_address.move new file mode 100644 index 0000000000000..368cb7469e473 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_address.move @@ -0,0 +1,34 @@ +#[deprecated] +address 0x42 { +module M { + use 0x41::N; + + struct S {} + + const C: u64 = 0; + + public fun foo(): N::S { let _foo = C + 3; N::bar() } + + spec foo {} +} +} + +module 0x41::N { + struct S has drop { } + + public fun bar(): S { S { } } + + public fun consume(_x: S) { } +} + +script { + use 0x42::M; + use 0x41::N::S; + + fun main() { + let foo: S = M::foo(); + 0x41::N::consume(foo); + } + + spec main { } +} diff --git a/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_address_module_members.exp b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_address_module_members.exp new file mode 100644 index 0000000000000..9e1d702f7c4a8 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_address_module_members.exp @@ -0,0 +1,76 @@ + +Diagnostics: +warning: Use of deprecated module + ┌─ tests/deprecated/deprecated_placement_address_module_members.move:33:9 + │ + 1 │ #[deprecated] // Think about using 0x43 instead + │ ---------- Module '0x42::M' deprecated here + · +33 │ use 0x42::M; + │ ^^^^^^^ Use of deprecated module '0x42::M' + +warning: Use of deprecated module + ┌─ tests/deprecated/deprecated_placement_address_module_members.move:34:9 + │ +20 │ #[deprecated] + │ ---------- Module '0x41::N' deprecated here + · +34 │ use 0x41::N::S; + │ ^^^^^^^ Use of deprecated module '0x41::N' + +warning: Use of deprecated struct + ┌─ tests/deprecated/deprecated_placement_address_module_members.move:34:18 + │ +22 │ #[deprecated] + │ ---------- Struct 'S' in module '0x41::N' deprecated here + · +34 │ use 0x41::N::S; + │ ^ Use of deprecated struct 'S' from module '0x41::N' + +warning: Use of deprecated struct + ┌─ tests/deprecated/deprecated_placement_address_module_members.move:37:11 + │ +22 │ #[deprecated] + │ ---------- Struct 'S' in module '0x41::N' deprecated here + · +37 │ let foo: S = M::foo(); + │ ^ Use of deprecated struct 'S' from module '0x41::N' + +warning: Use of deprecated module + ┌─ tests/deprecated/deprecated_placement_address_module_members.move:37:15 + │ + 1 │ #[deprecated] // Think about using 0x43 instead + │ ---------- Module '0x42::M' deprecated here + · +37 │ let foo: S = M::foo(); + │ ^ Use of deprecated module '0x42::M' + +warning: Use of deprecated function + ┌─ tests/deprecated/deprecated_placement_address_module_members.move:37:18 + │ +13 │ #[deprecated] + │ ---------- Function 'foo' in module '0x42::M' deprecated here + · +37 │ let foo: S = M::foo(); + │ ^^^ Use of deprecated function 'foo' from module '0x42::M' + +warning: Use of deprecated module + ┌─ tests/deprecated/deprecated_placement_address_module_members.move:38:2 + │ +20 │ #[deprecated] + │ ---------- Module '0x41::N' deprecated here + · +38 │ 0x41::N::consume(foo); + │ ^^^^^^^ Use of deprecated module '0x41::N' + +warning: Use of deprecated function + ┌─ tests/deprecated/deprecated_placement_address_module_members.move:38:11 + │ +28 │ #[deprecated] + │ ---------- Function 'consume' in module '0x41::N' deprecated here + · +38 │ 0x41::N::consume(foo); + │ ^^^^^^^ Use of deprecated function 'consume' from module '0x41::N' + + +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_address_module_members.move b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_address_module_members.move new file mode 100644 index 0000000000000..361ac55d38042 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_address_module_members.move @@ -0,0 +1,42 @@ +#[deprecated] // Think about using 0x43 instead +address 0x42 { +#[deprecated] // Try module M2 +module M { + use 0x41::N; + + #[deprecated] + struct S {} + + #[deprecated] + const C: u64 = 0; + + #[deprecated] + public fun foo(): N::S { let _foo = C + 3; N::bar() } + + spec foo {} +} +} + +#[deprecated] +module 0x41::N { + #[deprecated] + struct S has drop { } + + #[deprecated] + public fun bar(): S { S { } } + + #[deprecated] + public fun consume(_x: S) { } +} + +script { + use 0x42::M; + use 0x41::N::S; + + fun main() { + let foo: S = M::foo(); + 0x41::N::consume(foo); + } + + spec main { } +} diff --git a/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_members.exp b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_members.exp new file mode 100644 index 0000000000000..c5aa40b0e3e3f --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_members.exp @@ -0,0 +1,40 @@ + +Diagnostics: +warning: Use of deprecated struct + ┌─ tests/deprecated/deprecated_placement_members.move:31:18 + │ +19 │ #[deprecated] + │ ---------- Struct 'S' in module '0x41::N' deprecated here + · +31 │ use 0x41::N::S; + │ ^ Use of deprecated struct 'S' from module '0x41::N' + +warning: Use of deprecated struct + ┌─ tests/deprecated/deprecated_placement_members.move:34:11 + │ +19 │ #[deprecated] + │ ---------- Struct 'S' in module '0x41::N' deprecated here + · +34 │ let foo: S = M::foo(); + │ ^ Use of deprecated struct 'S' from module '0x41::N' + +warning: Use of deprecated function + ┌─ tests/deprecated/deprecated_placement_members.move:34:18 + │ +11 │ #[deprecated] + │ ---------- Function 'foo' in module '0x42::M' deprecated here + · +34 │ let foo: S = M::foo(); + │ ^^^ Use of deprecated function 'foo' from module '0x42::M' + +warning: Use of deprecated function + ┌─ tests/deprecated/deprecated_placement_members.move:35:11 + │ +25 │ #[deprecated] + │ ---------- Function 'consume' in module '0x41::N' deprecated here + · +35 │ 0x41::N::consume(foo); + │ ^^^^^^^ Use of deprecated function 'consume' from module '0x41::N' + + +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_members.move b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_members.move new file mode 100644 index 0000000000000..c05b48447a29a --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_members.move @@ -0,0 +1,39 @@ +address 0x42 { +module M { + use 0x41::N; + + #[deprecated] + struct S {} + + #[deprecated] + const C: u64 = 0; + + #[deprecated] + public fun foo(): N::S { let _foo = C + 3; N::bar() } + + spec foo {} +} +} + +module 0x41::N { + #[deprecated] + struct S has drop { } + + #[deprecated] + public fun bar(): S { S { } } + + #[deprecated] + public fun consume(_x: S) { } +} + +script { + use 0x42::M; + use 0x41::N::S; + + fun main() { + let foo: S = M::foo(); + 0x41::N::consume(foo); + } + + spec main { } +} diff --git a/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_module.exp b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_module.exp new file mode 100644 index 0000000000000..68a6f21363dd5 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_module.exp @@ -0,0 +1,22 @@ + +Diagnostics: +warning: Use of deprecated module + ┌─ tests/deprecated/deprecated_placement_module.move:25:9 + │ + 2 │ #[deprecated] + │ ---------- Module '0x42::M' deprecated here + · +25 │ use 0x42::M; + │ ^^^^^^^ Use of deprecated module '0x42::M' + +warning: Use of deprecated module + ┌─ tests/deprecated/deprecated_placement_module.move:29:15 + │ + 2 │ #[deprecated] + │ ---------- Module '0x42::M' deprecated here + · +29 │ let foo: S = M::foo(); + │ ^ Use of deprecated module '0x42::M' + + +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_module.move b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_module.move new file mode 100644 index 0000000000000..7f2041ed6215a --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_module.move @@ -0,0 +1,34 @@ +address 0x42 { +#[deprecated] +module M { + use 0x41::N; + + struct S {} + + const C: u64 = 0; + + public fun foo(): N::S { let _foo = C + 3; N::bar() } + + spec foo {} +} +} + +module 0x41::N { + struct S has drop { } + + public fun bar(): S { S { } } + + public fun consume(_x: S) { } +} + +script { + use 0x42::M; + use 0x41::N::S; + + fun main() { + let foo: S = M::foo(); + 0x41::N::consume(foo); + } + + spec main { } +} diff --git a/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_module2.exp b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_module2.exp new file mode 100644 index 0000000000000..ab9447a567186 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_module2.exp @@ -0,0 +1,49 @@ + +Diagnostics: +warning: Use of deprecated module + ┌─ tests/deprecated/deprecated_placement_module2.move:3:9 + │ + 3 │ use 0x41::N; + │ ^^^^^^^ Use of deprecated module '0x41::N' + · +15 │ #[deprecated] + │ ---------- Module '0x41::N' deprecated here + +warning: Use of deprecated module + ┌─ tests/deprecated/deprecated_placement_module2.move:9:23 + │ + 9 │ public fun foo(): N::S { let _foo = C + 3; N::bar() } + │ ^ Use of deprecated module '0x41::N' + · +15 │ #[deprecated] + │ ---------- Module '0x41::N' deprecated here + +warning: Use of deprecated module + ┌─ tests/deprecated/deprecated_placement_module2.move:9:48 + │ + 9 │ public fun foo(): N::S { let _foo = C + 3; N::bar() } + │ ^ Use of deprecated module '0x41::N' + · +15 │ #[deprecated] + │ ---------- Module '0x41::N' deprecated here + +warning: Use of deprecated module + ┌─ tests/deprecated/deprecated_placement_module2.move:26:9 + │ +15 │ #[deprecated] + │ ---------- Module '0x41::N' deprecated here + · +26 │ use 0x41::N::S; + │ ^^^^^^^ Use of deprecated module '0x41::N' + +warning: Use of deprecated module + ┌─ tests/deprecated/deprecated_placement_module2.move:30:2 + │ +15 │ #[deprecated] + │ ---------- Module '0x41::N' deprecated here + · +30 │ 0x41::N::consume(foo); + │ ^^^^^^^ Use of deprecated module '0x41::N' + + +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_module2.move b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_module2.move new file mode 100644 index 0000000000000..a1a98631b86d8 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_module2.move @@ -0,0 +1,34 @@ +address 0x42 { +module M { + use 0x41::N; + + struct S {} + + const C: u64 = 0; + + public fun foo(): N::S { let _foo = C + 3; N::bar() } + + spec foo {} +} +} + +#[deprecated] +module 0x41::N { + struct S has drop { } + + public fun bar(): S { S { } } + + public fun consume(_x: S) { } +} + +script { + use 0x42::M; + use 0x41::N::S; + + fun main() { + let foo: S = M::foo(); + 0x41::N::consume(foo); + } + + spec main { } +} diff --git a/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_module_members.exp b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_module_members.exp new file mode 100644 index 0000000000000..d8e3badc5994f --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_module_members.exp @@ -0,0 +1,76 @@ + +Diagnostics: +warning: Use of deprecated module + ┌─ tests/deprecated/deprecated_placement_module_members.move:32:9 + │ + 2 │ #[deprecated] + │ ---------- Module '0x42::M' deprecated here + · +32 │ use 0x42::M; + │ ^^^^^^^ Use of deprecated module '0x42::M' + +warning: Use of deprecated module + ┌─ tests/deprecated/deprecated_placement_module_members.move:33:9 + │ +19 │ #[deprecated] + │ ---------- Module '0x41::N' deprecated here + · +33 │ use 0x41::N::S; + │ ^^^^^^^ Use of deprecated module '0x41::N' + +warning: Use of deprecated struct + ┌─ tests/deprecated/deprecated_placement_module_members.move:33:18 + │ +21 │ #[deprecated] + │ ---------- Struct 'S' in module '0x41::N' deprecated here + · +33 │ use 0x41::N::S; + │ ^ Use of deprecated struct 'S' from module '0x41::N' + +warning: Use of deprecated struct + ┌─ tests/deprecated/deprecated_placement_module_members.move:36:11 + │ +21 │ #[deprecated] + │ ---------- Struct 'S' in module '0x41::N' deprecated here + · +36 │ let foo: S = M::foo(); + │ ^ Use of deprecated struct 'S' from module '0x41::N' + +warning: Use of deprecated module + ┌─ tests/deprecated/deprecated_placement_module_members.move:36:15 + │ + 2 │ #[deprecated] + │ ---------- Module '0x42::M' deprecated here + · +36 │ let foo: S = M::foo(); + │ ^ Use of deprecated module '0x42::M' + +warning: Use of deprecated function + ┌─ tests/deprecated/deprecated_placement_module_members.move:36:18 + │ +12 │ #[deprecated] + │ ---------- Function 'foo' in module '0x42::M' deprecated here + · +36 │ let foo: S = M::foo(); + │ ^^^ Use of deprecated function 'foo' from module '0x42::M' + +warning: Use of deprecated module + ┌─ tests/deprecated/deprecated_placement_module_members.move:37:2 + │ +19 │ #[deprecated] + │ ---------- Module '0x41::N' deprecated here + · +37 │ 0x41::N::consume(foo); + │ ^^^^^^^ Use of deprecated module '0x41::N' + +warning: Use of deprecated function + ┌─ tests/deprecated/deprecated_placement_module_members.move:37:11 + │ +27 │ #[deprecated] + │ ---------- Function 'consume' in module '0x41::N' deprecated here + · +37 │ 0x41::N::consume(foo); + │ ^^^^^^^ Use of deprecated function 'consume' from module '0x41::N' + + +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_module_members.move b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_module_members.move new file mode 100644 index 0000000000000..e3b71a074b341 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/deprecated/deprecated_placement_module_members.move @@ -0,0 +1,41 @@ +address 0x42 { +#[deprecated] +module M { + use 0x41::N; + + #[deprecated] + struct S {} + + #[deprecated] + const C: u64 = 0; + + #[deprecated] + public fun foo(): N::S { let _foo = C + 3; N::bar() } + + spec foo {} +} +} + +#[deprecated] +module 0x41::N { + #[deprecated] + struct S has drop { } + + #[deprecated] + public fun bar(): S { S { } } + + #[deprecated] + public fun consume(_x: S) { } +} + +script { + use 0x42::M; + use 0x41::N::S; + + fun main() { + let foo: S = M::foo(); + 0x41::N::consume(foo); + } + + spec main { } +} diff --git a/third_party/move/move-compiler-v2/tests/deprecated/public_script.exp b/third_party/move/move-compiler-v2/tests/deprecated/public_script.exp new file mode 100644 index 0000000000000..1463c4ca97cdf --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/deprecated/public_script.exp @@ -0,0 +1,13 @@ + +Diagnostics: +warning: DEPRECATED. will be removed + ┌─ tests/deprecated/public_script.move:2:5 + │ +2 │ public(script) fun main() { + │ ^^^^^^^^^^^^^^ 'public(script)' is deprecated in favor of the 'entry' modifier. Replace with 'public entry' + +error: address with no value + ┌─ tests/deprecated/public_script.move:4:30 + │ +4 │ let _addr:address = @Test; + │ ^^^^ address 'Test' is not assigned a value. Try assigning it a value when calling the compiler diff --git a/third_party/move/move-compiler-v2/tests/deprecated/public_script.move b/third_party/move/move-compiler-v2/tests/deprecated/public_script.move new file mode 100644 index 0000000000000..d225e0f525526 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/deprecated/public_script.move @@ -0,0 +1,6 @@ +module 0x1::Test { + public(script) fun main() { + // Previously, deprecation plus an error led to a compiler assert. Make sure that doesn't come back. + let _addr:address = @Test; + } +} diff --git a/third_party/move/move-compiler-v2/tests/testsuite.rs b/third_party/move/move-compiler-v2/tests/testsuite.rs index 14d5be58213a7..e940d1aa6ab4e 100644 --- a/third_party/move/move-compiler-v2/tests/testsuite.rs +++ b/third_party/move/move-compiler-v2/tests/testsuite.rs @@ -198,7 +198,7 @@ const TEST_CONFIGS: Lazy> = Lazy::new(|| { dump_bytecode: DumpLevel::None, // do not dump anything dump_bytecode_filter: None, }, - // Tests for inlining, simplifier, and folding + // Tests for front-end, diagnostics (inlining, simplifier, folding, etc.) TestConfig { name: "inlining-et-al", runner: |p| run_test(p, get_config_by_name("inlining-et-al")), @@ -226,6 +226,20 @@ const TEST_CONFIGS: Lazy> = Lazy::new(|| { dump_bytecode: DumpLevel::None, // do not dump anything dump_bytecode_filter: None, }, + // Tests for diagnostics, where dumping AST isn't useful. + TestConfig { + name: "diagnostics", + runner: |p| run_test(p, get_config_by_name("diagnostics")), + include: vec!["/deprecated/"], + exclude: vec![], + exp_suffix: None, + options: opts.clone().set_experiment(Experiment::AST_SIMPLIFY, true), + // Run the entire compiler pipeline to double-check the result + stop_after: StopAfter::FileFormat, + dump_ast: DumpLevel::None, + dump_bytecode: DumpLevel::None, // do not dump anything + dump_bytecode_filter: None, + }, // --- Tests for bytecode generation TestConfig { name: "bytecode-gen", @@ -539,6 +553,39 @@ const TEST_CONFIGS: Lazy> = Lazy::new(|| { dump_bytecode: DumpLevel::None, dump_bytecode_filter: None, }, + // Test for verify on and off + TestConfig { + name: "verification", + runner: |p| run_test(p, get_config_by_name("verification")), + include: vec!["/verification/verify/"], + exclude: vec![], + exp_suffix: None, + options: opts + .clone() + .set_experiment(Experiment::AST_SIMPLIFY, true) + .set_compile_test_code(true), + // Run the entire compiler pipeline to double-check the result + stop_after: StopAfter::FileFormat, + dump_ast: DumpLevel::None, + dump_bytecode: DumpLevel::None, + dump_bytecode_filter: None, + }, + TestConfig { + name: "verification-off", + runner: |p| run_test(p, get_config_by_name("verification-off")), + include: vec!["/verification/noverify/"], + exclude: vec![], + exp_suffix: None, + options: opts + .clone() + .set_experiment(Experiment::AST_SIMPLIFY, true) + .set_compile_test_code(false), + // Run the entire compiler pipeline to double-check the result + stop_after: StopAfter::FileFormat, + dump_ast: DumpLevel::None, + dump_bytecode: DumpLevel::None, + dump_bytecode_filter: None, + }, TestConfig { name: "skip-attribute-checks", runner: |p| run_test(p, get_config_by_name("skip-attribute-checks")), @@ -574,6 +621,8 @@ fn run_test(path: &Path, config: TestConfig) -> datatest_stable::Result<()> { let path_str = path.display().to_string(); let mut options = config.options.clone(); options.warn_unused = path_str.contains("/unused/"); + options.warn_deprecated = path_str.contains("/deprecated/"); + options.compile_verify_code = path_str.contains("/verification/verify/"); options.sources_deps = extract_test_directives(path, "// dep:")?; options.sources = vec![path_str.clone()]; options.dependencies = if extract_test_directives(path, "// no-stdlib")?.is_empty() { diff --git a/third_party/move/move-compiler-v2/tests/unit_test/notest/function_with_spec.exp b/third_party/move/move-compiler-v2/tests/unit_test/notest/function_with_spec.exp new file mode 100644 index 0000000000000..ed74cc91d766e --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unit_test/notest/function_with_spec.exp @@ -0,0 +1,7 @@ + +Diagnostics: +error: unresolved spec target + ┌─ tests/unit_test/notest/function_with_spec.move:18:10 + │ +18 │ spec baz { + │ ^^^ diff --git a/third_party/move/move-compiler-v2/tests/unit_test/notest/function_with_spec.move b/third_party/move/move-compiler-v2/tests/unit_test/notest/function_with_spec.move new file mode 100644 index 0000000000000..ed9d79304088e --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unit_test/notest/function_with_spec.move @@ -0,0 +1,22 @@ +// #[test_only] functions should be filtered out in non-test mode +address 0x1234 { +module M { + public fun foo() { } + + #[test] + public fun bar_test() { bar() } + + #[test_only] + public fun bar() { } + + // This should not cause an error in either test- nor non-test-mode. + spec bar { + aborts_if false; + } + + // This should always cause an error due to typo. + spec baz { + aborts_if false; + } +} +} diff --git a/third_party/move/move-compiler-v2/tests/unit_test/test/function_with_spec.exp b/third_party/move/move-compiler-v2/tests/unit_test/test/function_with_spec.exp new file mode 100644 index 0000000000000..fbcda8c812a5b --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unit_test/test/function_with_spec.exp @@ -0,0 +1,10 @@ + +Diagnostics: +error: unresolved spec target + ┌─ tests/unit_test/test/function_with_spec.move:18:10 + │ +18 │ spec baz { + │ ^^^ + + +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/unit_test/test/function_with_spec.move b/third_party/move/move-compiler-v2/tests/unit_test/test/function_with_spec.move new file mode 100644 index 0000000000000..ed9d79304088e --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unit_test/test/function_with_spec.move @@ -0,0 +1,22 @@ +// #[test_only] functions should be filtered out in non-test mode +address 0x1234 { +module M { + public fun foo() { } + + #[test] + public fun bar_test() { bar() } + + #[test_only] + public fun bar() { } + + // This should not cause an error in either test- nor non-test-mode. + spec bar { + aborts_if false; + } + + // This should always cause an error due to typo. + spec baz { + aborts_if false; + } +} +} diff --git a/third_party/move/move-compiler-v2/tests/v1.matched b/third_party/move/move-compiler-v2/tests/v1.matched index 25a816e67c53f..56577566e080d 100644 --- a/third_party/move/move-compiler-v2/tests/v1.matched +++ b/third_party/move/move-compiler-v2/tests/v1.matched @@ -1,3 +1,6 @@ +WARNING: test `move-compiler-v2/tests/more-v1/verification/cross_module_valid.verification.move` and `move-compiler-v2/tests/more-v1/verification/verify/cross_module_valid.move` share common key `verification/cross_module_valid.verification.move`, discarding former one +WARNING: test `move-compiler-v2/tests/more-v1/verification/double_annotation.verification.move` and `move-compiler-v2/tests/more-v1/verification/verify/double_annotation.move` share common key `verification/double_annotation.verification.move`, discarding former one +WARNING: test `move-compiler-v2/tests/more-v1/verification/single_module_valid.verification.move` and `move-compiler-v2/tests/more-v1/verification/verify/single_module_valid.move` share common key `verification/single_module_valid.verification.move`, discarding former one move-compiler/tests/move_check/translated_ir_tests/move/borrow_tests/borrow_global_acquires_1.exp move-compiler-v2/tests/acquires-checker/v1-borrow-tests/borrow_global_acquires_1.exp move-compiler/tests/move_check/translated_ir_tests/move/borrow_tests/borrow_global_acquires_2.exp move-compiler-v2/tests/acquires-checker/v1-borrow-tests/borrow_global_acquires_2.exp move-compiler/tests/move_check/translated_ir_tests/move/borrow_tests/borrow_global_acquires_3.exp move-compiler-v2/tests/acquires-checker/v1-borrow-tests/borrow_global_acquires_3.exp @@ -152,6 +155,17 @@ move-compiler/tests/move_check/translated_ir_tests/move/commands/use_before_assi move-compiler/tests/move_check/control_flow/for_loop_empty_novar.exp move-compiler-v2/tests/checking/control_flow/for_loop_empty_novar.exp move-compiler/tests/move_check/control_flow/for_type_mismatch.exp move-compiler-v2/tests/checking/control_flow/for_type_mismatch.exp move-compiler/tests/move_check/control_flow/loop_after_loop.exp move-compiler-v2/tests/checking/control_flow/loop_after_loop.exp +move-compiler/tests/move_check/deprecated/deprecated_constant_duplicated_struct.exp move-compiler-v2/tests/more-v1/deprecated/deprecated_constant_duplicated_struct.exp +move-compiler/tests/move_check/deprecated/deprecated_constant_duplicated_struct2.exp move-compiler-v2/tests/more-v1/deprecated/deprecated_constant_duplicated_struct2.exp +move-compiler/tests/move_check/deprecated/deprecated_field_type.exp move-compiler-v2/tests/more-v1/deprecated/deprecated_field_type.exp +move-compiler/tests/move_check/deprecated/deprecated_field_type2.exp move-compiler-v2/tests/more-v1/deprecated/deprecated_field_type2.exp +move-compiler/tests/move_check/deprecated/deprecated_placement_address.exp move-compiler-v2/tests/more-v1/deprecated/deprecated_placement_address.exp +move-compiler/tests/move_check/deprecated/deprecated_placement_address_module_members.exp move-compiler-v2/tests/more-v1/deprecated/deprecated_placement_address_module_members.exp +move-compiler/tests/move_check/deprecated/deprecated_placement_members.exp move-compiler-v2/tests/more-v1/deprecated/deprecated_placement_members.exp +move-compiler/tests/move_check/deprecated/deprecated_placement_module.exp move-compiler-v2/tests/more-v1/deprecated/deprecated_placement_module.exp +move-compiler/tests/move_check/deprecated/deprecated_placement_module2.exp move-compiler-v2/tests/more-v1/deprecated/deprecated_placement_module2.exp +move-compiler/tests/move_check/deprecated/deprecated_placement_module_members.exp move-compiler-v2/tests/more-v1/deprecated/deprecated_placement_module_members.exp +move-compiler/tests/move_check/deprecated/public_script.exp move-compiler-v2/tests/more-v1/deprecated/public_script.exp move-compiler/tests/move_check/folding/empty_vectors.exp move-compiler-v2/tests/folding/empty_vectors.exp move-compiler/tests/move_check/folding/empty_vectors2.exp move-compiler-v2/tests/folding/empty_vectors2.exp move-compiler/tests/move_check/folding/non_constant_empty_vec.exp move-compiler-v2/tests/folding/non_constant_empty_vec.exp @@ -623,3 +637,12 @@ move-compiler/tests/move_check/unit_test/test_filter_function.exp move-compile move-compiler/tests/move_check/unit_test/test_filter_struct.exp move-compiler-v2/tests/unit_test/notest/test_filter_struct.exp move-compiler/tests/move_check/unit_test/valid_test_module.exp move-compiler-v2/tests/unit_test/notest/valid_test_module.exp move-compiler/tests/move_check/unit_test/valid_test_module.unit_test.exp move-compiler-v2/tests/unit_test/test/valid_test_module.exp +move-compiler/tests/move_check/verification/cross_module_invalid.exp move-compiler-v2/tests/more-v1/verification/noverify/cross_module_invalid.exp +move-compiler/tests/move_check/verification/cross_module_valid.exp move-compiler-v2/tests/more-v1/verification/noverify/cross_module_valid.exp +move-compiler/tests/move_check/verification/cross_module_valid.verification.exp move-compiler-v2/tests/more-v1/verification/verify/cross_module_valid.exp +move-compiler/tests/move_check/verification/double_annotation.exp move-compiler-v2/tests/more-v1/verification/noverify/double_annotation.exp +move-compiler/tests/move_check/verification/double_annotation.verification.exp move-compiler-v2/tests/more-v1/verification/verify/double_annotation.exp +move-compiler/tests/move_check/verification/single_module_invalid.exp move-compiler-v2/tests/more-v1/verification/noverify/single_module_invalid.exp +move-compiler/tests/move_check/verification/single_module_invalid.verification.exp move-compiler-v2/tests/more-v1/verification/single_module_invalid.verification.exp +move-compiler/tests/move_check/verification/single_module_valid.exp move-compiler-v2/tests/more-v1/verification/noverify/single_module_valid.exp +move-compiler/tests/move_check/verification/single_module_valid.verification.exp move-compiler-v2/tests/more-v1/verification/verify/single_module_valid.exp diff --git a/third_party/move/move-compiler-v2/tests/v1.unmatched b/third_party/move/move-compiler-v2/tests/v1.unmatched index f2ad6f0903cec..9ee038364c30c 100644 --- a/third_party/move/move-compiler-v2/tests/v1.unmatched +++ b/third_party/move/move-compiler-v2/tests/v1.unmatched @@ -1,3 +1,6 @@ +WARNING: test `move-compiler-v2/tests/more-v1/verification/cross_module_valid.verification.move` and `move-compiler-v2/tests/more-v1/verification/verify/cross_module_valid.move` share common key `verification/cross_module_valid.verification.move`, discarding former one +WARNING: test `move-compiler-v2/tests/more-v1/verification/double_annotation.verification.move` and `move-compiler-v2/tests/more-v1/verification/verify/double_annotation.move` share common key `verification/double_annotation.verification.move`, discarding former one +WARNING: test `move-compiler-v2/tests/more-v1/verification/single_module_valid.verification.move` and `move-compiler-v2/tests/more-v1/verification/verify/single_module_valid.move` share common key `verification/single_module_valid.verification.move`, discarding former one move-compiler/tests/move_check/borrow_tests/{ borrow_global_acquires_duplicate_annotation.move, eq_bad.move, @@ -31,18 +34,7 @@ move-compiler/tests/move_check/control_flow/{ } move-compiler/tests/move_check/deprecated/{ assert_function.move, - deprecated_constant_duplicated_struct.move, - deprecated_constant_duplicated_struct2.move, - deprecated_field_type.move, - deprecated_field_type2.move, - deprecated_placement_address.move, - deprecated_placement_address_module_members.move, deprecated_placement_basecase.move, - deprecated_placement_members.move, - deprecated_placement_module.move, - deprecated_placement_module2.move, - deprecated_placement_module_members.move, - public_script.move, } move-compiler/tests/move_check/examples/{ multi_pool_money_market_token.move, @@ -279,10 +271,3 @@ move-compiler/tests/move_check/typing/{ move-compiler/tests/move_check/v2-not-supported/{ no_receiver_calls.move, } -move-compiler/tests/move_check/verification/{ - cross_module_invalid.move, - cross_module_valid.move, - double_annotation.move, - single_module_invalid.move, - single_module_valid.move, -} diff --git a/third_party/move/move-compiler-v2/tests/verification/cross_module_valid.verification b/third_party/move/move-compiler-v2/tests/verification/cross_module_valid.verification new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/third_party/move/move-compiler-v2/tests/verification/double_annotation.verification b/third_party/move/move-compiler-v2/tests/verification/double_annotation.verification new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/third_party/move/move-compiler-v2/tests/verification/noverify/cross_module_invalid.exp b/third_party/move/move-compiler-v2/tests/verification/noverify/cross_module_invalid.exp new file mode 100644 index 0000000000000..ca9e9067e0ff9 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/verification/noverify/cross_module_invalid.exp @@ -0,0 +1,7 @@ + +Diagnostics: +error: unbound module + ┌─ tests/verification/noverify/cross_module_invalid.move:23:9 + │ +23 │ A::build_foo() + │ ^ Unbound module or type alias 'A' diff --git a/third_party/move/move-compiler-v2/tests/verification/noverify/cross_module_invalid.move b/third_party/move/move-compiler-v2/tests/verification/noverify/cross_module_invalid.move new file mode 100644 index 0000000000000..9d78d065a3d6c --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/verification/noverify/cross_module_invalid.move @@ -0,0 +1,26 @@ +// check that `use`'s are filtered out correctly +address 0x1 { +module A { + struct Foo has drop {} + + public fun build_foo(): Foo { Foo {} } +} + +module B { + #[verify_only] + use 0x1::A::{Self, Foo}; + + #[verify_only] + fun x(_: Foo) { } + + #[verify_only] + fun tester() { + x(A::build_foo()) + } + + // this should fail + public fun bad(): Foo { + A::build_foo() + } +} +} diff --git a/third_party/move/move-compiler-v2/tests/verification/noverify/cross_module_valid.exp b/third_party/move/move-compiler-v2/tests/verification/noverify/cross_module_valid.exp new file mode 100644 index 0000000000000..90b32906711cc --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/verification/noverify/cross_module_valid.exp @@ -0,0 +1,2 @@ + +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/verification/noverify/cross_module_valid.move b/third_party/move/move-compiler-v2/tests/verification/noverify/cross_module_valid.move new file mode 100644 index 0000000000000..c141dc283e65f --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/verification/noverify/cross_module_valid.move @@ -0,0 +1,24 @@ +// Check that verify_only filtering and calling is supported across modules and +// different types of module members +address 0x1 { +module A { + #[verify_only] + struct Foo has drop {} + + #[verify_only] + public fun build_foo(): Foo { Foo {} } +} + +module B { + #[verify_only] + use 0x1::A::{Self, Foo}; + + #[verify_only] + fun x(_: Foo) { } + + #[verify_only] + fun tester() { + x(A::build_foo()) + } +} +} diff --git a/third_party/move/move-compiler-v2/tests/verification/noverify/double_annotation.exp b/third_party/move/move-compiler-v2/tests/verification/noverify/double_annotation.exp new file mode 100644 index 0000000000000..90b32906711cc --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/verification/noverify/double_annotation.exp @@ -0,0 +1,2 @@ + +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/verification/noverify/double_annotation.move b/third_party/move/move-compiler-v2/tests/verification/noverify/double_annotation.move new file mode 100644 index 0000000000000..60f63be52a624 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/verification/noverify/double_annotation.move @@ -0,0 +1,21 @@ +address 0x1 { +module M { + #[verify_only] + struct Foo {} + + // failure: double annotation + #[verify_only] + #[verify_only] + struct Bar {} + + public fun foo() { } + + #[verify_only] + public fun bar() { } + + // failure: double annotation + #[verify_only] + #[verify_only] + public fun d(_a: signer, _b: signer) { } +} +} diff --git a/third_party/move/move-compiler-v2/tests/verification/noverify/function_with_spec.exp b/third_party/move/move-compiler-v2/tests/verification/noverify/function_with_spec.exp new file mode 100644 index 0000000000000..ea64cb0f09875 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/verification/noverify/function_with_spec.exp @@ -0,0 +1,7 @@ + +Diagnostics: +error: unresolved spec target + ┌─ tests/verification/noverify/function_with_spec.move:15:10 + │ +15 │ spec baz { + │ ^^^ diff --git a/third_party/move/move-compiler-v2/tests/verification/noverify/function_with_spec.move b/third_party/move/move-compiler-v2/tests/verification/noverify/function_with_spec.move new file mode 100644 index 0000000000000..4671968e37fd2 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/verification/noverify/function_with_spec.move @@ -0,0 +1,19 @@ +// #[test_only] functions should be filtered out in non-test mode +address 0x1234 { +module M { + public fun foo() { } + + #[verify_only] + public fun bar() { } + + // This should not cause an error in either test- nor non-test-mode. + spec bar { + aborts_if false; + } + + // This should always cause an error due to typo. + spec baz { + aborts_if false; + } +} +} diff --git a/third_party/move/move-compiler-v2/tests/verification/noverify/single_module_invalid.exp b/third_party/move/move-compiler-v2/tests/verification/noverify/single_module_invalid.exp new file mode 100644 index 0000000000000..232c3ee5c36c7 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/verification/noverify/single_module_invalid.exp @@ -0,0 +1,19 @@ + +Diagnostics: +error: undeclared `0x1::M::Foo` + ┌─ tests/verification/noverify/single_module_invalid.move:8:23 + │ +8 │ public fun foo(): Foo { + │ ^^^ + +error: undeclared struct `M::Foo` + ┌─ tests/verification/noverify/single_module_invalid.move:9:9 + │ +9 │ Foo {} + │ ^^^ + +error: no function named `bar` found + ┌─ tests/verification/noverify/single_module_invalid.move:17:24 + │ +17 │ public fun baz() { bar() } + │ ^^^^^ diff --git a/third_party/move/move-compiler-v2/tests/verification/noverify/single_module_invalid.move b/third_party/move/move-compiler-v2/tests/verification/noverify/single_module_invalid.move new file mode 100644 index 0000000000000..06043755f6307 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/verification/noverify/single_module_invalid.move @@ -0,0 +1,19 @@ +address 0x1 { +module M { + #[verify_only] + struct Foo {} + + // This should cause an unbound type error in non-verify mode + // as the Foo struct declaration was filtered out + public fun foo(): Foo { + Foo {} + } + + #[verify_only] + public fun bar() { } + + // This should cause an unbound function error in non-verify mode + // as `bar` was filtered out + public fun baz() { bar() } +} +} diff --git a/third_party/move/move-compiler-v2/tests/verification/noverify/single_module_valid.exp b/third_party/move/move-compiler-v2/tests/verification/noverify/single_module_valid.exp new file mode 100644 index 0000000000000..90b32906711cc --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/verification/noverify/single_module_valid.exp @@ -0,0 +1,2 @@ + +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/verification/noverify/single_module_valid.move b/third_party/move/move-compiler-v2/tests/verification/noverify/single_module_valid.move new file mode 100644 index 0000000000000..a50d4ab3cf7da --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/verification/noverify/single_module_valid.move @@ -0,0 +1,16 @@ +// Make sure that legal usage is allowed +module 0x1::M { + // verify-only struct + #[verify_only] + struct Foo {} + + public fun foo() { } + + // verify-only struct used in a verify-only function + #[verify_only] + public fun bar(): Foo { Foo{} } + + // verify-only function used in a verify-only function + #[verify_only] + public fun baz(): Foo { bar() } +} diff --git a/third_party/move/move-compiler-v2/tests/verification/single_module_invalid.verification b/third_party/move/move-compiler-v2/tests/verification/single_module_invalid.verification new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/third_party/move/move-compiler-v2/tests/verification/single_module_valid.verification b/third_party/move/move-compiler-v2/tests/verification/single_module_valid.verification new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/third_party/move/move-compiler-v2/tests/verification/verify/cross_module_valid.exp b/third_party/move/move-compiler-v2/tests/verification/verify/cross_module_valid.exp new file mode 100644 index 0000000000000..90b32906711cc --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/verification/verify/cross_module_valid.exp @@ -0,0 +1,2 @@ + +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/verification/verify/cross_module_valid.move b/third_party/move/move-compiler-v2/tests/verification/verify/cross_module_valid.move new file mode 100644 index 0000000000000..c141dc283e65f --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/verification/verify/cross_module_valid.move @@ -0,0 +1,24 @@ +// Check that verify_only filtering and calling is supported across modules and +// different types of module members +address 0x1 { +module A { + #[verify_only] + struct Foo has drop {} + + #[verify_only] + public fun build_foo(): Foo { Foo {} } +} + +module B { + #[verify_only] + use 0x1::A::{Self, Foo}; + + #[verify_only] + fun x(_: Foo) { } + + #[verify_only] + fun tester() { + x(A::build_foo()) + } +} +} diff --git a/third_party/move/move-compiler-v2/tests/verification/verify/double_annotation.exp b/third_party/move/move-compiler-v2/tests/verification/verify/double_annotation.exp new file mode 100644 index 0000000000000..fbc781f959cb2 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/verification/verify/double_annotation.exp @@ -0,0 +1,20 @@ + +Diagnostics: +error: duplicate declaration, item, or annotation + ┌─ tests/verification/verify/double_annotation.move:8:7 + │ +7 │ #[verify_only] + │ ----------- Attribute previously given here +8 │ #[verify_only] + │ ^^^^^^^^^^^ Duplicate attribute 'verify_only' attached to the same item + +error: duplicate declaration, item, or annotation + ┌─ tests/verification/verify/double_annotation.move:18:7 + │ +17 │ #[verify_only] + │ ----------- Attribute previously given here +18 │ #[verify_only] + │ ^^^^^^^^^^^ Duplicate attribute 'verify_only' attached to the same item + + +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/verification/verify/double_annotation.move b/third_party/move/move-compiler-v2/tests/verification/verify/double_annotation.move new file mode 100644 index 0000000000000..60f63be52a624 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/verification/verify/double_annotation.move @@ -0,0 +1,21 @@ +address 0x1 { +module M { + #[verify_only] + struct Foo {} + + // failure: double annotation + #[verify_only] + #[verify_only] + struct Bar {} + + public fun foo() { } + + #[verify_only] + public fun bar() { } + + // failure: double annotation + #[verify_only] + #[verify_only] + public fun d(_a: signer, _b: signer) { } +} +} diff --git a/third_party/move/move-compiler-v2/tests/verification/verify/function_with_spec.exp b/third_party/move/move-compiler-v2/tests/verification/verify/function_with_spec.exp new file mode 100644 index 0000000000000..47f7a09cccdad --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/verification/verify/function_with_spec.exp @@ -0,0 +1,10 @@ + +Diagnostics: +error: unresolved spec target + ┌─ tests/verification/verify/function_with_spec.move:15:10 + │ +15 │ spec baz { + │ ^^^ + + +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/verification/verify/function_with_spec.move b/third_party/move/move-compiler-v2/tests/verification/verify/function_with_spec.move new file mode 100644 index 0000000000000..4671968e37fd2 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/verification/verify/function_with_spec.move @@ -0,0 +1,19 @@ +// #[test_only] functions should be filtered out in non-test mode +address 0x1234 { +module M { + public fun foo() { } + + #[verify_only] + public fun bar() { } + + // This should not cause an error in either test- nor non-test-mode. + spec bar { + aborts_if false; + } + + // This should always cause an error due to typo. + spec baz { + aborts_if false; + } +} +} diff --git a/third_party/move/move-compiler-v2/tests/verification/verify/single_module_valid.exp b/third_party/move/move-compiler-v2/tests/verification/verify/single_module_valid.exp new file mode 100644 index 0000000000000..90b32906711cc --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/verification/verify/single_module_valid.exp @@ -0,0 +1,2 @@ + +============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/verification/verify/single_module_valid.move b/third_party/move/move-compiler-v2/tests/verification/verify/single_module_valid.move new file mode 100644 index 0000000000000..a50d4ab3cf7da --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/verification/verify/single_module_valid.move @@ -0,0 +1,16 @@ +// Make sure that legal usage is allowed +module 0x1::M { + // verify-only struct + #[verify_only] + struct Foo {} + + public fun foo() { } + + // verify-only struct used in a verify-only function + #[verify_only] + public fun bar(): Foo { Foo{} } + + // verify-only function used in a verify-only function + #[verify_only] + public fun baz(): Foo { bar() } +} diff --git a/third_party/move/move-compiler-v2/tools/testdiff/src/main.rs b/third_party/move/move-compiler-v2/tools/testdiff/src/main.rs index cc33da8171255..c3c7b93ebaf3b 100644 --- a/third_party/move/move-compiler-v2/tools/testdiff/src/main.rs +++ b/third_party/move/move-compiler-v2/tools/testdiff/src/main.rs @@ -97,8 +97,8 @@ static UNIT_PATH_REMAP: Lazy> = Lazy::new(|| { ("acquires-checker/v1-borrow-tests", "borrow_tests"), ("attributes", "parser"), ("unit_test/notest", "unit_test"), - // Map file v2../unit_test/test/foo.move - // to file v1../unit_test/foo.unit_test.move. + // Map file v2../unit_test/test/foo.exp + // to file v1../unit_test/foo.unit_test.exp. ("unit_test/test", "unit_test.unit_test"), ("unused-assignment/v1-locals", "locals"), ("unused-assignment/v1-liveness", "liveness"), @@ -108,6 +108,10 @@ static UNIT_PATH_REMAP: Lazy> = Lazy::new(|| { ("ability-check/v1-signer", "signer"), ("ability-check/v1-borrow-tests", "commands"), ("ability-check/v1-locals", "locals"), + ("verification/noverify", "verification"), + // Map file v2../verification/verify/foo.exp + // to file v1../verification/foo.verification.exp. + ("verification/verify", "verification.verification"), ] }); @@ -205,7 +209,7 @@ fn collect_tests(root: &str) -> anyhow::Result> { let path_str = path.display().to_string(); if path_str.ends_with(".move") { result.insert(path); - } else if path_str.ends_with(".unit_test") { + } else if path_str.ends_with(".unit_test") || path_str.ends_with(".verification") { result.insert(PathBuf::from(format!("{}.{}", path_str, "move"))); } } diff --git a/third_party/move/move-compiler-v2/transactional-tests/tests/v1.matched b/third_party/move/move-compiler-v2/transactional-tests/tests/v1.matched index fecee90c8f243..db793a356d40e 100644 --- a/third_party/move/move-compiler-v2/transactional-tests/tests/v1.matched +++ b/third_party/move/move-compiler-v2/transactional-tests/tests/v1.matched @@ -1,5 +1,7 @@ move-compiler/transactional-tests/tests/constants/by_reference.exp move-compiler-v2/transactional-tests/tests/constants/by_reference.exp move-compiler/transactional-tests/tests/constants/default_int_size.exp move-compiler-v2/transactional-tests/tests/constants/default_int_size.exp +move-compiler/transactional-tests/tests/constants/empty_vectors.exp move-compiler-v2/transactional-tests/tests/constants/empty_vectors.exp +move-compiler/transactional-tests/tests/constants/empty_vectors2.exp move-compiler-v2/transactional-tests/tests/constants/empty_vectors2.exp move-compiler/transactional-tests/tests/constants/folding_boolean.exp move-compiler-v2/transactional-tests/tests/constants/folding_boolean.exp move-compiler/transactional-tests/tests/constants/folding_complex.exp move-compiler-v2/transactional-tests/tests/constants/folding_complex.exp move-compiler/transactional-tests/tests/constants/folding_equality.exp move-compiler-v2/transactional-tests/tests/constants/folding_equality.exp @@ -8,8 +10,9 @@ move-compiler/transactional-tests/tests/constants/folding_values.exp move-comp move-compiler/transactional-tests/tests/constants/folding_vector.exp move-compiler-v2/transactional-tests/tests/constants/folding_vector.exp move-compiler/transactional-tests/tests/constants/folding_vector_large.exp move-compiler-v2/transactional-tests/tests/constants/folding_vector_large.exp move-compiler/transactional-tests/tests/constants/non_constant_empty_vec.exp move-compiler-v2/transactional-tests/tests/constants/non_constant_empty_vec.exp +move-compiler/transactional-tests/tests/constants/nonempty_vectors.exp move-compiler-v2/transactional-tests/tests/constants/nonempty_vectors.exp move-compiler/transactional-tests/tests/control_flow/assert_in_while.exp move-compiler-v2/transactional-tests/tests/control_flow/assert_in_while.exp -move-compiler/transactional-tests/tests/control_flow/binop_eval_order.exp move-compiler-v2/transactional-tests/tests/control_flow/binop_eval_order.exp +move-compiler/transactional-tests/tests/control_flow/binop_eval_order.exp move-compiler-v2/transactional-tests/tests/operator_eval/control_flow/binop_eval_order.exp move-compiler/transactional-tests/tests/control_flow/branch_assigns_then_moves_then_assigns.exp move-compiler-v2/transactional-tests/tests/control_flow/branch_assigns_then_moves_then_assigns.exp move-compiler/transactional-tests/tests/control_flow/break_accumulator.exp move-compiler-v2/transactional-tests/tests/control_flow/break_accumulator.exp move-compiler/transactional-tests/tests/control_flow/break_continue_for_loop.exp move-compiler-v2/transactional-tests/tests/control_flow/break_continue_for_loop.exp diff --git a/third_party/move/move-compiler/src/parser/filter.rs b/third_party/move/move-compiler/src/parser/filter.rs index c205a3ffa36ed..fe09adcb4af28 100644 --- a/third_party/move/move-compiler/src/parser/filter.rs +++ b/third_party/move/move-compiler/src/parser/filter.rs @@ -2,8 +2,13 @@ // Copyright (c) The Move Contributors // SPDX-License-Identifier: Apache-2.0 -use crate::parser::ast as P; +use crate::parser::{ + ast as P, + ast::{ModuleMember, SpecBlockTarget_}, +}; use move_ir_types::location::sp; +use move_symbol_pool::Symbol; +use std::collections::BTreeSet; /// A trait that decides whether to include a parsed element in the compilation pub trait FilterContext { @@ -56,8 +61,10 @@ pub trait FilterContext { &mut self, function_def: P::Function, is_source_def: bool, + filtered_members: &mut BTreeSet, ) -> Option { if self.should_remove_by_attributes(&function_def.attributes, is_source_def) { + filtered_members.insert(function_def.name.0.value); None } else { Some(function_def) @@ -68,8 +75,10 @@ pub trait FilterContext { &mut self, struct_def: P::StructDefinition, is_source_def: bool, + filtered_members: &mut BTreeSet, ) -> Option { if self.should_remove_by_attributes(&struct_def.attributes, is_source_def) { + filtered_members.insert(struct_def.name.0.value); None } else { Some(struct_def) @@ -233,7 +242,8 @@ fn filter_script( // This is a bit weird, if the only function in the script is filtered, we consider // the whole script is filtered as well - let new_function = context.filter_map_function(function, is_source_def)?; + let new_function = + context.filter_map_function(function, is_source_def, &mut BTreeSet::new())?; let new_uses = uses .into_iter() @@ -278,9 +288,29 @@ fn filter_module( members, } = module_def; + // Collected filtered members in this set (functions and structs) + let mut filtered_members = BTreeSet::new(); + let new_members: Vec<_> = members .into_iter() - .filter_map(|member| filter_module_member(context, member, is_source_def)) + .filter_map(|member| { + filter_module_member(context, member, is_source_def, &mut filtered_members) + }) + .collect(); + + // Now remove all spec blocks for members which are filtered out + let new_members_filtered_spec_blocks = new_members + .into_iter() + .filter(|mem| { + if let ModuleMember::Spec(spec) = mem { + if let SpecBlockTarget_::Member(name, _) = &spec.value.target.value { + if filtered_members.contains(&name.value) { + return false; + } + } + } + true + }) .collect(); Some(P::ModuleDefinition { @@ -289,7 +319,7 @@ fn filter_module( address, name, is_spec_module, - members: new_members, + members: new_members_filtered_spec_blocks, }) } @@ -297,15 +327,16 @@ fn filter_module_member( context: &mut T, module_member: P::ModuleMember, is_source_def: bool, + filtered_members: &mut BTreeSet, ) -> Option { use P::ModuleMember as PM; match module_member { PM::Function(func_def) => context - .filter_map_function(func_def, is_source_def) + .filter_map_function(func_def, is_source_def, filtered_members) .map(PM::Function), PM::Struct(struct_def) => context - .filter_map_struct(struct_def, is_source_def) + .filter_map_struct(struct_def, is_source_def, filtered_members) .map(PM::Struct), PM::Spec(sp!(spec_loc, spec)) => context .filter_map_spec(spec, is_source_def) diff --git a/third_party/move/move-compiler/src/shared/mod.rs b/third_party/move/move-compiler/src/shared/mod.rs index c14b9ce386ac9..2a5c50f9a6ada 100644 --- a/third_party/move/move-compiler/src/shared/mod.rs +++ b/third_party/move/move-compiler/src/shared/mod.rs @@ -481,6 +481,13 @@ impl Flags { } } + pub fn set_verify(self, value: bool) -> Self { + Self { + verify: value, + ..self + } + } + pub fn set_keep_testing_functions(self, value: bool) -> Self { Self { keep_testing_functions: value, diff --git a/third_party/move/move-model/src/lib.rs b/third_party/move/move-model/src/lib.rs index dcc5b81e66fe0..d6d795ca5f67d 100644 --- a/third_party/move/move-model/src/lib.rs +++ b/third_party/move/move-model/src/lib.rs @@ -90,7 +90,10 @@ pub fn run_model_builder_in_compiler_mode( skip_attribute_checks: bool, known_attributes: &BTreeSet, language_version: LanguageVersion, + warn_of_deprecation_use: bool, + warn_of_deprecation_use_in_aptos_libs: bool, compile_test_code: bool, + compile_verify_code: bool, ) -> anyhow::Result { let to_package_paths = |PackageInfo { sources, @@ -110,7 +113,10 @@ pub fn run_model_builder_in_compiler_mode( ..ModelBuilderOptions::default() }, Flags::model_compilation() + .set_warn_of_deprecation_use(warn_of_deprecation_use) + .set_warn_of_deprecation_use_in_aptos_libs(warn_of_deprecation_use_in_aptos_libs) .set_skip_attribute_checks(skip_attribute_checks) + .set_verify(compile_verify_code) .set_keep_testing_functions(compile_test_code) .set_lang_v2(language_version != LanguageVersion::V1) .set_compiler_v2(true), diff --git a/third_party/move/move-prover/src/lib.rs b/third_party/move/move-prover/src/lib.rs index 9cf607d374075..d5f4e9f308463 100644 --- a/third_party/move/move-prover/src/lib.rs +++ b/third_party/move/move-prover/src/lib.rs @@ -84,9 +84,12 @@ pub fn run_move_prover_v2( experiment_cache: Default::default(), sources: cloned_options.move_sources, sources_deps: vec![], + warn_deprecated: false, + warn_of_deprecation_use_in_aptos_libs: false, warn_unused: false, whole_program: false, compile_test_code: false, + compile_verify_code: true, }; let mut env = move_compiler_v2::run_move_compiler_for_analysis(error_writer, compiler_options)?; diff --git a/third_party/move/tools/move-package/tests/test_sources/compilation/std-lib-conflicts/Move.v2_exp b/third_party/move/tools/move-package/tests/test_sources/compilation/std-lib-conflicts/Move.v2_exp new file mode 100644 index 0000000000000..842d430239fea --- /dev/null +++ b/third_party/move/tools/move-package/tests/test_sources/compilation/std-lib-conflicts/Move.v2_exp @@ -0,0 +1,53 @@ +CompiledPackageInfo { + package_name: "std-lib-conflicts", + address_alias_instantiation: { + "A": 0000000000000000000000000000000000000000000000000000000000000042, + "B": 0000000000000000000000000000000000000000000000000000000000000043, + "Extensions": 0000000000000000000000000000000000000000000000000000000000000001, + "aptos_framework": 0000000000000000000000000000000000000000000000000000000000000001, + "aptos_fungible_asset": 000000000000000000000000000000000000000000000000000000000000000a, + "aptos_std": 0000000000000000000000000000000000000000000000000000000000000001, + "aptos_token": 0000000000000000000000000000000000000000000000000000000000000003, + "core_resources": 000000000000000000000000000000000000000000000000000000000a550c18, + "std": 0000000000000000000000000000000000000000000000000000000000000001, + "vm": 0000000000000000000000000000000000000000000000000000000000000000, + "vm_reserved": 0000000000000000000000000000000000000000000000000000000000000000, + }, + source_digest: Some( + "ELIDED_FOR_TEST", + ), + build_flags: BuildConfig { + dev_mode: true, + test_mode: false, + override_std: None, + generate_docs: false, + generate_abis: false, + generate_move_model: false, + full_model_generation: false, + install_dir: Some( + "ELIDED_FOR_TEST", + ), + force_recompilation: false, + additional_named_addresses: {}, + architecture: None, + fetch_deps_only: false, + skip_fetch_latest_git_deps: false, + compiler_config: CompilerConfig { + bytecode_version: None, + known_attributes: { + "bytecode_instruction", + "deprecated", + "expected_failure", + "native_interface", + "test", + "test_only", + "verify_only", + }, + skip_attribute_checks: false, + compiler_version: Some( + V2_0, + ), + language_version: None, + }, + }, +}