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

Allow the 'calldata' type in internal/private/public functions #5545

Closed
jochem-brouwer opened this issue Nov 29, 2018 · 2 comments · Fixed by #8942
Closed

Allow the 'calldata' type in internal/private/public functions #5545

jochem-brouwer opened this issue Nov 29, 2018 · 2 comments · Fixed by #8942

Comments

@jochem-brouwer
Copy link
Member

Abstract

If I have data which is read-only in calldata solidity will copy it to memory anyways when passing it to internal/private/public functions.

Motivation

If read-only calldata is copied for memory for no reason (it should only be copied to memory if it is edited - if it is read-only calldata it should never be copied) this wastes gas. If this happens, it should only be read from calldata and not waste gas on copying to memory.

Specification

The public/internal/private function types should allow data (such as bytes or string) to be passed as calldata type. If this data is ever edited in the code, then the compiler should throw since this cannot be compiled: if it is explicitly passed as calldata this data is then read-only. If the user wishes to edit data, they should manually put it into a memory type of data.

Backwards Compatibility

This is incompatible with sol < 0.5 since calldata is not a valid keyword there.

@chriseth
Copy link
Contributor

Note that a prerequisite to this is fully implementing support for calldata types in the first place. For now, only one-dimensional arrays are supported.

@chriseth
Copy link
Contributor

For calldata variables we have a similar problem as with storage pointer variables: They cannot be properly auto-initialized and have to be assigned before they can be accessed.

Although it might be useful to auto-initialize them to calldatasize().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants