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

Encoding v1 for Configurables #5942

Merged
merged 24 commits into from May 12, 2024
Merged

Conversation

xunilrj
Copy link
Contributor

@xunilrj xunilrj commented May 1, 2024

Description

This PR uses AbiEncode on configurables. We can imagine that

configurable {
    SOMETHING: u64 = 1
}

fn main() -> u64 {
    SOMETHING
}

will be desugared into

configurable {
    SOMETHING: slice = encode(1)
}

fn main() -> u64 {
    abi_decode(SOMETHING)
}

To allow this, now the whole encode function and all trait impls run inside const_eval. To make this work, three new intrinsic were implemented: EncodeBufferEmpty, EncodeBufferAppend, and EncodeBufferAsRawSlice.

EncodeBufferEmpty creates an empty "encoding buffer", which is composed of a pointer to the buffer, the buffer capacity, and how many bytes were written already.

EncodeBufferAppend appends any primitive data types to the buffer. This intrinsic does not mutate its argument, it returns a new "encoding buffer". If no reallocation is needed, the pointer and the capacity stay the same.

EncodeBufferAsRawSlice returns a slice with is composed of the buffer pointer and its length (not the capacity).

Errors

Some constant expressions cannot live inside the data section because their encoding depends on some instance value, for example: string slices, Vecs, Sttrings, Bytes etc... For these we now we return an error in these cases, like

  error
            --> /home/xunilrj/github/sway/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/src/main.sw:33:5
             |
          31 | 
          32 |     C6: str[4] = __to_str_array("fuel"),
          33 |     C6_2: str = "fuel as str",
             |     ^^^^ This code cannot be evaluated to a configurable because its size is not always limited.
          34 |     C7: [u64; 4] = [1, 2, 3, 4],
          35 |     
             |
          ____

Future TODOs

This PR adds two more tasks to #5727:

  • Enable sdk-harness tests that were ignore. SDK needs to update configurable encoding.
  • Correctly error when a type with custom impl for AbiEncode is used in configurables
  • avoid decoding on each use

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).
  • 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.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@xunilrj xunilrj force-pushed the xunilrj/new-encoding-configurables branch from 6c90385 to 242f8d0 Compare May 2, 2024 13:26
Copy link

github-actions bot commented May 2, 2024

Benchmark for 3ab0c9b

Click to view benchmark
Test Base PR %
code_action 5.6±0.21ms 6.1±0.27ms +8.93%
code_lens 286.9±7.97ns 301.3±11.70ns +5.02%
compile 6.5±0.09s 6.4±0.08s -1.54%
completion 5.6±0.46ms 5.5±0.47ms -1.79%
did_change_with_caching 6.4±0.15s 6.4±0.15s 0.00%
document_symbol 943.0±13.21µs 1023.2±46.99µs +8.50%
format 87.7±2.38ms 88.5±2.78ms +0.91%
goto_definition 367.2±13.22µs 373.5±8.97µs +1.72%
highlight 9.1±0.23ms 9.2±0.38ms +1.10%
hover 615.4±21.06µs 613.7±16.57µs -0.28%
idents_at_position 123.1±2.80µs 123.2±1.91µs +0.08%
inlay_hints 665.1±23.73µs 680.1±20.50µs +2.26%
on_enter 489.8±18.88ns 552.0±16.22ns +12.70%
parent_decl_at_position 3.8±0.13ms 3.9±0.12ms +2.63%
prepare_rename 368.0±7.83µs 371.6±15.42µs +0.98%
rename 9.7±0.18ms 9.9±0.34ms +2.06%
semantic_tokens 1044.6±40.28µs 1040.6±19.47µs -0.38%
token_at_position 356.5±3.33µs 366.0±3.99µs +2.66%
tokens_at_position 3.8±0.17ms 3.8±0.09ms 0.00%
tokens_for_file 420.7±3.25µs 425.3±3.77µs +1.09%
traverse 51.3±2.14ms 50.7±2.50ms -1.17%

Copy link

github-actions bot commented May 2, 2024

Benchmark for 220b67a

Click to view benchmark
Test Base PR %
code_action 5.5±0.04ms 5.5±0.02ms 0.00%
code_lens 298.3±17.56ns 286.8±5.73ns -3.86%
compile 6.3±0.05s 6.3±0.05s 0.00%
completion 5.1±0.11ms 5.0±0.15ms -1.96%
did_change_with_caching 6.3±0.06s 6.2±0.11s -1.59%
document_symbol 1109.1±43.05µs 958.9±42.71µs -13.54%
format 89.8±2.14ms 89.5±1.19ms -0.33%
goto_definition 365.1±7.89µs 365.2±6.73µs +0.03%
highlight 9.1±0.30ms 9.1±0.39ms 0.00%
hover 609.1±14.32µs 605.6±22.22µs -0.57%
idents_at_position 123.2±2.28µs 123.6±1.97µs +0.32%
inlay_hints 676.3±42.55µs 670.0±14.93µs -0.93%
on_enter 497.7±16.38ns 516.5±15.94ns +3.78%
parent_decl_at_position 3.8±0.03ms 3.7±0.05ms -2.63%
prepare_rename 362.3±5.42µs 365.5±6.56µs +0.88%
rename 9.6±0.21ms 9.7±0.15ms +1.04%
semantic_tokens 1085.8±8.34µs 1065.3±17.07µs -1.89%
token_at_position 361.5±1.87µs 360.3±3.27µs -0.33%
tokens_at_position 3.8±0.03ms 3.7±0.03ms -2.63%
tokens_for_file 423.5±4.13µs 425.7±3.61µs +0.52%
traverse 50.0±2.14ms 50.4±1.55ms +0.80%

Copy link

github-actions bot commented May 3, 2024

Benchmark for 520aae7

Click to view benchmark
Test Base PR %
code_action 5.5±0.14ms 5.3±0.01ms -3.64%
code_lens 300.7±8.98ns 328.0±10.17ns +9.08%
compile 6.2±0.04s 6.1±0.06s -1.61%
completion 4.9±0.02ms 4.8±0.05ms -2.04%
did_change_with_caching 6.2±0.06s 6.0±0.08s -3.23%
document_symbol 924.4±11.97µs 960.4±54.36µs +3.89%
format 88.0±1.86ms 89.4±1.46ms +1.59%
goto_definition 370.5±4.05µs 367.9±21.42µs -0.70%
highlight 9.0±0.04ms 8.7±0.19ms -3.33%
hover 609.8±18.52µs 605.6±7.52µs -0.69%
idents_at_position 123.4±0.33µs 123.1±2.05µs -0.24%
inlay_hints 656.9±14.70µs 655.0±16.66µs -0.29%
on_enter 487.6±12.33ns 480.5±8.31ns -1.46%
parent_decl_at_position 3.7±0.02ms 3.6±0.06ms -2.70%
prepare_rename 368.1±4.99µs 360.8±4.48µs -1.98%
rename 9.6±0.20ms 9.1±0.19ms -5.21%
semantic_tokens 1049.4±14.18µs 1044.3±14.33µs -0.49%
token_at_position 366.6±2.51µs 354.9±4.58µs -3.19%
tokens_at_position 3.7±0.04ms 3.6±0.02ms -2.70%
tokens_for_file 419.5±4.71µs 420.6±4.40µs +0.26%
traverse 50.1±1.81ms 49.7±2.41ms -0.80%

Copy link

github-actions bot commented May 3, 2024

Benchmark for cb6635f

Click to view benchmark
Test Base PR %
code_action 5.5±0.06ms 5.5±0.09ms 0.00%
code_lens 292.4±8.20ns 329.4±10.28ns +12.65%
compile 6.3±0.06s 6.1±0.06s -3.17%
completion 4.9±0.03ms 4.9±0.08ms 0.00%
did_change_with_caching 6.2±0.07s 6.1±0.10s -1.61%
document_symbol 1006.8±51.31µs 987.4±21.07µs -1.93%
format 89.2±2.09ms 86.6±1.00ms -2.91%
goto_definition 357.3±6.92µs 361.5±7.00µs +1.18%
highlight 9.0±0.19ms 9.0±0.02ms 0.00%
hover 602.1±21.44µs 602.9±12.50µs +0.13%
idents_at_position 123.4±0.41µs 124.2±0.63µs +0.65%
inlay_hints 686.9±84.36µs 659.3±22.55µs -4.02%
on_enter 497.9±15.43ns 475.7±7.80ns -4.46%
parent_decl_at_position 3.7±0.04ms 3.7±0.05ms 0.00%
prepare_rename 360.1±8.37µs 360.3±6.98µs +0.06%
rename 9.5±0.05ms 9.6±0.10ms +1.05%
semantic_tokens 1032.5±16.63µs 1033.3±13.36µs +0.08%
token_at_position 356.8±1.69µs 359.2±3.53µs +0.67%
tokens_at_position 3.7±0.08ms 3.7±0.03ms 0.00%
tokens_for_file 423.5±2.53µs 417.6±3.26µs -1.39%
traverse 50.4±1.83ms 49.6±2.75ms -1.59%

Copy link

github-actions bot commented May 4, 2024

Benchmark for 1a12428

Click to view benchmark
Test Base PR %
code_action 5.4±0.01ms 5.4±0.03ms 0.00%
code_lens 287.7±8.67ns 294.8±6.83ns +2.47%
compile 6.2±0.03s 6.3±0.04s +1.61%
completion 4.9±0.07ms 4.8±0.07ms -2.04%
did_change_with_caching 6.2±0.06s 6.2±0.11s 0.00%
document_symbol 993.9±29.41µs 993.6±27.89µs -0.03%
format 89.5±1.28ms 87.0±0.55ms -2.79%
goto_definition 361.3±6.76µs 364.0±6.35µs +0.75%
highlight 9.0±0.13ms 8.7±0.06ms -3.33%
hover 595.5±24.26µs 617.6±18.19µs +3.71%
idents_at_position 123.2±0.43µs 124.5±0.97µs +1.06%
inlay_hints 663.7±23.04µs 656.7±21.54µs -1.05%
on_enter 491.9±11.73ns 476.5±12.71ns -3.13%
parent_decl_at_position 3.7±0.04ms 3.6±0.03ms -2.70%
prepare_rename 362.2±5.67µs 363.9±5.20µs +0.47%
rename 9.6±0.20ms 9.2±0.14ms -4.17%
semantic_tokens 1028.6±8.95µs 1054.3±7.90µs +2.50%
token_at_position 360.2±4.06µs 367.5±2.42µs +2.03%
tokens_at_position 3.7±0.02ms 3.6±0.04ms -2.70%
tokens_for_file 414.9±3.38µs 435.3±1.55µs +4.92%
traverse 50.4±1.66ms 50.9±1.80ms +0.99%

Copy link

github-actions bot commented May 4, 2024

Benchmark for 83f12af

Click to view benchmark
Test Base PR %
code_action 5.5±0.12ms 5.4±0.07ms -1.82%
code_lens 287.8±8.28ns 287.0±7.91ns -0.28%
compile 6.1±0.02s 6.2±0.02s +1.64%
completion 4.9±0.04ms 4.9±0.10ms 0.00%
did_change_with_caching 6.1±0.07s 6.0±0.06s -1.64%
document_symbol 1006.0±40.08µs 1023.8±30.45µs +1.77%
format 89.7±1.07ms 88.5±1.29ms -1.34%
goto_definition 356.9±9.92µs 372.6±6.05µs +4.40%
highlight 9.0±0.18ms 8.7±0.05ms -3.33%
hover 604.5±18.36µs 626.8±9.04µs +3.69%
idents_at_position 122.3±0.44µs 123.5±0.64µs +0.98%
inlay_hints 653.8±10.24µs 738.7±12.88µs +12.99%
on_enter 484.2±7.94ns 485.1±15.46ns +0.19%
parent_decl_at_position 3.7±0.02ms 3.6±0.03ms -2.70%
prepare_rename 358.7±6.22µs 380.0±3.11µs +5.94%
rename 9.5±0.02ms 9.3±0.19ms -2.11%
semantic_tokens 1011.9±10.41µs 1026.8±41.38µs +1.47%
token_at_position 355.4±1.98µs 373.1±2.13µs +4.98%
tokens_at_position 3.7±0.01ms 3.6±0.04ms -2.70%
tokens_for_file 415.6±2.57µs 425.9±2.13µs +2.48%
traverse 49.5±1.80ms 48.9±1.46ms -1.21%

Copy link

github-actions bot commented May 4, 2024

Benchmark for 78c35f3

Click to view benchmark
Test Base PR %
code_action 5.5±0.14ms 5.3±0.09ms -3.64%
code_lens 286.5±6.22ns 286.8±6.56ns +0.10%
compile 6.2±0.02s 6.1±0.04s -1.61%
completion 4.9±0.07ms 4.8±0.08ms -2.04%
did_change_with_caching 6.2±0.05s 6.1±0.08s -1.61%
document_symbol 969.6±39.17µs 992.2±35.23µs +2.33%
format 89.7±1.47ms 88.1±1.18ms -1.78%
goto_definition 364.9±6.21µs 365.0±6.02µs +0.03%
highlight 9.0±0.13ms 8.8±0.19ms -2.22%
hover 602.4±14.30µs 603.4±17.20µs +0.17%
idents_at_position 123.6±0.65µs 123.6±0.71µs 0.00%
inlay_hints 665.5±22.50µs 652.6±21.90µs -1.94%
on_enter 492.0±11.40ns 483.0±4.86ns -1.83%
parent_decl_at_position 3.7±0.02ms 3.6±0.04ms -2.70%
prepare_rename 360.0±5.56µs 363.0±6.23µs +0.83%
rename 9.5±0.04ms 9.2±0.15ms -3.16%
semantic_tokens 1052.3±24.17µs 1034.1±15.45µs -1.73%
token_at_position 354.8±2.11µs 359.1±2.48µs +1.21%
tokens_at_position 3.7±0.05ms 3.6±0.07ms -2.70%
tokens_for_file 421.1±1.70µs 430.3±2.49µs +2.18%
traverse 50.1±1.87ms 49.8±1.72ms -0.60%

Copy link

github-actions bot commented May 4, 2024

Benchmark for fac8e06

Click to view benchmark
Test Base PR %
code_action 5.4±0.02ms 5.3±0.04ms -1.85%
code_lens 291.0±9.59ns 284.9±6.50ns -2.10%
compile 6.2±0.07s 6.1±0.06s -1.61%
completion 4.9±0.09ms 4.8±0.02ms -2.04%
did_change_with_caching 6.2±0.05s 6.2±0.06s 0.00%
document_symbol 924.4±11.78µs 1015.5±35.01µs +9.86%
format 86.7±1.61ms 86.9±0.72ms +0.23%
goto_definition 359.8±4.98µs 536.1±1.45µs +49.00%
highlight 9.0±0.20ms 8.6±0.14ms -4.44%
hover 601.8±7.33µs 596.8±10.59µs -0.83%
idents_at_position 123.9±0.42µs 122.0±0.69µs -1.53%
inlay_hints 658.7±27.57µs 651.0±37.98µs -1.17%
on_enter 487.9±13.79ns 492.9±8.67ns +1.02%
parent_decl_at_position 3.7±0.04ms 3.6±0.04ms -2.70%
prepare_rename 358.4±6.02µs 366.1±7.65µs +2.15%
rename 9.5±0.25ms 9.1±0.02ms -4.21%
semantic_tokens 1033.4±9.84µs 1042.0±24.35µs +0.83%
token_at_position 355.4±2.90µs 357.0±1.97µs +0.45%
tokens_at_position 3.7±0.03ms 3.5±0.01ms -5.41%
tokens_for_file 416.1±1.91µs 429.7±2.66µs +3.27%
traverse 51.0±1.41ms 50.3±2.22ms -1.37%

@xunilrj xunilrj force-pushed the xunilrj/new-encoding-configurables branch from 0b0fae8 to 2e5041e Compare May 6, 2024 08:11
Copy link

github-actions bot commented May 6, 2024

Benchmark for 5836b4d

