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

Add equal method for cadence external types #2203

Merged
merged 1 commit into from
Jan 3, 2023
Merged

Conversation

SupunS
Copy link
Member

@SupunS SupunS commented Dec 21, 2022

Closes #2199

Description

Adds Type.Equal(Type) bool method for cadence external types, since Type.ID() cannot be used to compare some types (e.g: restricted types). This newly added Equal() method compares go structs recursively and hence doesn't do allocations (except for the restricted types).


  • 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

Comment on lines -2691 to -2696
// constructors

if t.IsConstructor != otherFunction.IsConstructor {
return false
}

Copy link
Member Author

Choose a reason for hiding this comment

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

A code cleanup; This check is already done above

@codecov
Copy link

codecov bot commented Dec 21, 2022

Codecov Report

Merging #2203 (3a9ece4) into master (cb7611b) will increase coverage by 0.09%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2203      +/-   ##
==========================================
+ Coverage   77.58%   77.68%   +0.09%     
==========================================
  Files         309      309              
  Lines       65409    65663     +254     
==========================================
+ Hits        50750    51011     +261     
+ Misses      12880    12874       -6     
+ Partials     1779     1778       -1     
Flag Coverage Δ
unittests 77.68% <100.00%> (+0.09%) ⬆️

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

Impacted Files Coverage Δ
runtime/sema/type.go 89.92% <ø> (+0.07%) ⬆️
types.go 92.84% <100.00%> (+2.61%) ⬆️
runtime/sema/errors.go 92.90% <0.00%> (+0.44%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@SupunS SupunS force-pushed the supun/type-equal branch 2 times, most recently from ab90cd0 to 6feb7b9 Compare December 21, 2022 20:03
@github-actions
Copy link

github-actions bot commented Dec 21, 2022

Cadence Benchstat comparison

This branch with compared with the base branch onflow:master commit ed1c493
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-2108µs ± 0%108µs ± 1%+0.48%(p=0.007 n=7+7)
ContractInterfaceFungibleToken-237.2µs ± 1%37.3µs ± 0%~(p=0.128 n=7+7)
InterpretRecursionFib-22.48ms ± 0%2.50ms ± 2%~(p=0.394 n=6+6)
NewInterpreter/new_interpreter-21.08µs ± 1%1.08µs ± 1%~(p=0.552 n=6+7)
NewInterpreter/new_sub-interpreter-2585ns ± 7%573ns ± 0%~(p=0.915 n=7+6)
ParseArray-27.66ms ± 3%7.76ms ± 6%~(p=1.000 n=7+7)
ParseDeploy/byte_array-211.5ms ± 1%11.5ms ± 2%~(p=0.945 n=6+7)
ParseDeploy/decode_hex-21.20ms ± 0%1.20ms ± 1%~(p=0.234 n=6+7)
ParseFungibleToken/With_memory_metering-2183µs ± 1%182µs ± 1%~(p=0.394 n=6+6)
ParseFungibleToken/Without_memory_metering-2145µs ± 4%142µs ± 1%~(p=0.535 n=7+7)
ParseInfix-27.07µs ± 1%7.08µs ± 0%~(p=0.927 n=7+7)
QualifiedIdentifierCreation/One_level-22.43ns ± 2%2.46ns ± 8%~(p=0.968 n=6+6)
QualifiedIdentifierCreation/Three_levels-2117ns ± 0%118ns ± 2%+1.03%(p=0.013 n=7+7)
RuntimeFungibleTokenTransfer-2437µs ± 2%490µs ±34%~(p=0.181 n=6+7)
RuntimeResourceDictionaryValues-25.12ms ± 1%5.10ms ± 0%~(p=0.731 n=7+6)
RuntimeScriptNoop-216.0µs ±28%13.1µs ± 0%~(p=0.599 n=7+6)
SuperTypeInference/arrays-2286ns ± 1%287ns ± 0%~(p=0.225 n=6+6)
SuperTypeInference/composites-2132ns ± 0%129ns ± 0%−2.26%(p=0.002 n=6+6)
SuperTypeInference/integers-294.7ns ± 0%92.1ns ± 0%−2.67%(p=0.001 n=7+6)
ValueIsSubtypeOfSemaType-286.0ns ± 1%86.7ns ± 3%~(p=0.302 n=7+7)
 
alloc/opdelta
CheckContractInterfaceFungibleTokenConformance-248.6kB ± 0%48.6kB ± 0%~(p=0.592 n=7+7)
ContractInterfaceFungibleToken-222.8kB ± 0%22.8kB ± 0%~(all equal)
InterpretRecursionFib-21.00MB ± 0%1.00MB ± 0%~(all equal)
NewInterpreter/new_interpreter-2768B ± 0%768B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-2200B ± 0%200B ± 0%~(all equal)
ParseArray-22.74MB ± 4%2.73MB ± 3%~(p=0.710 n=7+7)
ParseDeploy/byte_array-24.26MB ± 0%4.21MB ± 3%~(p=0.628 n=6+7)
ParseDeploy/decode_hex-2214kB ± 0%214kB ± 0%~(p=0.142 n=6+7)
ParseFungibleToken/With_memory_metering-229.2kB ± 0%29.2kB ± 0%~(p=1.000 n=7+7)
ParseFungibleToken/Without_memory_metering-229.2kB ± 0%29.2kB ± 0%~(p=0.755 n=7+7)
ParseInfix-21.92kB ± 0%1.92kB ± 0%~(p=0.723 n=7+7)
QualifiedIdentifierCreation/One_level-20.00B 0.00B ~(all equal)
QualifiedIdentifierCreation/Three_levels-264.0B ± 0%64.0B ± 0%~(all equal)
RuntimeFungibleTokenTransfer-2101kB ± 0%101kB ± 1%~(p=0.836 n=6+7)
RuntimeResourceDictionaryValues-22.28MB ± 0%2.28MB ± 0%~(p=0.128 n=7+7)
RuntimeScriptNoop-26.76kB ± 0%6.76kB ± 0%~(p=0.876 n=7+7)
SuperTypeInference/arrays-296.0B ± 0%96.0B ± 0%~(all equal)
SuperTypeInference/composites-20.00B 0.00B ~(all equal)
SuperTypeInference/integers-20.00B 0.00B ~(all equal)
ValueIsSubtypeOfSemaType-248.0B ± 0%48.0B ± 0%~(all equal)
 
allocs/opdelta
CheckContractInterfaceFungibleTokenConformance-2794 ± 0%794 ± 0%~(all equal)
ContractInterfaceFungibleToken-2363 ± 0%363 ± 0%~(all equal)
InterpretRecursionFib-218.9k ± 0%18.9k ± 0%~(all equal)
NewInterpreter/new_interpreter-213.0 ± 0%13.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-24.00 ± 0%4.00 ± 0%~(all equal)
ParseArray-259.6k ± 0%59.6k ± 0%~(p=1.000 n=7+6)
ParseDeploy/byte_array-289.4k ± 0%89.4k ± 0%~(p=1.000 n=7+7)
ParseDeploy/decode_hex-264.0 ± 0%64.0 ± 0%~(all equal)
ParseFungibleToken/With_memory_metering-2779 ± 0%779 ± 0%~(all equal)
ParseFungibleToken/Without_memory_metering-2779 ± 0%779 ± 0%~(all equal)
ParseInfix-248.0 ± 0%48.0 ± 0%~(all equal)
QualifiedIdentifierCreation/One_level-20.00 0.00 ~(all equal)
QualifiedIdentifierCreation/Three_levels-22.00 ± 0%2.00 ± 0%~(all equal)
RuntimeFungibleTokenTransfer-21.96k ± 0%1.96k ± 0%~(p=0.385 n=6+7)
RuntimeResourceDictionaryValues-236.9k ± 0%36.9k ± 0%~(p=0.854 n=6+7)
RuntimeScriptNoop-298.0 ± 0%98.0 ± 0%~(all equal)
SuperTypeInference/arrays-23.00 ± 0%3.00 ± 0%~(all equal)
SuperTypeInference/composites-20.00 0.00 ~(all equal)
SuperTypeInference/integers-20.00 0.00 ~(all equal)
ValueIsSubtypeOfSemaType-21.00 ± 0%1.00 ± 0%~(all equal)
 

@SupunS SupunS self-assigned this Dec 21, 2022
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 so far 👍

@SupunS
Copy link
Member Author

SupunS commented Jan 3, 2023

Oh, this should be ready to review. Work here is done, kept it as a draft until the CI passes, and then forgot to change the state.

@SupunS SupunS marked this pull request as ready for review January 3, 2023 17:35
@SupunS SupunS requested a review from dsainati1 as a code owner January 3, 2023 17:35
@SupunS SupunS requested a review from turbolent January 3, 2023 17:35
@SupunS SupunS merged commit 79b7013 into master Jan 3, 2023
@SupunS SupunS deleted the supun/type-equal branch January 3, 2023 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Type.Equal(Type) bool function to compare Cadence types efficiently
3 participants