mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00: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
5 changed files with 13 additions and 11 deletions
|
|
@ -401,10 +401,7 @@ func (g *irgen) buildClosure(outer *ir.Func, x ir.Node) ir.Node {
|
||||||
var dictVar *ir.Name
|
var dictVar *ir.Name
|
||||||
var dictAssign *ir.AssignStmt
|
var dictAssign *ir.AssignStmt
|
||||||
if outer != nil {
|
if outer != nil {
|
||||||
// Note: for now this is a compile-time constant, so we don't really need a closure
|
dictVar = ir.NewNameAt(pos, typecheck.LookupNum(typecheck.LocalDictName, g.dnum))
|
||||||
// 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))
|
|
||||||
g.dnum++
|
g.dnum++
|
||||||
dictVar.Class = ir.PAUTO
|
dictVar.Class = ir.PAUTO
|
||||||
typed(types.Types[types.TUINTPTR], dictVar)
|
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)
|
newf.Dcl = make([]*ir.Name, 0, len(gf.Dcl)+1)
|
||||||
|
|
||||||
// Create the needed dictionary param
|
// Create the needed dictionary param
|
||||||
dictionarySym := newsym.Pkg.Lookup(".dict")
|
dictionarySym := newsym.Pkg.Lookup(typecheck.LocalDictName)
|
||||||
dictionaryType := types.Types[types.TUINTPTR]
|
dictionaryType := types.Types[types.TUINTPTR]
|
||||||
dictionaryName := ir.NewNameAt(gf.Pos(), dictionarySym)
|
dictionaryName := ir.NewNameAt(gf.Pos(), dictionarySym)
|
||||||
typed(dictionaryType, dictionaryName)
|
typed(dictionaryType, dictionaryName)
|
||||||
|
|
@ -731,7 +728,7 @@ func (g *irgen) genericSubst(newsym *types.Sym, nameNode *ir.Name, shapes []*typ
|
||||||
dictionaryName.Curfn = newf
|
dictionaryName.Curfn = newf
|
||||||
newf.Dcl = append(newf.Dcl, dictionaryName)
|
newf.Dcl = append(newf.Dcl, dictionaryName)
|
||||||
for _, n := range gf.Dcl {
|
for _, n := range gf.Dcl {
|
||||||
if n.Sym().Name == ".dict" {
|
if n.Sym().Name == typecheck.LocalDictName {
|
||||||
panic("already has dictionary")
|
panic("already has dictionary")
|
||||||
}
|
}
|
||||||
newf.Dcl = append(newf.Dcl, subst.localvar(n))
|
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.
|
// Copy that closure variable to a local one.
|
||||||
// Note: this allows the dictionary to be captured by child closures.
|
// Note: this allows the dictionary to be captured by child closures.
|
||||||
// See issue 47723.
|
// 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)
|
typed(types.Types[types.TUINTPTR], ldict)
|
||||||
ldict.Class = ir.PAUTO
|
ldict.Class = ir.PAUTO
|
||||||
ldict.Curfn = newfn
|
ldict.Curfn = newfn
|
||||||
|
|
|
||||||
|
|
@ -2196,7 +2196,7 @@ func (w *exportWriter) localIdent(s *types.Sym) {
|
||||||
return
|
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)
|
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).
|
// information (e.g. length field for OSLICELIT).
|
||||||
const go117ExportTypes = true
|
const go117ExportTypes = true
|
||||||
const Go117ExportTypes = go117ExportTypes
|
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/base"
|
||||||
"cmd/compile/internal/ir"
|
"cmd/compile/internal/ir"
|
||||||
"cmd/compile/internal/types"
|
"cmd/compile/internal/types"
|
||||||
|
"cmd/internal/objabi"
|
||||||
"cmd/internal/src"
|
"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 := makeInstName1(gf.Name, targs, hasBrackets)
|
||||||
name = ".dict." + name
|
name = fmt.Sprintf("%s.%s", objabi.GlobalDictPrefix, name)
|
||||||
return gf.Pkg.Lookup(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 {
|
if strings.HasPrefix(s.Name, "go.itab.") && s.Type == objabi.SRODATA {
|
||||||
flag2 |= goobj.SymFlagItab
|
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
|
flag2 |= goobj.SymFlagDict
|
||||||
}
|
}
|
||||||
name := s.Name
|
name := s.Name
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import (
|
||||||
const (
|
const (
|
||||||
ElfRelocOffset = 256
|
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
|
// HeaderString returns the toolchain configuration string written in
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue