anza-xyz / move

Move compiler targeting llvm supported backends
https://discord.gg/wFgfjG9J
Apache License 2.0
108 stars 33 forks source link

Fix translation of generic structs instantiated with nested struct type parameters #316

Closed dmakarov closed 1 year ago

dmakarov commented 1 year ago

Motivation

Instantiations of structs like

    struct Box<T> has copy, drop, store { x: T }
    struct Box3<T> has copy, drop, store { x: Box<Box<T>> }
    struct Box7<T> has copy, drop, store { x: Box3<Box3<T>> }
    struct Box15<T> has copy, drop, store { x: Box7<Box7<T>> }
    struct Box31<T> has copy, drop, store { x: Box15<Box15<T>> }
    struct Box63<T> has copy, drop, store { x: Box31<Box31<T>> }
    struct Box127<T> has copy, drop, store { x: Box63<Box63<T>> }

were not handled correctly. This requires recursive processing of struct instantiations down to the struct that doesn't depend on struct type parameters, and also up again to declare properly all structs in a chain of instantiations. Some instantiations are not found until functions declarations are being generated. This PR changes handling of type parameterized structs to be continued also after function declarations have started being generated by the translator.

Resolves #312

ksolana commented 1 year ago

LGTM. It'll be great if @brson or @nvjle reviewed it as well.

dmakarov commented 1 year ago

Thank you, Brian. I agree, to_llvm_type doesn’t look good. I’ll think about revising this. For now merging, to move forward with move test and will follow up later. Jason, please comment too. I’ll rework this in later PRs.