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

Infer static type from the value itself for imported arrays/dictionaries #1049

Merged
merged 9 commits into from
Nov 18, 2021

Conversation

SupunS
Copy link
Member

@SupunS SupunS commented Jul 5, 2021

Work towards #870

Description

Infer the static type from the array/dictionary value, if the expected type is not specific enough/ not available.

Depends on #1025 and #1048


  • 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 requested a review from turbolent as a code owner July 5, 2021 10:35
@SupunS
Copy link
Member Author

SupunS commented Jul 5, 2021

The last two commits 1d26160 and bbba319 have the actual code changes. The rest is from the dependent PRs.

@SupunS SupunS changed the title Infer static type from array/dictionary value for imported values Infer static type from the value itself for imported arrays/dictionaries Jul 5, 2021
@SupunS SupunS self-assigned this Jul 5, 2021
@SupunS SupunS added the Feature label Jul 5, 2021
@codecov-commenter
Copy link

codecov-commenter commented Jul 5, 2021

Codecov Report

Merging #1049 (a21446f) into master (a523a95) will increase coverage by 0.00%.
The diff coverage is 66.66%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1049   +/-   ##
=======================================
  Coverage   77.59%   77.60%           
=======================================
  Files         274      274           
  Lines       35241    35243    +2     
=======================================
+ Hits        27347    27350    +3     
+ Misses       6809     6808    -1     
  Partials     1085     1085           
Flag Coverage Δ
unittests 77.60% <66.66%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
runtime/convertValues.go 77.26% <66.66%> (+0.40%) ⬆️
runtime/interpreter/primitivestatictype.go 72.42% <0.00%> (-0.94%) ⬇️
runtime/interpreter/value.go 82.49% <0.00%> (+0.02%) ⬆️

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 a523a95...a21446f. Read the comment docs.

@turbolent
Copy link
Member

@SupunS Do you think that we could hold off with this for now and get all the supertype inference PRs in later, i.e. the next release / spork? Do you think it's possible to do something simple for now, like e.g. infer [AnyStruct] for an array value where the expected static type is AnyStruct? (same for dictionaries)

@SupunS
Copy link
Member Author

SupunS commented Jul 5, 2021

@turbolent Yeah, that should be fine. I added this more as a way to test the concept/usage.
I think arrays are rather simple. We can assume it to be [AnyStruct]
Same can be done for dictionary values.

But for dictionary keys, AnyStruct might be a problem because it is not a valid type for keys. And might become a problem somewhere down the line?

@SupunS SupunS changed the base branch from feature/container-static-types to supun/common-supertype-3 November 9, 2021 17:53
@SupunS SupunS requested a review from dsainati1 November 9, 2021 18:42
Base automatically changed from supun/common-supertype-3 to master November 11, 2021 00:17
@github-actions
Copy link

github-actions bot commented Nov 12, 2021

Cadence Benchstat comparison

This branch with compared with the base branch onflow:master commit a523a95
The command go test ./... -run=XXX -bench=. -shuffle=on -count N was used.
Bench tests were run a total of 7 times on each branch.

Results

old.txtnew.txt
time/opdelta
RuntimeResourceDictionaryValues-216.0ms ± 3%16.9ms ± 4%+5.71%(p=0.001 n=6+7)
RuntimeStorageWriteCached-2166µs ±54%179µs ±24%~(p=0.318 n=7+7)
ParseDeploy/decode_hex-21.50ms ± 2%1.50ms ± 6%~(p=0.383 n=7+7)
ParseArray-223.0ms ± 0%23.0ms ± 2%~(p=0.731 n=6+7)
ParseInfix-224.3µs ± 2%24.1µs ± 2%~(p=0.535 n=7+7)
ParseFungibleToken-2472µs ± 4%465µs ± 2%~(p=0.318 n=7+7)
QualifiedIdentifierCreation/One_level-23.30ns ± 1%3.34ns ± 4%~(p=0.456 n=7+7)
QualifiedIdentifierCreation/Three_levels-2169ns ± 1%169ns ± 3%~(p=0.693 n=7+7)
CheckContractInterfaceFungibleTokenConformance-2170µs ± 0%171µs ± 1%~(p=0.535 n=7+7)
InterpretRecursionFib-22.82ms ± 9%2.77ms ± 1%~(p=0.445 n=7+6)
NewInterpreter/new_interpreter-21.21µs ± 6%1.22µs ± 3%~(p=0.805 n=7+7)
NewInterpreter/new_sub-interpreter-22.27µs ± 3%2.31µs ± 3%~(p=0.104 n=7+7)
ContractInterfaceFungibleToken-248.6µs ± 1%47.7µs ± 1%−1.69%(p=0.009 n=6+6)
ParseDeploy/byte_array-234.8ms ± 3%34.1ms ± 1%−1.94%(p=0.007 n=7+7)
RuntimeFungibleTokenTransfer-21.29ms ± 5%1.23ms ± 3%−4.88%(p=0.017 n=7+7)
 
alloc/opdelta
RuntimeStorageWriteCached-283.7kB ± 0%83.7kB ± 0%~(p=0.878 n=7+7)
RuntimeResourceDictionaryValues-24.34MB ± 0%4.34MB ± 0%~(p=0.620 n=7+7)
RuntimeFungibleTokenTransfer-2233kB ± 0%233kB ± 0%~(p=0.383 n=7+7)
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%~(all equal)
CheckContractInterfaceFungibleTokenConformance-266.4kB ± 0%66.4kB ± 0%~(all equal)
InterpretRecursionFib-21.21MB ± 0%1.21MB ± 0%~(p=0.678 n=7+6)
NewInterpreter/new_interpreter-2680B ± 0%680B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-21.06kB ± 0%1.06kB ± 0%~(all equal)
 
allocs/opdelta
RuntimeStorageWriteCached-21.42k ± 0%1.42k ± 0%~(all equal)
RuntimeResourceDictionaryValues-2108k ± 0%108k ± 0%~(p=0.551 n=7+7)
RuntimeFungibleTokenTransfer-24.42k ± 0%4.43k ± 0%~(p=0.098 n=6+7)
QualifiedIdentifierCreation/One_level-20.00 0.00 ~(all equal)
QualifiedIdentifierCreation/Three_levels-22.00 ± 0%2.00 ± 0%~(all equal)
ContractInterfaceFungibleToken-2458 ± 0%458 ± 0%~(all equal)
CheckContractInterfaceFungibleTokenConformance-21.07k ± 0%1.07k ± 0%~(all equal)
InterpretRecursionFib-225.0k ± 0%25.0k ± 0%~(all equal)
NewInterpreter/new_interpreter-211.0 ± 0%11.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-231.0 ± 0%31.0 ± 0%~(all equal)
 

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.

Nice!

runtime/convertValues.go Outdated Show resolved Hide resolved
SupunS and others added 2 commits November 18, 2021 12:26
Co-authored-by: Bastian Müller <bastian@axiomzen.co>
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