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 common supertype calculation for optionals #1594

Merged
merged 1 commit into from
Apr 20, 2022

Conversation

SupunS
Copy link
Member

@SupunS SupunS commented Apr 20, 2022

Closes #1592

Description

The optionals were not properly unwrapped before going into the struct-common-supertype finding path.

Solution:

  • Unwrap the optionals before going further
  • Re-wrap the same amount of level of optionals, before returning (if not already contain optionals).

With this, supertype of T, T?, T?? will be T??


  • 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

@SupunS SupunS added the Bugfix label Apr 20, 2022
@SupunS SupunS self-assigned this Apr 20, 2022
StringType,
},
expectedSuperType: AnyStructType,
},
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved these two tests to a dedicated test for optionals

@SupunS SupunS force-pushed the supun/fix-common-supertype branch from c77719d to 85dedf2 Compare April 20, 2022 16:15
@github-actions
Copy link

github-actions bot commented Apr 20, 2022

Cadence Benchstat comparison

This branch with compared with the base branch onflow:master commit f07c18f
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
ContractInterfaceFungibleToken-237.1µs ± 2%40.4µs ± 7%+8.91%(p=0.001 n=6+7)
CheckContractInterfaceFungibleTokenConformance-2123µs ± 4%131µs ± 2%+6.92%(p=0.001 n=7+6)
InterpretRecursionFib-22.56ms ± 3%2.66ms ± 3%+3.97%(p=0.008 n=6+7)
QualifiedIdentifierCreation/Three_levels-2134ns ± 4%138ns ± 1%+2.87%(p=0.038 n=7+6)
RuntimeFungibleTokenTransfer-21.09ms ±28%1.12ms ±26%~(p=0.535 n=7+7)
RuntimeResourceDictionaryValues-26.14ms ± 7%6.17ms ± 3%~(p=1.000 n=7+7)
Transfer-281.1ns ± 6%82.0ns ± 6%~(p=0.805 n=7+7)
ParseDeploy/decode_hex-21.12ms ± 4%1.13ms ± 5%~(p=0.620 n=7+7)
ParseInfix-28.09µs ± 6%8.30µs ± 4%~(p=0.209 n=7+7)
ParseArray-212.5ms ±11%12.4ms ± 9%~(p=1.000 n=7+7)
ParseFungibleToken-2174µs ± 4%178µs ± 6%~(p=0.731 n=6+7)
QualifiedIdentifierCreation/One_level-22.26ns ± 9%2.34ns ± 0%~(p=0.780 n=7+5)
NewInterpreter/new_interpreter-21.11µs ± 5%1.14µs ± 3%~(p=0.628 n=7+6)
NewInterpreter/new_sub-interpreter-22.13µs ± 5%2.18µs ± 4%~(p=0.165 n=7+7)
ParseDeploy/byte_array-219.7ms ± 6%18.8ms ± 4%−4.48%(p=0.038 n=7+7)
 
alloc/opdelta
RuntimeFungibleTokenTransfer-2273kB ± 0%273kB ± 0%~(p=0.435 n=7+7)
RuntimeResourceDictionaryValues-22.25MB ± 0%2.25MB ± 0%~(p=0.710 n=7+7)
Transfer-248.0B ± 0%48.0B ± 0%~(all equal)
QualifiedIdentifierCreation/One_level-20.00B 0.00B ~(all equal)
QualifiedIdentifierCreation/Three_levels-264.0B ± 0%64.0B ± 0%~(all equal)
ContractInterfaceFungibleToken-226.7kB ± 0%26.7kB ± 0%~(p=0.592 n=7+7)
CheckContractInterfaceFungibleTokenConformance-266.3kB ± 0%66.3kB ± 0%~(p=1.000 n=7+7)
InterpretRecursionFib-21.14MB ± 0%1.14MB ± 0%~(p=0.923 n=6+7)
NewInterpreter/new_interpreter-2848B ± 0%848B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-21.34kB ± 0%1.34kB ± 0%~(all equal)
 
allocs/opdelta
RuntimeFungibleTokenTransfer-24.58k ± 0%4.58k ± 0%~(p=0.991 n=7+7)
RuntimeResourceDictionaryValues-237.6k ± 0%37.6k ± 0%~(p=1.000 n=5+7)
Transfer-21.00 ± 0%1.00 ± 0%~(all equal)
QualifiedIdentifierCreation/One_level-20.00 0.00 ~(all equal)
QualifiedIdentifierCreation/Three_levels-22.00 ± 0%2.00 ± 0%~(all equal)
ContractInterfaceFungibleToken-2460 ± 0%460 ± 0%~(all equal)
CheckContractInterfaceFungibleTokenConformance-21.07k ± 0%1.07k ± 0%~(all equal)
InterpretRecursionFib-223.8k ± 0%23.8k ± 0%~(all equal)
NewInterpreter/new_interpreter-213.0 ± 0%13.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-240.0 ± 0%40.0 ± 0%~(all equal)
 

@codecov
Copy link

codecov bot commented Apr 20, 2022

Codecov Report

Merging #1594 (85dedf2) into master (f07c18f) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1594      +/-   ##
==========================================
+ Coverage   74.72%   74.73%   +0.01%     
==========================================
  Files         288      288              
  Lines       55305    55340      +35     
==========================================
+ Hits        41324    41359      +35     
  Misses      12487    12487              
  Partials     1494     1494              
Flag Coverage Δ
unittests 74.73% <100.00%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
runtime/sema/type_tags.go 94.42% <100.00%> (+0.45%) ⬆️

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 f07c18f...85dedf2. Read the comment docs.

Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

Great fix!

@SupunS SupunS merged commit 1216be2 into master Apr 20, 2022
@SupunS SupunS deleted the supun/fix-common-supertype branch April 20, 2022 17:19
@SupunS SupunS mentioned this pull request Apr 20, 2022
6 tasks
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.

commonSuperTypeOfComposites does not handle optionals
3 participants