Skip to content

Commit 1780807

Browse files
mdempskygopherbot
authored andcommitted
cmd/compile/internal/noder: remove unused noding code
This CL simplifies and removes some old noding code, which isn't necessary any more. Most notably, we no longer need separate posMaps for each noder, because noders are only used for parsing now. Before we started using types2, noders were also responsible for constructed (untyped) IR, so posMaps were necessary to translate syntax.Pos into src.XPos. Change-Id: Ic761abcd727f5ecefc71b611635a0f5b088c941f Reviewed-on: https://go-review.googlesource.com/c/go/+/463738 Auto-Submit: Matthew Dempsky <[email protected]> Run-TryBot: Matthew Dempsky <[email protected]> Reviewed-by: Keith Randall <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 7cf8593 commit 1780807

File tree

4 files changed

+13
-94
lines changed

4 files changed

+13
-94
lines changed

src/cmd/compile/internal/noder/irgen.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@ var versionErrorRx = regexp.MustCompile(`requires go[0-9]+\.[0-9]+ or later`)
1919

2020
// checkFiles configures and runs the types2 checker on the given
2121
// parsed source files and then returns the result.
22-
func checkFiles(noders []*noder) (posMap, *types2.Package, *types2.Info) {
22+
func checkFiles(m posMap, noders []*noder) (*types2.Package, *types2.Info) {
2323
if base.SyntaxErrors() != 0 {
2424
base.ErrorExit()
2525
}
2626

2727
// setup and syntax error reporting
28-
var m posMap
2928
files := make([]*syntax.File, len(noders))
3029
for i, p := range noders {
31-
m.join(&p.posMap)
3230
files[i] = p.file
3331
}
3432

@@ -117,7 +115,7 @@ func checkFiles(noders []*noder) (posMap, *types2.Package, *types2.Info) {
117115
base.FatalfAt(src.NoXPos, "conf.Check error: %v", err)
118116
}
119117

120-
return m, pkg, info
118+
return pkg, info
121119
}
122120

123121
// A cycleFinder detects anonymous interface cycles (go.dev/issue/56103).

src/cmd/compile/internal/noder/noder.go

Lines changed: 7 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"cmd/compile/internal/typecheck"
2222
"cmd/compile/internal/types"
2323
"cmd/internal/objabi"
24-
"cmd/internal/src"
2524
)
2625

2726
func LoadPackage(filenames []string) {
@@ -62,9 +61,10 @@ func LoadPackage(filenames []string) {
6261
}()
6362

6463
var lines uint
64+
var m posMap
6565
for _, p := range noders {
6666
for e := range p.err {
67-
p.errorAt(e.Pos, "%s", e.Msg)
67+
base.ErrorfAt(m.makeXPos(e.Pos), "%s", e.Msg)
6868
}
6969
if p.file == nil {
7070
base.ErrorExit()
@@ -73,11 +73,7 @@ func LoadPackage(filenames []string) {
7373
}
7474
base.Timer.AddEvent(int64(lines), "lines")
7575

76-
unified(noders)
77-
}
78-
79-
func (p *noder) errorAt(pos syntax.Pos, format string, args ...interface{}) {
80-
base.ErrorfAt(p.makeXPos(pos), format, args...)
76+
unified(m, noders)
8177
}
8278

8379
// trimFilename returns the "trimmed" filename of b, which is the
@@ -101,14 +97,10 @@ func trimFilename(b *syntax.PosBase) string {
10197

10298
// noder transforms package syntax's AST into a Node tree.
10399
type noder struct {
104-
posMap
105-
106-
file *syntax.File
107-
linknames []linkname
108-
pragcgobuf [][]string
109-
err chan syntax.Error
110-
importedUnsafe bool
111-
importedEmbed bool
100+
file *syntax.File
101+
linknames []linkname
102+
pragcgobuf [][]string
103+
err chan syntax.Error
112104
}
113105

114106
// linkname records a //go:linkname directive.
@@ -118,28 +110,6 @@ type linkname struct {
118110
remote string
119111
}
120112

121-
func (p *noder) processPragmas() {
122-
for _, l := range p.linknames {
123-
if !p.importedUnsafe {
124-
p.errorAt(l.pos, "//go:linkname only allowed in Go files that import \"unsafe\"")
125-
continue
126-
}
127-
n := ir.AsNode(typecheck.Lookup(l.local).Def)
128-
if n == nil || n.Op() != ir.ONAME {
129-
if types.AllowsGoVersion(1, 18) {
130-
p.errorAt(l.pos, "//go:linkname must refer to declared function or variable")
131-
}
132-
continue
133-
}
134-
if n.Sym().Linkname != "" {
135-
p.errorAt(l.pos, "duplicate //go:linkname for %s", l.local)
136-
continue
137-
}
138-
n.Sym().Linkname = l.remote
139-
}
140-
typecheck.Target.CgoPragmas = append(typecheck.Target.CgoPragmas, p.pragcgobuf...)
141-
}
142-
143113
var unOps = [...]ir.Op{
144114
syntax.Recv: ir.ORECV,
145115
syntax.Mul: ir.ODEREF,
@@ -176,23 +146,6 @@ var binOps = [...]ir.Op{
176146
syntax.Shr: ir.ORSH,
177147
}
178148

179-
func wrapname(pos src.XPos, x ir.Node) ir.Node {
180-
// These nodes do not carry line numbers.
181-
// Introduce a wrapper node to give them the correct line.
182-
switch x.Op() {
183-
case ir.OTYPE, ir.OLITERAL:
184-
if x.Sym() == nil {
185-
break
186-
}
187-
fallthrough
188-
case ir.ONAME, ir.ONONAME:
189-
p := ir.NewParenExpr(pos, x)
190-
p.SetImplicit(true)
191-
return p
192-
}
193-
return x
194-
}
195-
196149
// error is called concurrently if files are parsed concurrently.
197150
func (p *noder) error(err error) {
198151
p.err <- err.(syntax.Error)
@@ -442,26 +395,6 @@ func Renameinit() *types.Sym {
442395
return s
443396
}
444397

445-
func varEmbed(makeXPos func(syntax.Pos) src.XPos, name *ir.Name, decl *syntax.VarDecl, pragma *pragmas, haveEmbed bool) {
446-
pragmaEmbeds := pragma.Embeds
447-
pragma.Embeds = nil
448-
if len(pragmaEmbeds) == 0 {
449-
return
450-
}
451-
452-
if err := checkEmbed(decl, haveEmbed, typecheck.DeclContext != ir.PEXTERN); err != nil {
453-
base.ErrorfAt(makeXPos(pragmaEmbeds[0].Pos), "%s", err)
454-
return
455-
}
456-
457-
var embeds []ir.Embed
458-
for _, e := range pragmaEmbeds {
459-
embeds = append(embeds, ir.Embed{Pos: makeXPos(e.Pos), Patterns: e.Patterns})
460-
}
461-
typecheck.Target.Embeds = append(typecheck.Target.Embeds, name)
462-
name.Embed = &embeds
463-
}
464-
465398
func checkEmbed(decl *syntax.VarDecl, haveEmbed, withinFunc bool) error {
466399
switch {
467400
case !haveEmbed:

src/cmd/compile/internal/noder/posmap.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,3 @@ func (m *posMap) makeSrcPosBase(b0 *syntax.PosBase) *src.PosBase {
7272

7373
return b1
7474
}
75-
76-
func (m *posMap) join(other *posMap) {
77-
if m.bases == nil {
78-
m.bases = make(map[*syntax.PosBase]*src.PosBase)
79-
}
80-
for k, v := range other.bases {
81-
if m.bases[k] != nil {
82-
base.Fatalf("duplicate posmap bases")
83-
}
84-
m.bases[k] = v
85-
}
86-
}

src/cmd/compile/internal/noder/unified.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ var localPkgReader *pkgReader
6868
// the unified IR has the full typed AST needed for introspection during step (1).
6969
// In other words, we have all the necessary information to build the generic IR form
7070
// (see writer.captureVars for an example).
71-
func unified(noders []*noder) {
71+
func unified(m posMap, noders []*noder) {
7272
inline.InlineCall = unifiedInlineCall
7373
typecheck.HaveInlineBody = unifiedHaveInlineBody
7474

75-
data := writePkgStub(noders)
75+
data := writePkgStub(m, noders)
7676

7777
// We already passed base.Flag.Lang to types2 to handle validating
7878
// the user's source code. Bump it up now to the current version and
@@ -202,8 +202,8 @@ func readBodies(target *ir.Package, duringInlining bool) {
202202
// writePkgStub type checks the given parsed source files,
203203
// writes an export data package stub representing them,
204204
// and returns the result.
205-
func writePkgStub(noders []*noder) string {
206-
m, pkg, info := checkFiles(noders)
205+
func writePkgStub(m posMap, noders []*noder) string {
206+
pkg, info := checkFiles(m, noders)
207207

208208
pw := newPkgWriter(m, pkg, info)
209209

0 commit comments

Comments
 (0)