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.
Fix DCA warnings for log intrinsic and stdlib function (FuelLabs#3538)
This adds special handling for the log intrinsic, consuming the fields of all structs used inside the inner expressions. It also does the same for functions external to the current analysis, to solve the same thing for the stdlib log function, which could lead to some false negatives when it comes to the unused fields warning, but it's the best we can do for now without considerable effort refactoring the DCA engine to work inter-proceduraly/module. Closes FuelLabs#3012. Co-authored-by: Mohammad Fawaz <[email protected]>
- Loading branch information
1 parent
8dc9afa
commit b444422
Showing
15 changed files
with
198 additions
and
4 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
3 changes: 3 additions & 0 deletions
3
test/src/e2e_vm_tests/test_programs/should_pass/dca/log_intrinsic/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,3 @@ | ||
[[package]] | ||
name = 'log' | ||
source = 'member' |
6 changes: 6 additions & 0 deletions
6
test/src/e2e_vm_tests/test_programs/should_pass/dca/log_intrinsic/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,6 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "log" | ||
implicit-std = false |
10 changes: 10 additions & 0 deletions
10
test/src/e2e_vm_tests/test_programs/should_pass/dca/log_intrinsic/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,10 @@ | ||
script; | ||
|
||
struct Foo { | ||
value: u64 | ||
} | ||
|
||
fn main() -> u64 { | ||
__log(Foo {value: 0}); | ||
0 | ||
} |
4 changes: 4 additions & 0 deletions
4
test/src/e2e_vm_tests/test_programs/should_pass/dca/log_intrinsic/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,4 @@ | ||
category = "compile" | ||
|
||
# not: $()value: u64 | ||
# not: $()This struct field is never accessed. |
13 changes: 13 additions & 0 deletions
13
test/src/e2e_vm_tests/test_programs/should_pass/dca/log_stdlib/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-E6171879CB601FD9' | ||
|
||
[[package]] | ||
name = 'log_stdlib' | ||
source = 'member' | ||
dependencies = ['std'] | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-E6171879CB601FD9' | ||
dependencies = ['core'] |
8 changes: 8 additions & 0 deletions
8
test/src/e2e_vm_tests/test_programs/should_pass/dca/log_stdlib/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] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "log_stdlib" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../../sway-lib-std" } |
12 changes: 12 additions & 0 deletions
12
test/src/e2e_vm_tests/test_programs/should_pass/dca/log_stdlib/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,12 @@ | ||
script; | ||
|
||
use std::logging::log; | ||
|
||
struct Foo { | ||
value: u64 | ||
} | ||
|
||
fn main() -> u64 { | ||
log(Foo {value: 0}); | ||
0 | ||
} |
4 changes: 4 additions & 0 deletions
4
test/src/e2e_vm_tests/test_programs/should_pass/dca/log_stdlib/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,4 @@ | ||
category = "compile" | ||
|
||
# not: $()value: u64 | ||
# not: $()This struct field is never accessed. |
3 changes: 3 additions & 0 deletions
3
test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_fields/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,3 @@ | ||
[[package]] | ||
name = 'unused_fields' | ||
source = 'member' |
6 changes: 6 additions & 0 deletions
6
test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_fields/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,6 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "unused_fields" | ||
implicit-std = false |
19 changes: 19 additions & 0 deletions
19
test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_fields/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,19 @@ | ||
script; | ||
|
||
dep utils; | ||
use utils::Foo; | ||
|
||
|
||
struct Bar { | ||
value: u64 | ||
} | ||
|
||
fn internal_fn(s: Bar) { | ||
|
||
} | ||
|
||
fn main() -> u64 { | ||
internal_fn(Bar {value: 0}); | ||
utils::external_fn(Foo {value: 0}); | ||
0 | ||
} |
9 changes: 9 additions & 0 deletions
9
test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_fields/src/utils.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,9 @@ | ||
library utils; | ||
|
||
pub struct Foo { | ||
value: u64 | ||
} | ||
|
||
pub fn external_fn(s: Foo) { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
test/src/e2e_vm_tests/test_programs/should_pass/dca/unused_fields/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,7 @@ | ||
category = "compile" | ||
|
||
# check: $()struct Bar { | ||
# check: $()This struct field is never accessed. | ||
|
||
# not: $()value: u64 | ||
# not: $()This struct field is never accessed. |