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

Add a custom linter which detects Value composite literals #1481

Merged
merged 3 commits into from
Mar 9, 2022

Conversation

turbolent
Copy link
Member

Work towards https://github.com/dapperlabs/cadence-private-issues/issues/2

Description

Add a new linter which detects composite literals for Values.

It is not enabled by default and can be run using: make lint linters=constructorcheck


  • 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

@turbolent turbolent self-assigned this Mar 4, 2022
@codecov-commenter
Copy link

codecov-commenter commented Mar 4, 2022

Codecov Report

Merging #1481 (3d939cb) into master (3ecb20d) will decrease coverage by 0.00%.
The diff coverage is n/a.

❗ Current head 3d939cb differs from pull request most recent head 3c87b32. Consider uploading reports for the commit 3c87b32 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1481      +/-   ##
==========================================
- Coverage   73.01%   73.00%   -0.01%     
==========================================
  Files         288      288              
  Lines       39786    39786              
==========================================
- Hits        29048    29046       -2     
- Misses       9263     9265       +2     
  Partials     1475     1475              
Flag Coverage Δ
unittests 73.00% <ø> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
runtime/interpreter/storage.go 71.42% <0.00%> (-1.69%) ⬇️

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 3ecb20d...3c87b32. Read the comment docs.

@github-actions
Copy link

github-actions bot commented Mar 4, 2022

Cadence Benchstat comparison

This branch with compared with the base branch onflow:master commit 3ecb20d
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
CheckContractInterfaceFungibleTokenConformance-2131µs ± 1%135µs ± 4%+2.91%(p=0.005 n=6+7)
RuntimeResourceDictionaryValues-214.5ms ± 5%14.5ms ± 4%~(p=0.902 n=7+7)
RuntimeFungibleTokenTransfer-21.03ms ± 6%1.19ms ±23%~(p=0.628 n=6+7)
ParseArray-212.9ms ± 4%12.9ms ± 2%~(p=0.731 n=6+7)
ParseFungibleToken-2183µs ± 1%185µs ± 2%~(p=0.138 n=7+6)
ParseDeploy/byte_array-221.8ms ±10%21.1ms ± 4%~(p=0.945 n=7+6)
ParseDeploy/decode_hex-21.18ms ± 2%1.19ms ± 3%~(p=0.165 n=7+7)
ParseInfix-28.52µs ± 2%8.55µs ± 2%~(p=0.620 n=7+7)
QualifiedIdentifierCreation/One_level-22.37ns ± 4%2.34ns ± 0%~(p=0.697 n=7+6)
QualifiedIdentifierCreation/Three_levels-2140ns ± 2%142ns ± 5%~(p=0.456 n=7+7)
ContractInterfaceFungibleToken-240.4µs ± 8%39.6µs ± 1%~(p=0.731 n=7+6)
InterpretRecursionFib-22.87ms ± 2%2.92ms ± 4%~(p=0.295 n=6+7)
NewInterpreter/new_interpreter-21.12µs ± 2%1.14µs ± 2%~(p=0.101 n=6+7)
NewInterpreter/new_sub-interpreter-22.16µs ± 1%2.17µs ± 1%~(p=0.234 n=7+6)
 
alloc/opdelta
RuntimeResourceDictionaryValues-24.05MB ± 0%4.05MB ± 0%~(p=0.073 n=7+7)
RuntimeFungibleTokenTransfer-2273kB ± 0%273kB ± 0%~(p=0.924 n=7+7)
QualifiedIdentifierCreation/One_level-20.00B 0.00B ~(all equal)
QualifiedIdentifierCreation/Three_levels-264.0B ± 0%64.0B ± 0%~(all equal)
CheckContractInterfaceFungibleTokenConformance-266.2kB ± 0%66.2kB ± 0%~(all equal)
ContractInterfaceFungibleToken-226.6kB ± 0%26.6kB ± 0%~(p=1.000 n=7+7)
InterpretRecursionFib-21.26MB ± 0%1.26MB ± 0%~(all equal)
NewInterpreter/new_interpreter-2848B ± 0%848B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-21.32kB ± 0%1.32kB ± 0%~(all equal)
 
allocs/opdelta
RuntimeResourceDictionaryValues-2102k ± 0%102k ± 0%~(p=0.110 n=7+7)
RuntimeFungibleTokenTransfer-24.53k ± 0%4.53k ± 0%~(p=0.515 n=5+7)
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-2458 ± 0%458 ± 0%~(all equal)
InterpretRecursionFib-226.2k ± 0%26.2k ± 0%~(all equal)
NewInterpreter/new_interpreter-213.0 ± 0%13.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-239.0 ± 0%39.0 ± 0%~(all equal)
 

@turbolent turbolent added the Chore label Mar 4, 2022
Copy link
Contributor

@dsainati1 dsainati1 left a comment

Choose a reason for hiding this comment

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

Looks good to me.

I assume that like the other linters this will not run on test files, but for this one I think we should also disable it in value.go so that we don't need to add lint ignore comments all over the place.

@turbolent
Copy link
Member Author

turbolent commented Mar 9, 2022

@dsainati1 yes, the linter is disabled for test files: https://github.com/onflow/cadence/pull/1481/files#diff-6179837f7df53a6f05c522b6b7bb566d484d5465d9894fb04910dd08bb40dcc9R28

I think we should also disable it in value.go

The linter is not enabled (yet) by default, but once we are done with the metering, there should only be very few cases where we, because we should always use the metering/non-metering constructor functions instead of constructing values using a composite literal.

@turbolent turbolent merged commit a882c95 into master Mar 9, 2022
@turbolent turbolent deleted the bastian/value-literal-construction-check branch March 9, 2022 00:19
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.

4 participants