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

gengo: support for unions with stringprefix representation. #133

Merged
merged 2 commits into from
Jan 7, 2021

Conversation

warpfork
Copy link
Collaborator

@warpfork warpfork commented Jan 3, 2021

Title says it all, actually.

@warpfork warpfork force-pushed the gengo-union-repr-stringprefix branch from 024f852 to 4da73fb Compare January 3, 2021 17:44
Copy link
Contributor

@mvdan mvdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to admit it's hard to actually understand the template code, but it looks fine to me.

// SplitN is an alias of strings.SplitN, which is only present here to
// make it usable in codegen packages without requiring conditional imports
// in the generation process.
func SplitN(s, sep string, n int) []string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, just run goimports on the generated code? "figure out what imports we need" is a solved problem in go :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems significantly more complex. I'm not okay with pushing a need for goimports -- something from the x/tools repos -- onto users in order to have compilable code come out. (By contrast, while elsewhere we decided we're okay leaning on post-gen invocation of gofmt, that differs on two fronts: it's effectively always available, and it's also not strictly necessary to apply before compile will succeed.)

A small handful of cherry-picked constants like this seems fine to me.

We may want to consider moving such things to their own small package (or the minima file in the output?) to make them less obtrusive, though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess goimports is probably also possible to use as a library, so we could just add it to our own dependencies. But I'd still say for this small of a need, it's probably not worth it. I'd favor KISS on this until we really have a desire for conditional imports.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the assumption we'd be the only ones running this generator. Why would other people generate their own mixins directly?

Copy link
Collaborator Author

@warpfork warpfork Jan 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the comment is unclear -- SplitN is used in the parsing logic of the code that comes out.

https://github.com/ipld/go-ipld-prime/pull/133/files#diff-7b9d4887e3f1a6fe25da2c76ec88a55a2e71169f757cbe9b5c1cf2352f1985c3R155

TypeSymbol: adjCfg.TypeSymbol(typ),
},
pkgName,
typ,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use keyed fields? otherwise it's hard to tell what's going on here. I personally always use keys when the number of fields is more than 2

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine, done.

@warpfork warpfork merged commit a3d437a into master Jan 7, 2021
@warpfork warpfork deleted the gengo-union-repr-stringprefix branch January 7, 2021 19:47
@aschmahmann aschmahmann mentioned this pull request May 14, 2021
71 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants