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

better error and dca for configurables #6121

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

xunilrj
Copy link
Contributor

@xunilrj xunilrj commented Jun 13, 2024

Description

This PR closes #6118.

If for some reason an older core ends up being used, we now warn with a more user-friendly error.

error: Configurables need a function named "abi_decode_in_place" to be in scope.
  --> /home/xunilrj/github/sway/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/src/main.sw:42:5
   |
...
42 |     ARRAY_BOOL: [bool; 3] = [true, false, true],
   |     ^^^^^^^^^^
   |
   = help: Certify you are accessing a compatible version of the "core" library.
____

We also use a better span when warning about unused configurables.

warning
  --> /home/xunilrj/github/sway/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/src/main.sw:47:5
   |
45 | 
46 | 
47 |     NOT_USED: u8 = 1,
   |     -------- This declaration is never used.
48 |     #[allow(dead_code)]
49 |     NOT_USED_BUT_ALLOWED: u8 = 2,
   |
____

  Compiled script "configurable_consts" with 1 warning.

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 requested review from a team as code owners June 13, 2024 15:34
Copy link

Benchmark for a3a48db

Click to view benchmark
Test Base PR %
code_action 5.1±0.10ms 5.1±0.23ms 0.00%
code_lens 338.1±7.72ns 292.7±10.09ns -13.43%
compile 3.6±0.06s 3.5±0.07s -2.78%
completion 4.7±0.02ms 4.7±0.13ms 0.00%
did_change_with_caching 3.3±0.08s 3.3±0.11s 0.00%
document_symbol 932.2±16.64µs 956.6±18.71µs +2.62%
format 90.0±1.65ms 89.2±0.78ms -0.89%
goto_definition 348.7±8.16µs 361.8±12.85µs +3.76%
highlight 8.7±0.33ms 8.8±0.03ms +1.15%
hover 570.4±8.77µs 588.4±4.30µs +3.16%
idents_at_position 120.2±0.69µs 124.4±2.88µs +3.49%
inlay_hints 646.1±48.02µs 641.0±22.75µs -0.79%
on_enter 464.2±19.14ns 462.9±14.71ns -0.28%
parent_decl_at_position 3.6±0.03ms 3.6±0.05ms 0.00%
prepare_rename 349.1±5.64µs 358.4±5.45µs +2.66%
rename 8.9±0.15ms 9.2±0.55ms +3.37%
semantic_tokens 939.6±16.96µs 944.2±15.63µs +0.49%
token_at_position 355.5±3.58µs 351.2±2.70µs -1.21%
tokens_at_position 3.6±0.19ms 3.6±0.05ms 0.00%
tokens_for_file 415.5±17.63µs 412.1±5.55µs -0.82%
traverse 37.3±0.79ms 37.0±0.76ms -0.80%

Copy link

Benchmark for 6b6ef74

Click to view benchmark
Test Base PR %
code_action 5.1±0.03ms 5.1±0.07ms 0.00%
code_lens 341.1±6.47ns 283.3±7.88ns -16.95%
compile 3.4±0.10s 3.7±0.13s +8.82%
completion 4.7±0.02ms 4.7±0.21ms 0.00%
did_change_with_caching 3.2±0.07s 3.2±0.09s 0.00%
document_symbol 946.1±66.39µs 990.7±28.23µs +4.71%
format 88.2±1.84ms 90.4±1.22ms +2.49%
goto_definition 359.1±12.56µs 359.0±8.90µs -0.03%
highlight 8.7±0.27ms 8.9±0.25ms +2.30%
hover 592.5±7.67µs 581.3±11.36µs -1.89%
idents_at_position 121.0±0.38µs 121.2±1.93µs +0.17%
inlay_hints 648.3±22.53µs 652.5±28.60µs +0.65%
on_enter 466.6±29.86ns 463.3±9.51ns -0.71%
parent_decl_at_position 3.7±0.80ms 3.7±0.13ms 0.00%
prepare_rename 352.8±9.07µs 358.8±7.78µs +1.70%
rename 8.9±0.05ms 9.1±0.17ms +2.25%
semantic_tokens 978.6±19.08µs 966.1±11.66µs -1.28%
token_at_position 394.3±19.04µs 347.6±3.54µs -11.84%
tokens_at_position 3.6±0.04ms 3.6±0.09ms 0.00%
tokens_for_file 431.9±1.93µs 418.7±6.35µs -3.06%
traverse 37.4±1.34ms 46.1±2.23ms +23.26%

sway-error/src/error.rs Outdated Show resolved Hide resolved
sway-error/src/handler.rs Outdated Show resolved Hide resolved
sway-error/src/error.rs Outdated Show resolved Hide resolved
sway-error/src/error.rs Outdated Show resolved Hide resolved
@xunilrj xunilrj requested a review from ironcev June 14, 2024 09:01
Copy link

Benchmark for 24f90f9

Click to view benchmark
Test Base PR %
code_action 5.3±0.17ms 5.0±0.02ms -5.66%
code_lens 337.8±12.54ns 287.6±7.27ns -14.86%
compile 3.4±0.06s 3.4±0.07s 0.00%
completion 4.8±0.10ms 4.7±0.02ms -2.08%
did_change_with_caching 3.3±0.09s 3.2±0.07s -3.03%
document_symbol 951.0±23.97µs 959.2±22.89µs +0.86%
format 89.0±1.55ms 89.1±1.23ms +0.11%
goto_definition 356.7±6.29µs 350.7±6.54µs -1.68%
highlight 9.1±0.51ms 8.7±0.19ms -4.40%
hover 581.3±5.45µs 575.4±5.70µs -1.01%
idents_at_position 121.5±1.01µs 119.8±0.42µs -1.40%
inlay_hints 657.9±4.35µs 681.7±24.80µs +3.62%
on_enter 462.8±4.88ns 465.5±10.89ns +0.58%
parent_decl_at_position 3.7±0.03ms 3.6±0.09ms -2.70%
prepare_rename 356.5±6.04µs 350.1±5.35µs -1.80%
rename 9.3±0.10ms 8.9±0.56ms -4.30%
semantic_tokens 954.0±13.90µs 965.5±15.32µs +1.21%
token_at_position 351.0±1.68µs 347.8±3.25µs -0.91%
tokens_at_position 3.8±0.15ms 3.6±0.04ms -5.26%
tokens_for_file 409.4±3.74µs 411.7±2.40µs +0.56%
traverse 35.8±0.39ms 35.7±0.53ms -0.28%

),
hints: vec![],
help: vec![
"Function \"abi_decode_in_place\" is defined in the standard library module \"core::codec\".".into()
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, having just this first sentence in the help without the second proposed one that suggests to verify if the function is actually there, this help actually becomes confusing because it states that the function is defined in the "code::codec" and the error is there very likely because it is not defined.

There is another one issue. The error is currently emitted on every configurable because the span points to an individual configurable. It should be just a single error pointing to either the whole configurable block or to the text configurable, because it is not specific to a particular configurable.

Together with the above help message it results in actually a confusing experience.

Coming to an optimally crafted diagnostic is never easy 😄 and usually takes some polishing. After looking once again at the overall formulation I propose the following changes.

We leave the old-style single line formulation in line 967 as it is.

Reason should answer why is this an issue. The fact that "Configurables need a function named "abi_decode_in_place" to be in scope" is not an issue that's how it should be 😄

So, to be consistent with the guidelines, proposal is to reformulate the Reason as: Function "abi_decode_in_place" is not in scope

Issue::error should actually point at the configurable block or even better at the span of the "configurable" and further explain: Configurables need a function named "abi_decode_in_place" to be in scope. // With the fullstop this time 😄

Note that we can still emit the error for every configurable. That's fine because the deduplication will remove duplicates and leave only a single error message.

And finally in the help we have both sentences, to guide where to look:
"Function "abi_decode_in_place" is usually defined in the standard library module "core::codec".".into(),
"Verify that you are using a version of the "core" standard library that contains this function.".into(),

Note also the added word "usually" because we allow developers to define their own encoding/decoding mechanisms by implementing functions in scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is another one issue. The error is currently emitted on every configurable because the span points to an individual configurable. It should be just a single error pointing to either the whole configurable block or to the text configurable, because it is not specific to a particular configurable.

Not sure I understood this point. What is not being used is the configurable, not the block. Why highlighting the whole block would be better?

image

Copy link
Member

Choose a reason for hiding this comment

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

The warning is perfectly fine, of course 😄 I was talking about the error which is not related to a particular configurable and will be rendered on every configurable. Currently for e.g.:

configurable {
    MAX_SUPPLY: u64 = 3,
    OTHER: u64 = 3,
    MORE: u64 = 3,
}

rendered errors will be quite overwhelming and confusing:

Configurables need a function named abi_decode_in_place to be in scope

The impression those message give is, that there is something problematic with an individual configurable, but they are all perfectly fine and there is nothing to change about them. It is actually a piece of "infrastructure" that is missing. That's why I think having a single error (duplicates automatically removed via deduplication) pointing to the block will better communicate the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah. In this case it makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will use the keyword span, as the whole block renders very strangely.
image

Copy link
Member

Choose a reason for hiding this comment

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

Yes unfortunately this issue with code snippets is a know one, #5499, but still open. Using keyword is also fine.

@xunilrj
Copy link
Contributor Author

xunilrj commented Jun 25, 2024

As discussed, the error now points to the configurable block:

image

@xunilrj xunilrj force-pushed the xunilrj/configurables-better-error-and-dca branch from 58152c6 to 0a6fdb2 Compare June 25, 2024 14:54
Copy link

Benchmark for 56c2e27

Click to view benchmark
Test Base PR %
code_action 5.1±0.10ms 5.0±0.03ms -1.96%
code_lens 309.6±24.56ns 278.1±7.42ns -10.17%
compile 3.4±0.08s 3.4±0.08s 0.00%
completion 4.6±0.13ms 4.6±0.11ms 0.00%
did_change_with_caching 3.2±0.08s 3.2±0.08s 0.00%
document_symbol 919.4±17.15µs 868.4±8.19µs -5.55%
format 87.9±2.42ms 87.2±1.00ms -0.80%
goto_definition 339.3±5.90µs 347.9±8.14µs +2.53%
highlight 8.7±0.21ms 8.7±0.19ms 0.00%
hover 568.5±6.04µs 565.6±5.94µs -0.51%
idents_at_position 118.4±0.50µs 120.8±1.35µs +2.03%
inlay_hints 627.2±7.42µs 621.3±25.61µs -0.94%
on_enter 467.5±9.34ns 460.1±11.74ns -1.58%
parent_decl_at_position 3.5±0.03ms 3.6±0.04ms +2.86%
prepare_rename 339.8±7.13µs 341.2±5.94µs +0.41%
rename 8.9±0.16ms 9.0±0.27ms +1.12%
semantic_tokens 1257.3±14.25µs 1261.3±12.47µs +0.32%
token_at_position 336.2±3.69µs 335.5±2.08µs -0.21%
tokens_at_position 3.5±0.03ms 3.6±0.05ms +2.86%
tokens_for_file 393.7±2.86µs 404.7±2.35µs +2.79%
traverse 36.6±0.44ms 37.0±0.59ms +1.09%

ironcev
ironcev previously approved these changes Jun 25, 2024
Copy link

Benchmark for 408d703

Click to view benchmark
Test Base PR %
code_action 5.0±0.03ms 5.0±0.11ms 0.00%
code_lens 304.1±10.12ns 284.0±20.08ns -6.61%
compile 3.4±0.05s 3.5±0.10s +2.94%
completion 4.6±0.07ms 4.6±0.02ms 0.00%
did_change_with_caching 3.2±0.09s 3.2±0.07s 0.00%
document_symbol 904.8±33.87µs 873.6±31.45µs -3.45%
format 86.9±0.75ms 88.4±1.60ms +1.73%
goto_definition 341.7±8.67µs 342.2±10.05µs +0.15%
highlight 8.6±0.04ms 8.7±0.03ms +1.16%
hover 569.6±14.43µs 568.7±6.80µs -0.16%
idents_at_position 119.7±0.45µs 123.2±0.33µs +2.92%
inlay_hints 632.4±31.41µs 637.2±27.73µs +0.76%
on_enter 472.3±14.51ns 463.7±36.72ns -1.82%
parent_decl_at_position 3.6±0.01ms 3.6±0.04ms 0.00%
prepare_rename 343.6±7.54µs 343.1±6.72µs -0.15%
rename 8.9±0.03ms 8.9±0.02ms 0.00%
semantic_tokens 1228.4±17.33µs 1285.8±7.82µs +4.67%
token_at_position 342.6±3.20µs 341.3±3.42µs -0.38%
tokens_at_position 3.6±0.04ms 3.5±0.04ms -2.78%
tokens_for_file 398.4±3.17µs 399.3±2.03µs +0.23%
traverse 37.4±0.78ms 37.7±0.69ms +0.80%

@xunilrj xunilrj requested review from sdankel and ironcev June 25, 2024 20:46
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.

Compiler panics and no DCA warning when a configurable is never used
3 participants