-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[move] Add deprecation attributes to source language (#17964)
## Description Adds support for deprecation attributes to the source language: ``` #[deprecated] <member> #[deprecated(note = b"<string>")] <member> ``` where `<member>` can be a module, constant, struct, enum, or function. Note that deprecation checking must be performed after typechecking since we need to have methods resolved before determining whether the call uses a deprecated function. A couple things to note: 1. Accessing any member within a deprecated module, will raise a deprecation warning. The one exception to this is access/calls within a deprecated module -- in which case no warnings will be raised. ```move #[deprecated] module 0x42::m { public fun f() { } public fun call_f() { f(); } // no warning raised since internal access } ``` ```move #[deprecated] module 0x42::m { public fun f() { } public fun call_f() { f(); } // no warning raised since internal access } module 0x42::k { fun caller() { 0x42::m::f(); } // Will raise an error since an external access } ``` 2. Specific deprecations always override module deprecations, and they will always raise a deprecation warning, even for internal accesses. In particular: ```move #[deprecated] module 0x42::m { [deprecated(note = b"note")] public fun f() { } public fun call_f() { f(); } // warning will be raised with note "note" } module 0x42::k { fun caller() { 0x42::m::f(); } // warning will be raised with note "note" } ``` 3. Deprecations are grouped into single diagnostics -- one diagnostic per `(deprecation, named_context)` pair where a named context can be either a struct, enum, constant, or function. E.g., for the following code ```move module 0x42::m { #[deprecated] const A: u64 = 1; #[deprecated(note = b"use D instead")] const B: u64 = 2; #[deprecated(note = b"You should use E instead")] const C: u64 = 3; const D: u64 = 4; const E: u64 = 5; const Combo: u64 = { A + B + C + D + E + B }; } ``` Will produce the following warnings since: ``` warning[W04037]: use of deprecated constant ┌─ tests/move_2024/typing/deprecation_use_in_constants.move:15:9 │ 15 │ A + B + C + D + E + B │ ^ This constant is deprecated warning[W04037]: use of deprecated constant ┌─ tests/move_2024/typing/deprecation_use_in_constants.move:15:13 │ 15 │ A + B + C + D + E + B │ ^ - Deprecated constant used again here │ │ │ This constant is deprecated: use D instead warning[W04037]: use of deprecated constant ┌─ tests/move_2024/typing/deprecation_use_in_constants.move:15:17 │ 15 │ A + B + C + D + E + B │ ^ This constant is deprecated: You should use E instead ``` Notice the warning for `B` has multiple labels -- one per usage of the deprecated constant within the named context. ## Test plan Added new positive and negative tests for the deprecation behavior.
- Loading branch information
Showing
34 changed files
with
1,336 additions
and
13 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
external-crates/move/crates/move-cli/tests/build_tests/dependency_deprecations/Move.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "A" | ||
edition = "2024.beta" | ||
|
||
[addresses] | ||
A = "0x1" | ||
|
||
[dependencies] | ||
Dep = { local = "./dep" } |
33 changes: 33 additions & 0 deletions
33
external-crates/move/crates/move-cli/tests/build_tests/dependency_deprecations/args.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Command `build -v`: | ||
INCLUDING DEPENDENCY Dep | ||
BUILDING A | ||
warning[W04037]: deprecated usage | ||
┌─ ./sources/l.move:8:13 | ||
│ | ||
8 │ am::deprecated_function(); | ||
│ ^^^^^^^^^^^^^^^^^^^ The function 'A::m::deprecated_function' is deprecated: use a different function instead | ||
|
||
warning[W04037]: deprecated usage | ||
┌─ ./sources/l.move:10:25 | ||
│ | ||
10 │ mod_deprecated::deprecated_function(); | ||
│ ^^^^^^^^^^^^^^^^^^^ The function 'A::mod_deprecated::deprecated_function' is deprecated: This function is deprecated with a deprecated module | ||
|
||
warning[W04037]: deprecated usage | ||
┌─ ./sources/l.move:11:25 | ||
│ | ||
11 │ mod_deprecated::make_f(); | ||
│ ^^^^^^ The 'A::mod_deprecated::make_f' member of the module 'A::mod_deprecated' is deprecated. It is deprecated since its whole module is marked deprecated: This module is deprecated | ||
|
||
warning[W04037]: deprecated usage | ||
┌─ ./sources/l.move:13:15 | ||
│ | ||
13 │ l<am::Bar>(); | ||
│ ^^^ The struct 'A::m::Bar' is deprecated: use a different struct instead | ||
|
||
warning[W04037]: deprecated usage | ||
┌─ ./sources/l.move:15:27 | ||
│ | ||
15 │ l<mod_deprecated::F>(); | ||
│ ^ The 'A::mod_deprecated::F' member of the module 'A::mod_deprecated' is deprecated. It is deprecated since its whole module is marked deprecated: This module is deprecated | ||
|
1 change: 1 addition & 0 deletions
1
external-crates/move/crates/move-cli/tests/build_tests/dependency_deprecations/args.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build -v |
6 changes: 6 additions & 0 deletions
6
external-crates/move/crates/move-cli/tests/build_tests/dependency_deprecations/dep/Move.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[package] | ||
name = "Dep" | ||
edition = "2024.beta" | ||
|
||
[addresses] | ||
A = "_" |
13 changes: 13 additions & 0 deletions
13
...-crates/move/crates/move-cli/tests/build_tests/dependency_deprecations/dep/sources/m.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module A::m { | ||
#[deprecated(note = b"use a different struct instead")] | ||
public struct Bar() has drop; | ||
|
||
|
||
public fun make_bar(): Bar { | ||
Bar() | ||
} | ||
|
||
|
||
#[deprecated(note = b"use a different function instead")] | ||
public fun deprecated_function() { } | ||
} |
12 changes: 12 additions & 0 deletions
12
...crates/move-cli/tests/build_tests/dependency_deprecations/dep/sources/mod_deprecated.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#[deprecated(note = b"This module is deprecated")] | ||
module A::mod_deprecated { | ||
public struct F() has drop; | ||
|
||
public fun make_f(): F { | ||
F() | ||
} | ||
|
||
#[deprecated(note = b"This function is deprecated with a deprecated module")] | ||
public fun deprecated_function() { } | ||
} | ||
|
20 changes: 20 additions & 0 deletions
20
...rnal-crates/move/crates/move-cli/tests/build_tests/dependency_deprecations/sources/l.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module A::l { | ||
use A::m as am; | ||
use A::mod_deprecated; | ||
|
||
#[allow(unused_function)] | ||
fun f() { | ||
am::make_bar(); | ||
am::deprecated_function(); | ||
|
||
mod_deprecated::deprecated_function(); | ||
mod_deprecated::make_f(); | ||
|
||
l<am::Bar>(); | ||
|
||
l<mod_deprecated::F>(); | ||
} | ||
|
||
#[allow(unused_function, unused_type_parameter)] | ||
fun l<T>() { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.