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

Check reference expression operator #1566

Closed
wants to merge 1 commit into from

Conversation

turbolent
Copy link
Member

Closes #1406

Description

Reference expressions and casting expressions have the same syntax, so reference expressions are parsed by parsing casting expressions.

Ensure the casting expression has the correct operator (as).

At least make the current syntax / parsing strict, but we still might want to change the syntax has discussed.


  • 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 added Bugfix Language Breaking Change Breaks Cadence contracts deployed on Mainnet labels Apr 8, 2022
@turbolent turbolent requested a review from SupunS as a code owner April 8, 2022 22:41
@turbolent turbolent self-assigned this Apr 8, 2022
@turbolent turbolent removed the request for review from relatko April 8, 2022 22:41
@codecov-commenter
Copy link

Codecov Report

Merging #1566 (7bc31c1) into master (423ef34) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #1566   +/-   ##
=======================================
  Coverage   74.73%   74.73%           
=======================================
  Files         289      289           
  Lines       55659    55673   +14     
=======================================
+ Hits        41595    41607   +12     
- Misses      12563    12565    +2     
  Partials     1501     1501           
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/ast/expression.go 87.61% <ø> (ø)
runtime/parser2/expression.go 92.88% <100.00%> (+0.07%) ⬆️
runtime/sema/simple_type.go 92.30% <0.00%> (-3.85%) ⬇️
runtime/sema/check_member_expression.go 97.64% <0.00%> (+0.01%) ⬆️

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 423ef34...7bc31c1. Read the comment docs.

@github-actions
Copy link

github-actions bot commented Apr 8, 2022

Cadence Benchstat comparison

This branch with compared with the base branch onflow:master commit 07c27c2
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-248.8µs ± 1%49.9µs ± 3%+2.30%(p=0.008 n=6+7)
RuntimeFungibleTokenTransfer-21.52ms ±32%1.68ms ±24%~(p=0.456 n=7+7)
RuntimeResourceDictionaryValues-216.7ms ± 6%17.0ms ± 4%~(p=0.456 n=7+7)
ParseFungibleToken-2230µs ± 3%237µs ± 4%~(p=0.132 n=6+6)
ParseArray-215.8ms ±13%15.4ms ± 4%~(p=0.620 n=7+7)
ParseInfix-210.0µs ± 3%10.1µs ± 2%~(p=0.388 n=7+6)
ParseDeploy/byte_array-224.6ms ±15%24.3ms ± 8%~(p=1.000 n=7+7)
ParseDeploy/decode_hex-21.43ms ± 4%1.43ms ± 2%~(p=1.000 n=7+7)
QualifiedIdentifierCreation/One_level-23.34ns ± 3%3.30ns ± 7%~(p=0.259 n=7+7)
QualifiedIdentifierCreation/Three_levels-2168ns ± 4%170ns ± 4%~(p=0.318 n=7+7)
CheckContractInterfaceFungibleTokenConformance-2172µs ± 2%176µs ± 3%~(p=0.101 n=6+7)
NewInterpreter/new_interpreter-21.41µs ± 5%1.37µs ± 1%~(p=0.054 n=7+6)
NewInterpreter/new_sub-interpreter-22.67µs ± 7%2.69µs ± 4%~(p=0.535 n=7+7)
InterpretRecursionFib-23.19ms ± 3%3.19ms ± 3%~(p=1.000 n=7+7)
 
alloc/opdelta
RuntimeFungibleTokenTransfer-2273kB ± 0%273kB ± 0%~(p=1.000 n=7+7)
RuntimeResourceDictionaryValues-24.05MB ± 0%4.05MB ± 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)
CheckContractInterfaceFungibleTokenConformance-266.2kB ± 0%66.2kB ± 0%~(all equal)
ContractInterfaceFungibleToken-226.6kB ± 0%26.6kB ± 0%~(all equal)
NewInterpreter/new_interpreter-2848B ± 0%848B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-21.34kB ± 0%1.34kB ± 0%~(all equal)
InterpretRecursionFib-21.26MB ± 0%1.26MB ± 0%~(p=0.639 n=7+7)
 
allocs/opdelta
RuntimeFungibleTokenTransfer-24.54k ± 0%4.54k ± 0%~(p=0.423 n=7+7)
RuntimeResourceDictionaryValues-2102k ± 0%102k ± 0%~(p=0.764 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-2458 ± 0%458 ± 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-226.2k ± 0%26.2k ± 0%~(all equal)
 

@dsainati1
Copy link
Contributor

I agree that this is an improvement over not doing the check, but I think this error is going to be very confusing to people. If people were using as! and as? instead of as because they didn't understand the difference between a reference and a cast, complaining that they are using the wrong one is not going to make sense. IMO at least until we have time to address the syntax similarity we should include something in the text of the error that either explains the difference or at least links to the docs.

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.

This sounds like a good temporary solution to me

@turbolent
Copy link
Member Author

@dsainati1 Agreed. We won't merge this for Secure Cadence, I just opened it so we would at least start to do something about it, even if just reporting some error until we have a proper decision about what to do here (e.g change the syntax, like discussed before).

[...] we should include something in the text of the error that either explains the difference or at least links to the docs.
Could you maybe add this? You might be better at phrasing this than I would

@turbolent
Copy link
Member Author

Replaced by #1661

@turbolent turbolent closed this Jul 7, 2022
@turbolent turbolent deleted the bastian/1406-check-reference-operator branch July 7, 2022 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bugfix Language Breaking Change Breaks Cadence contracts deployed on Mainnet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parser/Checker do not reject invalid reference operators
5 participants