Skip to content

Commit 49d0eb4

Browse files
authored
Allow ldc opcode in predicates (#6964)
## Description This PR allows `LDC` opcode in predicates. Historically, it was not allowed in the FuelVM, but this restriction is removed and we are removing it now from Sway as well. ## Checklist - [ ] I have linked to any relevant issues. - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [x] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
1 parent a090937 commit 49d0eb4

File tree

7 files changed

+27
-8
lines changed

7 files changed

+27
-8
lines changed

sway-core/src/asm_generation/fuel/checks.rs

-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ pub(crate) fn check_predicate_opcodes(
104104
span: get_op_span(op),
105105
});
106106
}
107-
LDC(..) => invalid_opcode("LDC"),
108107
LOG(..) => invalid_opcode("LOG"),
109108
LOGD(..) => invalid_opcode("LOGD"),
110109
MINT(..) => invalid_opcode("MINT"),

test/src/e2e_vm_tests/test_programs/should_fail/predicate_invalid_opcodes/src/main.sw

-4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ fn main() -> bool {
5656
r1: u64
5757
};
5858

59-
asm(r1: 0, r2: 0, r3: 0) {
60-
ldc r1 r2 r3 i0;
61-
}
62-
6359
asm(r1: 0, r2: 0, r3: 0, r4: 0) {
6460
log r1 r2 r3 r4;
6561
}

test/src/e2e_vm_tests/test_programs/should_fail/predicate_invalid_opcodes/test.toml

-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ category = "fail"
3535

3636
# not: $()The GM (get-metadata) opcode, when called from an external context, will cause the VM to panic.
3737

38-
# check: ldc r1 r2 r3 i0;
39-
# nextln: $()The LDC opcode cannot be used in a predicate.
40-
4138
# check: log r1 r2 r3 r4;
4239
# nextln: $()The LOG opcode cannot be used in a predicate.
4340

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[[package]]
2+
name = "core"
3+
source = "path+from-root-441B0FE8436A0A54"
4+
5+
[[package]]
6+
name = "ldc"
7+
source = "member"
8+
dependencies = ["core"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[project]
2+
authors = ["Fuel Labs <contact@fuel.sh>"]
3+
entry = "main.sw"
4+
license = "Apache-2.0"
5+
name = "ldc"
6+
7+
[dependencies]
8+
core = { path = "../../../../../../../../../sway-lib-core" }
9+
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
predicate;
2+
3+
fn main() -> bool {
4+
asm(r1: 0, r2: 0, r3: 0) {
5+
ldc r1 r2 r3 i0;
6+
}
7+
true
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
category = "compile"

0 commit comments

Comments
 (0)