mirror of
https://github.com/golang/go
synced 2024-11-26 09:48:14 -07:00
[dev.typeparams] cmd/compile: add built-in name/type "comparable".
This allows exporting comparable type bounds, and importing back into types2 for typechecking. Fixes typeparam/mdempsky/8.go Change-Id: I3ee12433df2ed68ac6ef4cad24be9fcdfaaca4e3 Reviewed-on: https://go-review.googlesource.com/c/go/+/333129 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Dan Scales <danscales@google.com>
This commit is contained in:
parent
b4844c9f54
commit
b614c05a15
@ -101,6 +101,8 @@ var predeclared = []types2.Type{
|
|||||||
|
|
||||||
// error
|
// error
|
||||||
types2.Universe.Lookup("error").Type(),
|
types2.Universe.Lookup("error").Type(),
|
||||||
|
// comparable
|
||||||
|
types2.Universe.Lookup("comparable").Type(),
|
||||||
|
|
||||||
// untyped types
|
// untyped types
|
||||||
types2.Typ[types2.UntypedBool],
|
types2.Typ[types2.UntypedBool],
|
||||||
|
@ -189,14 +189,6 @@ func (g *irgen) typ0(typ types2.Type) *types.Type {
|
|||||||
|
|
||||||
// With Go 1.18, an embedded element can be any type, not
|
// With Go 1.18, an embedded element can be any type, not
|
||||||
// just an interface.
|
// just an interface.
|
||||||
if t := types2.AsInterface(e); t != nil {
|
|
||||||
if t.IsComparable() {
|
|
||||||
// Ignore predefined type 'comparable', since it
|
|
||||||
// doesn't resolve and it doesn't have any
|
|
||||||
// relevant methods.
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
embeddeds[j] = types.NewField(src.NoXPos, nil, g.typ1(e))
|
embeddeds[j] = types.NewField(src.NoXPos, nil, g.typ1(e))
|
||||||
j++
|
j++
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,8 @@ func predeclared() []*types.Type {
|
|||||||
|
|
||||||
// error
|
// error
|
||||||
types.ErrorType,
|
types.ErrorType,
|
||||||
|
// comparable
|
||||||
|
types.ComparableType,
|
||||||
|
|
||||||
// untyped types
|
// untyped types
|
||||||
types.UntypedBool,
|
types.UntypedBool,
|
||||||
|
@ -158,6 +158,15 @@ func InitUniverse() {
|
|||||||
s.Def = n
|
s.Def = n
|
||||||
types.CalcSize(types.ErrorType)
|
types.CalcSize(types.ErrorType)
|
||||||
|
|
||||||
|
// comparable type (interface)
|
||||||
|
s = types.BuiltinPkg.Lookup("comparable")
|
||||||
|
n = ir.NewDeclNameAt(src.NoXPos, ir.OTYPE, s)
|
||||||
|
types.ComparableType = types.NewNamed(n)
|
||||||
|
types.ComparableType.SetUnderlying(makeComparableInterface())
|
||||||
|
n.SetType(types.ComparableType)
|
||||||
|
s.Def = n
|
||||||
|
types.CalcSize(types.ComparableType)
|
||||||
|
|
||||||
types.Types[types.TUNSAFEPTR] = defBasic(types.TUNSAFEPTR, ir.Pkgs.Unsafe, "Pointer")
|
types.Types[types.TUNSAFEPTR] = defBasic(types.TUNSAFEPTR, ir.Pkgs.Unsafe, "Pointer")
|
||||||
|
|
||||||
// simple aliases
|
// simple aliases
|
||||||
@ -338,6 +347,12 @@ func makeErrorInterface() *types.Type {
|
|||||||
return types.NewInterface(types.NoPkg, []*types.Field{method})
|
return types.NewInterface(types.NoPkg, []*types.Field{method})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func makeComparableInterface() *types.Type {
|
||||||
|
sig := types.NewSignature(types.NoPkg, fakeRecvField(), nil, nil, nil)
|
||||||
|
method := types.NewField(src.NoXPos, Lookup("=="), sig)
|
||||||
|
return types.NewInterface(types.NoPkg, []*types.Field{method})
|
||||||
|
}
|
||||||
|
|
||||||
// DeclareUniverse makes the universe block visible within the current package.
|
// DeclareUniverse makes the universe block visible within the current package.
|
||||||
func DeclareUniverse() {
|
func DeclareUniverse() {
|
||||||
// Operationally, this is similar to a dot import of builtinpkg, except
|
// Operationally, this is similar to a dot import of builtinpkg, except
|
||||||
|
@ -123,6 +123,8 @@ var (
|
|||||||
|
|
||||||
// Predeclared error interface type.
|
// Predeclared error interface type.
|
||||||
ErrorType *Type
|
ErrorType *Type
|
||||||
|
// Predeclared comparable interface type.
|
||||||
|
ComparableType *Type
|
||||||
|
|
||||||
// Types to represent untyped string and boolean constants.
|
// Types to represent untyped string and boolean constants.
|
||||||
UntypedString = New(TSTRING)
|
UntypedString = New(TSTRING)
|
||||||
|
@ -104,6 +104,8 @@ var predeclared = []types.Type{
|
|||||||
|
|
||||||
// error
|
// error
|
||||||
types.Universe.Lookup("error").Type(),
|
types.Universe.Lookup("error").Type(),
|
||||||
|
// comparable
|
||||||
|
types.Universe.Lookup("comparable").Type(),
|
||||||
|
|
||||||
// untyped types
|
// untyped types
|
||||||
types.Typ[types.UntypedBool],
|
types.Typ[types.UntypedBool],
|
||||||
|
@ -2210,7 +2210,6 @@ var g3Failures = setOf(
|
|||||||
"typeparam/mdempsky/4.go",
|
"typeparam/mdempsky/4.go",
|
||||||
"typeparam/mdempsky/5.go",
|
"typeparam/mdempsky/5.go",
|
||||||
"typeparam/mdempsky/7.go",
|
"typeparam/mdempsky/7.go",
|
||||||
"typeparam/mdempsky/8.go",
|
|
||||||
"typeparam/mdempsky/9.go",
|
"typeparam/mdempsky/9.go",
|
||||||
"typeparam/mdempsky/11.go",
|
"typeparam/mdempsky/11.go",
|
||||||
"typeparam/mdempsky/12.go",
|
"typeparam/mdempsky/12.go",
|
||||||
|
Loading…
Reference in New Issue
Block a user