Go compiler typechecker - why are there two ways to test type equality(checker.identical0() and unifier)?

89 views
Skip to first unread message

messi...@gmail.com

unread,
Mar 25, 2021, 11:21:07 PM3/25/21
to golang-nuts
Hi,

While reading the source code of typechecker, I found there're two ways to check type equality:
1. Method checker.identical(x, y Type) bool {}, defined in predicates.go, used by many places to see if two types are identical during typecheck process;
2. Method unifier.unify(x, y Type) bool {}, defined in unify.go,  used by method lookup to compare two Signature types

And there's comment "For changes to this code the corresponding changes should be made to unifier.nify." for method checker.identical0().

I wonder why there're two implementations for one thing? And if there're some reason, why the name "unify"?

Thanks for any help:-)

Ian Lance Taylor

unread,
Mar 26, 2021, 1:19:44 AM3/26/21
to messi...@gmail.com, golang-nuts
You are looking at the type checker on tip, which is in the process of
being modified to support generics
(https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md).
This work is in progress and the code will continue to change.

For type unification, see
https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md#type-unification.

Ian
Reply all
Reply to author
Forward
0 new messages