Earlier quoted context omitted.
If the comments impact correctness (which inlining doesn't, but I believe there are other directives that do), saying it's "an implementation detail" waves away "it's an implementation detail that everyone needs" aka part of the spec. The reason it feels like a kludge is that "comments" are normally understood to be non-impactful. Is a source transformation that removes all comments valid? If comments have no impact…
There's nothing unique to Go about this kind of tooling. It exists in C, Java, Rust, Typescript, and probably dozens of other settings as well. It's the standard way of implementing "after-market" opt-in directives.
//go:fix inline and the source-level inliner
31–40 of 81 posts
Re: //go:fix inline and the source-level inliner
#32Earlier quoted context omitted.
Are we referring to 'go fix' as after market tooling? It's certainly done in many places. JsDoc is the biggest example I can think of. But they're all walking the line of "this doesn't have an impact, except when it does". It being done by the language owners just makes them the ones walking the line.
That's exactly how this works: it doesn't have an impact, except when you ask it to. This is an idiomatic approach to this problem.
In practice, the Go language developers carved syntax out of comments, so that a comment is "anything that starts with //, unless the next characters are go:"
Re: //go:fix inline and the source-level inliner
#33I wonder why they chose to add these directives as comments as opposed to adding new syntax for them. It feels like a kludge. https://wiki.c2.com/?HotComments
For other things, like `//go:noinline`, this is fair criticism. `//go:fix inline` is quite different in every way.
Re: //go:fix inline and the source-level inliner
#34Earlier quoted context omitted.
> The reason it feels like a kludge is that "comments" are normally understood to be non-impactful. Is a source transformation that removes all comments valid? If comments have no impact per the spec, yes. But that's not the case here. This is not inlining in the compiler. It's a directive to a source transformation (refactoring) tool. So yes, this has no impact on the code. It will do things if you run `go fix` on y…
And yet it still breaks "comments aren't semantic". That transformation I described is still invalid.
Re: //go:fix inline and the source-level inliner
#35Re: //go:fix inline and the source-level inliner
#36Earlier quoted context omitted.
That's exactly how this works: it doesn't have an impact, except when you ask it to. This is an idiomatic approach to this problem.
The part I object to is overloading comments, which aren't meant to be load bearing. A tool developed outside the language has no choice but to take something that has no meaning and overload it, but language owners weren't forced to take this route; they could've made directives not comments. In practice, the Go language developers carved syntax out of comments, so that a comment is "anything that starts with //, un…
Re: //go:fix inline and the source-level inliner
#37Earlier submission: https://news.ycombinator.com/item?id=47385766
There was even a more upvoted post between your triple dupe and this https://news.ycombinator.com/item?id=47347322 #scp
Re: //go:fix inline and the source-level inliner
#38If I follow, this isn't a compile time inline directive, it's a `go fix` time source transformation of client code calling the annotated function. Per the post, it sounds like this is most effective in closed-ecosystem internal monorepo-like contexts where an organisation has control over every instance of client code & can `go fix` all of the call sites to completely eradicate all usage of a deprecated APIs: > For m…
Re: //go:fix inline and the source-level inliner
#39It looks the following code will be rewritten badly, but no ways to avoid it? If this is true, maybe the blog article should mention this. package main //go:fix inline func handle() { recover() } func foo() { handle() } func main() { defer foo() panic("bye") }
Another example (fixable): package main import "unsafe" //go:fix inline func foo[T any]() { var t T _ = 1 / unsafe.Sizeof(t) } func main() { foo[struct{}]() } Go is a language full of details: https://go101.org/details-and-tips/101.html
package main
//go:fix inline
func foo[T [8]byte | [4]uint16]() {
var v T
var n byte = 1 > len(v)
if n == 0 {
println("T is [8]byte")
} else {
println("T is [4]uint16]")
}
}
func main() {
foo[[8]byte]()
}Re: //go:fix inline and the source-level inliner
#40Earlier quoted context omitted.
And yet it still breaks "comments aren't semantic". That transformation I described is still invalid.
I don’t understand why that wouldn’t be valid. As far as I understand if you compile code with these go:fix comments, they will be ignored. But if instead of compiling the code you run ‘go fix’, the source code will be modified to inline the function call. Only after the source code has been modified in this way would compiling reflect the inlining. Do you have a different understanding?