onflow / cadence

Cadence, the resource-oriented smart contract programming language 🏃‍♂️
https://developers.flow.com/cadence
Apache License 2.0
526 stars 136 forks source link

[v0.42] Simplify nil-coalescing checking #3422

Closed SupunS closed 2 weeks ago

SupunS commented 2 weeks ago

Closes https://github.com/dapperlabs/cadence-internal/issues/237

Port of https://github.com/dapperlabs/cadence-internal/pull/239

Description

The expression type of a nil-coalescing expression (T?) ?? R should be the super type of (T, R).


github-actions[bot] commented 2 weeks ago

Cadence Benchstat comparison

This branch with compared with the base branch onflow:v0.42 commit 3d85ceab77f883da2e0e9660a7fdb07fad19264f 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.txtnew.txt
time/opdelta
CheckContractInterfaceFungibleTokenConformance-481.9µs ± 0%82.3µs ± 0%~(p=1.000 n=1+1)
ContractInterfaceFungibleToken-427.6µs ± 0%27.8µs ± 0%~(p=1.000 n=1+1)
DecodeBatchEventsCCF-4118ms ± 0%118ms ± 0%~(p=1.000 n=1+1)
DecodeBatchEventsJSON-4401ms ± 0%407ms ± 0%~(p=1.000 n=1+1)
DecodeCCF/FlowFees.FeesDeducted-42.46µs ± 0%2.45µs ± 0%~(p=1.000 n=1+1)
DecodeCCF/FlowFees.TokensWithdrawn-41.99µs ± 0%2.01µs ± 0%~(p=1.000 n=1+1)
DecodeCCF/FlowIDTableStaking.DelegatorRewardsPaid-42.56µs ± 0%2.59µs ± 0%~(p=1.000 n=1+1)
DecodeCCF/FlowIDTableStaking.EpochTotalRewardsPaid-42.66µs ± 0%2.65µs ± 0%~(p=1.000 n=1+1)
DecodeCCF/FlowIDTableStaking.NewWeeklyPayout-42.01µs ± 0%2.01µs ± 0%~(all equal)
DecodeCCF/FlowIDTableStaking.RewardsPaid-42.35µs ± 0%2.33µs ± 0%~(p=1.000 n=1+1)
DecodeCCF/FlowToken.TokensDeposited-42.38µs ± 0%2.35µs ± 0%~(p=1.000 n=1+1)
DecodeCCF/FlowToken.TokensDeposited_with_nil_receiver-42.34µs ± 0%2.29µs ± 0%~(p=1.000 n=1+1)
DecodeCCF/FlowToken.TokensMinted-41.99µs ± 0%1.98µs ± 0%~(p=1.000 n=1+1)
DecodeCCF/FlowToken.TokensWithdrawn-42.40µs ± 0%2.38µs ± 0%~(p=1.000 n=1+1)
DecodeJSON/FlowFees.FeesDeducted-431.6µs ± 0%10.0µs ± 0%~(p=1.000 n=1+1)
DecodeJSON/FlowFees.TokensWithdrawn-45.76µs ± 0%5.73µs ± 0%~(p=1.000 n=1+1)
DecodeJSON/FlowIDTableStaking.DelegatorRewardsPaid-49.71µs ± 0%9.06µs ± 0%~(p=1.000 n=1+1)
DecodeJSON/FlowIDTableStaking.EpochTotalRewardsPaid-412.3µs ± 0%13.1µs ± 0%~(p=1.000 n=1+1)
DecodeJSON/FlowIDTableStaking.NewWeeklyPayout-45.90µs ± 0%5.90µs ± 0%~(p=1.000 n=1+1)
DecodeJSON/FlowIDTableStaking.RewardsPaid-47.67µs ± 0%7.62µs ± 0%~(p=1.000 n=1+1)
DecodeJSON/FlowToken.TokensDeposited-47.93µs ± 0%8.07µs ± 0%~(p=1.000 n=1+1)
DecodeJSON/FlowToken.TokensDeposited_with_nil_receiver-47.21µs ± 0%7.23µs ± 0%~(p=1.000 n=1+1)
DecodeJSON/FlowToken.TokensMinted-45.81µs ± 0%5.80µs ± 0%~(p=1.000 n=1+1)
DecodeJSON/FlowToken.TokensWithdrawn-47.94µs ± 0%7.97µs ± 0%~(p=1.000 n=1+1)
EncodeBatchEventsCCF-460.0ms ± 0%60.1ms ± 0%~(p=1.000 n=1+1)
EncodeBatchEventsJSON-497.3ms ± 0%99.0ms ± 0%~(p=1.000 n=1+1)
EncodeCCF/FlowFees.FeesDeducted-41.29µs ± 0%1.24µs ± 0%~(p=1.000 n=1+1)
EncodeCCF/FlowFees.TokensWithdrawn-41.01µs ± 0%1.00µs ± 0%~(p=1.000 n=1+1)
EncodeCCF/FlowIDTableStaking.DelegatorRewardsPaid-41.25µs ± 0%1.23µs ± 0%~(p=1.000 n=1+1)
EncodeCCF/FlowIDTableStaking.EpochTotalRewardsPaid-41.37µs ± 0%1.35µs ± 0%~(p=1.000 n=1+1)
EncodeCCF/FlowIDTableStaking.NewWeeklyPayout-41.03µs ± 0%1.02µs ± 0%~(p=1.000 n=1+1)
EncodeCCF/FlowIDTableStaking.RewardsPaid-41.14µs ± 0%1.15µs ± 0%~(p=1.000 n=1+1)
EncodeCCF/FlowToken.TokensDeposited-41.23µs ± 0%1.24µs ± 0%~(p=1.000 n=1+1)
EncodeCCF/FlowToken.TokensDeposited_with_nil_receiver-41.21µs ± 0%1.20µs ± 0%~(p=1.000 n=1+1)
EncodeCCF/FlowToken.TokensMinted-41.02µs ± 0%1.02µs ± 0%~(p=1.000 n=1+1)
EncodeCCF/FlowToken.TokensWithdrawn-41.24µs ± 0%1.24µs ± 0%~(p=1.000 n=1+1)
EncodeJSON/FlowFees.FeesDeducted-42.34µs ± 0%2.40µs ± 0%~(p=1.000 n=1+1)
EncodeJSON/FlowFees.TokensWithdrawn-41.31µs ± 0%1.33µs ± 0%~(p=1.000 n=1+1)
EncodeJSON/FlowIDTableStaking.DelegatorRewardsPaid-42.08µs ± 0%2.10µs ± 0%~(p=1.000 n=1+1)
EncodeJSON/FlowIDTableStaking.EpochTotalRewardsPaid-42.91µs ± 0%2.93µs ± 0%~(p=1.000 n=1+1)
EncodeJSON/FlowIDTableStaking.NewWeeklyPayout-41.32µs ± 0%1.35µs ± 0%~(p=1.000 n=1+1)
EncodeJSON/FlowIDTableStaking.RewardsPaid-41.74µs ± 0%1.77µs ± 0%~(p=1.000 n=1+1)
EncodeJSON/FlowToken.TokensDeposited-41.99µs ± 0%2.01µs ± 0%~(p=1.000 n=1+1)
EncodeJSON/FlowToken.TokensDeposited_with_nil_receiver-41.55µs ± 0%1.57µs ± 0%~(p=1.000 n=1+1)
EncodeJSON/FlowToken.TokensMinted-41.30µs ± 0%1.32µs ± 0%~(p=1.000 n=1+1)
EncodeJSON/FlowToken.TokensWithdrawn-41.98µs ± 0%1.99µs ± 0%~(p=1.000 n=1+1)
ExportType/composite_type-4219ns ± 0%216ns ± 0%~(p=1.000 n=1+1)
ExportType/simple_type-465.6ns ± 0%65.7ns ± 0%~(p=1.000 n=1+1)
InterpretRecursionFib-41.87ms ± 0%1.86ms ± 0%~(p=1.000 n=1+1)
NewInterpreter/new_interpreter-4942ns ± 0%1018ns ± 0%~(p=1.000 n=1+1)
NewInterpreter/new_sub-interpreter-4497ns ± 0%456ns ± 0%~(p=1.000 n=1+1)
ParseArray-46.09ms ± 0%6.09ms ± 0%~(p=1.000 n=1+1)
ParseDeploy/byte_array-49.16ms ± 0%8.96ms ± 0%~(p=1.000 n=1+1)
ParseDeploy/decode_hex-41.02ms ± 0%1.03ms ± 0%~(p=1.000 n=1+1)
ParseFungibleToken/With_memory_metering-4149µs ± 0%151µs ± 0%~(p=1.000 n=1+1)
ParseFungibleToken/Without_memory_metering-4113µs ± 0%115µs ± 0%~(p=1.000 n=1+1)
ParseInfix-45.33µs ± 0%5.38µs ± 0%~(p=1.000 n=1+1)
QualifiedIdentifierCreation/One_level-42.17ns ± 0%2.48ns ± 0%~(p=1.000 n=1+1)
QualifiedIdentifierCreation/Three_levels-483.6ns ± 0%83.5ns ± 0%~(p=1.000 n=1+1)
RuntimeResourceDictionaryValues-44.04ms ± 0%4.11ms ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-43.71µs ± 0%3.63µs ± 0%~(p=1.000 n=1+1)
SuperTypeInference/arrays-4240ns ± 0%233ns ± 0%~(p=1.000 n=1+1)
SuperTypeInference/composites-488.3ns ± 0%87.5ns ± 0%~(p=1.000 n=1+1)
SuperTypeInference/integers-4131ns ± 0%132ns ± 0%~(p=1.000 n=1+1)
ValueIsSubtypeOfSemaType-466.7ns ± 0%73.9ns ± 0%~(p=1.000 n=1+1)
 
alloc/opdelta
CheckContractInterfaceFungibleTokenConformance-449.2kB ± 0%49.2kB ± 0%~(all equal)
ContractInterfaceFungibleToken-423.4kB ± 0%23.4kB ± 0%~(all equal)
DecodeBatchEventsCCF-467.4MB ± 0%67.4MB ± 0%~(p=1.000 n=1+1)
DecodeBatchEventsJSON-4246MB ± 0%246MB ± 0%~(p=1.000 n=1+1)
DecodeCCF/FlowFees.FeesDeducted-41.41kB ± 0%1.41kB ± 0%~(all equal)
DecodeCCF/FlowFees.TokensWithdrawn-41.22kB ± 0%1.22kB ± 0%~(all equal)
DecodeCCF/FlowIDTableStaking.DelegatorRewardsPaid-41.49kB ± 0%1.49kB ± 0%~(all equal)
DecodeCCF/FlowIDTableStaking.EpochTotalRewardsPaid-41.50kB ± 0%1.50kB ± 0%~(all equal)
DecodeCCF/FlowIDTableStaking.NewWeeklyPayout-41.26kB ± 0%1.26kB ± 0%~(all equal)
DecodeCCF/FlowIDTableStaking.RewardsPaid-41.38kB ± 0%1.38kB ± 0%~(all equal)
DecodeCCF/FlowToken.TokensDeposited-41.34kB ± 0%1.34kB ± 0%~(all equal)
DecodeCCF/FlowToken.TokensDeposited_with_nil_receiver-41.33kB ± 0%1.33kB ± 0%~(all equal)
DecodeCCF/FlowToken.TokensMinted-41.22kB ± 0%1.22kB ± 0%~(all equal)
DecodeCCF/FlowToken.TokensWithdrawn-41.35kB ± 0%1.35kB ± 0%~(all equal)
DecodeJSON/FlowFees.FeesDeducted-46.02kB ± 0%6.02kB ± 0%~(all equal)
DecodeJSON/FlowFees.TokensWithdrawn-43.62kB ± 0%3.62kB ± 0%~(all equal)
DecodeJSON/FlowIDTableStaking.DelegatorRewardsPaid-45.45kB ± 0%5.45kB ± 0%~(all equal)
DecodeJSON/FlowIDTableStaking.EpochTotalRewardsPaid-47.37kB ± 0%7.37kB ± 0%~(all equal)
DecodeJSON/FlowIDTableStaking.NewWeeklyPayout-43.66kB ± 0%3.66kB ± 0%~(all equal)
DecodeJSON/FlowIDTableStaking.RewardsPaid-44.55kB ± 0%4.55kB ± 0%~(all equal)
DecodeJSON/FlowToken.TokensDeposited-44.91kB ± 0%4.91kB ± 0%~(all equal)
DecodeJSON/FlowToken.TokensDeposited_with_nil_receiver-44.49kB ± 0%4.49kB ± 0%~(all equal)
DecodeJSON/FlowToken.TokensMinted-43.62kB ± 0%3.62kB ± 0%~(all equal)
DecodeJSON/FlowToken.TokensWithdrawn-44.91kB ± 0%4.91kB ± 0%~(all equal)
EncodeBatchEventsCCF-437.1MB ± 0%37.1MB ± 0%~(p=1.000 n=1+1)
EncodeBatchEventsJSON-434.0MB ± 0%34.0MB ± 0%~(p=1.000 n=1+1)
EncodeCCF/FlowFees.FeesDeducted-4736B ± 0%736B ± 0%~(all equal)
EncodeCCF/FlowFees.TokensWithdrawn-4688B ± 0%688B ± 0%~(all equal)
EncodeCCF/FlowIDTableStaking.DelegatorRewardsPaid-4800B ± 0%800B ± 0%~(all equal)
EncodeCCF/FlowIDTableStaking.EpochTotalRewardsPaid-4768B ± 0%768B ± 0%~(all equal)
EncodeCCF/FlowIDTableStaking.NewWeeklyPayout-4704B ± 0%704B ± 0%~(all equal)
EncodeCCF/FlowIDTableStaking.RewardsPaid-4784B ± 0%784B ± 0%~(all equal)
EncodeCCF/FlowToken.TokensDeposited-4752B ± 0%752B ± 0%~(all equal)
EncodeCCF/FlowToken.TokensDeposited_with_nil_receiver-4736B ± 0%736B ± 0%~(all equal)
EncodeCCF/FlowToken.TokensMinted-4688B ± 0%688B ± 0%~(all equal)
EncodeCCF/FlowToken.TokensWithdrawn-4752B ± 0%752B ± 0%~(all equal)
EncodeJSON/FlowFees.FeesDeducted-4768B ± 0%768B ± 0%~(all equal)
EncodeJSON/FlowFees.TokensWithdrawn-4408B ± 0%408B ± 0%~(all equal)
EncodeJSON/FlowIDTableStaking.DelegatorRewardsPaid-4760B ± 0%760B ± 0%~(all equal)
EncodeJSON/FlowIDTableStaking.EpochTotalRewardsPaid-4952B ± 0%952B ± 0%~(all equal)
EncodeJSON/FlowIDTableStaking.NewWeeklyPayout-4424B ± 0%424B ± 0%~(all equal)
EncodeJSON/FlowIDTableStaking.RewardsPaid-4624B ± 0%624B ± 0%~(all equal)
EncodeJSON/FlowToken.TokensDeposited-4680B ± 0%680B ± 0%~(all equal)
EncodeJSON/FlowToken.TokensDeposited_with_nil_receiver-4544B ± 0%544B ± 0%~(all equal)
EncodeJSON/FlowToken.TokensMinted-4416B ± 0%416B ± 0%~(all equal)
EncodeJSON/FlowToken.TokensWithdrawn-4672B ± 0%672B ± 0%~(all equal)
ExportType/composite_type-4136B ± 0%136B ± 0%~(all equal)
ExportType/simple_type-40.00B 0.00B ~(all equal)
InterpretRecursionFib-41.00MB ± 0%1.00MB ± 0%~(p=1.000 n=1+1)
NewInterpreter/new_interpreter-4976B ± 0%976B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-4200B ± 0%200B ± 0%~(all equal)
ParseArray-42.71MB ± 0%2.65MB ± 0%~(p=1.000 n=1+1)
ParseDeploy/byte_array-44.22MB ± 0%4.09MB ± 0%~(p=1.000 n=1+1)
ParseDeploy/decode_hex-4214kB ± 0%214kB ± 0%~(p=1.000 n=1+1)
ParseFungibleToken/With_memory_metering-428.9kB ± 0%28.9kB ± 0%~(p=1.000 n=1+1)
ParseFungibleToken/Without_memory_metering-428.9kB ± 0%28.9kB ± 0%~(p=1.000 n=1+1)
ParseInfix-41.92kB ± 0%1.92kB ± 0%~(p=1.000 n=1+1)
QualifiedIdentifierCreation/One_level-40.00B 0.00B ~(all equal)
QualifiedIdentifierCreation/Three_levels-464.0B ± 0%64.0B ± 0%~(all equal)
RuntimeResourceDictionaryValues-42.29MB ± 0%2.30MB ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-43.02kB ± 0%3.02kB ± 0%~(all equal)
SuperTypeInference/arrays-496.0B ± 0%96.0B ± 0%~(all equal)
SuperTypeInference/composites-40.00B 0.00B ~(all equal)
SuperTypeInference/integers-40.00B 0.00B ~(all equal)
ValueIsSubtypeOfSemaType-448.0B ± 0%48.0B ± 0%~(all equal)
 
