Invalidate resource references when the referenced resource is moved
Description
This is the draft implementation of the FLIP: https://github.com/onflow/flow/pull/1043
Adds a run-time check to invalidate references, if the pointed resource is being moved.
Note: This PR doesn't invalidate the references upon stack-to-stack moves. Adding that is subjected to the final verdict on the proposed FLIP.
- [ ] Targeted PR against
masterbranch - [x] Linked to Github issue with discussion and accepted design OR link to spec that describes this work
- [x] Code follows the standards mentioned here
- [x] Updated relevant documentation
- [x] Re-reviewed
Files changedin the Github PR explorer - [x] Added appropriate labels
Codecov Report
Merging #1999 (6bfa821) into feature/stable-cadence (0e3bc7b) will increase coverage by
0.03%. The diff coverage is86.36%.
:exclamation: Current head 6bfa821 differs from pull request most recent head cb06d74. Consider uploading reports for the commit cb06d74 to get more accurate results
@@ Coverage Diff @@
## feature/stable-cadence #1999 +/- ##
==========================================================
+ Coverage 77.89% 77.93% +0.03%
==========================================================
Files 304 304
Lines 63759 63757 -2
==========================================================
+ Hits 49667 49689 +22
+ Misses 12347 12323 -24
Partials 1745 1745
| Flag | Coverage Δ | |
|---|---|---|
| unittests | 77.93% <86.36%> (+0.03%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Impacted Files | Coverage Δ | |
|---|---|---|
| runtime/interpreter/value.go | 70.50% <79.31%> (+0.05%) |
:arrow_up: |
| runtime/interpreter/errors.go | 57.20% <100.00%> (+1.25%) |
:arrow_up: |
| runtime/interpreter/interpreter.go | 89.01% <100.00%> (+0.04%) |
:arrow_up: |
| runtime/interpreter/storage.go | 69.04% <0.00%> (-1.59%) |
:arrow_down: |
| runtime/interpreter/statictype.go | 82.03% <0.00%> (-0.65%) |
:arrow_down: |
| runtime/sema/checker.go | 92.33% <0.00%> (+0.01%) |
:arrow_up: |
| runtime/sema/check_conditional.go | 95.36% <0.00%> (+0.06%) |
:arrow_up: |
| runtime/sema/resources.go | 88.44% <0.00%> (+0.54%) |
:arrow_up: |
| ... and 2 more |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.
Cadence Benchstat comparison
This branch with compared with the base branch onflow:feature/stable-cadence commit b0c0e27409b809d97a89d4c2372b8ae8cf5d9768
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.txt | new.txt | |||
|---|---|---|---|---|
| time/op | delta | |||
| CheckContractInterfaceFungibleTokenConformance-2 | 123µs ± 3% | 119µs ± 1% | −2.54% | (p=0.015 n=6+6) |
| ContractInterfaceFungibleToken-2 | 42.1µs ± 3% | 41.2µs ± 1% | −2.22% | (p=0.011 n=7+7) |
| InterpretRecursionFib-2 | 2.55ms ± 2% | 2.51ms ± 1% | −1.65% | (p=0.011 n=7+7) |
| NewInterpreter/new_interpreter-2 | 1.17µs ± 1% | 1.16µs ± 3% | −0.87% | (p=0.045 n=7+6) |
| NewInterpreter/new_sub-interpreter-2 | 622ns ± 3% | 613ns ± 1% | ~ | (p=0.128 n=7+7) |
| ParseArray-2 | 8.33ms ± 3% | 8.12ms ± 1% | −2.42% | (p=0.014 n=7+6) |
| ParseDeploy/byte_array-2 | 12.6ms ± 2% | 12.3ms ± 2% | −2.59% | (p=0.011 n=7+7) |
| ParseDeploy/decode_hex-2 | 1.22ms ± 1% | 1.21ms ± 0% | −1.03% | (p=0.026 n=6+6) |
| ParseFungibleToken/With_memory_metering-2 | 194µs ± 1% | 192µs ± 3% | ~ | (p=0.181 n=6+7) |
| ParseFungibleToken/Without_memory_metering-2 | 154µs ± 2% | 151µs ± 1% | −2.11% | (p=0.004 n=7+7) |
| ParseInfix-2 | 7.26µs ± 1% | 7.10µs ± 0% | −2.23% | (p=0.002 n=6+6) |
| QualifiedIdentifierCreation/One_level-2 | 2.35ns ± 0% | 2.35ns ± 0% | ~ | (p=0.293 n=7+6) |
| QualifiedIdentifierCreation/Three_levels-2 | 139ns ± 2% | 139ns ± 3% | ~ | (p=0.279 n=6+7) |
| RuntimeFungibleTokenTransfer-2 | 685µs ±21% | 613µs ±27% | ~ | (p=0.165 n=7+7) |
| RuntimeResourceDictionaryValues-2 | 5.14ms ± 3% | 5.00ms ± 1% | −2.62% | (p=0.008 n=7+6) |
| RuntimeScriptNoop-2 | 15.2µs ± 2% | 18.3µs ±32% | ~ | (p=0.945 n=6+7) |
| ValueIsSubtypeOfSemaType-2 | 90.1ns ± 2% | 91.9ns ± 3% | ~ | (p=0.128 n=7+7) |
| alloc/op | delta | |||
| CheckContractInterfaceFungibleTokenConformance-2 | 51.6kB ± 0% | 51.6kB ± 0% | ~ | (all equal) |
| ContractInterfaceFungibleToken-2 | 24.9kB ± 0% | 24.9kB ± 0% | ~ | (all equal) |
| InterpretRecursionFib-2 | 1.00MB ± 0% | 1.00MB ± 0% | ~ | (all equal) |
| NewInterpreter/new_interpreter-2 | 800B ± 0% | 800B ± 0% | ~ | (all equal) |
| NewInterpreter/new_sub-interpreter-2 | 216B ± 0% | 216B ± 0% | ~ | (all equal) |
| ParseArray-2 | 2.75MB ± 3% | 2.71MB ± 2% | ~ | (p=0.456 n=7+7) |
| ParseDeploy/byte_array-2 | 4.21MB ± 3% | 4.18MB ± 3% | ~ | (p=0.383 n=7+7) |
| ParseDeploy/decode_hex-2 | 214kB ± 0% | 214kB ± 0% | ~ | (p=1.000 n=7+7) |
| ParseFungibleToken/With_memory_metering-2 | 29.8kB ± 0% | 29.8kB ± 0% | ~ | (p=0.470 n=7+7) |
| ParseFungibleToken/Without_memory_metering-2 | 29.8kB ± 0% | 29.8kB ± 0% | ~ | (p=0.805 n=7+7) |
| ParseInfix-2 | 1.93kB ± 0% | 1.93kB ± 0% | ~ | (p=0.848 n=6+7) |
| QualifiedIdentifierCreation/One_level-2 | 0.00B | 0.00B | ~ | (all equal) |
| QualifiedIdentifierCreation/Three_levels-2 | 64.0B ± 0% | 64.0B ± 0% | ~ | (all equal) |
| RuntimeFungibleTokenTransfer-2 | 103kB ± 1% | 103kB ± 1% | ~ | (p=0.301 n=7+7) |
| RuntimeResourceDictionaryValues-2 | 2.27MB ± 0% | 2.27MB ± 0% | ~ | (p=0.620 n=7+7) |
| RuntimeScriptNoop-2 | 8.83kB ± 1% | 8.85kB ± 1% | ~ | (p=0.710 n=7+7) |
| ValueIsSubtypeOfSemaType-2 | 48.0B ± 0% | 48.0B ± 0% | ~ | (all equal) |
| allocs/op | delta | |||
| CheckContractInterfaceFungibleTokenConformance-2 | 905 ± 0% | 905 ± 0% | ~ | (all equal) |
| ContractInterfaceFungibleToken-2 | 435 ± 0% | 435 ± 0% | ~ | (all equal) |
| InterpretRecursionFib-2 | 18.9k ± 0% | 18.9k ± 0% | ~ | (all equal) |
| NewInterpreter/new_interpreter-2 | 13.0 ± 0% | 13.0 ± 0% | ~ | (all equal) |
| NewInterpreter/new_sub-interpreter-2 | 4.00 ± 0% | 4.00 ± 0% | ~ | (all equal) |
| ParseArray-2 | 69.6k ± 0% | 69.6k ± 0% | ~ | (p=1.000 n=7+7) |
| ParseDeploy/byte_array-2 | 104k ± 0% | 104k ± 0% | ~ | (p=1.000 n=7+7) |
| ParseDeploy/decode_hex-2 | 75.0 ± 0% | 75.0 ± 0% | ~ | (all equal) |
| ParseFungibleToken/With_memory_metering-2 | 1.00k ± 0% | 1.00k ± 0% | ~ | (all equal) |
| ParseFungibleToken/Without_memory_metering-2 | 1.00k ± 0% | 1.00k ± 0% | ~ | (all equal) |
| ParseInfix-2 | 60.0 ± 0% | 60.0 ± 0% | ~ | (all equal) |
| QualifiedIdentifierCreation/One_level-2 | 0.00 | 0.00 | ~ | (all equal) |
| QualifiedIdentifierCreation/Three_levels-2 | 2.00 ± 0% | 2.00 ± 0% | ~ | (all equal) |
| RuntimeFungibleTokenTransfer-2 | 2.05k ± 0% | 2.05k ± 0% | ~ | (all equal) |
| RuntimeResourceDictionaryValues-2 | 36.9k ± 0% | 36.9k ± 0% | ~ | (p=0.237 n=7+7) |
| RuntimeScriptNoop-2 | 143 ± 0% | 143 ± 0% | ~ | (all equal) |
| ValueIsSubtypeOfSemaType-2 | 1.00 ± 0% | 1.00 ± 0% | ~ | (all equal) |