+// Code generated by "go run generator.go"; DO NOT EDIT.
+
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Elem returns element type of array a.
func (a *Array) Elem() Type { return a.elem }
-func (t *Array) Underlying() Type { return t }
-func (t *Array) String() string { return TypeString(t, nil) }
+func (a *Array) Underlying() Type { return a }
+func (a *Array) String() string { return TypeString(a, nil) }
+// Code generated by "go run generator.go"; DO NOT EDIT.
+
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Name returns the name of basic type b.
func (b *Basic) Name() string { return b.name }
-func (t *Basic) Underlying() Type { return t }
-func (t *Basic) String() string { return TypeString(t, nil) }
+func (b *Basic) Underlying() Type { return b }
+func (b *Basic) String() string { return TypeString(b, nil) }
+// Code generated by "go run generator.go"; DO NOT EDIT.
+
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
type action func(in *ast.File)
var filemap = map[string]action{
- "chan.go": nil,
- "context.go": nil,
- "gccgosizes.go": nil,
- "lookup.go": nil,
- "main_test.go": nil,
- "map.go": nil,
- "named.go": func(f *ast.File) { fixTokenPos(f); fixTraceSel(f) },
- "objset.go": nil,
- "pointer.go": nil,
- "selection.go": nil,
- "sizes.go": func(f *ast.File) { rename(f, "IsSyncAtomicAlign64", "isSyncAtomicAlign64") },
- "slice.go": nil,
- "subst.go": func(f *ast.File) { fixTokenPos(f); fixTraceSel(f) },
- "termlist.go": nil,
- "termlist_test.go": nil,
- "tuple.go": nil,
- "typelists.go": nil,
- "typeparam.go": nil,
- "typeterm.go": nil,
- "validtype.go": nil,
+ "array.go": nil,
+ "basic.go": nil,
+ "chan.go": nil,
+ "context.go": nil,
+ "context_test.go": nil,
+ "gccgosizes.go": nil,
+ "instantiate_test.go": func(f *ast.File) { renameImportPath(f, `"cmd/compile/internal/types2"`, `"go/types"`) },
+ "lookup.go": nil,
+ "main_test.go": nil,
+ "map.go": nil,
+ "named.go": func(f *ast.File) { fixTokenPos(f); fixTraceSel(f) },
+ "object.go": func(f *ast.File) { fixTokenPos(f); renameIdent(f, "NewTypeNameLazy", "_NewTypeNameLazy") },
+ "objset.go": nil,
+ "package.go": nil,
+ "pointer.go": nil,
+ "predicates.go": nil,
+ "selection.go": nil,
+ "sizes.go": func(f *ast.File) { renameIdent(f, "IsSyncAtomicAlign64", "isSyncAtomicAlign64") },
+ "slice.go": nil,
+ "subst.go": func(f *ast.File) { fixTokenPos(f); fixTraceSel(f) },
+ "termlist.go": nil,
+ "termlist_test.go": nil,
+ "tuple.go": nil,
+ "typelists.go": nil,
+ "typeparam.go": nil,
+ "typeterm_test.go": nil,
+ "typeterm.go": nil,
+ "universe.go": fixGlobalTypVarDecl,
+ "validtype.go": nil,
}
// TODO(gri) We should be able to make these rewriters more configurable/composable.
// For now this is a good starting point.
-func rename(f *ast.File, from, to string) {
+// renameIdent renames an identifier.
+// Note: This doesn't change the use of the identifier in comments.
+func renameIdent(f *ast.File, from, to string) {
ast.Inspect(f, func(n ast.Node) bool {
switch n := n.(type) {
case *ast.Ident:
})
}
+// renameImportPath renames an import path.
+func renameImportPath(f *ast.File, from, to string) {
+ ast.Inspect(f, func(n ast.Node) bool {
+ switch n := n.(type) {
+ case *ast.ImportSpec:
+ if n.Path.Kind == token.STRING && n.Path.Value == from {
+ n.Path.Value = to
+ return false
+ }
+ }
+ return true
+ })
+}
+
+// fixTokenPos changes imports of "cmd/compile/internal/syntax" to "go/token"
+// and uses of syntax.Pos to token.Pos.
func fixTokenPos(f *ast.File) {
ast.Inspect(f, func(n ast.Node) bool {
switch n := n.(type) {
})
}
+// fixTraceSel renames uses of x.Trace to x.trace, where x for any x with a Trace field.
func fixTraceSel(f *ast.File) {
ast.Inspect(f, func(n ast.Node) bool {
switch n := n.(type) {
return true
})
}
+
+// fixGlobalTypVarDecl changes the global Typ variable from an array to a slice
+// (in types2 we use an array for efficiency, in go/types it's a slice and we
+// cannot change that).
+func fixGlobalTypVarDecl(f *ast.File) {
+ ast.Inspect(f, func(n ast.Node) bool {
+ switch n := n.(type) {
+ case *ast.ValueSpec:
+ if len(n.Names) == 1 && n.Names[0].Name == "Typ" && len(n.Values) == 1 {
+ n.Values[0].(*ast.CompositeLit).Type.(*ast.ArrayType).Len = nil
+ return false
+ }
+ }
+ return true
+ })
+}
+// Code generated by "go run generator.go"; DO NOT EDIT.
+
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-
package types_test
import (
func TestInstantiateNonEquality(t *testing.T) {
const src = "package p; type T[P any] int"
-
pkg1 := mustTypecheck(".", src, nil)
pkg2 := mustTypecheck(".", src, nil)
-
// We consider T1 and T2 to be distinct types, so their instances should not
// be deduplicated by the context.
T1 := pkg1.Scope().Lookup("T").Type().(*Named)
T2 := pkg2.Scope().Lookup("T").Type().(*Named)
-
ctxt := NewContext()
res1, err := Instantiate(ctxt, T1, []Type{Typ[Int]}, false)
if err != nil {
if err != nil {
t.Fatal(err)
}
-
if res1 == res2 {
t.Errorf("instance from pkg1 (%s) is pointer-equivalent to instance from pkg2 (%s)", res1, res2)
}
+// Code generated by "go run generator.go"; DO NOT EDIT.
+
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
"fmt"
"go/constant"
"go/token"
+ "unicode"
+ "unicode/utf8"
)
// An Object describes a named language entity such as a package,
setScopePos(pos token.Pos)
}
+func isExported(name string) bool {
+ ch, _ := utf8.DecodeRuneInString(name)
+ return unicode.IsUpper(ch)
+}
+
// Id returns name if it is exported, otherwise it
// returns the name qualified with the package path.
func Id(pkg *Package, name string) string {
- if token.IsExported(name) {
+ if isExported(name) {
return name
}
// unexported names need the package path for differentiation
// Exported reports whether the object is exported (starts with a capital letter).
// It doesn't take into account whether the object is in a local (function) scope
// or not.
-func (obj *object) Exported() bool { return token.IsExported(obj.name) }
+func (obj *object) Exported() bool { return isExported(obj.name) }
// Id is a wrapper for Id(obj.Pkg(), obj.Name()).
func (obj *object) Id() string { return Id(obj.pkg, obj.name) }
return pkg.path == obj.pkg.path
}
+// less reports whether object a is ordered before object b.
+//
+// Objects are ordered nil before non-nil, exported before
+// non-exported, then by name, and finally (for non-exported
+// functions) by package path.
+func (a *object) less(b *object) bool {
+ if a == b {
+ return false
+ }
+
+ // Nil before non-nil.
+ if a == nil {
+ return true
+ }
+ if b == nil {
+ return false
+ }
+
+ // Exported functions before non-exported.
+ ea := isExported(a.name)
+ eb := isExported(b.name)
+ if ea != eb {
+ return ea
+ }
+
+ // Order by name and then (for non-exported names) by package.
+ if a.name != b.name {
+ return a.name < b.name
+ }
+ if !ea {
+ return a.pkg.path < b.pkg.path
+ }
+
+ return false
+}
+
// A PkgName represents an imported Go package.
// PkgNames don't have a type.
type PkgName struct {
return &TypeName{object{nil, pos, pkg, name, typ, 0, colorFor(typ), nopos}}
}
-// _NewTypeNameLazy returns a new defined type like NewTypeName, but it
+// NewTypeNameLazy returns a new defined type like NewTypeName, but it
// lazily calls resolve to finish constructing the Named object.
func _NewTypeNameLazy(pos token.Pos, pkg *Package, name string, load func(named *Named) (tparams []*TypeParam, underlying Type, methods []*Func)) *TypeName {
obj := NewTypeName(pos, pkg, name, nil)
+// Code generated by "go run generator.go"; DO NOT EDIT.
+
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
path string
name string
scope *Scope
- complete bool
imports []*Package
+ complete bool
fake bool // scope lookup errors are silently dropped if package is fake (internal use only)
cgo bool // uses of this package will be rewritten into uses of declarations from _cgo_gotypes.go
}
+// Code generated by "go run generator.go"; DO NOT EDIT.
+
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// allX is an optimized version of isX(coreType(t)) (which
// is the same as underIs(t, isX)).
-func allBoolean(typ Type) bool { return allBasic(typ, IsBoolean) }
-func allInteger(typ Type) bool { return allBasic(typ, IsInteger) }
-func allUnsigned(typ Type) bool { return allBasic(typ, IsUnsigned) }
-func allNumeric(typ Type) bool { return allBasic(typ, IsNumeric) }
-func allString(typ Type) bool { return allBasic(typ, IsString) }
-func allOrdered(typ Type) bool { return allBasic(typ, IsOrdered) }
-func allNumericOrString(typ Type) bool { return allBasic(typ, IsNumeric|IsString) }
+func allBoolean(t Type) bool { return allBasic(t, IsBoolean) }
+func allInteger(t Type) bool { return allBasic(t, IsInteger) }
+func allUnsigned(t Type) bool { return allBasic(t, IsUnsigned) }
+func allNumeric(t Type) bool { return allBasic(t, IsNumeric) }
+func allString(t Type) bool { return allBasic(t, IsString) }
+func allOrdered(t Type) bool { return allBasic(t, IsOrdered) }
+func allNumericOrString(t Type) bool { return allBasic(t, IsNumeric|IsString) }
// allBasic reports whether under(t) is a basic type with the specified info.
// If t is a type parameter, the result is true if isBasic(t, info) is true
// Misc
{Scope{}, 44, 88},
- {Package{}, 40, 80},
+ {Package{}, 36, 72},
{_TypeSet{}, 28, 56},
}
for _, test := range tests {
+// Code generated by "go run generator.go"; DO NOT EDIT.
+
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+// Code generated by "go run generator.go"; DO NOT EDIT.
+
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.