mirror of
https://github.com/golang/go
synced 2024-11-24 02:10:11 -07:00
cmd/compile: break out constants for local and global dictionary prefixes
Create constant LocalDictName for the pname/refix for dictionary parameters or local variables, and constant GlobalDictPrefix for the prefix for names of global dictionaries. I wanted to make sure these constants were set up as we add more reference to dictionaries for debugging, etc. Change-Id: Ide801f842383300a2699c96943ec06decaecc358 Reviewed-on: https://go-review.googlesource.com/c/go/+/351450 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
parent
1319b1476e
commit
ee69b09424
@ -401,10 +401,7 @@ func (g *irgen) buildClosure(outer *ir.Func, x ir.Node) ir.Node {
|
||||
var dictVar *ir.Name
|
||||
var dictAssign *ir.AssignStmt
|
||||
if outer != nil {
|
||||
// Note: for now this is a compile-time constant, so we don't really need a closure
|
||||
// to capture it (a wrapper function would work just as well). But eventually it
|
||||
// will be a read of a subdictionary from the parent dictionary.
|
||||
dictVar = ir.NewNameAt(pos, typecheck.LookupNum(".dict", g.dnum))
|
||||
dictVar = ir.NewNameAt(pos, typecheck.LookupNum(typecheck.LocalDictName, g.dnum))
|
||||
g.dnum++
|
||||
dictVar.Class = ir.PAUTO
|
||||
typed(types.Types[types.TUINTPTR], dictVar)
|
||||
@ -723,7 +720,7 @@ func (g *irgen) genericSubst(newsym *types.Sym, nameNode *ir.Name, shapes []*typ
|
||||
newf.Dcl = make([]*ir.Name, 0, len(gf.Dcl)+1)
|
||||
|
||||
// Create the needed dictionary param
|
||||
dictionarySym := newsym.Pkg.Lookup(".dict")
|
||||
dictionarySym := newsym.Pkg.Lookup(typecheck.LocalDictName)
|
||||
dictionaryType := types.Types[types.TUINTPTR]
|
||||
dictionaryName := ir.NewNameAt(gf.Pos(), dictionarySym)
|
||||
typed(dictionaryType, dictionaryName)
|
||||
@ -731,7 +728,7 @@ func (g *irgen) genericSubst(newsym *types.Sym, nameNode *ir.Name, shapes []*typ
|
||||
dictionaryName.Curfn = newf
|
||||
newf.Dcl = append(newf.Dcl, dictionaryName)
|
||||
for _, n := range gf.Dcl {
|
||||
if n.Sym().Name == ".dict" {
|
||||
if n.Sym().Name == typecheck.LocalDictName {
|
||||
panic("already has dictionary")
|
||||
}
|
||||
newf.Dcl = append(newf.Dcl, subst.localvar(n))
|
||||
@ -1127,7 +1124,7 @@ func (subst *subster) node(n ir.Node) ir.Node {
|
||||
// Copy that closure variable to a local one.
|
||||
// Note: this allows the dictionary to be captured by child closures.
|
||||
// See issue 47723.
|
||||
ldict := ir.NewNameAt(x.Pos(), newfn.Sym().Pkg.Lookup(".dict"))
|
||||
ldict := ir.NewNameAt(x.Pos(), newfn.Sym().Pkg.Lookup(typecheck.LocalDictName))
|
||||
typed(types.Types[types.TUINTPTR], ldict)
|
||||
ldict.Class = ir.PAUTO
|
||||
ldict.Curfn = newfn
|
||||
|
@ -2196,7 +2196,7 @@ func (w *exportWriter) localIdent(s *types.Sym) {
|
||||
return
|
||||
}
|
||||
|
||||
if i := strings.LastIndex(name, "."); i >= 0 && !strings.HasPrefix(name, ".dict") { // TODO: just use autotmp names for dictionaries?
|
||||
if i := strings.LastIndex(name, "."); i >= 0 && !strings.HasPrefix(name, LocalDictName) {
|
||||
base.Fatalf("unexpected dot in identifier: %v", name)
|
||||
}
|
||||
|
||||
@ -2232,3 +2232,6 @@ func (w *intWriter) uint64(x uint64) {
|
||||
// information (e.g. length field for OSLICELIT).
|
||||
const go117ExportTypes = true
|
||||
const Go117ExportTypes = go117ExportTypes
|
||||
|
||||
// The name used for dictionary parameters or local variables.
|
||||
const LocalDictName = ".dict"
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"cmd/compile/internal/base"
|
||||
"cmd/compile/internal/ir"
|
||||
"cmd/compile/internal/types"
|
||||
"cmd/internal/objabi"
|
||||
"cmd/internal/src"
|
||||
)
|
||||
|
||||
@ -987,7 +988,7 @@ func MakeDictSym(gf *types.Sym, targs []*types.Type, hasBrackets bool) *types.Sy
|
||||
}
|
||||
}
|
||||
name := makeInstName1(gf.Name, targs, hasBrackets)
|
||||
name = ".dict." + name
|
||||
name = fmt.Sprintf("%s.%s", objabi.GlobalDictPrefix, name)
|
||||
return gf.Pkg.Lookup(name)
|
||||
}
|
||||
|
||||
|
@ -340,7 +340,7 @@ func (w *writer) Sym(s *LSym) {
|
||||
if strings.HasPrefix(s.Name, "go.itab.") && s.Type == objabi.SRODATA {
|
||||
flag2 |= goobj.SymFlagItab
|
||||
}
|
||||
if strings.HasPrefix(s.Name, w.ctxt.Pkgpath) && strings.HasPrefix(s.Name[len(w.ctxt.Pkgpath):], "..dict") {
|
||||
if strings.HasPrefix(s.Name, w.ctxt.Pkgpath) && strings.HasPrefix(s.Name[len(w.ctxt.Pkgpath):], ".") && strings.HasPrefix(s.Name[len(w.ctxt.Pkgpath)+1:], objabi.GlobalDictPrefix) {
|
||||
flag2 |= goobj.SymFlagDict
|
||||
}
|
||||
name := s.Name
|
||||
|
@ -13,7 +13,8 @@ import (
|
||||
|
||||
const (
|
||||
ElfRelocOffset = 256
|
||||
MachoRelocOffset = 2048 // reserve enough space for ELF relocations
|
||||
MachoRelocOffset = 2048 // reserve enough space for ELF relocations
|
||||
GlobalDictPrefix = ".dict" // prefix for names of global dictionaries
|
||||
)
|
||||
|
||||
// HeaderString returns the toolchain configuration string written in
|
||||
|
Loading…
Reference in New Issue
Block a user