Thanks for your explanation, that's very helpful :-) 

On Friday, March 12, 2021 at 3:03:00 PM UTC+8 axel.wa...@googlemail.com 
wrote:

> On Fri, Mar 12, 2021 at 4:55 AM messi...@gmail.com <messi...@gmail.com> 
> wrote:
>
>> Does it use for generics constraints only?
>
>
> That is my understanding.
>  
>
>> As described at 
>> https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md#comparable-types-in-constraints
>>  
>> . If so the type comparison and this interface is two unrelated things?
>>
>
> They are related in the sense that `comparable` expresses exactly the 
> constraint of being able to compare values of a type. But the compiler 
> already knows how to compare values of the same type, if that type is 
> comparable. And the `comparable` interface won't be usable as an actual 
> type which can have a value (that would be useless - you need two values of 
> the same concrete type to actually compare, but there is, in general, no 
> guarantee that two values of an interface type are the same concrete type). 
> So there doesn't have to be a direct connection between the two.
>  
>
>>
>> On Friday, March 12, 2021 at 11:42:07 AM UTC+8 messi...@gmail.com wrote:
>>
>>> Hi, 
>>>
>>> I'm reading the new typechecker source code of go compiler(under 
>>> directory cmd/compile/internal/types2), during the initialization process, 
>>> universe.go registers an implicit interface "comparable" inside function 
>>> defPredeclaredComparable 
>>> <https://github.com/golang/go/blob/e8b82789cda6c9d9e3dfc9a652b4d7a823b834f2/src/cmd/compile/internal/types2/universe.go#L199>,
>>>  
>>> I know it's supposed to be used for type comparison 
>>> <https://golang.org/ref/spec#Comparison_operators>but failed to find 
>>> where and how this interface and related method "==" is used. 
>>>
>>> In predicates.go 
>>> <https://github.com/golang/go/blob/e8b82789cda6c9d9e3dfc9a652b4d7a823b834f2/src/cmd/compile/internal/types2/predicates.go#L86>
>>>  there's 
>>> a function 'Comparable" to check whether a type is comparable or not, but 
>>> seems there's nothing to do with the interface.
>>>
>>> And I don't understand the lookup logic for method "==" in type.go 
>>> <https://github.com/golang/go/blob/e8b82789cda6c9d9e3dfc9a652b4d7a823b834f2/src/cmd/compile/internal/types2/type.go#L465>
>>>  neither, 
>>> how could an Interface type have method named "=="?
>>>
>>> I searched a lot from the code base but failed to find the answer, could 
>>> anybody kindly give me some clue?
>>>
>>> Thanks a lot :-)
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/50661f0e-289e-43f3-a9d7-a42feb77f7fbn%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/golang-nuts/50661f0e-289e-43f3-a9d7-a42feb77f7fbn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/14cc2521-a155-48db-b000-a5300c6711f1n%40googlegroups.com.

Reply via email to