Click to view benchmark
Test Base PR %
code_action 5.3±0.14ms 5.6±0.49ms +5.66%
code_lens 294.2±8.84ns 332.1±8.76ns +12.88%
compile 6.8±0.10s 6.8±0.11s 0.00%
completion 4.8±0.10ms 4.9±0.02ms +2.08%
did_change_with_caching 6.4±0.03s 6.2±0.05s -3.13%
document_symbol 935.2±15.93µs 992.0±31.91µs +6.07%
format 88.3±2.55ms 86.6±1.31ms -1.93%
goto_definition 351.7±5.98µs 355.3±6.78µs +1.02%
highlight 8.7±0.16ms 9.0±0.19ms +3.45%
hover 588.1±11.88µs 592.4±10.04µs +0.73%
idents_at_position 122.4±0.36µs 122.5±1.37µs +0.08%
inlay_hints 647.5±19.11µs 663.4±24.20µs +2.46%
on_enter 488.7±7.45ns 496.4±25.22ns +1.58%
parent_decl_at_position 3.6±0.10ms 3.7±0.03ms +2.78%
prepare_rename 348.4±7.42µs 352.4±5.45µs +1.15%
rename 9.2±0.13ms 9.6±0.03ms +4.35%
semantic_tokens 1034.4±44.47µs 1048.9±19.97µs +1.40%
token_at_position 345.3±11.29µs 348.7±6.07µs +0.98%
tokens_at_position 3.6±0.05ms 3.7±0.05ms +2.78%
tokens_for_file 419.6±3.20µs 457.5±11.46µs +9.03%
traverse 52.2±1.83ms 52.4±1.82ms +0.38%

Copy link

github-actions bot commented May 6, 2024

Benchmark for 47a7010

Click to view benchmark
Test Base PR %
code_action 5.4±0.10ms 5.3±0.13ms -1.85%
code_lens 291.5±7.41ns 286.0±7.89ns -1.89%
compile 6.8±0.13s 6.6±0.08s -2.94%
completion 4.8±0.03ms 4.8±0.14ms 0.00%
did_change_with_caching 6.1±0.07s 6.1±0.07s 0.00%
document_symbol 1007.5±49.58µs 1058.6±48.38µs +5.07%
format 88.7±1.23ms 87.1±1.74ms -1.80%
goto_definition 347.7±8.09µs 350.4±7.26µs +0.78%
highlight 8.7±0.15ms 8.7±0.26ms 0.00%
hover 579.2±8.91µs 584.5±25.98µs +0.92%
idents_at_position 120.8±0.42µs 120.7±1.07µs -0.08%
inlay_hints 648.7±22.49µs 640.5±26.23µs -1.26%
on_enter 481.1±12.56ns 485.1±7.95ns +0.83%
parent_decl_at_position 3.7±0.03ms 3.6±0.04ms -2.70%
prepare_rename 348.9±15.20µs 348.6±5.69µs -0.09%
rename 9.3±0.20ms 9.2±0.03ms -1.08%
semantic_tokens 1056.6±19.78µs 1125.4±7.83µs +6.51%
token_at_position 349.1±7.71µs 346.8±4.22µs -0.66%
tokens_at_position 3.7±0.04ms 3.6±0.03ms -2.70%
tokens_for_file 417.6±1.92µs 422.3±9.43µs +1.13%
traverse 51.0±2.25ms 49.8±1.19ms -2.35%

@xunilrj xunilrj mentioned this pull request May 6, 2024
22 tasks
Copy link

github-actions bot commented May 6, 2024

Benchmark for 1f0e379

Click to view benchmark
Test Base PR %
code_action 5.3±0.11ms 5.3±0.04ms 0.00%
code_lens 292.7±3.96ns 295.3±33.47ns +0.89%
compile 6.7±0.12s 6.7±0.13s 0.00%
completion 4.8±0.12ms 4.8±0.04ms 0.00%
did_change_with_caching 6.2±0.05s 6.1±0.08s -1.61%
document_symbol 967.1±45.24µs 956.4±15.10µs -1.11%
format 91.4±0.69ms 87.4±1.12ms -4.38%
goto_definition 351.1±4.77µs 347.5±9.47µs -1.03%
highlight 8.7±0.24ms 8.7±0.03ms 0.00%
hover 591.6±6.45µs 610.4±20.19µs +3.18%
idents_at_position 119.6±0.72µs 119.3±0.51µs -0.25%
inlay_hints 690.2±20.37µs 644.2±23.51µs -6.66%
on_enter 478.6±12.51ns 483.4±9.37ns +1.00%
parent_decl_at_position 3.6±0.06ms 3.6±0.04ms 0.00%
prepare_rename 347.6±6.62µs 353.5±6.21µs +1.70%
rename 9.2±0.24ms 9.7±0.35ms +5.43%
semantic_tokens 1043.5±17.24µs 1076.5±14.61µs +3.16%
token_at_position 413.9±2.41µs 345.2±4.89µs -16.60%
tokens_at_position 3.6±0.04ms 3.6±0.05ms 0.00%
tokens_for_file 413.8±2.39µs 422.5±4.22µs +2.10%
traverse 50.4±1.58ms 49.7±2.47ms -1.39%

