Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-29 Thread tapi...@gmail.com
On Thursday, February 29, 2024 at 7:04:14 PM UTC+8 Axel Wagner wrote: Yes. It means "violating a rule, without setting a precedent for future violations". One of the main objections to the loop variable change has been the breaking of compatibility and the fear of setting a precedent for

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-29 Thread tapi...@gmail.com
On Thursday, February 29, 2024 at 3:14:40 PM UTC+8 Axel Wagner wrote: The loop var change *does* break compatibility. And it did so knowingly and - as clearly explained - was an exception. Stop arguing in bad faith. An exception. :D On Thu, Feb 29, 2024 at 7:03 AM tapi...@gmail.com

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-28 Thread 'Axel Wagner' via golang-nuts
The loop var change *does* break compatibility. And it did so knowingly and - as clearly explained - was an exception. Stop arguing in bad faith. On Thu, Feb 29, 2024 at 7:03 AM tapi...@gmail.com wrote: > > > On Wednesday, February 28, 2024 at 3:19:37 PM UTC+8 Axel Wagner wrote: > > That would

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-28 Thread tapi...@gmail.com
On Wednesday, February 28, 2024 at 3:19:37 PM UTC+8 Axel Wagner wrote: That would break backwards compatibility, though. And it would be a re-definition (i.e. existing code would compile, but behave differently at runtime) and is hence not allowed even under the Go 2 transition rules. With

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-27 Thread 'Axel Wagner' via golang-nuts
That would break backwards compatibility, though. And it would be a re-definition (i.e. existing code would compile, but behave differently at runtime) and is hence not allowed even under the Go 2 transition rules. I'm also not sure you can exclude *all* pointers to zero-sized variables. Note that

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-27 Thread 'Brian Candler' via golang-nuts
> let's consider the two possible definitions: > > 1. Pointers to distinct zero-size variables are equal: [...] > 2. Pointers to distinct zero-size variables are not equal: Another possibility: 3. Equality comparisons between pointers to zero-size variables are forbidden at compile time. 3a. If

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-27 Thread Brien Colwell
I think the surprising part is that the comparison result can change for the same values because of the assumption that pointers never change. This is implied by the spec but easy to miss. "Pointers to distinct zero-size variables may or may not be equal." "Pointers to distinct zero-size

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-27 Thread 'Axel Wagner' via golang-nuts
On Tue, Feb 27, 2024 at 8:19 PM Marvin Renich wrote: > Prior to generics, the type of the > arguments to == were easily known to the programmer, and so it was > obvious when this "undefined" exception would raise its ugly head, and > you just didn't use it for empty struct types. But now, with

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-27 Thread Marvin Renich
* Kurtis Rader [240227 03:10]: > On Mon, Feb 26, 2024 at 11:52 PM tapi...@gmail.com > wrote: > > > On Tuesday, February 27, 2024 at 3:42:25 PM UTC+8 Jan Mercl wrote: > > > > On Tue, Feb 27, 2024 at 6:20 AM tapi...@gmail.com > > wrote: > > > > > From common sense, this is an obvious bug. But

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-27 Thread Kurtis Rader
On Mon, Feb 26, 2024 at 11:52 PM tapi...@gmail.com wrote: > On Tuesday, February 27, 2024 at 3:42:25 PM UTC+8 Jan Mercl wrote: > > On Tue, Feb 27, 2024 at 6:20 AM tapi...@gmail.com > wrote: > > > From common sense, this is an obvious bug. But the spec is indeed not > clear enough. > > It

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-26 Thread tapi...@gmail.com
On Tuesday, February 27, 2024 at 3:42:25 PM UTC+8 Jan Mercl wrote: On Tue, Feb 27, 2024 at 6:20 AM tapi...@gmail.com wrote: > From common sense, this is an obvious bug. But the spec is indeed not clear enough. > It doesn't state whether or not comparisons of pointers to two distinct

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-26 Thread Jan Mercl
On Tue, Feb 27, 2024 at 6:20 AM tapi...@gmail.com wrote: > From common sense, this is an obvious bug. But the spec is indeed not clear > enough. > It doesn't state whether or not comparisons of pointers to two distinct > zero-size variables should be consistent in a run session. > Though, from

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-26 Thread tapi...@gmail.com
On Tuesday, February 27, 2024 at 2:25:46 AM UTC+8 Brien Colwell wrote: Interesting. That seems to break the comparable spec. >> Pointer types are comparable. Two pointer values are equal if they point to the same variable or if both have value nil. Pointers to distinct zero-size variables

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-26 Thread Brien Colwell
>> Note that there are two distinct variables involved (a and b). You’re right. I misread this. > On Feb 26, 2024, at 1:15 PM, Axel Wagner > wrote: > > On Mon, Feb 26, 2024 at 7:25 PM Brien Colwell > wrote: >> Interesting. That seems to break the comparable spec.

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-26 Thread 'Axel Wagner' via golang-nuts
On Mon, Feb 26, 2024 at 7:25 PM Brien Colwell wrote: > Interesting. That seems to break the comparable spec. > > >> Pointer types are comparable. Two pointer values are equal if they > point to the same variable or if both have value nil. Pointers to distinct > zero-size variables may or may not

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-26 Thread Brien Colwell
Interesting. That seems to break the comparable spec. >> Pointer types are comparable. Two pointer values are equal if they point to >> the same variable or if both have value nil. Pointers to distinct zero-size >> variables may or may not be equal. >> it would be valid for `==` on pointers

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-24 Thread 'Axel Wagner' via golang-nuts
FWIW I believe there is enough subtlety here (small changes in the code might trigger different compiler optimizations) that I wouldn't rely too much on probing the compiler with different programs. Instead, I'd suggest decompiling the binary and/or running it in a debugger, to check what the

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-24 Thread jake...@gmail.com
What is really fantastical is that a==b prints false, even though the pointers are actually the same. I am guessing some sort of optimization effect is at play here. https://go.dev/play/p/Dsqeh_aAXKT type Foo struct { } func main() { a := {} b := {} fmt.Printf("%t\n", *a == *b)

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-22 Thread burak serdar
On Thu, Feb 22, 2024 at 10:39 AM Axel Wagner wrote: > > > > On Thu, Feb 22, 2024 at 6:06 PM burak serdar wrote: >> >> I don't think this case really applies here. I get that comparison of >> a==b may or may not be true. The problem is that if a==b at some point >> in a program, it should be the

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-22 Thread burak serdar
I don't think this case really applies here. I get that comparison of a==b may or may not be true. The problem is that if a==b at some point in a program, it should be the case that a==b for all other cases in that same program. That is, if a==b, then interface{}(a)==interface{}(b), and vice

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-22 Thread burak serdar
Creating an interface is not creating a pointer to a zero sized variable. a==b prints false. That means, a and b point to different locations Bar(a)==Bar(b) prints true. If a!=b, then Bar(a) must be different from Bar(b) On Thu, Feb 22, 2024 at 9:15 AM Axel Wagner wrote: > > If you expect

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-22 Thread burak serdar
On Thu, Feb 22, 2024 at 9:00 AM Axel Wagner wrote: > > Note that in the Spec section I quoted above it says "Two distinct zero-size > variables may have the same address in memory" (emphasis mine). > There is no guarantee, that all zero-sized values have the same address > (otherwise, you'd get

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-22 Thread burak serdar
The compiler can allocate the same address for empty structs, so I actually expected a==b to be true, not false. However, there's something more interesting going on here because: a := {} b := {} fmt.Printf("%t\n", *a == *b) fmt.Printf("%t\n", a == b) fmt.Printf("%p %p\n", a, b) x := Bar(a) y :=

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-22 Thread 'Axel Wagner' via golang-nuts
>From the spec : > A struct or array type has size zero if it contains no fields (or elements, respectively) that have a size greater than zero. Two distinct zero-size variables may have the same address in memory. On Thu, Feb 22, 2024 at

[go-nuts] Equality of interface of an empty struct - why?

2024-02-22 Thread Brien Colwell
I'm confused by this output. It appears that the interface of two different pointers to an empty struct are equal. In all other cases, interface equality seems to be the pointer equality. What's going on in the empty struct case? ``` package main import "fmt" type Foo struct { } func (self