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 parsing of reference expressions #1622

Merged
merged 1 commit into from
May 11, 2022
Merged

Conversation

turbolent
Copy link
Member

@turbolent turbolent commented May 5, 2022

Description

Reference expressions are parsed by parsing them as a casting expression.

Currently the reference operator & parses any expression, which leads to confusing error messages for valid programs.
For example, currently an expression &v as &T? ?? panic("no v") is parsed as a reference to a nil-coalescing operation (??), instead of a nil-coalescing operation of a reference expression.

Only parse an expression which has a precedence as high as a casting expression, the expression kind we expect to parse.

This is not a breaking change: Previously the expressions were not accepted, now they will be.


  • 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 May 5, 2022
@turbolent turbolent requested review from SupunS and dsainati1 as code owners May 5, 2022 01:44
@codecov
Copy link

codecov bot commented May 5, 2022

Codecov Report

Merging #1622 (f8e663e) into master (f615bea) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #1622   +/-   ##
=======================================
  Coverage   74.73%   74.73%           
=======================================
  Files         288      288           
  Lines       55340    55339    -1     
=======================================
+ Hits        41357    41358    +1     
+ Misses      12489    12487    -2     
  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/parser2/expression.go 92.80% <100.00%> (-0.01%) ⬇️
runtime/interpreter/storage.go 72.78% <0.00%> (+1.36%) ⬆️

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 f615bea...f8e663e. Read the comment docs.

@github-actions
Copy link

github-actions bot commented May 5, 2022

Cadence Benchstat comparison

This branch with compared with the base branch onflow:master commit f615bea
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
RuntimeResourceDictionaryValues-25.90ms ± 6%5.76ms ± 1%~(p=0.343 n=7+5)
RuntimeFungibleTokenTransfer-2985µs ±32%1170µs ±28%~(p=0.318 n=7+7)
Transfer-276.7ns ± 4%74.8ns ± 7%~(p=0.209 n=7+7)
ParseDeploy/byte_array-217.7ms ± 3%18.4ms ±10%~(p=0.165 n=7+7)
ParseDeploy/decode_hex-21.04ms ± 6%1.04ms ± 7%~(p=0.620 n=7+7)
ParseArray-211.5ms ±11%11.2ms ± 4%~(p=0.620 n=7+7)
ParseFungibleToken-2166µs ± 8%158µs ± 1%~(p=0.073 n=7+6)
ParseInfix-27.70µs ±10%7.64µs ± 4%~(p=1.000 n=7+7)
QualifiedIdentifierCreation/One_level-22.02ns ± 1%2.20ns ± 9%~(p=0.168 n=6+7)
QualifiedIdentifierCreation/Three_levels-2125ns ± 3%124ns ± 7%~(p=0.829 n=7+7)
ContractInterfaceFungibleToken-235.8µs ± 5%36.0µs ±10%~(p=0.902 n=7+7)
CheckContractInterfaceFungibleTokenConformance-2118µs ± 9%116µs ± 6%~(p=0.620 n=7+7)
NewInterpreter/new_interpreter-21.03µs ± 4%1.03µs ± 6%~(p=0.535 n=7+7)
NewInterpreter/new_sub-interpreter-22.02µs ± 8%2.03µs ± 1%~(p=0.704 n=7+6)
InterpretRecursionFib-22.45ms ± 3%2.43ms ± 7%~(p=0.620 n=7+7)
 
alloc/opdelta
RuntimeResourceDictionaryValues-22.25MB ± 0%2.25MB ± 0%~(p=0.620 n=7+7)
RuntimeFungibleTokenTransfer-2273kB ± 0%273kB ± 0%~(p=0.805 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=1.000 n=7+7)
CheckContractInterfaceFungibleTokenConformance-266.3kB ± 0%66.3kB ± 0%~(p=0.385 n=6+7)
NewInterpreter/new_interpreter-2848B ± 0%848B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-21.34kB ± 0%1.34kB ± 0%~(all equal)
InterpretRecursionFib-21.14MB ± 0%1.14MB ± 0%~(p=1.000 n=7+7)
 
allocs/opdelta
RuntimeResourceDictionaryValues-237.6k ± 0%37.6k ± 0%~(p=1.000 n=5+7)
RuntimeFungibleTokenTransfer-24.58k ± 0%4.58k ± 0%~(p=0.164 n=7+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)
NewInterpreter/new_interpreter-213.0 ± 0%13.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-240.0 ± 0%40.0 ± 0%~(all equal)
InterpretRecursionFib-223.8k ± 0%23.8k ± 0%~(all equal)
 

@turbolent turbolent merged commit 909fd42 into master May 11, 2022
@turbolent turbolent deleted the bastian/fix-reference-parsing branch May 11, 2022 23:03
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