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

Fix resource field nesting check for enum raw value field #1459

Merged
merged 1 commit into from
Mar 1, 2022

Conversation

turbolent
Copy link
Member

Port of dapperlabs/cadence-internal#60

Description

Fix a checker crasher.

Enums have an implicitly declared rawValue field.

The checker validates that a resource-typed field only occurs in resources and contracts. When an invalid field is detected, its position is included in the error.

If the raw type of an enum declaration is a resource type, then an error is reported.
However, the rawValue field is not declared as a field, but through the raw type, i.e. the conformance list.

Fixes:

  • Do not perform the resource-typed field check for enums' rawValue field. If the raw type of the enum is a resource, there is already a separate error reported for it (invalid enum raw type).
  • Report the first conformance as the position of an enum's rawValue field

  • 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 1, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #1459 (1dd16b8) into master (f3de22f) will increase coverage by 0.00%.
The diff coverage is 83.33%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1459   +/-   ##
=======================================
  Coverage   72.65%   72.66%           
=======================================
  Files         288      288           
  Lines       39303    39313   +10     
=======================================
+ Hits        28555    28565   +10     
  Misses       9259     9259           
  Partials     1489     1489           
Flag Coverage Δ
unittests 72.66% <83.33%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
runtime/sema/type.go 88.38% <75.00%> (-0.05%) ⬇️
runtime/sema/check_composite_declaration.go 95.48% <100.00%> (ø)
runtime/sema/check_interface_declaration.go 96.61% <100.00%> (ø)
runtime/sema/checker.go 89.12% <100.00%> (+0.01%) ⬆️
runtime/interpreter/storage.go 73.10% <0.00%> (+1.68%) ⬆️

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 f3de22f...1dd16b8. Read the comment docs.

@github-actions
Copy link

github-actions bot commented Mar 1, 2022

Cadence Benchstat comparison

This branch with compared with the base branch onflow:master commit f3de22f
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
QualifiedIdentifierCreation/One_level-22.42ns ± 0%2.66ns ±20%+10.11%(p=0.001 n=6+7)
ParseInfix-28.42µs ± 1%8.55µs ± 1%+1.58%(p=0.001 n=7+7)
QualifiedIdentifierCreation/Three_levels-2118ns ± 0%119ns ± 1%+0.68%(p=0.032 n=6+6)
NewInterpreter/new_sub-interpreter-22.18µs ± 0%2.19µs ± 1%+0.58%(p=0.045 n=6+7)
RuntimeResourceDictionaryValues-213.1ms ± 4%12.9ms ± 2%~(p=0.259 n=7+7)
RuntimeFungibleTokenTransfer-2840µs ± 2%949µs ±27%~(p=0.209 n=7+7)
ParseFungibleToken-2182µs ± 1%183µs ± 1%~(p=0.181 n=6+7)
ParseArray-212.0ms ± 1%11.9ms ± 1%~(p=0.534 n=6+7)
ParseDeploy/byte_array-218.4ms ± 1%19.7ms ± 8%~(p=0.101 n=6+7)
ParseDeploy/decode_hex-21.13ms ± 0%1.13ms ± 2%~(p=0.731 n=7+6)
CheckContractInterfaceFungibleTokenConformance-2128µs ± 1%127µs ± 1%~(p=0.445 n=6+7)
ContractInterfaceFungibleToken-240.9µs ± 8%39.8µs ± 1%~(p=0.165 n=7+7)
NewInterpreter/new_interpreter-21.04µs ± 1%1.04µs ± 1%~(p=0.663 n=7+6)
InterpretRecursionFib-22.54ms ± 1%2.55ms ± 3%~(p=1.000 n=7+6)
 
alloc/opdelta
RuntimeResourceDictionaryValues-24.05MB ± 0%4.05MB ± 0%+0.01%(p=0.005 n=6+7)
RuntimeFungibleTokenTransfer-2271kB ± 0%271kB ± 0%~(p=0.138 n=7+6)
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)
NewInterpreter/new_interpreter-2768B ± 0%768B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-21.24kB ± 0%1.24kB ± 0%~(all equal)
InterpretRecursionFib-21.24MB ± 0%1.24MB ± 0%~(p=0.098 n=7+6)
 
allocs/opdelta
RuntimeResourceDictionaryValues-2102k ± 0%102k ± 0%+0.00%(p=0.033 n=7+6)
RuntimeFungibleTokenTransfer-24.51k ± 0%4.51k ± 0%~(p=0.140 n=6+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)
NewInterpreter/new_interpreter-212.0 ± 0%12.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-238.0 ± 0%38.0 ± 0%~(all equal)
InterpretRecursionFib-225.0k ± 0%25.0k ± 0%~(all equal)
 

@turbolent turbolent merged commit 9d442ef into master Mar 1, 2022
@turbolent turbolent deleted the bastian/fix-resource-nesting-check branch March 1, 2022 20:25
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.

3 participants