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

Pretty print statements #1280

Merged
merged 15 commits into from
Dec 7, 2021
Merged

Pretty print statements #1280

merged 15 commits into from
Dec 7, 2021

Conversation

turbolent
Copy link
Member

@turbolent turbolent commented Nov 29, 2021

Work towards #209

Description

Implement pretty-printing functions for all statement AST nodes:

  • ReturnStatement
  • BreakStatement
  • ContinueStatement
  • IfStatement
  • WhileStatement
  • ForStatement
  • EmitStatement
  • AssignmentStatement
  • SwapStatement
  • ExpressionStatement

Also:

  • Add missing JSON marshaling tests
  • Allow inserting tabs (4 spaces) in the pretty printer tool's text area

  • 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 Nov 29, 2021
@turbolent turbolent mentioned this pull request Nov 30, 2021
6 tasks
Base automatically changed from bastian/prettier to master November 30, 2021 00:37
@codecov-commenter
Copy link

Codecov Report

Merging #1280 (f60a37f) into master (7091617) will increase coverage by 0.12%.
The diff coverage is 98.56%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1280      +/-   ##
==========================================
+ Coverage   77.22%   77.35%   +0.12%     
==========================================
  Files         278      278              
  Lines       35814    35932     +118     
==========================================
+ Hits        27659    27796     +137     
+ Misses       7069     7050      -19     
  Partials     1086     1086              
Flag Coverage Δ
unittests 77.35% <98.56%> (+0.12%) ⬆️

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

Impacted Files Coverage Δ
tools/pretty/main.go 0.00% <ø> (ø)
runtime/ast/block.go 89.79% <89.47%> (-0.21%) ⬇️
runtime/ast/expression.go 82.89% <100.00%> (+0.01%) ⬆️
runtime/ast/statement.go 92.98% <100.00%> (+14.72%) ⬆️
runtime/ast/transfer.go 80.00% <0.00%> (+15.00%) ⬆️

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 7091617...f60a37f. Read the comment docs.

@github-actions
Copy link

Cadence Benchstat comparison

This branch with compared with the base branch onflow:master commit 7091617
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
RuntimeFungibleTokenTransfer-21.14ms ±25%1.07ms ± 2%~(p=0.628 n=7+6)
RuntimeResourceDictionaryValues-214.4ms ± 2%15.7ms ±11%~(p=0.101 n=6+7)
ParseDeploy/byte_array-232.7ms ± 6%32.3ms ± 5%~(p=0.534 n=6+7)
ParseDeploy/decode_hex-21.30ms ± 2%1.29ms ± 4%~(p=0.620 n=7+7)
ParseArray-220.4ms ± 2%20.9ms ± 5%~(p=0.073 n=7+7)
QualifiedIdentifierCreation/One_level-22.91ns ± 5%2.84ns ± 6%~(p=0.155 n=7+7)
QualifiedIdentifierCreation/Three_levels-2146ns ± 4%143ns ± 4%~(p=0.318 n=7+7)
CheckContractInterfaceFungibleTokenConformance-2161µs ±10%154µs ± 3%~(p=0.073 n=7+7)
ContractInterfaceFungibleToken-243.4µs ± 4%42.9µs ± 3%~(p=0.534 n=7+6)
NewInterpreter/new_interpreter-21.04µs ± 2%1.04µs ± 2%~(p=0.810 n=6+7)
InterpretRecursionFib-22.41ms ± 2%2.41ms ± 5%~(p=0.945 n=6+7)
ParseFungibleToken-2434µs ± 4%418µs ± 4%−3.81%(p=0.022 n=6+7)
ParseInfix-222.6µs ± 3%21.5µs ± 4%−4.89%(p=0.002 n=7+7)
NewInterpreter/new_sub-interpreter-21.98µs ± 2%1.88µs ± 5%−5.18%(p=0.002 n=7+7)
RuntimeStorageWriteCached-2139µs ± 4%123µs ± 3%−11.51%(p=0.001 n=6+7)
 
alloc/opdelta
RuntimeFungibleTokenTransfer-2233kB ± 0%233kB ± 0%~(p=1.000 n=7+7)
RuntimeStorageWriteCached-283.7kB ± 0%83.7kB ± 0%~(p=0.538 n=6+7)
RuntimeResourceDictionaryValues-24.34MB ± 0%4.34MB ± 0%~(p=0.394 n=6+6)
QualifiedIdentifierCreation/One_level-20.00B 0.00B ~(all equal)
QualifiedIdentifierCreation/Three_levels-264.0B ± 0%64.0B ± 0%~(all equal)
CheckContractInterfaceFungibleTokenConformance-265.7kB ± 0%65.7kB ± 0%~(p=0.462 n=7+7)
ContractInterfaceFungibleToken-226.5kB ± 0%26.5kB ± 0%~(all equal)
NewInterpreter/new_interpreter-2720B ± 0%720B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-21.11kB ± 0%1.11kB ± 0%~(all equal)
InterpretRecursionFib-21.24MB ± 0%1.24MB ± 0%~(p=0.245 n=6+7)
 
allocs/opdelta
RuntimeFungibleTokenTransfer-24.40k ± 0%4.40k ± 0%~(p=0.462 n=7+7)
RuntimeStorageWriteCached-21.42k ± 0%1.42k ± 0%~(all equal)
RuntimeResourceDictionaryValues-2108k ± 0%108k ± 0%~(p=0.404 n=7+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-2457 ± 0%457 ± 0%~(all equal)
NewInterpreter/new_interpreter-211.0 ± 0%11.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-232.0 ± 0%32.0 ± 0%~(all equal)
InterpretRecursionFib-225.0k ± 0%25.0k ± 0%~(all equal)
 

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.

Nice!

const forStatementSpaceInKeywordSpaceDoc = prettier.Text(" in ")

func (s *ForStatement) Doc() prettier.Doc {
doc := prettier.Concat{
Copy link
Member

@SupunS SupunS Dec 3, 2021

Choose a reason for hiding this comment

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

need this concat?

Copy link
Member Author

Choose a reason for hiding this comment

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

}

if s.Index != nil {
doc = append(
Copy link
Member

@SupunS SupunS Dec 3, 2021

Choose a reason for hiding this comment

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

Is there a difference between using an array (append) vs prettier.Concat{}?

Copy link
Member Author

Choose a reason for hiding this comment

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

prettier.Concat is a prettier document, but is also just a slice of documents, so we can use the Go append to add to it

@turbolent turbolent merged commit 64592b4 into master Dec 7, 2021
@turbolent turbolent deleted the bastian/prettier-2 branch December 7, 2021 10:17
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