5 ms·
Sounds like a UI bug more than anything. The compiler certainly knows how to determine if there is only one implementation of an interface and remove the inter
by randomdata 2y ago
Sounds like a UI bug more than anything.
The compiler certainly knows how to determine if there is only one implementation of an interface and remove the interface indirection when so. There is nothing really stopping the cmd+click tooling from doing the same.
- anonymoushn 2y agoDoes the compiler do that? That sounds extremely unlikely, especially because an interface with only one implementation can store the nil type tag or a tagged pointer to an instance of that implementation.
- randomdata 2y agoThe nil interface is another implementation. I mean, unless it is being used as the sole implementation, but I think we can assume that isn't the implementation being talked about given that it isn't a practical implementation. We're talking about where there is one implementation.
- anonymoushn 2y agoRight. Can you cite anything that says that the go compiler does this sort of whole-program analysis to try to prove that a certain argument to a function is always non-nil, so that it can change the signature of that function and the types of variables declared in other functions?
- randomdata 2y agoUh. No. Why would I ever waste my time proving something I said? If I'm right, I'm right. If I'm wrong, you'll be sure to tell me. No reason for my involvement.
- Dylan16807 2y agoIf a nil is another implementation then interfaces with a single implementation don't exist.
- randomdata 2y agoGiven the following, where is the nil implementation found? package main type FooInterface interface { Baz() } func bar(fizz FooInterface) { bizz.Baz() } type MyFoo struct{} func (*MyFoo) Baz() {} func main() { var foo FooInterface = &MyFoo{} bar(foo) }
- Dylan16807 2y agoNil is built-in. You just have to write the code to instantiate it and the compiler gives you one. The coder does not need to create an implementation, it's there for free. I would not have called it a "second implementation" myself, but that's your claim to defend, not mine.
- randomdata 2y agomap is also built-in. Where do you find the hash map in the given program? By your logic some nebulous package in a random GitHub repository that happens to satisfy an interface is also another implementation, but you would have to be completely out to lunch to think that fits with the topic of discussion.
- Dylan16807 2y ago> map is also built-in. Where do you find the hash map in the given program? If you told me a type can be optimized because the compiler knows it can only have non-hash-map uses, but I could put that type into a hash map with a single line, I think I would be right to be skeptical. > By your logic some nebulous package in a GitHub repository that happens to satisfy an interface is also another implementation, but you would have to be completely out to lunch to think that fits with the topic of discussion. I expect the compiler to have a list of implementations somewhere. I don't know if I can expect it to track if nil is ever used with an interface. I could believe the optimization exists with the right analysis setup but you called the idea of finding a citation a "waste of time" so that's not very convincing.