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

Explicit nested struct serialization options #1050

Open
Gusarich opened this issue Nov 17, 2024 · 1 comment
Open

Explicit nested struct serialization options #1050

Gusarich opened this issue Nov 17, 2024 · 1 comment
Labels
feature: structs Structures and messages (struct Foo, message Foo) kind: discussion Ideas that are not fully formed and require discussion kind: language feature Intent to add a language feature
Milestone

Comments

@Gusarich
Copy link
Member

Currently, the compiler automatically determines whether to serialize a nested struct inlined in the same cell or as a reference, based on whether it fits. This proposal introduces a way for developers to explicitly specify the desired serialization mode.

For example:

struct B {
    c: Int;
    d: Int;
}

struct A {
    a: Int;
    b: Int;
    c: B as inline;  // Always inline
    d: B as ref;     // Always reference
}

With this feature:

  • c will always be serialized in the same cell as A, while
  • d will always be serialized as a reference, regardless of their sizes.

If the specified serialization mode is not feasible (e.g., a large struct is forced as inline but cannot fit in the cell), the compiler will throw a compilation error.

@Gusarich Gusarich added kind: discussion Ideas that are not fully formed and require discussion kind: language feature Intent to add a language feature labels Nov 17, 2024
@Gusarich Gusarich changed the title Explicit nested struct serialization Explicit nested struct serialization options Nov 17, 2024
@anton-trunov anton-trunov added the feature: structs Structures and messages (struct Foo, message Foo) label Jan 3, 2025
@anton-trunov
Copy link
Member

Some people found a workaround for our missing references to structs (Foo as ref), for instance https://github.com/makhanovable/contest_bridge uses the following pattern:

message(0x11a78ffe) NewKeyBlock {
    queryId: Int as uint64;
    block: Cell;
    signatures: Cell;
}
// ...
receive(message: NewKeyBlock) {
// ...
        let candidate = MasterChainBlock.fromCell(message.block);       // <--- HERE
        let blockSignatures = BlockSignatures.fromCell(message.signatures);
// ...
}

Thus making the block and signatures fields references, as if the NewKeyBlock message was defined like so:

message(0x11a78ffe) NewKeyBlock {
    queryId: Int as uint64;
    block: ^MasterChainBlock;
    signatures: ^BlockSignatures;
}

@anton-trunov anton-trunov added this to the v1.7.0 milestone Feb 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: structs Structures and messages (struct Foo, message Foo) kind: discussion Ideas that are not fully formed and require discussion kind: language feature Intent to add a language feature
Projects
None yet
Development

No branches or pull requests

2 participants