Commit 00b9d02
authored
Improve Contract Call by not encoding method name (#7455)
## Description
This is an optimisation of contract calls on top of
#7440.
The old version would pass a string with the method name and encode it,
which is `<LEN><BYTES`. Now the compiler generates these bytes directly,
avoiding encoding the method name in the first place.
For that this PR creats the concept of `Literal::Binary` that does not
exist in the language, yet. Would be something like `b""` in Rust.
## Improvements
| Test | Before | After | Percentage |
|------|--------|-------|------------|
| should_pass/empty_fields_in_storage_struct
(test.toml)::test_read_write_bytes | 19298 | 17533 | 9.15% |
| should_pass/empty_fields_in_storage_struct
(test.toml)::test_read_write_map | 14971 | 13986 | 6.58% |
| should_pass/empty_fields_in_storage_struct
(test.toml)::test_read_write_vec | 31061 | 29288 | 5.71% |
| should_pass/language/associated_const_abi (test.toml)::test | 8789 |
7817 | 11.06% |
| should_pass/language/associated_const_abi_multiple (test.toml)::test |
2421 | 2097 | 13.38% |
| should_pass/language/associated_const_in_decls_of_other_constants
(test.toml)::test | 870 | 709 | 18.51% |
| should_pass/language/contract_caller_dynamic_address (test.toml) | 540
| 379 | 29.81% |
| should_pass/language/contract_ret_intrinsic (test.toml)::test | 2133 |
1809 | 15.19% |
| should_pass/language/pusha_popa_multiple_defreg
(test.toml)::incorrect_pusha_popa | 819 | 624 | 23.81% |
| should_pass/language/raw_identifiers (test.error_type.toml)::test |
1236 | 1075 | 13.03% |
| should_pass/language/raw_identifiers (test.toml)::test | 1236 | 1075 |
13.03% |
| should_pass/language/references/mutability_of_references_memcpy_bug
(test.toml)::test | 1364 | 1203 | 11.80% |
| should_pass/language/slice/slice_contract (test.toml)::test_success |
1338 | 1145 | 14.42% |
| should_pass/language/string_slice/string_slice_contract
(test.toml)::test_success | 1515 | 1322 | 12.74% |
| should_pass/stdlib/storage_vec_insert (test.toml)::test_test_function
| 3992 | 3831 | 4.03% |
| should_pass/storage_element_key_modification
(test.toml)::test_storage_key_address | 1300 | 1138 | 12.46% |
| should_pass/storage_element_key_modification
(test.toml)::test_storage_key_modification | 919 | 757 | 17.63% |
| should_pass/storage_slot_key_calculation (test.toml)::test | 3140 |
2979 | 5.13% |
| should_pass/superabi_contract_calls (test.toml)::tests | 2136 | 1812 |
15.17% |
| should_pass/superabi_supertrait_same_methods (test.toml)::tests | 1097
| 936 | 14.68% |
| should_pass/test_abis/abi_impl_methods_callable (test.toml)::tests |
933 | 772 | 17.26% |
| should_pass/test_abis/contract_abi-auto_impl (test.toml)::tests | 933
| 772 | 17.26% |
| should_pass/unit_tests/aggr_indexing (test.toml)::test1 | 6007 | 5443
| 9.39% |
| should_pass/unit_tests/contract-multi-contract-calls
(test.toml)::test_contract_2_call | 966 | 804 | 16.77% |
| should_pass/unit_tests/contract-multi-contract-calls
(test.toml)::test_contract_call | 969 | 807 | 16.72% |
| should_pass/unit_tests/contract-multi-contract-calls
(test.toml)::test_contract_multi_call | 1916 | 1592 | 16.91% |
| should_pass/unit_tests/contract_multi_test (test.toml)::test_fail |
970 | 808 | 16.70% |
| should_pass/unit_tests/contract_multi_test (test.toml)::test_success |
968 | 806 | 16.74% |
| should_pass/unit_tests/script-contract-calls
(test.toml)::test_contract_call | 931 | 736 | 20.95% |
| should_pass/unit_tests/workspace_test (test.toml)::test_fail | 970 |
808 | 16.70% |
| should_pass/unit_tests/workspace_test (test.toml)::test_success | 969
| 807 | 16.72% |
## Failed Test
Only now I realized that the test for array of size zero `[u64; 0]` is
not working. As this is not a useful case, I will solve it in another
PR.
## Checklist
- [x] I have linked to any relevant issues.
- [x] 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 fc2aed7 commit 00b9d02
File tree
14 files changed
+189
-128
lines changed- sway-core/src
- ir_generation
- language
- semantic_analysis/ast_node/expression
- match_expression/analysis
- typed_expression
- sway-ir/src
- sway-lib-std/src
- sway-lsp/src
- traverse
- utils
- test/src/e2e_vm_tests/test_programs/should_pass
- language/panic_expression/panicking_contract
- test_contracts
- const_of_contract_call
- dynamic_contract_call/src
14 files changed
+189
-128
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
| 54 | + | |
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
457 | 457 | | |
458 | 458 | | |
459 | 459 | | |
460 | | - | |
| 460 | + | |
| 461 | + | |
461 | 462 | | |
462 | 463 | | |
463 | 464 | | |
464 | | - | |
465 | | - | |
| 465 | + | |
| 466 | + | |
466 | 467 | | |
467 | 468 | | |
468 | 469 | | |
| |||
471 | 472 | | |
472 | 473 | | |
473 | 474 | | |
474 | | - | |
| 475 | + | |
475 | 476 | | |
476 | | - | |
| 477 | + | |
477 | 478 | | |
478 | 479 | | |
479 | 480 | | |
| |||
569 | 570 | | |
570 | 571 | | |
571 | 572 | | |
572 | | - | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
573 | 591 | | |
574 | 592 | | |
575 | 593 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
77 | 82 | | |
78 | 83 | | |
79 | 84 | | |
| |||
90 | 95 | | |
91 | 96 | | |
92 | 97 | | |
| 98 | + | |
93 | 99 | | |
94 | 100 | | |
95 | 101 | | |
| |||
111 | 117 | | |
112 | 118 | | |
113 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
114 | 125 | | |
115 | 126 | | |
116 | 127 | | |
| |||
154 | 165 | | |
155 | 166 | | |
156 | 167 | | |
| 168 | + | |
157 | 169 | | |
158 | 170 | | |
159 | 171 | | |
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
183 | 186 | | |
184 | 187 | | |
185 | 188 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
635 | 635 | | |
636 | 636 | | |
637 | 637 | | |
| 638 | + | |
638 | 639 | | |
639 | 640 | | |
640 | 641 | | |
| |||
Lines changed: 11 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
533 | 533 | | |
534 | 534 | | |
535 | 535 | | |
536 | | - | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
537 | 544 | | |
538 | | - | |
539 | | - | |
| 545 | + | |
| 546 | + | |
540 | 547 | | |
541 | 548 | | |
542 | 549 | | |
| |||
581 | 588 | | |
582 | 589 | | |
583 | 590 | | |
584 | | - | |
| 591 | + | |
585 | 592 | | |
586 | 593 | | |
587 | 594 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
123 | 130 | | |
124 | 131 | | |
125 | 132 | | |
| |||
181 | 188 | | |
182 | 189 | | |
183 | 190 | | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
184 | 197 | | |
185 | 198 | | |
186 | 199 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
143 | 147 | | |
144 | 148 | | |
145 | 149 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5347 | 5347 | | |
5348 | 5348 | | |
5349 | 5349 | | |
5350 | | - | |
| 5350 | + | |
5351 | 5351 | | |
5352 | 5352 | | |
5353 | 5353 | | |
| |||
5357 | 5357 | | |
5358 | 5358 | | |
5359 | 5359 | | |
5360 | | - | |
5361 | 5360 | | |
5362 | 5361 | | |
5363 | 5362 | | |
5364 | | - | |
| 5363 | + | |
5365 | 5364 | | |
5366 | 5365 | | |
5367 | 5366 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1252 | 1252 | | |
1253 | 1253 | | |
1254 | 1254 | | |
| 1255 | + | |
1255 | 1256 | | |
1256 | 1257 | | |
0 commit comments