Skip to content

Reject duplicate cases in switch-statement #1307

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

Closed
wants to merge 6 commits into from

Conversation

SupunS
Copy link
Member

@SupunS SupunS commented Dec 13, 2021

Closes onflow/cadence-tools#61

Description

This is not an urgent PR. Just a nice to have feature I worked on sometimes back.


  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@github-actions
Copy link

Cadence Benchstat comparison

This branch with compared with the base branch onflow:master commit 4fffc3b
The command for i in {1..N}; do go test ./... -run=XXX -bench=. -shuffle=on; done was used.
Bench tests were run a total of 7 times on each branch.

Results

old.txtnew.txt
time/opdelta
RuntimeResourceDictionaryValues-219.1ms ± 3%19.2ms ± 3%~(p=0.535 n=7+7)
RuntimeFungibleTokenTransfer-21.50ms ± 1%1.50ms ± 1%~(p=0.534 n=7+6)
ParseFungibleToken-2550µs ± 0%555µs ± 2%~(p=0.073 n=6+7)
ParseInfix-229.0µs ± 2%28.8µs ± 2%~(p=0.445 n=7+6)
ParseArray-226.9ms ± 1%27.1ms ± 3%~(p=0.383 n=7+7)
ParseDeploy/byte_array-241.3ms ± 3%41.2ms ± 3%~(p=1.000 n=7+7)
ParseDeploy/decode_hex-21.68ms ± 3%1.68ms ± 2%~(p=1.000 n=7+7)
QualifiedIdentifierCreation/One_level-23.75ns ± 2%3.76ns ± 1%~(p=0.703 n=7+6)
QualifiedIdentifierCreation/Three_levels-2191ns ± 2%189ns ± 2%~(p=0.136 n=7+7)
CheckContractInterfaceFungibleTokenConformance-2199µs ± 4%202µs ± 4%~(p=0.383 n=7+7)
ContractInterfaceFungibleToken-257.3µs ± 6%55.6µs ± 3%~(p=0.128 n=7+7)
NewInterpreter/new_interpreter-21.38µs ± 1%1.38µs ± 5%~(p=0.534 n=6+7)
NewInterpreter/new_sub-interpreter-22.73µs ± 3%2.69µs ± 2%~(p=0.101 n=7+6)
InterpretRecursionFib-23.10ms ± 3%3.13ms ± 4%~(p=0.628 n=6+7)
 
alloc/opdelta
RuntimeResourceDictionaryValues-24.04MB ± 0%4.04MB ± 0%~(p=0.053 n=7+7)
QualifiedIdentifierCreation/One_level-20.00B 0.00B ~(all equal)
QualifiedIdentifierCreation/Three_levels-264.0B ± 0%64.0B ± 0%~(all equal)
CheckContractInterfaceFungibleTokenConformance-265.7kB ± 0%65.7kB ± 0%~(p=1.000 n=7+7)
ContractInterfaceFungibleToken-226.5kB ± 0%26.5kB ± 0%~(p=0.462 n=7+7)
NewInterpreter/new_interpreter-2720B ± 0%720B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-21.18kB ± 0%1.18kB ± 0%~(all equal)
InterpretRecursionFib-21.24MB ± 0%1.24MB ± 0%~(p=0.462 n=7+7)
RuntimeFungibleTokenTransfer-2238kB ± 0%238kB ± 0%−0.01%(p=0.023 n=7+5)
 
allocs/opdelta
RuntimeResourceDictionaryValues-2102k ± 0%102k ± 0%+0.00%(p=0.013 n=7+7)
RuntimeFungibleTokenTransfer-24.54k ± 0%4.54k ± 0%~(all equal)
QualifiedIdentifierCreation/One_level-20.00 0.00 ~(all equal)
QualifiedIdentifierCreation/Three_levels-22.00 ± 0%2.00 ± 0%~(all equal)
CheckContractInterfaceFungibleTokenConformance-21.07k ± 0%1.07k ± 0%~(all equal)
ContractInterfaceFungibleToken-2457 ± 0%457 ± 0%~(all equal)
NewInterpreter/new_interpreter-211.0 ± 0%11.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-236.0 ± 0%36.0 ± 0%~(all equal)
InterpretRecursionFib-225.0k ± 0%25.0k ± 0%~(all equal)
 

@codecov-commenter
Copy link

Codecov Report

Merging #1307 (61f6a3a) into master (a9ef2ce) will decrease coverage by 0.03%.
The diff coverage is 61.53%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    onflow/cadence#1307      +/-   ##
==========================================
- Coverage   77.41%   77.37%   -0.04%     
==========================================
  Files         279      279              
  Lines       36113    36283     +170     
==========================================
+ Hits        27956    28074     +118     
- Misses       7066     7104      +38     
- Partials     1091     1105      +14     
Flag Coverage Δ
unittests 77.37% <61.53%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
runtime/sema/check_switch.go 74.00% <59.34%> (-23.41%) ⬇️
runtime/sema/check_casting_expression.go 96.73% <100.00%> (ø)
runtime/sema/check_force_expression.go 91.30% <100.00%> (ø)
runtime/sema/checker.go 89.64% <100.00%> (ø)
runtime/sema/errors.go 58.52% <100.00%> (+0.05%) ⬆️
runtime/sema/type.go 88.27% <100.00%> (+0.08%) ⬆️
runtime/runtime.go 87.02% <0.00%> (+0.01%) ⬆️
runtime/interpreter/value.go 80.24% <0.00%> (+0.02%) ⬆️
runtime/interpreter/interpreter.go 89.66% <0.00%> (+0.07%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a9ef2ce...61f6a3a. Read the comment docs.

@SupunS SupunS self-assigned this Dec 18, 2021
@SupunS SupunS marked this pull request as ready for review December 18, 2021 04:46
@SupunS SupunS requested a review from turbolent as a code owner December 18, 2021 04:46
@SupunS SupunS added the Feature label Dec 18, 2021
@SupunS
Copy link
Member Author

SupunS commented Jul 6, 2022

Given that linter is now in a separate repo, I'll add this there.

@SupunS SupunS closed this Jul 6, 2022
@turbolent
Copy link
Member

Thank you for working on this @SupunS, it's going to be great to have this in the linter! Sorry we missed this when migrating the linter to the separate repo, and thanks for porting it over 👌

@SupunS SupunS deleted the supun/improve-switch-case branch October 24, 2024 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lint] Reject duplicate cases in switch-statement
4 participants