@xunilrj xunilrj self-assigned this May 6, 2024
@xunilrj xunilrj marked this pull request as ready for review May 6, 2024 10:02
@xunilrj xunilrj requested a review from kayagokalp as a code owner May 6, 2024 10:02
@xunilrj xunilrj requested a review from a team May 6, 2024 10:15
Copy link

github-actions bot commented May 6, 2024

Benchmark for 48efa0d

Click to view benchmark
Test Base PR %
code_action 5.4±0.11ms 5.3±0.10ms -1.85%
code_lens 287.6±8.67ns 287.1±8.07ns -0.17%
compile 6.8±0.09s 6.8±0.09s 0.00%
completion 4.9±0.16ms 4.8±0.06ms -2.04%
did_change_with_caching 6.3±0.06s 6.3±0.08s 0.00%
document_symbol 1018.4±14.89µs 1029.9±14.66µs +1.13%
format 89.0±1.21ms 87.4±1.04ms -1.80%
goto_definition 353.4±8.82µs 355.1±2.78µs +0.48%
highlight 8.8±0.29ms 8.8±0.23ms 0.00%
hover 596.2±17.78µs 585.2±5.78µs -1.85%
idents_at_position 120.2±0.47µs 120.5±0.46µs +0.25%
inlay_hints 639.7±26.27µs 644.8±14.76µs +0.80%
on_enter 484.0±15.21ns 489.1±14.31ns +1.05%
parent_decl_at_position 3.6±0.02ms 3.6±0.04ms 0.00%
prepare_rename 354.0±7.04µs 349.5±11.47µs -1.27%
rename 9.4±0.27ms 9.3±0.26ms -1.06%
semantic_tokens 1040.1±19.64µs 1038.1±13.72µs -0.19%
token_at_position 347.1±3.30µs 347.8±3.55µs +0.20%
tokens_at_position 3.7±0.15ms 3.6±0.04ms -2.70%
tokens_for_file 428.1±2.93µs 420.8±3.30µs -1.71%
traverse 51.6±2.09ms 50.4±1.45ms -2.33%

Copy link

github-actions bot commented May 6, 2024

Benchmark for ce45538

Click to view benchmark
Test Base PR %
code_action 5.5±0.03ms 5.6±0.31ms +1.82%
code_lens 288.7±10.07ns 302.4±5.66ns +4.75%
compile 6.7±0.08s 6.6±0.05s -1.49%
completion 5.0±0.08ms 4.9±0.06ms -2.00%
did_change_with_caching 6.2±0.07s 6.1±0.05s -1.61%
document_symbol 989.2±32.55µs 943.6±10.20µs -4.61%
format 89.8±1.29ms 89.0±1.14ms -0.89%
goto_definition 352.0±9.94µs 350.4±4.41µs -0.45%
highlight 9.0±0.15ms 9.1±0.13ms +1.11%
hover 579.5±7.76µs 587.3±8.13µs +1.35%
idents_at_position 119.8±0.45µs 121.2±1.09µs +1.17%
inlay_hints 648.7±18.73µs 649.3±22.84µs +0.09%
on_enter 473.6±15.39ns 482.8±19.12ns +1.94%
parent_decl_at_position 3.7±0.01ms 3.7±0.09ms 0.00%
prepare_rename 348.2±11.28µs 345.6±5.87µs -0.75%
rename 9.5±0.17ms 9.7±0.19ms +2.11%
semantic_tokens 1021.4±22.94µs 1052.3±11.95µs +3.03%
token_at_position 340.1±2.21µs 342.5±3.64µs +0.71%
tokens_at_position 3.7±0.03ms 3.7±0.02ms 0.00%
tokens_for_file 412.1±2.16µs 413.0±2.08µs +0.22%
traverse 49.9±1.67ms 49.1±1.01ms -1.60%

@xunilrj xunilrj force-pushed the xunilrj/new-encoding-configurables branch from 23d1c8f to d0d9b04 Compare May 6, 2024 20:40
Copy link

github-actions bot commented May 6, 2024

Benchmark for f0772f4

Click to view benchmark
Test Base PR %
code_action 5.5±0.07ms 5.5±0.13ms 0.00%
code_lens 291.3±18.66ns 345.3±33.29ns +18.54%
compile 6.7±0.07s 7.0±0.09s +4.48%
completion 4.9±0.16ms 4.9±0.10ms 0.00%
did_change_with_caching 6.3±0.11s 6.4±0.05s +1.59%
document_symbol 1000.3±36.68µs 990.8±18.01µs -0.95%
format 89.5±4.30ms 90.6±0.55ms +1.23%
goto_definition 359.9±8.98µs 345.8±8.26µs -3.92%
highlight 9.0±0.61ms 9.0±0.05ms 0.00%
hover 606.7±19.86µs 585.5±8.53µs -3.49%
idents_at_position 120.3±1.58µs 119.5±1.75µs -0.67%
inlay_hints 702.8±21.96µs 647.7±29.79µs -7.84%
on_enter 472.8±14.34ns 510.1±35.61ns +7.89%
parent_decl_at_position 3.7±0.05ms 3.7±0.05ms 0.00%
prepare_rename 359.3±5.88µs 350.9±7.00µs -2.34%
rename 9.5±0.18ms 9.7±0.28ms +2.11%
semantic_tokens 1053.5±24.67µs 1072.3±29.16µs +1.78%
token_at_position 415.1±1.98µs 347.4±5.40µs -16.31%
tokens_at_position 3.7±0.05ms 3.7±0.04ms 0.00%
tokens_for_file 417.8±1.92µs 420.7±5.19µs +0.69%
traverse 51.0±1.54ms 52.8±1.58ms +3.53%

@xunilrj xunilrj requested review from a team and IGI-111 May 7, 2024 09:48
Copy link
Member

@ironcev ironcev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before reviewing the implementation, there are two points that IMO needs to be addressed: the serious change in the semantics of configurables as entities and the cost of usage.

Semantics

Up to now, configurables were treated like other constants, with the difference being deploy-time defined. But unchangable at runtime and in every aspect same as other constants at runtime.

This means, considering:

configurable {
    CONF: SomeStruct = SomeStruct { x: 0, y: 0 },
}

fn fun() {
    let p_1 = _addr_of(CONF);
    let p_2 = _addr_of(CONF);

    let r_1 = &CONF:
    let r_2 = &CONF:
}

the two pointers were pointing to the same struct, same as the two references.

With the current v1 implementation the code becomes, simplified to demonstrate the new semantics:

fn fun() {
    let p_1 = _addr_of(abi_decode(CONF));
    let p_2 = _addr_of(abi_decode(CONF));

    let r_1 = &abi_decode(CONF):
    let r_2 = &abi_decode(CONF):
}

This gives us four different entities, means different pointers and different references.

Cost of usage

Calling abi_decode on every use explodes the generated IR code tremendously. The simple line from above:

let p_1 = _addr_of(CONF);

used to be just one IR instruction (store c0 to v0). Understandably it is now dozens of costly instructions like function calls, memcpy, asm, ...

This makes simple expressions like CONF.x + CONF.y extremely expensive at run-time, prohibits every function using configurables to be inlined because it will be huge etc. E.g., just having CONF used in a loop could end up in a huge gas consumption.

Mitigation

I am thinking how to mitigate both points, to keep the proper semantics and also to remove the hidden runtime cost because it is huge and on every call site.

Could we perhaps do the decoding only once in the __entry and also store the decoded values in the config section and then use them as we use them now, as direct pointers? I am not sure if we can write to config from the code, but if possible, the config would look like e.g.:

// Encoded values.
c0 = config [u8; 16] [u8 0, u8 0, u8 0, u8 0, u8 0, u8 0, u8 0, u8 0, u8 0, u8 0, u8 0, u8 0, u8 0, u8 0, u8 0, u8 0],
c1 = config [u8; 8] [u8 0, u8 0, u8 0, u8 0, u8 0, u8 1, u8 182, u8 105],
...
// Their decoded counterparts filled in `__entry`.
c10 = config { u64, u64 } .... some value here ....,
c11 = config u64 112233,

We can explore other options too.

I see it as necessary to resolve the above two issues, semantics and cost, before getting the feature out.

@xunilrj
Copy link
Contributor Author

xunilrj commented May 7, 2024

I agree, but the question is if makes sense to merge this PR as is and improve these things later. Because the SDK needs this PR to finish their migration to encoding V1.
And we can improve code generation in parallel, without blocking them.

@ironcev
Copy link
Member

ironcev commented May 7, 2024

I am fine with merging as is to unblock the SDK team as long as we continue immediately working on the points. Because as mentioned having the feature out as is would have serious unwanted consequences. Also, I can ignore configurables in my work in properly treating consts everywhere in IR and in inlining until the above issues are solved that also shouldn't be a problem.

@xunilrj
Copy link
Contributor Author

xunilrj commented May 7, 2024

I am fine with merging as is to unblock the SDK team as long as we continue immediately working on the points.

This is the idea.

xunilrj and others added 24 commits May 12, 2024 17:58
ir generation for intrinsics

intrinsics compilation to ir

IR generation for encoding intrinsics working

configurable encoding bytes as arrays

uints working

configurable_const test ok

append for string array

more tests passing

fmt and clippy issue

support for string slice as configurable

don´t allow storage to be initialized with configurables

fmt core lib

clippy issues

fix uints smaller than u64

clippy issues

fixing configurable encoding for enums

fix enum encoding

more size hints implemented

more tests

fixing CI issues
@xunilrj xunilrj force-pushed the xunilrj/new-encoding-configurables branch from e4b9542 to 4252fe2 Compare May 12, 2024 16:59
Copy link

Benchmark for ded4b0d

Click to view benchmark
Test Base PR %
code_action 5.4±0.02ms 5.4±0.07ms 0.00%
code_lens 331.1±9.81ns 296.0±3.58ns -10.60%
compile 3.0±0.04s 2.9±0.04s -3.33%
completion 4.7±0.03ms 4.7±0.05ms 0.00%
did_change_with_caching 2.9±0.04s 2.8±0.04s -3.45%
document_symbol 1036.0±45.07µs 956.6±16.68µs -7.66%
format 71.8±1.11ms 72.2±0.59ms +0.56%
goto_definition 365.1±7.01µs 357.9±6.25µs -1.97%
highlight 9.0±0.01ms 9.1±0.03ms +1.11%
hover 484.7±5.40µs 476.0±5.49µs -1.79%
idents_at_position 123.0±0.34µs 122.6±1.51µs -0.33%
inlay_hints 670.4±7.11µs 666.8±20.37µs -0.54%
on_enter 484.4±14.87ns 507.6±12.25ns +4.79%
parent_decl_at_position 3.7±0.04ms 3.7±0.01ms 0.00%
prepare_rename 365.7±4.35µs 357.8±6.42µs -2.16%
rename 9.6±0.03ms 9.6±0.12ms 0.00%
semantic_tokens 1039.2±13.58µs 1056.9±18.11µs +1.70%
token_at_position 358.4±2.31µs 361.6±2.87µs +0.89%
tokens_at_position 3.7±0.04ms 3.7±0.05ms 0.00%
tokens_for_file 437.1±2.18µs 425.0±2.91µs -2.77%
traverse 41.9±1.63ms 40.6±1.07ms -3.10%

@xunilrj xunilrj merged commit a7d35d3 into master May 12, 2024
38 checks passed
@xunilrj xunilrj deleted the xunilrj/new-encoding-configurables branch May 12, 2024 17:22
@hal3e hal3e restored the xunilrj/new-encoding-configurables branch May 12, 2024 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking May cause existing user code to break. Requires a minor or major release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants