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

build.Doc() doesn't play well with multi-line doc strings. #230

Open
vsivsi opened this issue Nov 13, 2021 · 3 comments
Open

build.Doc() doesn't play well with multi-line doc strings. #230

vsivsi opened this issue Nov 13, 2021 · 3 comments

Comments

@vsivsi
Copy link
Contributor

vsivsi commented Nov 13, 2021

Attempt A:

For example:

TEXT("add", NOSPLIT, "func(x, y uint64) uint64")
Doc("add uint64 x and y\nreturns uint64 sum of x and y")

Produces invalid syntax:

// add uint64 x and y
returns uint64 sum of x and y
func add(x uint64, y uint64) uint64

Attempt B:

Using Doc multiple times...

TEXT("add", NOSPLIT, "func(x, y uint64) uint64")
Doc("add uint64 x and y")
Doc("returns uint64 sum of x and y")

... doesn't work as expected:

// returns uint64 sum of x and y
func add(x uint64, y uint64) uint64

Attempt C:

Just writing a really long docstring...

TEXT("add", NOSPLIT, "func(x, y uint64) uint64")
Doc("add uint64 x and y returns uint64 sum of x and y which is super useful when you just want to add two numbers with a whole bunch of call overhead as an excuse to use Avo")

...doesn't result in a sensibly wrapped output:

// add uint64 x and y returns uint64 sum of x and y which is super useful when you just want to add two numbers with a whole bunch of call overhead as an excuse to use Avo
func add(x uint64, y uint64) uint64

Suggestion:

Cases A and B are arguably bugs. Case C would be nice to fix, but is probably not needed if A and B are fixed.

@vsivsi
Copy link
Contributor Author

vsivsi commented Nov 13, 2021

I hasten to add: yes, I know that Doc() is variadic, and using it that way is the "correct" way to address the use cases above. But attempts A-C above are not unreasonable things for a user to try, and they all fail in their own way to generate the predicted output.

@mmcloughlin
Copy link
Owner

Hmmm, yes agree A and B are not ideal. I could change Doc to append. I find it hard to believe anyone would be relying on the existing overwrite behavior.

Not sure about auto-wrapping, it's not always what you'd want. Maybe a different function like WrapDoc? Is there a better name?

@vsivsi
Copy link
Contributor Author

vsivsi commented Nov 13, 2021

I'm not that enthusiastic about auto-wrapping, agree that's really on the coder to auto wrap if they want.

Note that Comment and Commentf also suffer from case A:

TEXT("add", NOSPLIT, "func(x, y uint64) uint64")
Doc("add adds x and y.")
Comment("This belongs on\n multiple lines")

In asm output:

// func add(x uint64, y uint64) uint64
TEXT ·add(SB), NOSPLIT, $0-24
	// This belongs on
 multiple lines
	MOVQ x+0(FP), AX

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

No branches or pull requests

2 participants