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

Disallow arithmetic, comparison and bitwise operations on number supertypes #1360

Merged
merged 9 commits into from Feb 3, 2022

Conversation

SupunS
Copy link
Member

@SupunS SupunS commented Jan 14, 2022

Closes https://github.com/dapperlabs/cadence-private-issues/issues/10

Description

This is a reference implementation for the changes proposed on FLIP: onflow/flow#729


  • 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

leftType, rightType Type,
leftIsInvalid, rightIsInvalid, anyInvalid bool,
anyInvalid bool,
Copy link
Member Author

Choose a reason for hiding this comment

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

Cleaning up some unused params

@@ -837,252 +835,3 @@ func TestInterpretSaturatedArithmeticFunctions(t *testing.T) {
test(ty, "Divide", testCase.divide)
}
}

func TestInterpretArithmeticOnSubTypes(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This test is no longer valid, as it will never reach the runtime

Comment on lines -148 to -151
ast.OperationGreater,
ast.OperationGreaterEqual,
ast.OperationLess,
ast.OperationLessEqual,
Copy link
Member Author

@SupunS SupunS Jan 14, 2022

Choose a reason for hiding this comment

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

Similarly, these tests (i.e: checking the runtime behavior for these operations) are no longer valid, since they don't reach runtime

@codecov-commenter
Copy link

codecov-commenter commented Jan 14, 2022

Codecov Report

Merging #1360 (4d806f5) into master (95aea4a) will decrease coverage by 2.75%.
The diff coverage is 81.81%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1360      +/-   ##
==========================================
- Coverage   75.78%   73.03%   -2.76%     
==========================================
  Files         280      279       -1     
  Lines       38779    38794      +15     
==========================================
- Hits        29390    28333    -1057     
- Misses       8039     9023     +984     
- Partials     1350     1438      +88     
Flag Coverage Δ
unittests 73.03% <81.81%> (-2.76%) ⬇️

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

Impacted Files Coverage Δ
runtime/sema/type.go 88.34% <60.00%> (-0.12%) ⬇️
runtime/sema/check_binary_expression.go 88.26% <100.00%> (+0.20%) ⬆️
runtime/interpreter/value.go 55.84% <0.00%> (-15.54%) ⬇️
runtime/parser2/parser.go 85.26% <0.00%> (-7.46%) ⬇️
runtime/parser2/function.go 64.66% <0.00%> (-4.62%) ⬇️
runtime/parser2/expression.go 90.38% <0.00%> (-3.30%) ⬇️
runtime/stdlib/crypto.go 71.79% <0.00%> (-0.71%) ⬇️
runtime/sema/errors.go 58.24% <0.00%> (-0.23%) ⬇️
runtime/sema/hashalgorithm_string.go 0.00% <0.00%> (ø)
runtime/sema/check_reference_expression.go 100.00% <0.00%> (ø)
... and 4 more

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 95aea4a...4d806f5. Read the comment docs.

@github-actions
Copy link

github-actions bot commented Jan 14, 2022

Cadence Benchstat comparison

This branch with compared with the base branch onflow:master commit 86d42e3
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
QualifiedIdentifierCreation/One_level-22.24ns ± 3%2.60ns ± 6%+15.81%(p=0.001 n=7+7)
RuntimeFungibleTokenTransfer-21.16ms ±32%1.37ms ± 8%~(p=0.295 n=7+6)
RuntimeResourceDictionaryValues-213.9ms ± 2%13.5ms ± 6%~(p=0.165 n=7+7)
ParseInfix-29.49µs ± 9%9.28µs ± 4%~(p=0.456 n=7+7)
ParseDeploy/byte_array-219.8ms ± 6%20.3ms ±10%~(p=0.710 n=7+7)
ParseDeploy/decode_hex-21.14ms ± 6%1.12ms ± 3%~(p=0.535 n=7+7)
ParseFungibleToken-2180µs ± 7%172µs ± 2%~(p=0.051 n=7+6)
ParseArray-212.3ms ±12%12.1ms ± 3%~(p=0.902 n=7+7)
QualifiedIdentifierCreation/Three_levels-2137ns ± 6%134ns ± 6%~(p=0.219 n=7+7)
ContractInterfaceFungibleToken-240.0µs ± 6%38.7µs ± 8%~(p=0.209 n=7+7)
CheckContractInterfaceFungibleTokenConformance-2130µs ± 6%127µs ± 7%~(p=0.383 n=7+7)
NewInterpreter/new_interpreter-21.05µs ± 2%1.04µs ± 4%~(p=0.731 n=6+7)
NewInterpreter/new_sub-interpreter-22.05µs ± 4%2.04µs ± 6%~(p=0.833 n=7+7)
InterpretRecursionFib-22.28ms ± 5%2.15ms ± 3%−5.83%(p=0.004 n=6+6)
 
alloc/opdelta
RuntimeFungibleTokenTransfer-2273kB ± 0%277kB ± 0%+1.34%(p=0.001 n=7+7)
RuntimeResourceDictionaryValues-24.05MB ± 0%4.05MB ± 0%+0.04%(p=0.001 n=7+7)
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%~(all equal)
NewInterpreter/new_interpreter-2768B ± 0%768B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-21.24kB ± 0%1.24kB ± 0%~(all equal)
InterpretRecursionFib-21.24MB ± 0%1.24MB ± 0%−0.00%(p=0.024 n=6+7)
ContractInterfaceFungibleToken-226.5kB ± 0%26.5kB ± 0%−0.00%(p=0.021 n=7+7)
 
allocs/opdelta
RuntimeFungibleTokenTransfer-24.55k ± 0%4.61k ± 0%+1.51%(p=0.001 n=7+6)
RuntimeResourceDictionaryValues-2102k ± 0%102k ± 0%+0.05%(p=0.001 n=7+6)
QualifiedIdentifierCreation/One_level-20.00 0.00 ~(all equal)
QualifiedIdentifierCreation/Three_levels-22.00 ± 0%2.00 ± 0%~(all equal)
ContractInterfaceFungibleToken-2457 ± 0%457 ± 0%~(all equal)
CheckContractInterfaceFungibleTokenConformance-21.07k ± 0%1.07k ± 0%~(all equal)
InterpretRecursionFib-225.0k ± 0%25.0k ± 0%~(all equal)
NewInterpreter/new_interpreter-212.0 ± 0%12.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-238.0 ± 0%38.0 ± 0%~(all equal)
 

@SupunS SupunS added the Language Breaking Change Breaks Cadence contracts deployed on Mainnet label Jan 15, 2022
@SupunS SupunS marked this pull request as ready for review January 25, 2022 16:38
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/tests/checker/operations_test.go Show resolved Hide resolved
runtime/sema/type.go Outdated Show resolved Hide resolved
@turbolent
Copy link
Member

Took the liberty to quickly fix the PR

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.

Looks good! Nice work 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Language Breaking Change Breaks Cadence contracts deployed on Mainnet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants