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

fallback when all contract selectors fail #5703

Merged
merged 20 commits into from Mar 14, 2024
Merged

Conversation

xunilrj
Copy link
Contributor

@xunilrj xunilrj commented Mar 6, 2024

Description

This PR closes #5566.

Contracts now can have a special function decorated with #[fallback] which is called when the contract method selection fails.

This function for all intents and purposes works as a standard contract method, so:

  • it cannot call others contracts methods;
  • it has the same limitations of inputs and outputs.

This function can return a value like a normal contract would, or it can use the __contract_ret intrinsics to return any value.

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/contract-fallback-fn branch from 25e15f5 to 3a3dd7c Compare March 8, 2024 11:01
Copy link

github-actions bot commented Mar 8, 2024

Benchmark for be4e7b8

Click to view benchmark
Test Base PR %
code_action 5.3±0.02ms 5.2±0.16ms -1.89%
code_lens 309.6±10.67ns 287.0±13.15ns -7.30%
compile 5.9±0.10s 5.7±0.10s -3.39%
completion 4.9±0.18ms 4.9±0.08ms 0.00%
did_change_with_caching 5.2±0.03s 5.2±0.07s 0.00%
document_symbol 1021.4±49.43µs 994.1±57.31µs -2.67%
format 68.9±0.58ms 69.6±3.29ms +1.02%
goto_definition 361.7±8.37µs 351.9±10.78µs -2.71%
highlight 9.0±0.14ms 9.0±0.04ms 0.00%
hover 586.2±13.34µs 595.2±7.56µs +1.54%
idents_at_position 121.7±0.48µs 123.7±2.51µs +1.64%
inlay_hints 657.9±7.72µs 664.6±6.22µs +1.02%
on_enter 492.6±10.33ns 461.6±16.08ns -6.29%
parent_decl_at_position 3.7±0.06ms 3.7±0.02ms 0.00%
prepare_rename 362.5±6.82µs 354.9±10.60µs -2.10%
rename 9.4±0.10ms 9.2±0.21ms -2.13%
semantic_tokens 1122.6±32.86µs 1049.6±11.20µs -6.50%
token_at_position 360.8±7.72µs 358.8±2.07µs -0.55%
tokens_at_position 3.7±0.24ms 3.7±0.03ms 0.00%
tokens_for_file 411.3±1.45µs 414.3±1.84µs +0.73%
traverse 43.6±1.94ms 42.2±1.10ms -3.21%

@xunilrj xunilrj force-pushed the xunilrj/contract-fallback-fn branch from 3a3dd7c to 2b74ee3 Compare March 8, 2024 15:47
Copy link

github-actions bot commented Mar 8, 2024

Benchmark for 15338b8

Click to view benchmark
Test Base PR %
code_action 5.4±0.09ms 5.2±0.05ms -3.70%
code_lens 296.9±9.72ns 295.6±10.57ns -0.44%
compile 5.8±0.10s 5.8±0.09s 0.00%
completion 4.9±0.02ms 4.8±0.05ms -2.04%
did_change_with_caching 5.2±0.04s 5.2±0.04s 0.00%
document_symbol 968.4±26.91µs 974.0±10.99µs +0.58%
format 69.7±1.08ms 70.3±1.07ms +0.86%
goto_definition 365.8±10.81µs 361.6±5.54µs -1.15%
highlight 9.1±0.13ms 8.9±0.28ms -2.20%
hover 589.4±8.24µs 581.8±7.75µs -1.29%
idents_at_position 121.9±1.69µs 122.5±0.52µs +0.49%
inlay_hints 671.8±31.19µs 650.2±20.24µs -3.22%
on_enter 492.0±12.04ns 489.8±17.03ns -0.45%
parent_decl_at_position 3.7±0.03ms 3.6±0.03ms -2.70%
prepare_rename 361.6±8.26µs 358.8±7.69µs -0.77%
rename 9.4±0.02ms 9.3±0.70ms -1.06%
semantic_tokens 1052.3±14.72µs 1050.1±13.82µs -0.21%
token_at_position 359.2±1.69µs 354.3±2.83µs -1.36%
tokens_at_position 3.7±0.04ms 3.6±0.05ms -2.70%
tokens_for_file 414.5±5.74µs 423.2±15.79µs +2.10%
traverse 43.8±1.43ms 43.6±1.78ms -0.46%

Copy link

github-actions bot commented Mar 8, 2024

Benchmark for cc54d69

Click to view benchmark
Test Base PR %
code_action 5.4±0.11ms 5.3±0.21ms -1.85%
code_lens 287.0±8.07ns 298.4±11.93ns +3.97%
compile 5.7±0.12s 5.8±0.14s +1.75%
completion 4.9±0.09ms 4.8±0.18ms -2.04%
did_change_with_caching 5.2±0.05s 5.2±0.05s 0.00%
document_symbol 956.9±25.16µs 998.2±70.48µs +4.32%
format 70.1±0.65ms 69.6±0.94ms -0.71%
goto_definition 360.8±6.71µs 363.4±5.36µs +0.72%
highlight 9.1±0.30ms 8.8±0.14ms -3.30%
hover 594.4±40.03µs 619.3±22.96µs +4.19%
idents_at_position 122.4±0.75µs 121.8±0.90µs -0.49%
inlay_hints 657.8±26.47µs 654.0±27.46µs -0.58%
on_enter 496.8±17.13ns 479.6±14.17ns -3.46%
parent_decl_at_position 3.7±0.09ms 3.6±0.05ms -2.70%
prepare_rename 358.8±3.25µs 362.6±16.54µs +1.06%
rename 9.4±0.14ms 9.2±0.18ms -2.13%
semantic_tokens 1048.2±20.19µs 1077.6±18.29µs +2.80%
token_at_position 354.7±4.47µs 360.2±3.21µs +1.55%
tokens_at_position 3.7±0.03ms 3.6±0.05ms -2.70%
tokens_for_file 410.3±2.57µs 410.4±1.87µs +0.02%
traverse 43.3±1.81ms 43.6±2.25ms +0.69%

@xunilrj xunilrj marked this pull request as ready for review March 8, 2024 22:31
@xunilrj xunilrj requested review from IGI-111 and a team March 8, 2024 22:32
Copy link
Contributor

@IGI-111 IGI-111 left a comment

Choose a reason for hiding this comment

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

This is great, but can we add some documentation?
DevEx will improve on this but we should still have some minimal advertisement of the feature existing in the first place.

@IGI-111 IGI-111 requested a review from a team March 9, 2024 13:40
Copy link

Benchmark for 9ab8965

Click to view benchmark
Test Base PR %
code_action 5.4±0.10ms 5.4±0.16ms 0.00%
code_lens 288.9±3.77ns 296.5±10.67ns +2.63%
compile 5.9±0.09s 6.0±0.16s +1.69%
completion 5.0±0.19ms 4.9±0.20ms -2.00%
did_change_with_caching 5.4±0.06s 5.4±0.08s 0.00%
document_symbol 999.0±42.11µs 982.9±21.51µs -1.61%
format 70.1±0.90ms 71.5±1.33ms +2.00%
goto_definition 363.6±9.42µs 365.0±5.97µs +0.39%
highlight 9.1±0.19ms 8.9±0.23ms -2.20%
hover 580.5±6.72µs 651.5±17.41µs +12.23%
idents_at_position 121.9±0.31µs 122.2±0.69µs +0.25%
inlay_hints 712.6±22.76µs 656.3±22.47µs -7.90%
on_enter 501.4±23.05ns 494.4±20.63ns -1.40%
parent_decl_at_position 3.8±0.07ms 3.6±0.06ms -5.26%
prepare_rename 360.2±6.19µs 365.0±7.49µs +1.33%
rename 9.5±0.13ms 9.4±0.34ms -1.05%
semantic_tokens 1029.9±42.87µs 1036.9±16.33µs +0.68%
token_at_position 356.5±1.63µs 355.9±2.52µs -0.17%
tokens_at_position 3.7±0.04ms 3.6±0.05ms -2.70%
tokens_for_file 408.3±6.38µs 411.6±1.93µs +0.81%
traverse 44.4±1.78ms 44.8±1.63ms +0.90%

@xunilrj xunilrj requested a review from IGI-111 March 11, 2024 07:49
@xunilrj xunilrj force-pushed the xunilrj/contract-fallback-fn branch from 7ae2254 to 85daa73 Compare March 11, 2024 15:36
Copy link

Benchmark for 85f20a2

Click to view benchmark
Test Base PR %
code_action 5.4±0.09ms 5.3±0.05ms -1.85%
code_lens 304.9±11.45ns 289.6±10.56ns -5.02%
compile 6.1±0.09s 6.2±0.07s +1.64%
completion 5.0±0.10ms 4.9±0.15ms -2.00%
did_change_with_caching 5.5±0.14s 5.5±0.06s 0.00%
document_symbol 962.4±30.53µs 958.0±28.24µs -0.46%
format 70.0±1.49ms 72.0±1.80ms +2.86%
goto_definition 370.2±7.92µs 358.0±5.61µs -3.30%
highlight 9.1±0.02ms 8.8±0.55ms -3.30%
hover 603.6±20.27µs 591.7±11.66µs -1.97%
idents_at_position 122.6±0.35µs 122.8±2.81µs +0.16%
inlay_hints 668.2±12.53µs 659.5±33.23µs -1.30%
on_enter 497.1±22.74ns 498.0±15.31ns +0.18%
parent_decl_at_position 3.7±0.02ms 3.6±0.04ms -2.70%
prepare_rename 367.9±5.91µs 359.0±12.71µs -2.42%
rename 9.6±0.20ms 9.2±0.10ms -4.17%
semantic_tokens 1050.1±19.97µs 1046.0±20.79µs -0.39%
token_at_position 366.2±1.85µs 360.7±19.97µs -1.50%
tokens_at_position 3.7±0.03ms 3.7±0.07ms 0.00%
tokens_for_file 419.4±1.17µs 425.2±2.66µs +1.38%
traverse 44.2±1.15ms 45.1±2.45ms +2.04%

IGI-111
IGI-111 previously approved these changes Mar 11, 2024
Copy link

Benchmark for 1114189

Click to view benchmark
Test Base PR %
code_action 5.3±0.05ms 5.4±0.13ms +1.89%
code_lens 287.8±8.47ns 327.5±6.12ns +13.79%
compile 6.3±0.12s 6.2±0.08s -1.59%
completion 4.8±0.05ms 4.9±0.04ms +2.08%
did_change_with_caching 5.7±0.04s 5.6±0.05s -1.75%
document_symbol 961.3±22.18µs 993.6±28.77µs +3.36%
format 70.8±1.27ms 71.7±1.78ms +1.27%
goto_definition 364.6±21.93µs 369.1±5.40µs +1.23%
highlight 8.9±0.30ms 9.1±0.04ms +2.25%
hover 621.3±19.15µs 605.8±24.18µs -2.49%
idents_at_position 123.0±0.43µs 124.1±0.79µs +0.89%
inlay_hints 707.0±35.60µs 670.6±23.12µs -5.15%
on_enter 500.7±11.57ns 490.0±12.22ns -2.14%
parent_decl_at_position 3.6±0.04ms 3.7±0.03ms +2.78%
prepare_rename 364.5±14.47µs 367.0±4.16µs +0.69%
rename 9.4±0.23ms 9.6±0.45ms +2.13%
semantic_tokens 1030.7±21.10µs 1057.1±6.93µs +2.56%
token_at_position 353.7±2.22µs 360.5±2.05µs +1.92%
tokens_at_position 3.6±0.02ms 3.7±0.03ms +2.78%
tokens_for_file 421.1±5.41µs 407.8±5.63µs -3.16%
traverse 46.2±2.11ms 46.2±2.12ms 0.00%

@xunilrj xunilrj requested a review from IGI-111 March 12, 2024 13:05
IGI-111
IGI-111 previously approved these changes Mar 12, 2024
@IGI-111 IGI-111 requested a review from a team March 12, 2024 14:07
@xunilrj xunilrj force-pushed the xunilrj/contract-fallback-fn branch from 4203af3 to 8916886 Compare March 12, 2024 14:17
Copy link

Benchmark for 0ea2994

Click to view benchmark
Test Base PR %
code_action 5.3±0.16ms 5.2±0.03ms -1.89%
code_lens 287.9±9.09ns 328.2±4.03ns +14.00%
compile 6.2±0.08s 6.1±0.10s -1.61%
completion 4.8±0.13ms 4.8±0.14ms 0.00%
did_change_with_caching 5.6±0.04s 5.7±0.02s +1.79%
document_symbol 1001.9±34.19µs 973.2±29.93µs -2.86%
format 70.6±1.46ms 70.4±1.62ms -0.28%
goto_definition 356.9±5.62µs 363.5±3.92µs +1.85%
highlight 8.8±0.31ms 8.8±0.04ms 0.00%
hover 596.9±17.52µs 602.0±35.05µs +0.85%
idents_at_position 123.0±0.49µs 122.1±0.69µs -0.73%
inlay_hints 651.3±23.84µs 663.7±28.14µs +1.90%
on_enter 486.9±13.49ns 513.0±9.88ns +5.36%
parent_decl_at_position 3.6±0.02ms 3.6±0.03ms 0.00%
prepare_rename 354.1±4.28µs 365.3±3.80µs +3.16%
rename 9.2±0.20ms 9.2±0.20ms 0.00%
semantic_tokens 1056.2±16.40µs 1047.8±11.45µs -0.80%
token_at_position 350.2±4.01µs 361.8±3.06µs +3.31%
tokens_at_position 3.6±0.07ms 3.6±0.03ms 0.00%
tokens_for_file 408.9±2.49µs 423.2±3.76µs +3.50%
traverse 44.7±1.31ms 46.1±2.05ms +3.13%

@xunilrj xunilrj enabled auto-merge (squash) March 12, 2024 15:47
@xunilrj xunilrj mentioned this pull request Mar 13, 2024
22 tasks
IGI-111
IGI-111 previously approved these changes Mar 13, 2024
@IGI-111 IGI-111 requested a review from a team March 13, 2024 14:01
Copy link

Benchmark for 2d1c2ca

Click to view benchmark
Test Base PR %
code_action 5.3±0.13ms 5.4±0.15ms +1.89%
code_lens 287.4±8.17ns 328.0±9.08ns +14.13%
compile 6.3±0.08s 6.3±0.09s 0.00%
completion 5.0±0.34ms 4.9±0.21ms -2.00%
did_change_with_caching 5.9±0.05s 5.8±0.05s -1.69%
document_symbol 985.2±34.56µs 946.8±17.03µs -3.90%
format 70.9±0.90ms 71.4±1.30ms +0.71%
goto_definition 360.2±8.47µs 366.3±6.00µs +1.69%
highlight 8.9±0.17ms 8.8±0.13ms -1.12%
hover 603.9±20.01µs 607.5±26.76µs +0.60%
idents_at_position 122.6±0.57µs 121.9±1.50µs -0.57%
inlay_hints 648.6±30.93µs 652.5±23.46µs +0.60%
on_enter 494.3±15.81ns 490.4±24.10ns -0.79%
parent_decl_at_position 3.6±0.06ms 3.6±0.06ms 0.00%
prepare_rename 356.2±3.02µs 369.0±11.35µs +3.59%
rename 9.5±0.24ms 9.3±0.16ms -2.11%
semantic_tokens 1048.1±13.10µs 1052.3±23.08µs +0.40%
token_at_position 352.0±2.14µs 360.8±4.26µs +2.50%
tokens_at_position 3.6±0.06ms 3.6±0.06ms 0.00%
tokens_for_file 407.0±3.55µs 447.4±3.10µs +9.93%
traverse 46.4±2.06ms 46.6±1.34ms +0.43%

tritao
tritao previously approved these changes Mar 14, 2024
Copy link
Contributor

@tritao tritao left a comment

Choose a reason for hiding this comment

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

Just some minor suggestions, else looks good

docs/book/src/blockchain-development/calling_contracts.md Outdated Show resolved Hide resolved
docs/book/src/blockchain-development/calling_contracts.md Outdated Show resolved Hide resolved
docs/book/src/blockchain-development/calling_contracts.md Outdated Show resolved Hide resolved
docs/book/src/reference/attributes.md Outdated Show resolved Hide resolved
@IGI-111 IGI-111 dismissed stale reviews from tritao and themself via 940477b March 14, 2024 11:46
Co-authored-by: João Matos <joao@tritao.eu>
@IGI-111 IGI-111 requested a review from tritao March 14, 2024 11:47
Copy link

Benchmark for 56de7f3

Click to view benchmark
Test Base PR %
code_action 5.4±0.09ms 5.5±0.06ms +1.85%
code_lens 291.3±4.94ns 297.0±43.33ns +1.96%
compile 6.1±0.09s 6.0±0.07s -1.64%
completion 4.9±0.01ms 5.0±0.05ms +2.04%
did_change_with_caching 5.6±0.07s 5.8±0.03s +3.57%
document_symbol 1008.9±45.49µs 956.0±17.91µs -5.24%
format 77.6±1.28ms 69.4±1.44ms -10.57%
goto_definition 362.6±8.67µs 358.7±10.33µs -1.08%
highlight 9.1±0.13ms 9.1±0.02ms 0.00%
hover 602.6±9.06µs 621.3±18.24µs +3.10%
idents_at_position 122.8±0.35µs 123.2±0.48µs +0.33%
inlay_hints 666.0±11.61µs 670.0±19.97µs +0.60%
on_enter 485.2±7.44ns 499.7±24.49ns +2.99%
parent_decl_at_position 3.7±0.04ms 3.7±0.03ms 0.00%
prepare_rename 361.9±7.52µs 362.7±6.22µs +0.22%
rename 9.5±0.17ms 9.6±0.20ms +1.05%
semantic_tokens 1028.2±20.70µs 1064.1±25.25µs +3.49%
token_at_position 363.0±11.52µs 350.3±2.39µs -3.50%
tokens_at_position 3.7±0.02ms 3.7±0.03ms 0.00%
tokens_for_file 420.1±2.44µs 411.4±7.61µs -2.07%
traverse 45.3±2.09ms 44.7±1.72ms -1.32%

@xunilrj xunilrj merged commit 39d25b6 into master Mar 14, 2024
39 checks passed
@xunilrj xunilrj deleted the xunilrj/contract-fallback-fn branch March 14, 2024 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow method selector fallback
3 participants