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

Support ink! messages and constructors that take references as parameters #989

Open
Robbepop opened this issue Oct 29, 2021 · 0 comments
Open
Labels
A-ink_lang [ink_lang] Work item

Comments

@Robbepop
Copy link
Collaborator

Currently ink! messages and constructors are required to be Sized and scale::Decode.
This means that ink! messages and constructors that take simple references are not allowed, e.g.:

#[ink(message)]
fn transfer(&mut self, from: &AccountId, to: &AccountId, amount: &Balance) -> bool;

This is a downside with respect to Wasm file sizes since in Wasm references are 32-bit sizes while types such as Balance and AccountId have massive sizes that force Wasm to costly put them on the shadow stack. This produces badly performing Wasm code as well as bloats the resulting Wasm binary.

In order to counteract this slightly users currently can add private methods that take their arguments by references where the ink! messages and constructors immediately forward to. This has the downside of mostly repeating the APIs over and over again in those common cases.

For ink! we should do better and allow ink! messages and constructors to take their arguments as references.
This could work by making ink! aware of input reference parameters and adjust ink! codegen in a way that the ink! message and constructor decoders forward their arguments in ExecuteMessage and ExecuteConstructor by reference using the ref Rust keyword.

This requires to adjust the ink_lang_ir and ink_lang_codegen crates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ink_lang [ink_lang] Work item
Projects
None yet
Development

No branches or pull requests

1 participant