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

Improve the AST visitor further #1919

Merged
merged 4 commits into from
Aug 29, 2022
Merged

Conversation

turbolent
Copy link
Member

@turbolent turbolent commented Aug 26, 2022

Description

Remove the combined Visitor and introduce separate Accept* functions for declarations, statements, and expressions. This allows implementations, like the checker and interpreter, to specify different return values. For example, the interpreter returns Values for expressions, but StatementResult for statements.


  • 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 requested a review from SupunS as a code owner August 26, 2022 19:49
@turbolent turbolent self-assigned this Aug 26, 2022
@turbolent turbolent requested a review from dsainati1 as a code owner August 26, 2022 19:49
@turbolent turbolent mentioned this pull request Aug 26, 2022
6 tasks
Base automatically changed from bastian/optimize-visitor to master August 29, 2022 16:49
@codecov
Copy link

codecov bot commented Aug 29, 2022

Codecov Report

Merging #1919 (aa41abb) into master (c9a3614) will increase coverage by 0.09%.
The diff coverage is 76.51%.

@@            Coverage Diff             @@
##           master    #1919      +/-   ##
==========================================
+ Coverage   77.62%   77.72%   +0.09%     
==========================================
  Files         303      303              
  Lines       62081    62009      -72     
==========================================
+ Hits        48190    48194       +4     
+ Misses      12171    12096      -75     
+ Partials     1720     1719       -1     
Flag Coverage Δ
unittests 77.72% <76.51%> (+0.09%) ⬆️

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

Impacted Files Coverage Δ
runtime/ast/block.go 98.23% <ø> (+1.10%) ⬆️
runtime/ast/composite.go 86.64% <ø> (+1.07%) ⬆️
runtime/ast/expression.go 91.01% <ø> (+2.54%) ⬆️
runtime/ast/function_declaration.go 81.35% <ø> (+1.02%) ⬆️
runtime/ast/import.go 91.11% <ø> (-0.20%) ⬇️
runtime/ast/interface.go 100.00% <ø> (ø)
runtime/ast/pragma.go 78.37% <ø> (+4.01%) ⬆️
runtime/ast/program.go 69.23% <ø> (-0.59%) ⬇️
runtime/ast/statement.go 92.10% <ø> (+3.82%) ⬆️
runtime/ast/transaction_declaration.go 82.65% <ø> (+1.65%) ⬆️
... and 52 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@github-actions
Copy link

Cadence Benchstat comparison

This branch with compared with the base branch onflow:master commit 599dda3
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.

Collapsed results for better readability

old.txtnew.txt
time/opdelta
CheckContractInterfaceFungibleTokenConformance-2211µs ± 9%182µs ± 4%−13.95%(p=0.001 n=7+6)
ContractInterfaceFungibleToken-255.6µs ±12%49.5µs ± 7%−10.91%(p=0.002 n=7+7)
InterpretRecursionFib-23.54ms ± 6%3.08ms ± 6%−13.00%(p=0.001 n=7+7)
NewInterpreter/new_interpreter-21.45µs ± 4%1.39µs ± 9%~(p=0.097 n=7+7)
NewInterpreter/new_sub-interpreter-2839ns ± 2%799ns ± 8%~(p=0.101 n=6+7)
ParseArray-210.9ms ± 2%10.3ms ± 5%−5.46%(p=0.002 n=7+6)
ParseDeploy/byte_array-216.9ms ± 7%15.8ms ± 5%−6.82%(p=0.005 n=7+6)
ParseDeploy/decode_hex-21.49ms ± 3%1.41ms ± 3%−5.14%(p=0.001 n=7+6)
ParseFungibleToken/With_memory_metering-2277µs ± 4%272µs ± 9%~(p=0.710 n=7+7)
ParseFungibleToken/Without_memory_metering-2211µs ± 7%197µs ± 4%−6.73%(p=0.014 n=7+6)
ParseInfix-29.41µs ± 3%9.11µs ±11%~(p=0.128 n=7+7)
QualifiedIdentifierCreation/One_level-23.48ns ± 3%3.27ns ± 2%−6.03%(p=0.001 n=7+6)
QualifiedIdentifierCreation/Three_levels-2185ns ± 5%174ns ± 7%−5.89%(p=0.017 n=7+7)
RuntimeFungibleTokenTransfer-2876µs ±23%787µs ±25%~(p=0.073 n=7+7)
RuntimeResourceDictionaryValues-26.71ms ± 6%6.13ms ± 5%−8.68%(p=0.002 n=7+6)
RuntimeScriptNoop-225.5µs ±47%22.2µs ±54%~(p=0.165 n=7+7)
ValueIsSubtypeOfSemaType-2118ns ± 6%112ns ± 1%−4.99%(p=0.018 n=7+5)
 
alloc/opdelta
CheckContractInterfaceFungibleTokenConformance-261.5kB ± 0%61.5kB ± 0%−0.01%(p=0.001 n=7+7)
ContractInterfaceFungibleToken-223.9kB ± 0%23.9kB ± 0%~(all equal)
InterpretRecursionFib-21.23MB ± 0%1.23MB ± 0%−0.00%(p=0.003 n=7+6)
NewInterpreter/new_interpreter-2848B ± 0%848B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-2264B ± 0%264B ± 0%~(all equal)
ParseArray-22.81MB ± 2%2.79MB ± 3%~(p=0.334 n=7+7)
ParseDeploy/byte_array-24.47MB ± 3%4.47MB ± 3%~(p=0.710 n=7+7)
ParseDeploy/decode_hex-2214kB ± 0%214kB ± 0%~(p=0.639 n=7+6)
ParseFungibleToken/With_memory_metering-236.3kB ± 0%36.3kB ± 0%~(p=0.538 n=6+7)
ParseFungibleToken/Without_memory_metering-236.3kB ± 0%36.3kB ± 0%~(p=0.559 n=7+7)
ParseInfix-22.17kB ± 0%2.17kB ± 0%~(p=1.000 n=7+7)
QualifiedIdentifierCreation/One_level-20.00B 0.00B ~(all equal)
QualifiedIdentifierCreation/Three_levels-264.0B ± 0%64.0B ± 0%~(all equal)
RuntimeFungibleTokenTransfer-2111kB ± 1%111kB ± 1%~(p=0.620 n=7+7)
RuntimeResourceDictionaryValues-22.27MB ± 0%2.27MB ± 0%~(p=0.805 n=7+7)
RuntimeScriptNoop-28.64kB ± 1%8.63kB ± 1%~(p=0.902 n=7+7)
ValueIsSubtypeOfSemaType-248.0B ± 0%48.0B ± 0%~(all equal)
 
allocs/opdelta
CheckContractInterfaceFungibleTokenConformance-21.03k ± 0%1.03k ± 0%~(all equal)
ContractInterfaceFungibleToken-2426 ± 0%426 ± 0%~(all equal)
InterpretRecursionFib-222.5k ± 0%22.5k ± 0%~(all equal)
NewInterpreter/new_interpreter-214.0 ± 0%14.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-25.00 ± 0%5.00 ± 0%~(all equal)
ParseArray-270.0k ± 0%70.0k ± 0%~(p=1.000 n=7+7)
ParseDeploy/byte_array-2105k ± 0%105k ± 0%~(p=1.000 n=7+7)
ParseDeploy/decode_hex-277.0 ± 0%77.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-22.20k ± 0%2.20k ± 0%~(p=1.000 n=7+7)
RuntimeResourceDictionaryValues-236.9k ± 0%36.9k ± 0%~(p=1.000 n=7+6)
RuntimeScriptNoop-2143 ± 0%143 ± 0%~(all equal)
ValueIsSubtypeOfSemaType-21.00 ± 0%1.00 ± 0%~(all equal)
 

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.

Nice

@turbolent turbolent merged commit 010f6bf into master Aug 29, 2022
@turbolent turbolent deleted the bastian/optimize-visitor-2 branch August 29, 2022 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants