github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/compile/internal/types2/unify.go (about) 1 // Copyright 2020 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // This file implements type unification. 6 // 7 // Type unification attempts to make two types x and y structurally 8 // equivalent by determining the types for a given list of (bound) 9 // type parameters which may occur within x and y. If x and y are 10 // structurally different (say []T vs chan T), or conflicting 11 // types are determined for type parameters, unification fails. 12 // If unification succeeds, as a side-effect, the types of the 13 // bound type parameters may be determined. 14 // 15 // Unification typically requires multiple calls u.unify(x, y) to 16 // a given unifier u, with various combinations of types x and y. 17 // In each call, additional type parameter types may be determined 18 // as a side effect and recorded in u. 19 // If a call fails (returns false), unification fails. 20 // 21 // In the unification context, structural equivalence of two types 22 // ignores the difference between a defined type and its underlying 23 // type if one type is a defined type and the other one is not. 24 // It also ignores the difference between an (external, unbound) 25 // type parameter and its core type. 26 // If two types are not structurally equivalent, they cannot be Go 27 // identical types. On the other hand, if they are structurally 28 // equivalent, they may be Go identical or at least assignable, or 29 // they may be in the type set of a constraint. 30 // Whether they indeed are identical or assignable is determined 31 // upon instantiation and function argument passing. 32 33 package types2