-
Notifications
You must be signed in to change notification settings - Fork 140
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 more purity annotations to built-in and standard library function types #2125
Conversation
@@ -145,8 +149,8 @@ func NewChecker( | |||
} | |||
|
|||
functionActivations := &FunctionActivations{} | |||
functionActivations.EnterFunction(&FunctionType{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can save an allocation for each new checker
sema.ByteArrayType, | ||
), | ||
}, | ||
sema.ToBigEndianBytesFunctionType, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use existing function type
@@ -3059,10 +3059,7 @@ var typeFunction = NewUnmeteredHostFunctionValue( | |||
staticType := ConvertSemaToStaticType(invocation.Interpreter, ty) | |||
return NewTypeValue(invocation.Interpreter, staticType) | |||
}, | |||
&sema.FunctionType{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to sema, define a function type like for all other run-time type constructors
@@ -661,8 +662,10 @@ func OptionalTypeMapFunctionType(typ Type) *FunctionType { | |||
TypeParameter: typeParameter, | |||
} | |||
|
|||
const functionPurity = FunctionPurityImpure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure the purities stay in sync
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating these.
One quick suggestion, AccountForEachFunctionType
is defined in publicaccount_type.go
and should be impure. It is in practice because that's the default, but since we are making the default explicit elsewhere in this PR it would be nice to update that function as well.
@dsainati1 Good point! Added in 46069fb |
Codecov Report
@@ Coverage Diff @@
## feature/stable-cadence #2125 +/- ##
=======================================================
Coverage 77.99% 77.99%
=======================================================
Files 306 306
Lines 64134 64138 +4
=======================================================
+ Hits 50021 50027 +6
+ Misses 12353 12352 -1
+ Partials 1760 1759 -1
Flags with carried forward coverage won't be shown. Click here to find out 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 comparisonThis branch with compared with the base branch onflow:feature/stable-cadence commit ce3978a Collapsed results for better readability
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@@ -193,6 +195,7 @@ Returns nil if no contract/contract interface with the given name exists in the | |||
` | |||
|
|||
var AuthAccountContractsTypeRemoveFunctionType = &FunctionType{ | |||
Purity: FunctionPurityImpure, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't have to be in this PR, but maybe we could replace the struct literals with a constructor to enforce the proper purity status
Work towards #2084
Description
Updating the NFT Storefront contracts identified that some more built-in and standard library functions are impure, but could be view: onflow/nft-storefront#74 (comment)
Add explicit purity annotations to more built-in and standard library function types, make functions view when possible.
master
branchFiles changed
in the Github PR explorer