-
Notifications
You must be signed in to change notification settings - Fork 210
Open
Description
What is the current state of array yul code generation?
On the master branch, the following code
pub fn thisCompiles(arr: [u256; 3]) -> u64 {
let x = 0
if x > 10 {
let y : u64 = arr[1]
y
} else {
10
}
}compiles to
function thisCompiles(arr) -> ret {
let v0 := 0
let v1 := 0
if gt(v0, 10) {
v1 := y
}
if iszero(gt(v0, 10)) {
v1 := 10
}
ret := v1
}Notice the array value retrieval code is bypassed.
Additionally, the following code won't compile.
pub fn thisDoesnt(arr: [u256; 3]) -> u64 {
let x = 0
let y : u64 = arr[1]
if x > 10 {
y
} else {
10
}
}
pub fn thisDoesnt2(arr: [u256; 3]) -> u64 {
let x = 0
let y = 0
while x < 10 {
let z : u64 = arr[1]
x = x + 1
}
y
}Resulting in.
MIR ERROR: only arithmetic/logical binary expressions are supported right now
And my follow up question is how would arrays be implemented in Yul? Should we do the whole byte retreival (e.g. mload(add(arr, mul(v1, 32)))). Or is there a higher abstraction available?
Metadata
Metadata
Assignees
Labels
No labels