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

Fix and improve errors when the entry fns cannot be generated #5824

Merged
merged 8 commits into from
Apr 9, 2024

Conversation

xunilrj
Copy link
Contributor

@xunilrj xunilrj commented Apr 3, 2024

Description

This PR improves fix a problem when a type cannot be auto-impled and improve error messages for this case.

This can be seen on tests/types/contracts/type_inside_enum in the Rust SDK repo.

     Running `target/debug/forc build --path /home/xunilrj/github/fuels-rs/packages/fuels --experimental-new-encoding`
thread 'main' panicked at sway-ir/src/constant.rs:172:14:
Enums are aggregates.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Given that this PR also improve implementation of arrays for AbiEncode and AbiDecode, the entry function is actually generated. But in case of error, it will fail like:

error
    --> /home/xunilrj/.forc/git/checkouts/std-9be0d6062747ea7/5645f10143243e1fd64a55002cd5c09730636ece/sway-lib-core/src/codec.sw:2192:8
     |
2190 | 
2191 | pub trait AbiDecode {
2192 |     fn abi_decode(ref mut buffer: BufferReader) -> Self;
     |        ^^^^^^^^^^ No method named "abi_decode" found for type "SomeEnum".
2193 | }
     |
____

error
 --> <autogenerated>:5:61
  |
3 | 
4 |                     let args: (SomeEnum,) = decode_second_param::<(SomeEnum,)>();
5 |                     let result_arr_inside_enum: raw_slice = encode::<SomeEnum>(__contract_entry_arr_inside_enum(args.0));
  |                                                             ^^^^^^^^^^^^^^^^^^ Trait "AbiEncode" is not implemented for type "SomeEnum".
6 |                     __contract_ret(result_arr_inside_enum.ptr(), result_arr_inside_enum.len::<u8>());
7 |                 }
  |
____

error
  --> <autogenerated>:24:61
   |
22 | 
23 |                     let args: (SomeEnum,) = decode_second_param::<(SomeEnum,)>();
24 |                     let result_str_inside_enum: raw_slice = encode::<SomeEnum>(__contract_entry_str_inside_enum(args.0));
   |                                                             ^^^^^^^^^^^^^^^^^^ Trait "AbiEncode" is not implemented for type "SomeEnum".
25 |                     __contract_ret(result_str_inside_enum.ptr(), result_str_inside_enum.len::<u8>());
26 |                 }
   |
____

error: Could not generate the entry method because one of the arguments does not implement AbiEncode/AbiDecode
____

  Aborting due to 4 errors.
Error: Failed to compile type_inside_enum

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.

Copy link

github-actions bot commented Apr 3, 2024

Benchmark for d8c8acd

Click to view benchmark
Test Base PR %
code_action 5.5±0.35ms 5.3±0.17ms -3.64%
code_lens 297.7±4.93ns 296.6±8.61ns -0.37%
compile 6.0±0.11s 6.0±0.11s 0.00%
completion 4.9±0.15ms 4.8±0.13ms -2.04%
did_change_with_caching 5.5±0.03s 5.5±0.05s 0.00%
document_symbol 1005.3±43.41µs 1006.4±35.91µs +0.11%
format 70.6±1.15ms 72.1±1.35ms +2.12%
goto_definition 365.0±10.14µs 363.9±7.60µs -0.30%
highlight 8.8±0.22ms 8.7±0.17ms -1.14%
hover 659.4±12.27µs 594.1±10.46µs -9.90%
idents_at_position 122.3±1.36µs 121.7±0.71µs -0.49%
inlay_hints 660.1±37.95µs 654.4±7.42µs -0.86%
on_enter 485.3±13.18ns 504.7±11.28ns +4.00%
parent_decl_at_position 3.6±0.04ms 3.6±0.02ms 0.00%
prepare_rename 360.6±5.76µs 359.7±5.87µs -0.25%
rename 9.3±0.17ms 9.2±0.20ms -1.08%
semantic_tokens 1047.8±14.63µs 1038.1±28.66µs -0.93%
token_at_position 363.8±3.72µs 356.8±3.73µs -1.92%
tokens_at_position 3.6±0.02ms 3.6±0.04ms 0.00%
tokens_for_file 408.6±2.43µs 409.9±3.32µs +0.32%
traverse 44.9±1.55ms 44.7±1.83ms -0.45%

Copy link

github-actions bot commented Apr 3, 2024

Benchmark for af8c0f4

Click to view benchmark
Test Base PR %
code_action 5.5±0.05ms 5.5±0.02ms 0.00%
code_lens 288.2±9.00ns 334.6±10.42ns +16.10%
compile 6.0±0.07s 5.9±0.04s -1.67%
completion 4.9±0.02ms 5.0±0.02ms +2.04%
did_change_with_caching 5.4±0.03s 5.4±0.03s 0.00%
document_symbol 993.0±41.40µs 988.5±33.87µs -0.45%
format 93.6±1.83ms 89.5±5.15ms -4.38%
goto_definition 365.1±5.17µs 369.1±9.66µs +1.10%
highlight 9.1±0.20ms 9.1±0.03ms 0.00%
hover 609.8±18.84µs 663.3±12.83µs +8.77%
idents_at_position 121.8±0.34µs 122.6±0.61µs +0.66%
inlay_hints 670.6±16.71µs 723.9±22.62µs +7.95%
on_enter 503.7±12.15ns 497.1±15.63ns -1.31%
parent_decl_at_position 3.7±0.02ms 3.8±0.02ms +2.70%
prepare_rename 361.7±6.46µs 362.2±6.16µs +0.14%
rename 9.6±0.15ms 9.6±0.02ms 0.00%
semantic_tokens 1036.1±33.15µs 1059.9±21.22µs +2.30%
token_at_position 348.8±3.10µs 356.0±3.03µs +2.06%
tokens_at_position 3.8±0.12ms 3.7±0.03ms -2.63%
tokens_for_file 430.6±5.18µs 410.5±2.24µs -4.67%
traverse 43.6±1.66ms 43.5±1.32ms -0.23%

Copy link

github-actions bot commented Apr 3, 2024

Benchmark for 7f9340c

Click to view benchmark
Test Base PR %
code_action 5.3±0.07ms 5.6±0.08ms +5.66%
code_lens 296.4±13.49ns 292.6±5.83ns -1.28%
compile 6.0±0.05s 7.8±0.22s +30.00%
completion 4.9±0.10ms 5.3±0.44ms +8.16%
did_change_with_caching 5.6±0.04s 7.3±0.15s +30.36%
document_symbol 956.4±9.18µs 970.2±23.74µs +1.44%
format 73.2±2.61ms 81.7±2.13ms +11.61%
goto_definition 367.6±5.75µs 367.6±5.51µs 0.00%
highlight 8.8±0.06ms 9.1±0.03ms +3.41%
hover 602.0±19.43µs 651.0±15.53µs +8.14%
idents_at_position 124.3±1.30µs 122.4±1.64µs -1.53%
inlay_hints 677.0±24.76µs 675.2±19.16µs -0.27%
on_enter 487.3±13.89ns 494.2±14.16ns +1.42%
parent_decl_at_position 3.6±0.05ms 3.8±0.09ms +5.56%
prepare_rename 366.6±5.69µs 361.8±7.57µs -1.31%
rename 9.3±0.17ms 9.9±0.53ms +6.45%
semantic_tokens 1056.9±24.05µs 1058.8±34.11µs +0.18%
token_at_position 361.7±7.27µs 362.6±3.22µs +0.25%
tokens_at_position 3.6±0.05ms 3.7±0.03ms +2.78%
tokens_for_file 411.5±1.99µs 420.6±4.35µs +2.21%
traverse 46.4±2.72ms 51.3±2.67ms +10.56%

Copy link

github-actions bot commented Apr 3, 2024

Benchmark for c663ef2

Click to view benchmark
Test Base PR %
code_action 5.5±0.03ms 5.4±0.14ms -1.82%
code_lens 290.4±6.59ns 339.5±16.66ns +16.91%
compile 5.9±0.08s 7.2±0.04s +22.03%
completion 4.9±0.08ms 4.9±0.09ms 0.00%
did_change_with_caching 5.4±0.03s 6.9±0.03s +27.78%
document_symbol 1000.6±36.20µs 1040.5±21.12µs +3.99%
format 91.9±1.12ms 92.2±0.94ms +0.33%
goto_definition 362.4±2.92µs 371.4±4.14µs +2.48%
highlight 9.1±0.03ms 8.8±0.02ms -3.30%
hover 665.7±36.96µs 650.7±27.11µs -2.25%
idents_at_position 123.9±0.53µs 123.6±0.67µs -0.24%
inlay_hints 662.4±20.53µs 661.7±19.83µs -0.11%
on_enter 505.4±11.79ns 493.4±21.99ns -2.37%
parent_decl_at_position 3.7±0.03ms 3.6±0.03ms -2.70%
prepare_rename 361.9±8.31µs 373.7±4.66µs +3.26%
rename 9.6±0.16ms 9.3±0.02ms -3.12%
semantic_tokens 1040.1±16.91µs 1049.1±12.41µs +0.87%
token_at_position 350.3±3.26µs 358.3±5.24µs +2.28%
tokens_at_position 3.7±0.03ms 3.6±0.25ms -2.70%
tokens_for_file 414.1±1.84µs 406.9±2.89µs -1.74%
traverse 42.9±1.62ms 49.5±1.86ms +15.38%

@xunilrj xunilrj self-assigned this Apr 4, 2024
@xunilrj xunilrj added the breaking May cause existing user code to break. Requires a minor or major release. label Apr 4, 2024
@xunilrj xunilrj marked this pull request as ready for review April 4, 2024 08:56
Copy link

github-actions bot commented Apr 4, 2024

Benchmark for 6764d51

Click to view benchmark
Test Base PR %
code_action 5.5±0.13ms 5.5±0.15ms 0.00%
code_lens 292.1±11.24ns 298.1±8.61ns +2.05%
compile 6.1±0.09s 7.5±0.07s +22.95%
completion 5.0±0.13ms 5.0±0.15ms 0.00%
did_change_with_caching 5.6±0.05s 7.0±0.04s +25.00%
document_symbol 968.5±30.27µs 1045.9±48.06µs +7.99%
format 91.2±2.10ms 90.3±1.59ms -0.99%
goto_definition 360.2±8.65µs 365.7±20.52µs +1.53%
highlight 9.2±0.30ms 9.0±0.24ms -2.17%
hover 606.1±20.87µs 650.5±14.11µs +7.33%
idents_at_position 122.9±0.43µs 124.3±2.89µs +1.14%
inlay_hints 666.9±17.14µs 668.0±32.04µs +0.16%
on_enter 478.0±17.22ns 479.9±25.53ns +0.40%
parent_decl_at_position 3.7±0.07ms 3.7±0.09ms 0.00%
prepare_rename 362.2±16.99µs 363.4±8.87µs +0.33%
rename 9.6±0.21ms 9.6±0.15ms 0.00%
semantic_tokens 1031.7±16.01µs 1042.7±11.46µs +1.07%
token_at_position 363.5±2.93µs 362.0±4.05µs -0.41%
tokens_at_position 3.7±0.03ms 3.7±0.05ms 0.00%
tokens_for_file 412.3±2.46µs 411.0±2.78µs -0.32%
traverse 44.3±1.94ms 51.0±1.80ms +15.12%

@xunilrj xunilrj requested a review from a team April 4, 2024 09:30
@xunilrj xunilrj requested a review from a team April 5, 2024 11:29
Copy link

github-actions bot commented Apr 5, 2024

Benchmark for 4ce2783

Click to view benchmark
Test Base PR %
code_action 5.4±0.03ms 5.3±0.03ms -1.85%
code_lens 327.8±10.98ns 290.1±6.74ns -11.50%
compile 6.0±0.13s 7.5±0.16s +25.00%
completion 4.9±0.12ms 5.0±0.20ms +2.04%
did_change_with_caching 5.5±0.09s 7.1±0.14s +29.09%
document_symbol 952.0±9.69µs 1014.1±41.37µs +6.52%
format 89.6±1.62ms 90.8±2.18ms +1.34%
goto_definition 363.1±5.41µs 367.1±8.83µs +1.10%
highlight 9.0±0.17ms 9.0±0.09ms 0.00%
hover 608.4±14.92µs 643.6±9.69µs +5.79%
idents_at_position 121.7±0.73µs 122.2±1.55µs +0.41%
inlay_hints 651.7±17.27µs 657.8±21.28µs +0.94%
on_enter 485.3±14.95ns 519.3±28.67ns +7.01%
parent_decl_at_position 3.7±0.05ms 3.6±0.07ms -2.70%
prepare_rename 361.8±8.01µs 367.8±4.65µs +1.66%
rename 9.5±0.22ms 9.3±0.39ms -2.11%
semantic_tokens 1037.4±10.62µs 1062.8±14.79µs +2.45%
token_at_position 355.0±5.32µs 365.2±3.87µs +2.87%
tokens_at_position 3.7±0.05ms 3.6±0.05ms -2.70%
tokens_for_file 422.0±4.70µs 426.1±1.71µs +0.97%
traverse 45.6±1.28ms 52.5±2.03ms +15.13%

@IGI-111 IGI-111 requested a review from a team April 8, 2024 12:56
@IGI-111 IGI-111 mentioned this pull request Apr 8, 2024
@xunilrj xunilrj force-pushed the xunilrj/improve-err-msg-new-encoding branch from 3ca56c1 to 1f498b8 Compare April 9, 2024 12:46
Copy link

github-actions bot commented Apr 9, 2024

Benchmark for 5570e1d

Click to view benchmark
Test Base PR %
code_action 5.4±0.11ms 5.5±0.07ms +1.85%
code_lens 308.7±8.67ns 288.9±14.07ns -6.41%
compile 5.1±0.12s 6.5±0.11s +27.45%
completion 4.9±0.08ms 5.0±0.05ms +2.04%
did_change_with_caching 4.9±0.04s 6.3±0.05s +28.57%
document_symbol 933.2±23.18µs 944.4±9.65µs +1.20%
format 72.0±2.71ms 77.0±1.68ms +6.94%
goto_definition 374.7±8.23µs 372.8±7.78µs -0.51%
highlight 9.0±0.02ms 9.1±0.30ms +1.11%
hover 563.8±8.66µs 608.1±17.01µs +7.86%
idents_at_position 123.8±1.30µs 124.4±0.89µs +0.48%
inlay_hints 667.1±21.68µs 677.3±21.36µs +1.53%
on_enter 491.3±11.84ns 503.0±12.23ns +2.38%
parent_decl_at_position 3.7±0.05ms 3.7±0.06ms 0.00%
prepare_rename 365.1±5.26µs 374.2±8.43µs +2.49%
rename 9.5±0.03ms 9.6±0.18ms +1.05%
semantic_tokens 1041.2±18.66µs 1056.6±12.59µs +1.48%
token_at_position 365.5±5.51µs 370.8±1.78µs +1.45%
tokens_at_position 3.7±0.04ms 3.7±0.02ms 0.00%
tokens_for_file 414.1±3.26µs 418.0±5.53µs +0.94%
traverse 43.6±0.98ms 49.6±1.29ms +13.76%

@xunilrj xunilrj merged commit 89e5708 into master Apr 9, 2024
36 checks passed
@xunilrj xunilrj deleted the xunilrj/improve-err-msg-new-encoding branch April 9, 2024 13:24
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.

3 participants