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

Properly support super types in ConformsToStaticType implementations #1694

Merged
merged 16 commits into from
Jun 7, 2022

Conversation

turbolent
Copy link
Member

@turbolent turbolent commented Jun 3, 2022

Closes #1693

Description

Change ConformsToStaticType so it only determines if the value conforms to its own static type, recursively.


  • 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

github-actions bot commented Jun 3, 2022

Cadence Benchstat comparison

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

Results

old.txtnew.txt
time/opdelta
CheckContractInterfaceFungibleTokenConformance-2170µs ± 7%166µs ± 3%~(p=0.456 n=7+7)
ContractInterfaceFungibleToken-249.9µs ± 1%51.1µs ± 2%+2.55%(p=0.002 n=7+7)
InterpretRecursionFib-23.38ms ± 1%3.39ms ± 8%~(p=0.318 n=7+7)
NewInterpreter/new_interpreter-21.31µs ± 1%1.32µs ± 1%~(p=0.195 n=6+7)
NewInterpreter/new_sub-interpreter-22.87µs ± 5%2.87µs ± 5%~(p=0.594 n=7+7)
ParseArray-210.8ms ± 6%10.5ms ± 2%~(p=0.101 n=7+6)
ParseDeploy/byte_array-216.1ms ± 1%16.1ms ± 3%~(p=1.000 n=5+7)
ParseDeploy/decode_hex-21.38ms ± 1%1.39ms ± 2%~(p=0.234 n=6+7)
ParseFungibleToken/With_memory_metering-2253µs ± 1%254µs ± 1%~(p=0.818 n=6+6)
ParseFungibleToken/Without_memory_metering-2198µs ± 5%197µs ± 0%~(p=0.876 n=7+5)
ParseInfix-29.19µs ± 1%9.25µs ± 3%~(p=0.740 n=7+7)
QualifiedIdentifierCreation/One_level-23.22ns ± 0%3.22ns ± 0%~(p=0.972 n=6+6)
QualifiedIdentifierCreation/Three_levels-2167ns ± 1%168ns ± 1%~(p=0.221 n=7+6)
RuntimeFungibleTokenTransfer-21.50ms ±23%1.44ms ±19%~(p=0.902 n=7+7)
RuntimeResourceDictionaryValues-27.57ms ± 2%7.64ms ± 4%~(p=0.383 n=7+7)
Transfer-2106ns ± 1%110ns ± 3%+4.34%(p=0.001 n=7+6)
 
alloc/opdelta
CheckContractInterfaceFungibleTokenConformance-266.3kB ± 0%66.3kB ± 0%~(p=0.592 n=7+7)
ContractInterfaceFungibleToken-226.7kB ± 0%26.7kB ± 0%~(all equal)
InterpretRecursionFib-21.25MB ± 0%1.25MB ± 0%~(p=0.417 n=7+6)
NewInterpreter/new_interpreter-2872B ± 0%872B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-21.38kB ± 0%1.38kB ± 0%~(all equal)
ParseArray-22.82MB ± 2%2.77MB ± 0%~(p=0.179 n=7+6)
ParseDeploy/byte_array-24.59MB ± 0%4.44MB ± 3%−3.35%(p=0.014 n=6+7)
ParseDeploy/decode_hex-2214kB ± 0%214kB ± 0%~(p=0.790 n=7+7)
ParseFungibleToken/With_memory_metering-236.3kB ± 0%36.3kB ± 0%~(p=0.559 n=7+7)
ParseFungibleToken/Without_memory_metering-236.3kB ± 0%36.3kB ± 0%~(p=0.505 n=7+5)
ParseInfix-22.17kB ± 0%2.17kB ± 0%~(p=0.179 n=7+7)
QualifiedIdentifierCreation/One_level-20.00B 0.00B ~(all equal)
QualifiedIdentifierCreation/Three_levels-264.0B ± 0%64.0B ± 0%~(all equal)
RuntimeFungibleTokenTransfer-2237kB ± 0%237kB ± 0%~(p=0.383 n=7+7)
RuntimeResourceDictionaryValues-22.25MB ± 0%2.25MB ± 0%~(p=0.138 n=6+7)
Transfer-248.0B ± 0%48.0B ± 0%~(all equal)
 
allocs/opdelta
CheckContractInterfaceFungibleTokenConformance-21.07k ± 0%1.07k ± 0%~(all equal)
ContractInterfaceFungibleToken-2460 ± 0%460 ± 0%~(all equal)
InterpretRecursionFib-223.8k ± 0%23.8k ± 0%~(all equal)
NewInterpreter/new_interpreter-212.0 ± 0%12.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-240.0 ± 0%40.0 ± 0%~(all equal)
ParseArray-270.0k ± 0%70.0k ± 0%~(p=0.245 n=6+7)
ParseDeploy/byte_array-2105k ± 0%105k ± 0%~(p=0.140 n=6+7)
ParseDeploy/decode_hex-278.0 ± 0%78.0 ± 0%~(all equal)
ParseFungibleToken/With_memory_metering-21.06k ± 0%1.06k ± 0%~(all equal)
ParseFungibleToken/Without_memory_metering-21.06k ± 0%1.06k ± 0%~(all equal)
ParseInfix-266.0 ± 0%66.0 ± 0%~(all equal)
QualifiedIdentifierCreation/One_level-20.00 0.00 ~(all equal)
QualifiedIdentifierCreation/Three_levels-22.00 ± 0%2.00 ± 0%~(all equal)
RuntimeFungibleTokenTransfer-24.52k ± 0%4.51k ± 0%−0.02%(p=0.045 n=7+7)
RuntimeResourceDictionaryValues-237.6k ± 0%37.6k ± 0%~(p=0.247 n=7+7)
Transfer-21.00 ± 0%1.00 ± 0%~(all equal)
 

@turbolent turbolent marked this pull request as ready for review June 7, 2022 04:35
@codecov
Copy link

codecov bot commented Jun 7, 2022

Codecov Report

Merging #1694 (9d3d900) into master (16c5038) will increase coverage by 0.08%.
The diff coverage is 88.29%.

@@            Coverage Diff             @@
##           master    #1694      +/-   ##
==========================================
+ Coverage   76.64%   76.72%   +0.08%     
==========================================
  Files         292      292              
  Lines       61199    61171      -28     
==========================================
+ Hits        46904    46936      +32     
+ Misses      12682    12623      -59     
+ Partials     1613     1612       -1     
Flag Coverage Δ
unittests 76.72% <88.29%> (+0.08%) ⬆️

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

Impacted Files Coverage Δ
runtime/convertValues.go 78.18% <ø> (-0.03%) ⬇️
runtime/interpreter/interpreter.go 89.53% <ø> (-0.01%) ⬇️
runtime/interpreter/simplecompositevalue.go 66.89% <84.61%> (+2.98%) ⬆️
runtime/interpreter/value.go 72.19% <87.83%> (+0.27%) ⬆️
runtime/interpreter/function.go 73.21% <100.00%> (+9.37%) ⬆️
runtime/runtime.go 86.51% <100.00%> (-0.03%) ⬇️
runtime/interpreter/primitivestatictype.go 84.61% <0.00%> (+0.76%) ⬆️
... and 1 more

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 16c5038...9d3d900. Read the comment docs.

Copy link
Member

@SupunS SupunS left a comment

Choose a reason for hiding this comment

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

This seems a good solution 👌

Just to make sure I understand correctly: This extends the existing ConformsToStaticType check of CompositeValue to other containers as well, and all the leaf-values / non-container-values are assumed to conform to their type always.

@turbolent
Copy link
Member Author

@SupunS great summary, correct! I've added a comment in 9d3d900

@turbolent turbolent merged commit 3484a89 into master Jun 7, 2022
@turbolent turbolent deleted the bastian/1693-fix-value-static-type-conformance branch June 7, 2022 18:49
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.

Value.ConformsToStaticType implementations do not always properly handle supertypes
2 participants