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

Resolve recursive type issue #19

Open
i-norden opened this issue Jun 22, 2021 · 2 comments
Open

Resolve recursive type issue #19

i-norden opened this issue Jun 22, 2021 · 2 comments

Comments

@i-norden
Copy link
Collaborator

The current IPLD code gen creates recursive types (TrieNode) that won't compile.

This is also an issue for go-codec-dagcosmos (MerkleTreeNode,IAVLNode, and SMTNode are all recursive types).

@i-norden i-norden added this to To Do in Ethereum IPLD via automation Jun 22, 2021
@i-norden i-norden added this to To Do in Tendermint/Cosmos IPLD via automation Jun 22, 2021
@i-norden i-norden moved this from To Do to In Progress in Ethereum IPLD Jun 22, 2021
@i-norden i-norden moved this from To Do to In Progress in Tendermint/Cosmos IPLD Jun 22, 2021
@i-norden
Copy link
Collaborator Author

This was fixed for the types here manually to get things working and the tests passing, but we need to upstream a fix to the fundamental issue in go-ipld-prime. An issue to track that is opened at #20, it includes other code gen issues other than this recursive one.

@warpfork
Copy link

warpfork commented Jul 2, 2021

This is currently a poorly documented / alpha API issue, sorry about the discoverability --

If you've got a union in there somewhere, you can probably fix this with a bit of config which tells the codegen to use interfaces (which use pointers, and thus break the cycle problem), like this:

https://github.com/ipld/go-ipld-prime/blob/b7347f196aa5653fddb5631124f8821ce425bfc9/schema/gen/go/testUnionsKinded_test.go#L25

Alternatively, if you haven't got a union, but you've got a maybe (either a nullable or an optional, or both at once) somewhere, then you can use this kind of config (except set it to true, to get a pointer):

https://github.com/ipld/go-ipld-prime/blob/b7347f196aa5653fddb5631124f8821ce425bfc9/schema/gen/go/testStructsContainingMaybe_test.go#L25

If you don't have either of those -- well, you must, actually :) otherwise the schema would be describing a structure that would legitimaty be infinite in size, which would be a bad schema.

(We intended to put a better configuration interface on this thing, but are in a bit of a tumble with prioritization lately, unfortunately.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Ethereum IPLD
In Progress
Development

No branches or pull requests

2 participants