Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spans via metadata to IR. #808

Merged
merged 4 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sway-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pest = { version = "3.0.4", package = "fuel-pest" }
pest_derive = { version = "3.0.4", package = "fuel-pest_derive" }
petgraph = "0.5"
prettydiff = "0.5"
regex = "1"
serde = { version = "1.0", features = ["derive"] }
sha2 = "0.9"
smallvec = "1.7"
Expand Down
871 changes: 627 additions & 244 deletions sway-core/src/asm_generation/from_ir.rs

Large diffs are not rendered by default.

349 changes: 233 additions & 116 deletions sway-core/src/optimize.rs

Large diffs are not rendered by default.

38 changes: 24 additions & 14 deletions sway-core/tests/sway_to_ir/array_simple.ir
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,30 @@ script script {
local ptr [bool; 3] a

entry:
v0 = const [bool; 3] [bool undef, bool undef, bool undef]
v1 = const bool false
v2 = const u64 0
v3 = insert_element v0, [bool; 3], v1, v2
v4 = const bool true
v5 = const u64 1
v6 = insert_element v3, [bool; 3], v4, v5
v7 = const bool false
v8 = const u64 2
v9 = insert_element v6, [bool; 3], v7, v8
store v9, ptr [bool; 3] a
v10 = load ptr [bool; 3] a
v11 = const u64 1
v12 = extract_element v10, [bool; 3], v11
v0 = const [bool; 3] [bool undef, bool undef, bool undef], !1
v1 = const bool false, !2
v2 = const u64 0, !1
v3 = insert_element v0, [bool; 3], v1, v2, !1
v4 = const bool true, !3
v5 = const u64 1, !1
v6 = insert_element v3, [bool; 3], v4, v5, !1
v7 = const bool false, !4
v8 = const u64 2, !1
v9 = insert_element v6, [bool; 3], v7, v8, !1
store v9, ptr [bool; 3] a, !5
v10 = load ptr [bool; 3] a, !6
v11 = const u64 1, !7
v12 = extract_element v10, [bool; 3], v11, !8
ret bool v12
}
}

!0 = filepath "/path/to/array_simple.sw"
!1 = span !0 42 60
!2 = span !0 42 47
!3 = span !0 49 53
!4 = span !0 55 60
!5 = span !0 33 62
!6 = span !0 67 68
!7 = span !0 69 70
!8 = span !0 67 72
11 changes: 8 additions & 3 deletions sway-core/tests/sway_to_ir/asm_block.ir
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
script script {
fn get_global_gas() -> u64 {
entry:
v0 = asm() -> ggas {
v0 = asm() -> ggas, !1 {
}
ret u64 v0
}

fn main() -> u64 {
entry:
v0 = asm(r1) -> r1 {
bhei r1
v0 = asm(r1) -> r1, !2 {
bhei r1, !3
}
ret u64 v0
}
}

!0 = filepath "/path/to/asm_block.sw"
!1 = span !0 139 165
!2 = span !0 192 240
!3 = span !0 210 218
30 changes: 21 additions & 9 deletions sway-core/tests/sway_to_ir/b256_immeds.ir
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
script script {
fn cmp(a: b256, b: b256) -> bool {
fn cmp(a !1: b256, b !2: b256) -> bool {
entry:
v0 = asm(lhs: a, rhs: b, sz, res) -> res {
addi sz zero i32
meq res lhs rhs sz
v0 = asm(lhs: a, rhs: b, sz, res) -> res, !3 {
addi sz zero i32, !4
meq res lhs rhs sz, !5
}
ret bool v0
}
Expand All @@ -12,11 +12,23 @@ script script {
local ptr b256 a

entry:
v0 = const b256 0x0202020202020202020202020202020202020202020202020202020202020202
store v0, ptr b256 a
v1 = load ptr b256 a
v2 = const b256 0x0303030303030303030303030303030303030303030303030303030303030303
v3 = call cmp(v1, v2)
v0 = const b256 0x0202020202020202020202020202020202020202020202020202020202020202, !6
store v0, ptr b256 a, !7
v1 = load ptr b256 a, !8
v2 = const b256 0x0303030303030303030303030303030303030303030303030303030303030303, !9
v3 = call cmp(v1, v2), !10
ret bool v3
}
}

!0 = filepath "/path/to/b256_immeds.sw"
!1 = span !0 198 199
!2 = span !0 207 208
!3 = span !0 230 338
!4 = span !0 269 286
!5 = span !0 295 314
!6 = span !0 41 107
!7 = span !0 33 108
!8 = span !0 117 118
!9 = span !0 120 186
!10 = span !0 191 340
39 changes: 25 additions & 14 deletions sway-core/tests/sway_to_ir/enum.ir
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
script script {
fn eat(meal: { u64, { () | () | u64 } }) -> bool {
fn eat(meal !1: { u64, { () | () | u64 } }) -> bool {
entry:
v0 = const bool false
v0 = const bool false, !2
ret bool v0
}

fn main() -> () {
local ptr { u64, { () | () | u64 } } lunch

entry:
v0 = const { u64, { () | () | u64 } } { u64 undef, { () | () | u64 } undef }
v1 = const u64 1
v2 = insert_value v0, { u64, { () | () | u64 } }, v1, 0
store v2, ptr { u64, { () | () | u64 } } lunch
v3 = get_ptr ptr { u64, { () | () | u64 } } lunch
v4 = call eat(v3)
v5 = const { u64, { () | () | u64 } } { u64 undef, { () | () | u64 } undef }
v6 = const u64 2
v7 = insert_value v5, { u64, { () | () | u64 } }, v6, 0
v8 = const u64 3
v9 = insert_value v7, { u64, { () | () | u64 } }, v8, 1
v10 = call eat(v9)
v0 = const { u64, { () | () | u64 } } { u64 undef, { () | () | u64 } undef }, !3
v1 = const u64 1, !3
v2 = insert_value v0, { u64, { () | () | u64 } }, v1, 0, !3
store v2, ptr { u64, { () | () | u64 } } lunch, !4
v3 = get_ptr ptr { u64, { () | () | u64 } } lunch, !5
v4 = call eat(v3), !6
v5 = const { u64, { () | () | u64 } } { u64 undef, { () | () | u64 } undef }, !7
v6 = const u64 2, !7
v7 = insert_value v5, { u64, { () | () | u64 } }, v6, 0, !7
v8 = const u64 3, !8
v9 = insert_value v7, { u64, { () | () | u64 } }, v8, 1, !7
v10 = call eat(v9), !9
ret () v10
}
}

!0 = filepath "/path/to/enum.sw"
!1 = span !0 169 173
!2 = span !0 196 201
!3 = span !0 9 71
!4 = span !0 89 115
!5 = span !0 124 129
!6 = span !0 162 203
!7 = span !0 9 71
!8 = span !0 154 155
!9 = span !0 162 203
18 changes: 11 additions & 7 deletions sway-core/tests/sway_to_ir/enum_enum.ir
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
script script {
fn main() -> () {
entry:
v0 = const { u64, { () | { u64, { () | bool | () } } | () } } { u64 undef, { () | { u64, { () | bool | () } } | () } undef }
v1 = const u64 1
v2 = insert_value v0, { u64, { () | { u64, { () | bool | () } } | () } }, v1, 0
v3 = const { u64, { () | bool | () } } { u64 undef, { () | bool | () } undef }
v4 = const u64 0
v5 = insert_value v3, { u64, { () | bool | () } }, v4, 0
v6 = insert_value v2, { u64, { () | { u64, { () | bool | () } } | () } }, v5, 1
v0 = const { u64, { () | { u64, { () | bool | () } } | () } } { u64 undef, { () | { u64, { () | bool | () } } | () } undef }, !1
v1 = const u64 1, !1
v2 = insert_value v0, { u64, { () | { u64, { () | bool | () } } | () } }, v1, 0, !1
v3 = const { u64, { () | bool | () } } { u64 undef, { () | bool | () } undef }, !2
v4 = const u64 0, !2
v5 = insert_value v3, { u64, { () | bool | () } }, v4, 0, !2
v6 = insert_value v2, { u64, { () | { u64, { () | bool | () } } | () } }, v5, 1, !1
ret () v6
}
}

!0 = filepath "/path/to/enum_enum.sw"
!1 = span !0 9 55
!2 = span !0 57 104
29 changes: 18 additions & 11 deletions sway-core/tests/sway_to_ir/enum_struct.ir
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
script script {
fn main() -> () {
entry:
v0 = const { u64, { () | { b256, bool, u64 } | () } } { u64 undef, { () | { b256, bool, u64 } | () } undef }
v1 = const u64 1
v2 = insert_value v0, { u64, { () | { b256, bool, u64 } | () } }, v1, 0
v3 = const { b256, bool, u64 } { b256 undef, bool undef, u64 undef }
v4 = const b256 0x0001010101010101000101010101010100010101010101010001010101010101
v5 = insert_value v3, { b256, bool, u64 }, v4, 0
v6 = const bool true
v7 = insert_value v5, { b256, bool, u64 }, v6, 1
v8 = const u64 53
v9 = insert_value v7, { b256, bool, u64 }, v8, 2
v10 = insert_value v2, { u64, { () | { b256, bool, u64 } | () } }, v9, 1
v0 = const { u64, { () | { b256, bool, u64 } | () } } { u64 undef, { () | { b256, bool, u64 } | () } undef }, !1
v1 = const u64 1, !1
v2 = insert_value v0, { u64, { () | { b256, bool, u64 } | () } }, v1, 0, !1
v3 = const { b256, bool, u64 } { b256 undef, bool undef, u64 undef }, !2
v4 = const b256 0x0001010101010101000101010101010100010101010101010001010101010101, !3
v5 = insert_value v3, { b256, bool, u64 }, v4, 0, !2
v6 = const bool true, !4
v7 = insert_value v5, { b256, bool, u64 }, v6, 1, !2
v8 = const u64 53, !5
v9 = insert_value v7, { b256, bool, u64 }, v8, 2, !2
v10 = insert_value v2, { u64, { () | { b256, bool, u64 } | () } }, v9, 1, !1
ret () v10
}
}

!0 = filepath "/path/to/enum_struct.sw"
!1 = span !0 9 55
!2 = span !0 134 256
!3 = span !0 151 217
!4 = span !0 230 234
!5 = span !0 247 249
17 changes: 12 additions & 5 deletions sway-core/tests/sway_to_ir/fn_call.ir
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
script script {
fn a(x: u64) -> u64 {
fn a(x !1: u64) -> u64 {
entry:
ret u64 x
}

fn main() -> u64 {
entry:
v0 = const u64 0
v1 = call a(v0)
v2 = const u64 1
v3 = call a(v2)
v0 = const u64 0, !2
v1 = call a(v0), !3
v2 = const u64 1, !4
v3 = call a(v2), !5
ret u64 v3
}
}

!0 = filepath "/path/to/fn_call.sw"
!1 = span !0 14 15
!2 = span !0 65 66
!3 = span !0 9 38
!4 = span !0 75 76
!5 = span !0 9 38
14 changes: 10 additions & 4 deletions sway-core/tests/sway_to_ir/if_expr.ir
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
script script {
fn main() -> u64 {
entry:
v0 = const bool false
cbr v0, block0, block1
v0 = const bool false, !1
cbr v0, block0, block1, !2

block0:
v1 = const u64 1000000
v1 = const u64 1000000, !3
br block2

block1:
v2 = const u64 42
v2 = const u64 42, !4
br block2

block2:
v3 = phi(block0: v1, block1: v2)
ret u64 v3
}
}

!0 = filepath "/path/to/if_expr.sw"
!1 = span !0 35 40
!2 = span !0 35 40
!3 = span !0 51 60
!4 = span !0 82 84
5 changes: 4 additions & 1 deletion sway-core/tests/sway_to_ir/impl_ret_int.ir
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
script script {
fn main() -> u64 {
entry:
v0 = const u64 42
v0 = const u64 42, !1
ret u64 v0
}
}

!0 = filepath "/path/to/impl_ret_int.sw"
!1 = span !0 32 34
23 changes: 15 additions & 8 deletions sway-core/tests/sway_to_ir/lazy_binops.ir
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
script script {
fn main() -> bool {
entry:
v0 = const bool false
v0 = const bool false
cbr v0, block0, block1
v0 = const bool false, !1
v0 = const bool false, !1
cbr v0, block0, block1, !2

block0:
v1 = phi(entry: v0)
v2 = const bool true
br block1
v2 = const bool true, !3
br block1, !2

block1:
v3 = phi(entry: v0, block0: v2)
cbr v3, block3, block2
cbr v3, block3, block2, !4

block2:
v4 = phi(block1: v3)
v5 = const bool true
br block3
v5 = const bool true, !5
br block3, !4

block3:
v6 = phi(block1: v3, block2: v5)
ret bool v6
}
}

!0 = filepath "/path/to/lazy_binops.sw"
!1 = span !0 34 39
!2 = span !0 34 47
!3 = span !0 43 47
!4 = span !0 34 56
!5 = span !0 52 56
Loading