forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve warnings on unnecessary storage annotations (FuelLabs#3414)
Fixes FuelLabs#1183: just trying to improve the error message. This PR also provides a fix for the following issue: the purity analyzer did not report the case where *both* read and write storage annotations were unused, i.e. in this case there were no warnings: ``` contract; abi MyContract { #[storage(read, write)] fn foo() -> u64; } impl MyContract for Contract { #[storage(read, write)] fn foo() -> u64 { 0 } } ```
- Loading branch information
1 parent
a7fa7d9
commit f8d22d2
Showing
14 changed files
with
119 additions
and
4 deletions.
There are no files selected for viewing
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
13 changes: 13 additions & 0 deletions
13
...tests/test_programs/should_pass/static_analysis/storage_annotations_unused_read/Forc.lock
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 @@ | ||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-B415B1E0A318C0B0' | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-B415B1E0A318C0B0' | ||
dependencies = ['core'] | ||
|
||
[[package]] | ||
name = 'storage_annotations_unused_read' | ||
source = 'member' | ||
dependencies = ['std'] |
8 changes: 8 additions & 0 deletions
8
...tests/test_programs/should_pass/static_analysis/storage_annotations_unused_read/Forc.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,8 @@ | ||
[project] | ||
name = "storage_annotations_unused_read" | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../../sway-lib-std" } |
13 changes: 13 additions & 0 deletions
13
...sts/test_programs/should_pass/static_analysis/storage_annotations_unused_read/src/main.sw
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 @@ | ||
contract; | ||
|
||
abi MyContract { | ||
#[storage(read)] | ||
fn foo() -> u64; | ||
} | ||
|
||
impl MyContract for Contract { | ||
#[storage(read)] | ||
fn foo() -> u64 { | ||
0 | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...tests/test_programs/should_pass/static_analysis/storage_annotations_unused_read/test.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,3 @@ | ||
category = "compile" | ||
|
||
# check: $()This function's storage attributes declaration does not match this function's actual storage access pattern: 'read' attribute(s) can be removed. |
13 changes: 13 additions & 0 deletions
13
..._programs/should_pass/static_analysis/storage_annotations_unused_read_and_write/Forc.lock
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 @@ | ||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-F9F255B625A3400C' | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-F9F255B625A3400C' | ||
dependencies = ['core'] | ||
|
||
[[package]] | ||
name = 'storage_annotations_unused_read_and_write' | ||
source = 'member' | ||
dependencies = ['std'] |
8 changes: 8 additions & 0 deletions
8
..._programs/should_pass/static_analysis/storage_annotations_unused_read_and_write/Forc.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,8 @@ | ||
[project] | ||
name = "storage_annotations_unused_read_and_write" | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../../sway-lib-std" } |
13 changes: 13 additions & 0 deletions
13
...rograms/should_pass/static_analysis/storage_annotations_unused_read_and_write/src/main.sw
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 @@ | ||
contract; | ||
|
||
abi MyContract { | ||
#[storage(read, write)] | ||
fn foo() -> u64; | ||
} | ||
|
||
impl MyContract for Contract { | ||
#[storage(read, write)] | ||
fn foo() -> u64 { | ||
0 | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
..._programs/should_pass/static_analysis/storage_annotations_unused_read_and_write/test.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,3 @@ | ||
category = "compile" | ||
|
||
# check: $()This function's storage attributes declaration does not match this function's actual storage access pattern: 'read, write' attribute(s) can be removed. |
13 changes: 13 additions & 0 deletions
13
...ests/test_programs/should_pass/static_analysis/storage_annotations_unused_write/Forc.lock
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 @@ | ||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-4A37DED755D546B6' | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-4A37DED755D546B6' | ||
dependencies = ['core'] | ||
|
||
[[package]] | ||
name = 'storage_annotations_unused_write' | ||
source = 'member' | ||
dependencies = ['std'] |
8 changes: 8 additions & 0 deletions
8
...ests/test_programs/should_pass/static_analysis/storage_annotations_unused_write/Forc.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,8 @@ | ||
[project] | ||
name = "storage_annotations_unused_write" | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../../sway-lib-std" } |
13 changes: 13 additions & 0 deletions
13
...ts/test_programs/should_pass/static_analysis/storage_annotations_unused_write/src/main.sw
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 @@ | ||
contract; | ||
|
||
abi MyContract { | ||
#[storage(write)] // Or any other storage annotation | ||
fn foo() -> u64; | ||
} | ||
|
||
impl MyContract for Contract { | ||
#[storage(write)] // Or any other storage annotation | ||
fn foo() -> u64 { | ||
0 | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...ests/test_programs/should_pass/static_analysis/storage_annotations_unused_write/test.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,3 @@ | ||
category = "compile" | ||
|
||
# check: $()This function's storage attributes declaration does not match this function's actual storage access pattern: 'write' attribute(s) can be removed. |