allocs/opdelta
CheckContractInterfaceFungibleTokenConformance-4811 ± 0%811 ± 0%~(all equal)
ContractInterfaceFungibleToken-4370 ± 0%370 ± 0%~(all equal)
DecodeBatchEventsCCF-41.48M ± 0%1.48M ± 0%~(p=1.000 n=1+1)
DecodeBatchEventsJSON-44.70M ± 0%4.70M ± 0%~(p=1.000 n=1+1)
DecodeCCF/FlowFees.FeesDeducted-430.0 ± 0%30.0 ± 0%~(all equal)
DecodeCCF/FlowFees.TokensWithdrawn-426.0 ± 0%26.0 ± 0%~(all equal)
DecodeCCF/FlowIDTableStaking.DelegatorRewardsPaid-430.0 ± 0%30.0 ± 0%~(all equal)
DecodeCCF/FlowIDTableStaking.EpochTotalRewardsPaid-432.0 ± 0%32.0 ± 0%~(all equal)
DecodeCCF/FlowIDTableStaking.NewWeeklyPayout-426.0 ± 0%26.0 ± 0%~(all equal)
DecodeCCF/FlowIDTableStaking.RewardsPaid-429.0 ± 0%29.0 ± 0%~(all equal)
DecodeCCF/FlowToken.TokensDeposited-431.0 ± 0%31.0 ± 0%~(all equal)
DecodeCCF/FlowToken.TokensDeposited_with_nil_receiver-429.0 ± 0%29.0 ± 0%~(all equal)
DecodeCCF/FlowToken.TokensMinted-426.0 ± 0%26.0 ± 0%~(all equal)
DecodeCCF/FlowToken.TokensWithdrawn-431.0 ± 0%31.0 ± 0%~(all equal)
DecodeJSON/FlowFees.FeesDeducted-4126 ± 0%126 ± 0%~(all equal)
DecodeJSON/FlowFees.TokensWithdrawn-471.0 ± 0%71.0 ± 0%~(all equal)
DecodeJSON/FlowIDTableStaking.DelegatorRewardsPaid-4102 ± 0%102 ± 0%~(all equal)
DecodeJSON/FlowIDTableStaking.EpochTotalRewardsPaid-4159 ± 0%159 ± 0%~(all equal)
DecodeJSON/FlowIDTableStaking.NewWeeklyPayout-470.0 ± 0%70.0 ± 0%~(all equal)
DecodeJSON/FlowIDTableStaking.RewardsPaid-487.0 ± 0%87.0 ± 0%~(all equal)
DecodeJSON/FlowToken.TokensDeposited-495.0 ± 0%95.0 ± 0%~(all equal)
DecodeJSON/FlowToken.TokensDeposited_with_nil_receiver-486.0 ± 0%86.0 ± 0%~(all equal)
DecodeJSON/FlowToken.TokensMinted-471.0 ± 0%71.0 ± 0%~(all equal)
DecodeJSON/FlowToken.TokensWithdrawn-495.0 ± 0%95.0 ± 0%~(all equal)
EncodeBatchEventsCCF-4467k ± 0%467k ± 0%~(p=1.000 n=1+1)
EncodeBatchEventsJSON-4757k ± 0%757k ± 0%~(p=1.000 n=1+1)
EncodeCCF/FlowFees.FeesDeducted-49.00 ± 0%9.00 ± 0%~(all equal)
EncodeCCF/FlowFees.TokensWithdrawn-49.00 ± 0%9.00 ± 0%~(all equal)
EncodeCCF/FlowIDTableStaking.DelegatorRewardsPaid-49.00 ± 0%9.00 ± 0%~(all equal)
EncodeCCF/FlowIDTableStaking.EpochTotalRewardsPaid-49.00 ± 0%9.00 ± 0%~(all equal)
EncodeCCF/FlowIDTableStaking.NewWeeklyPayout-49.00 ± 0%9.00 ± 0%~(all equal)
EncodeCCF/FlowIDTableStaking.RewardsPaid-49.00 ± 0%9.00 ± 0%~(all equal)
EncodeCCF/FlowToken.TokensDeposited-410.0 ± 0%10.0 ± 0%~(all equal)
EncodeCCF/FlowToken.TokensDeposited_with_nil_receiver-410.0 ± 0%10.0 ± 0%~(all equal)
EncodeCCF/FlowToken.TokensMinted-49.00 ± 0%9.00 ± 0%~(all equal)
EncodeCCF/FlowToken.TokensWithdrawn-410.0 ± 0%10.0 ± 0%~(all equal)
EncodeJSON/FlowFees.FeesDeducted-417.0 ± 0%17.0 ± 0%~(all equal)
EncodeJSON/FlowFees.TokensWithdrawn-410.0 ± 0%10.0 ± 0%~(all equal)
EncodeJSON/FlowIDTableStaking.DelegatorRewardsPaid-414.0 ± 0%14.0 ± 0%~(all equal)
EncodeJSON/FlowIDTableStaking.EpochTotalRewardsPaid-423.0 ± 0%23.0 ± 0%~(all equal)
EncodeJSON/FlowIDTableStaking.NewWeeklyPayout-410.0 ± 0%10.0 ± 0%~(all equal)
EncodeJSON/FlowIDTableStaking.RewardsPaid-413.0 ± 0%13.0 ± 0%~(all equal)
EncodeJSON/FlowToken.TokensDeposited-417.0 ± 0%17.0 ± 0%~(all equal)
EncodeJSON/FlowToken.TokensDeposited_with_nil_receiver-412.0 ± 0%12.0 ± 0%~(all equal)
EncodeJSON/FlowToken.TokensMinted-411.0 ± 0%11.0 ± 0%~(all equal)
EncodeJSON/FlowToken.TokensWithdrawn-416.0 ± 0%16.0 ± 0%~(all equal)
ExportType/composite_type-43.00 ± 0%3.00 ± 0%~(all equal)
ExportType/simple_type-40.00 0.00 ~(all equal)
InterpretRecursionFib-418.9k ± 0%18.9k ± 0%~(all equal)
NewInterpreter/new_interpreter-416.0 ± 0%16.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-44.00 ± 0%4.00 ± 0%~(all equal)
ParseArray-459.6k ± 0%59.6k ± 0%~(p=1.000 n=1+1)
ParseDeploy/byte_array-489.4k ± 0%89.4k ± 0%~(p=1.000 n=1+1)
ParseDeploy/decode_hex-463.0 ± 0%63.0 ± 0%~(all equal)
ParseFungibleToken/With_memory_metering-4768 ± 0%768 ± 0%~(all equal)
ParseFungibleToken/Without_memory_metering-4768 ± 0%768 ± 0%~(all equal)
ParseInfix-448.0 ± 0%48.0 ± 0%~(all equal)
QualifiedIdentifierCreation/One_level-40.00 0.00 ~(all equal)
QualifiedIdentifierCreation/Three_levels-42.00 ± 0%2.00 ± 0%~(all equal)
RuntimeResourceDictionaryValues-437.0k ± 0%37.0k ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-450.0 ± 0%50.0 ± 0%~(all equal)
SuperTypeInference/arrays-43.00 ± 0%3.00 ± 0%~(all equal)
SuperTypeInference/composites-40.00 0.00 ~(all equal)
SuperTypeInference/integers-40.00 0.00 ~(all equal)
ValueIsSubtypeOfSemaType-41.00 ± 0%1.00 ± 0%~(all equal)