Skip to content

Compiler attribute to guarantee that types are trivially encodable/decodable #7567

@xunilrj

Description

@xunilrj

Contract functions can gain a lot of performance if their inputs are trivially decodable, but today there is no easy way for a developer to check if a type is "trivially decodable" or not. And there is not way to fail compilation if a type is not, possibly causing silent regressions.

This issue is a suggestion for create an attribute that would force the compiler guarantee this:

#[trivial_decode]
struct ComplexType {
    ...
}

The idea is to make the compilation fail, if ComplexType is not trivially decodable.
For completeness we would have both attributes:

1 - trivial_decode;
2 - trivial_encode;

Another improvement would be to have performance hints analysing ABIs and suggesting that types should be trivial encodable and decodables. To turn these off, we would need:

#[allow(not(trivial_decode))]

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions