openmina / mina-p2p-messages-rs

0 stars 0 forks source link

Exclude unneeded parameterized types from generation #19

Closed akoptelov closed 1 year ago

akoptelov commented 1 year ago

Currently generated types closely follow OCaml structure, i.e. there's a separate type definition for polymorphic types and there's one for each type to be able to encode version. That makes much harder to understand data structure.

Ideally there should be a type in Rust corresponding only to non-polymorphic types, and Versioned definitions only for limited number of types (like top-level types).

akoptelov commented 1 year ago

For example, consider the following definition. Note also that each of MinaBasePendingCoinbaseMerkleTreeVersionedStableV2 and MinaBasePendingCoinbaseStackIdStableV1 has similar indirection.

pub struct MinaBasePendingCoinbaseStableV2(
    pub  MinaBasePendingCoinbaseStableV2Poly<
        MinaBasePendingCoinbaseMerkleTreeVersionedStableV2,
        MinaBasePendingCoinbaseStackIdStableV1,
    >,
);

pub struct MinaBasePendingCoinbaseStableV2Poly<Tree, StackId> {
    pub tree: Tree,
    pub pos_list: Vec<StackId>,
    pub new_pos: StackId,
}

This should be more succinct and comprehensible:

pub struct MinaBasePendingCoinbaseStableV2 {
    pub tree: MinaBasePendingCoinbaseMerkleTreeVersionedStableV2,
    pub pos_list: Vec<MinaBasePendingCoinbaseStackIdStableV1>,
    pub new_pos: MinaBasePendingCoinbaseStackIdStableV1,
}
akoptelov commented 1 year ago

An update on this task.

These are the main issues I'm struggling with: