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

Storage name based slots and namespaces. #6064

Merged
merged 21 commits into from
Jun 18, 2024
Merged

Conversation

esdrubal
Copy link
Contributor

@esdrubal esdrubal commented May 28, 2024

Description

With this change storage keys will have a hash based on:
sha256("storage::<storage_namespace_name1>::<storage_namespace_name2>.<storage_field_name>"
or a given key.

A key can be provided by using the in keyword in a storage field as such:

storage {
    a in 0x02dac99c283f16bc91b74f6942db7f012699a2ad51272b15207b9cc14a70dbae: u64
}

Or by using a const expression:

const C1 = 0x02dac99c283f16bc91b74f6942db7f012699a2ad51272b15207b9cc14a70dbae;
storage {
    a in C1: u64
}

StorageKey.field_id is now based on:
sha256("storage::<storage_namespace_name1>::<storage_namespace_name2>.<storage_field_name>.<struct_field_name1>.<struct_field_name2>")

Nested storage namespaces such as the following are now supported.

storage {
    my_namespace1 {
        my_namespace2 {
            b:u64 = 1,
        }
    }
}

A deprecated warning is now thrown when the attribute #[namespace(ns)] is used.

A warning is thrown when storage fields use the same storage slot key. The warning looks like this:

          Two storage fields are using the same storage key.
          First field: storage::ns1.f3
          Second field: storage::ns2.f4
          Key: 5F4C20CE4BD128E5393A4C2B82007DAC795FA0006D01ACF8DB4C42632BC680CA 

This PR does not include yet the necessary documentation updates.
Created dev-rel documentation request: https://github.com/FuelLabs/devrel-requests/issues/14

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.

@esdrubal esdrubal self-assigned this May 28, 2024
@esdrubal esdrubal added compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen breaking May cause existing user code to break. Requires a minor or major release. labels May 28, 2024
Copy link

Benchmark for 7d96ceb

Click to view benchmark
Test Base PR %
code_action 5.6±0.05ms 5.4±0.02ms -3.57%
code_lens 293.4±4.24ns 292.5±9.15ns -0.31%
compile 3.0±0.03s 3.1±0.05s +3.33%
completion 4.8±0.18ms 4.7±0.07ms -2.08%
did_change_with_caching 2.9±0.04s 3.0±0.04s +3.45%
document_symbol 1001.4±9.04µs 1079.9±31.20µs +7.84%
format 74.6±1.50ms 71.3±1.82ms -4.42%
goto_definition 404.0±4.94µs 363.8±8.44µs -9.95%
highlight 9.1±0.11ms 9.1±0.15ms 0.00%
hover 527.5±6.21µs 488.3±5.05µs -7.43%
idents_at_position 124.8±0.83µs 124.4±1.96µs -0.32%
inlay_hints 662.1±6.68µs 665.7±28.55µs +0.54%
on_enter 470.1±9.07ns 471.2±18.58ns +0.23%
parent_decl_at_position 3.7±0.02ms 3.7±0.09ms 0.00%
prepare_rename 401.2±6.49µs 360.2±2.74µs -10.22%
rename 9.7±0.10ms 9.7±0.10ms 0.00%
semantic_tokens 965.2±18.31µs 971.7±27.08µs +0.67%
token_at_position 361.8±3.04µs 363.7±5.16µs +0.53%
tokens_at_position 3.7±0.03ms 3.7±0.03ms 0.00%
tokens_for_file 416.6±2.60µs 418.4±1.66µs +0.43%
traverse 41.7±0.97ms 41.3±1.18ms -0.96%

@esdrubal esdrubal force-pushed the esdrubal/storage_key_change branch 2 times, most recently from 802e600 to 4893a59 Compare June 5, 2024 18:54
Copy link

github-actions bot commented Jun 6, 2024

Benchmark for 8599040

Click to view benchmark
Test Base PR %
code_action 5.4±0.02ms 5.4±0.02ms 0.00%
code_lens 333.7±9.04ns 285.7±8.48ns -14.38%
compile 4.0±0.10s 3.9±0.08s -2.50%
completion 4.7±0.02ms 4.7±0.06ms 0.00%
did_change_with_caching 3.6±0.06s 3.6±0.04s 0.00%
document_symbol 959.8±23.87µs 994.7±37.21µs +3.64%
format 74.0±1.63ms 69.6±1.06ms -5.95%
goto_definition 360.8±7.73µs 348.5±5.04µs -3.41%
highlight 9.0±0.03ms 9.0±0.02ms 0.00%
hover 534.8±6.37µs 519.7±7.67µs -2.82%
idents_at_position 122.8±0.29µs 121.6±1.16µs -0.98%
inlay_hints 652.8±12.08µs 651.8±21.37µs -0.15%
on_enter 456.1±9.01ns 462.7±14.17ns +1.45%
parent_decl_at_position 3.7±0.02ms 3.7±0.04ms 0.00%
prepare_rename 360.1±9.78µs 346.3±7.40µs -3.83%
rename 9.6±0.34ms 9.6±0.19ms 0.00%
semantic_tokens 970.4±15.07µs 979.6±29.12µs +0.95%
token_at_position 354.2±1.98µs 333.7±2.42µs -5.79%
tokens_at_position 3.7±0.02ms 3.7±0.03ms 0.00%
tokens_for_file 425.0±2.02µs 408.9±2.42µs -3.79%
traverse 39.3±0.89ms 39.2±1.80ms -0.25%

@esdrubal esdrubal force-pushed the esdrubal/storage_key_change branch from 703c1ce to 3941df8 Compare June 6, 2024 12:21
Copy link

github-actions bot commented Jun 6, 2024

Benchmark for 5fd1e80

Click to view benchmark
Test Base PR %
code_action 5.4±0.14ms 5.2±0.02ms -3.70%
code_lens 338.5±10.31ns 280.9±4.83ns -17.02%
compile 4.2±0.08s 4.2±0.12s 0.00%
completion 4.7±0.05ms 4.7±0.14ms 0.00%
did_change_with_caching 3.8±0.07s 3.8±0.05s 0.00%
document_symbol 978.4±22.71µs 1023.6±47.37µs +4.62%
format 75.0±1.11ms 74.0±0.67ms -1.33%
goto_definition 365.4±5.03µs 359.6±6.16µs -1.59%
highlight 9.1±0.11ms 8.7±0.04ms -4.40%
hover 542.7±14.40µs 536.3±5.06µs -1.18%
idents_at_position 122.9±0.95µs 122.2±0.71µs -0.57%
inlay_hints 669.5±27.83µs 649.5±24.18µs -2.99%
on_enter 456.6±9.12ns 479.3±16.54ns +4.97%
parent_decl_at_position 3.7±0.04ms 3.6±0.04ms -2.70%
prepare_rename 362.4±4.99µs 361.9±18.23µs -0.14%
rename 9.6±0.21ms 9.3±0.13ms -3.12%
semantic_tokens 986.4±23.75µs 976.3±34.31µs -1.02%
token_at_position 361.6±2.13µs 354.8±4.70µs -1.88%
tokens_at_position 3.7±0.05ms 3.6±0.05ms -2.70%
tokens_for_file 434.2±4.34µs 424.1±4.85µs -2.33%
traverse 41.3±0.96ms 41.4±0.90ms +0.24%

@esdrubal esdrubal force-pushed the esdrubal/storage_key_change branch from 3941df8 to 60958b7 Compare June 11, 2024 10:52
Copy link

Benchmark for 99e1d6d

Click to view benchmark
Test Base PR %
code_action 5.2±0.16ms 5.1±0.09ms -1.92%
code_lens 341.9±8.16ns 312.2±9.02ns -8.69%
compile 3.5±0.07s 3.5±0.10s 0.00%
completion 5.0±0.22ms 4.7±0.14ms -6.00%
did_change_with_caching 3.3±0.09s 3.3±0.10s 0.00%
document_symbol 969.2±36.32µs 989.5±39.59µs +2.09%
format 89.5±1.41ms 75.5±1.47ms -15.64%
goto_definition 351.8±17.42µs 350.9±7.55µs -0.26%
highlight 8.8±0.23ms 8.7±0.30ms -1.14%
hover 578.5±6.65µs 571.2±6.25µs -1.26%
idents_at_position 119.5±0.36µs 117.1±0.97µs -2.01%
inlay_hints 710.2±27.20µs 645.7±25.75µs -9.08%
on_enter 450.3±19.51ns 467.0±19.62ns +3.71%
parent_decl_at_position 3.6±0.04ms 3.6±0.07ms 0.00%
prepare_rename 349.2±6.61µs 349.2±7.29µs 0.00%
rename 9.0±0.46ms 9.0±0.17ms 0.00%
semantic_tokens 968.3±25.76µs 956.9±11.72µs -1.18%
token_at_position 346.6±6.48µs 348.7±7.65µs +0.61%
tokens_at_position 3.6±0.08ms 3.6±0.10ms 0.00%
tokens_for_file 413.8±7.46µs 408.8±3.09µs -1.21%
traverse 37.7±0.91ms 37.7±0.62ms 0.00%

@esdrubal esdrubal marked this pull request as ready for review June 11, 2024 11:24
@esdrubal esdrubal requested review from a team as code owners June 11, 2024 11:24
Copy link
Member

@sdankel sdankel left a comment

Choose a reason for hiding this comment

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

The changes in swayfmt and sway-lsp look good to me. I just left a comment about the compatibility with #[namespace]

@esdrubal esdrubal requested review from a team as code owners June 17, 2024 12:51
With this change storage keys will have a hash based on:
`sha256("storage::<storage_field_name1>::<storage_field_name2>")`
or a given key.

A key can be provide by using the `in` keyword in a storage field as such:
```
storage {
    a in 0x02dac99c283f16bc91b74f6942db7f012699a2ad51272b15207b9cc14a70dbae: u64
}
```

StorageKey.field_id is now based on:
`sha256("storage::<storage_field_name1>::<storage_field_name2>.<struct_field_name1>.<struct_field_name2>")`

Nested storage field such as the following are not yet supported and will be added in a later pull request.
```
storage {
    a {
        b:u64
    }
}
```
@esdrubal esdrubal force-pushed the esdrubal/storage_key_change branch 2 times, most recently from d60ec12 to 30784d6 Compare June 17, 2024 15:20
Copy link

Benchmark for 73458fc

Click to view benchmark
Test Base PR %
code_action 5.2±0.09ms 5.2±0.16ms 0.00%
code_lens 289.3±7.13ns 287.3±7.06ns -0.69%
compile 3.5±0.09s 3.5±0.09s 0.00%
completion 4.9±0.18ms 4.7±0.08ms -4.08%
did_change_with_caching 3.2±0.07s 3.3±0.12s +3.12%
document_symbol 962.5±17.83µs 942.6±19.74µs -2.07%
format 90.1±2.24ms 75.3±1.27ms -16.43%
goto_definition 360.1±3.54µs 337.7±7.03µs -6.22%
highlight 9.0±0.13ms 9.0±0.06ms 0.00%
hover 587.1±12.22µs 564.1±7.14µs -3.92%
idents_at_position 121.8±0.48µs 116.8±1.44µs -4.11%
inlay_hints 653.8±21.41µs 637.9±26.99µs -2.43%
on_enter 494.4±12.82ns 468.4±7.24ns -5.26%
parent_decl_at_position 3.7±0.05ms 3.7±0.06ms 0.00%
prepare_rename 355.7±6.52µs 338.5±6.98µs -4.84%
rename 9.4±0.11ms 9.3±0.14ms -1.06%
semantic_tokens 999.8±17.56µs 976.8±13.39µs -2.30%
token_at_position 353.3±3.19µs 334.4±2.84µs -5.35%
tokens_at_position 3.7±0.08ms 3.7±0.04ms 0.00%
tokens_for_file 405.4±2.48µs 400.7±3.78µs -1.16%
traverse 36.6±0.40ms 37.6±0.50ms +2.73%

Copy link

Benchmark for 7182d62

Click to view benchmark
Test Base PR %
code_action 5.3±0.01ms 5.2±0.10ms -1.89%
code_lens 285.3±9.07ns 301.5±9.02ns +5.68%
compile 3.4±0.09s 3.3±0.06s -2.94%
completion 4.8±0.12ms 4.7±0.07ms -2.08%
did_change_with_caching 3.2±0.05s 3.1±0.08s -3.13%
document_symbol 1024.6±48.49µs 999.1±55.40µs -2.49%
format 89.3±1.15ms 74.3±2.20ms -16.80%
goto_definition 357.3±3.91µs 335.2±6.97µs -6.19%
highlight 9.1±0.19ms 9.0±0.33ms -1.10%
hover 581.1±7.21µs 558.1±8.19µs -3.96%
idents_at_position 119.4±0.20µs 116.1±1.14µs -2.76%
inlay_hints 643.5±23.41µs 634.8±20.38µs -1.35%
on_enter 485.9±14.68ns 475.5±17.07ns -2.14%
parent_decl_at_position 3.7±0.05ms 3.7±0.06ms 0.00%
prepare_rename 359.6±10.07µs 332.2±7.28µs -7.62%
rename 9.3±0.03ms 9.2±0.18ms -1.08%
semantic_tokens 981.6±34.58µs 976.5±38.38µs -0.52%
token_at_position 348.1±1.76µs 332.9±2.57µs -4.37%
tokens_at_position 3.8±0.05ms 3.7±0.06ms -2.63%
tokens_for_file 404.8±8.09µs 392.2±3.35µs -3.11%
traverse 36.7±0.55ms 35.8±0.79ms -2.45%

@esdrubal esdrubal force-pushed the esdrubal/storage_key_change branch from bcbbbd0 to a36179a Compare June 18, 2024 09:03
Copy link

Benchmark for 342ffec

Click to view benchmark
Test Base PR %
code_action 5.2±0.07ms 5.2±0.14ms 0.00%
code_lens 284.7±9.66ns 287.6±4.99ns +1.02%
compile 3.4±0.08s 3.4±0.06s 0.00%
completion 4.8±0.04ms 4.7±0.08ms -2.08%
did_change_with_caching 3.1±0.05s 3.3±0.10s +6.45%
document_symbol 977.8±53.44µs 1018.1±53.29µs +4.12%
format 89.5±1.96ms 74.2±1.85ms -17.09%
goto_definition 347.4±3.89µs 335.9±9.07µs -3.31%
highlight 8.9±0.04ms 9.0±0.26ms +1.12%
hover 581.4±12.02µs 562.1±6.39µs -3.32%
idents_at_position 119.7±0.46µs 119.5±0.44µs -0.17%
inlay_hints 632.7±23.26µs 636.5±32.70µs +0.60%
on_enter 463.8±17.74ns 471.3±9.55ns +1.62%
parent_decl_at_position 3.7±0.03ms 3.7±0.04ms 0.00%
prepare_rename 351.4±5.77µs 337.3±12.76µs -4.01%
rename 9.3±0.24ms 9.2±0.32ms -1.08%
semantic_tokens 975.4±22.26µs 982.1±20.31µs +0.69%
token_at_position 349.2±2.76µs 337.3±4.43µs -3.41%
tokens_at_position 3.7±0.03ms 3.7±0.02ms 0.00%
tokens_for_file 407.8±2.52µs 392.0±2.24µs -3.87%
traverse 36.5±0.86ms 36.6±0.76ms +0.27%

@IGI-111 IGI-111 requested review from a team and sdankel June 18, 2024 09:59
Copy link

Benchmark for 96ef3cf

Click to view benchmark
Test Base PR %
code_action 5.3±0.08ms 5.2±0.04ms -1.89%
code_lens 282.7±4.29ns 286.7±7.50ns +1.41%
compile 3.5±0.06s 3.4±0.05s -2.86%
completion 4.8±0.08ms 4.8±0.24ms 0.00%
did_change_with_caching 3.3±0.07s 3.3±0.06s 0.00%
document_symbol 1031.2±39.44µs 947.9±30.28µs -8.08%
format 89.6±1.11ms 75.0±0.61ms -16.29%
goto_definition 354.2±7.13µs 338.7±6.16µs -4.38%
highlight 9.1±0.17ms 8.9±0.03ms -2.20%
hover 575.6±9.26µs 564.1±6.81µs -2.00%
idents_at_position 120.9±0.61µs 117.2±1.54µs -3.06%
inlay_hints 643.3±11.63µs 635.3±11.44µs -1.24%
on_enter 461.9±14.76ns 505.6±6.23ns +9.46%
parent_decl_at_position 3.7±0.04ms 3.7±0.06ms 0.00%
prepare_rename 353.5±9.27µs 336.6±9.74µs -4.78%
rename 9.5±0.21ms 9.3±0.30ms -2.11%
semantic_tokens 969.7±30.30µs 965.7±15.77µs -0.41%
token_at_position 346.6±2.88µs 333.0±6.95µs -3.92%
tokens_at_position 3.8±0.08ms 3.7±0.03ms -2.63%
tokens_for_file 404.8±3.14µs 400.7±6.17µs -1.01%
traverse 38.0±0.83ms 37.6±0.72ms -1.05%

@IGI-111 IGI-111 merged commit e30497c into master Jun 18, 2024
41 checks passed
@IGI-111 IGI-111 deleted the esdrubal/storage_key_change branch June 18, 2024 12:03
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. compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants