X7ROOT File Manager
Current Path:
/opt/golang/1.19.4/src/cmd/compile/internal/types2
opt
/
golang
/
1.19.4
/
src
/
cmd
/
compile
/
internal
/
types2
/
📁
..
📄
api.go
(17.37 KB)
📄
api_test.go
(79.44 KB)
📄
array.go
(803 B)
📄
assignments.go
(13.89 KB)
📄
basic.go
(1.48 KB)
📄
builtins.go
(23.73 KB)
📄
builtins_test.go
(9.89 KB)
📄
call.go
(19.08 KB)
📄
chan.go
(910 B)
📄
check.go
(17.12 KB)
📄
check_test.go
(8.96 KB)
📄
compilersupport.go
(1.05 KB)
📄
context.go
(4.34 KB)
📄
context_test.go
(2.3 KB)
📄
conversions.go
(8.27 KB)
📄
decl.go
(27.86 KB)
📄
errorcalls_test.go
(1.15 KB)
📄
errors.go
(7.62 KB)
📄
errors_test.go
(1.01 KB)
📄
example_test.go
(7.41 KB)
📄
expr.go
(54.01 KB)
📄
gccgosizes.go
(1017 B)
📄
hilbert_test.go
(3.63 KB)
📄
importer_test.go
(913 B)
📄
index.go
(11.13 KB)
📄
infer.go
(24.86 KB)
📄
initorder.go
(9.55 KB)
📄
instantiate.go
(9.93 KB)
📄
instantiate_test.go
(5.98 KB)
📄
interface.go
(6.04 KB)
📄
issues_test.go
(17.4 KB)
📄
labels.go
(7.05 KB)
📄
lookup.go
(17.01 KB)
📄
main_test.go
(336 B)
📄
map.go
(659 B)
📄
mono.go
(9.03 KB)
📄
mono_test.go
(2.65 KB)
📄
named.go
(22.4 KB)
📄
named_test.go
(2.35 KB)
📄
object.go
(18.8 KB)
📄
object_test.go
(5.13 KB)
📄
objset.go
(928 B)
📄
operand.go
(10.62 KB)
📄
package.go
(2.67 KB)
📄
pointer.go
(635 B)
📄
predicates.go
(14.64 KB)
📄
resolver.go
(24.88 KB)
📄
resolver_test.go
(4.81 KB)
📄
return.go
(4.34 KB)
📄
scope.go
(9.38 KB)
📄
selection.go
(3.99 KB)
📄
self_test.go
(2.58 KB)
📄
signature.go
(12.1 KB)
📄
sizeof_test.go
(1.28 KB)
📄
sizes.go
(7.56 KB)
📄
sizes_test.go
(3.25 KB)
📄
slice.go
(577 B)
📄
stdlib_test.go
(8.8 KB)
📄
stmt.go
(25.66 KB)
📄
struct.go
(6.24 KB)
📄
subst.go
(10.78 KB)
📄
termlist.go
(3.68 KB)
📄
termlist_test.go
(7.18 KB)
📁
testdata
📄
tuple.go
(929 B)
📄
type.go
(2.92 KB)
📄
typelists.go
(1.84 KB)
📄
typeparam.go
(4.75 KB)
📄
typeset.go
(13.87 KB)
📄
typeset_test.go
(2.41 KB)
📄
typestring.go
(10.61 KB)
📄
typestring_test.go
(4.11 KB)
📄
typeterm.go
(3.52 KB)
📄
typeterm_test.go
(5.08 KB)
📄
typexpr.go
(14.8 KB)
📄
unify.go
(18.34 KB)
📄
union.go
(6.1 KB)
📄
universe.go
(7.58 KB)
📄
validtype.go
(7.77 KB)
📄
version.go
(2.13 KB)
Editing: context.go
// 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 types2 import ( "bytes" "fmt" "strconv" "strings" "sync" ) // This file contains a definition of the type-checking context; an opaque type // that may be supplied by users during instantiation. // // Contexts serve two purposes: // - reduce the duplication of identical instances // - short-circuit instantiation cycles // // For the latter purpose, we must always have a context during instantiation, // whether or not it is supplied by the user. For both purposes, it must be the // case that hashing a pointer-identical type produces consistent results // (somewhat obviously). // // However, neither of these purposes require that our hash is perfect, and so // this was not an explicit design goal of the context type. In fact, due to // concurrent use it is convenient not to guarantee de-duplication. // // Nevertheless, in the future it could be helpful to allow users to leverage // contexts to canonicalize instances, and it would probably be possible to // achieve such a guarantee. // A Context is an opaque type checking context. It may be used to share // identical type instances across type-checked packages or calls to // Instantiate. Contexts are safe for concurrent use. // // The use of a shared context does not guarantee that identical instances are // deduplicated in all cases. type Context struct { mu sync.Mutex typeMap map[string][]ctxtEntry // type hash -> instances entries nextID int // next unique ID originIDs map[Type]int // origin type -> unique ID } type ctxtEntry struct { orig Type targs []Type instance Type // = orig[targs] } // NewContext creates a new Context. func NewContext() *Context { return &Context{ typeMap: make(map[string][]ctxtEntry), originIDs: make(map[Type]int), } } // instanceHash returns a string representation of typ instantiated with targs. // The hash should be a perfect hash, though out of caution the type checker // does not assume this. The result is guaranteed to not contain blanks. func (ctxt *Context) instanceHash(orig Type, targs []Type) string { assert(ctxt != nil) assert(orig != nil) var buf bytes.Buffer h := newTypeHasher(&buf, ctxt) h.string(strconv.Itoa(ctxt.getID(orig))) // Because we've already written the unique origin ID this call to h.typ is // unnecessary, but we leave it for hash readability. It can be removed later // if performance is an issue. h.typ(orig) if len(targs) > 0 { // TODO(rfindley): consider asserting on isGeneric(typ) here, if and when // isGeneric handles *Signature types. h.typeList(targs) } return strings.Replace(buf.String(), " ", "#", -1) // ReplaceAll is not available in Go1.4 } // lookup returns an existing instantiation of orig with targs, if it exists. // Otherwise, it returns nil. func (ctxt *Context) lookup(h string, orig Type, targs []Type) Type { ctxt.mu.Lock() defer ctxt.mu.Unlock() for _, e := range ctxt.typeMap[h] { if identicalInstance(orig, targs, e.orig, e.targs) { return e.instance } if debug { // Panic during development to surface any imperfections in our hash. panic(fmt.Sprintf("non-identical instances: (orig: %s, targs: %v) and %s", orig, targs, e.instance)) } } return nil } // update de-duplicates n against previously seen types with the hash h. If an // identical type is found with the type hash h, the previously seen type is // returned. Otherwise, n is returned, and recorded in the Context for the hash // h. func (ctxt *Context) update(h string, orig Type, targs []Type, inst Type) Type { assert(inst != nil) ctxt.mu.Lock() defer ctxt.mu.Unlock() for _, e := range ctxt.typeMap[h] { if inst == nil || Identical(inst, e.instance) { return e.instance } if debug { // Panic during development to surface any imperfections in our hash. panic(fmt.Sprintf("%s and %s are not identical", inst, e.instance)) } } ctxt.typeMap[h] = append(ctxt.typeMap[h], ctxtEntry{ orig: orig, targs: targs, instance: inst, }) return inst } // getID returns a unique ID for the type t. func (ctxt *Context) getID(t Type) int { ctxt.mu.Lock() defer ctxt.mu.Unlock() id, ok := ctxt.originIDs[t] if !ok { id = ctxt.nextID ctxt.originIDs[t] = id ctxt.nextID++ } return id }
Upload File
Create Folder