Skip to content

Commit

Permalink
cmd/compile: streamline pragma checks for TypeDecl
Browse files Browse the repository at this point in the history
Simplify the handling of pragmas in type declarations within
noder/writer.go. Remove redundant checks by calling checkPragmas once at
the beginning of case *syntax.TypeDecl and eliminate unnecessary else block.
Also, ensure unique ID assignment for function-scoped defined types is only
performed when n.Alias is false.

Fixes a redundancy issue where pragma checks were performed inside both
branches of an if-else statement unnecessarily.

Update golang#46731
  • Loading branch information
aimuz committed Nov 12, 2023
1 parent 8da6405 commit cd66b5a
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/cmd/compile/internal/noder/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2503,19 +2503,15 @@ func (c *declCollector) Visit(n syntax.Node) syntax.Visitor {
return c.withTParams(obj)

case *syntax.TypeDecl:
pw.checkPragmas(n.Pragma, 0, false)

obj := pw.info.Defs[n.Name].(*types2.TypeName)
d := typeDeclGen{TypeDecl: n, implicits: c.implicits}

if n.Alias {
pw.checkPragmas(n.Pragma, 0, false)
} else {
pw.checkPragmas(n.Pragma, 0, false)

// Assign a unique ID to function-scoped defined types.
if c.withinFunc {
*c.typegen++
d.gen = *c.typegen
}
// Assign a unique ID to function-scoped defined types.
if !n.Alias && c.withinFunc {
*c.typegen++
d.gen = *c.typegen
}

pw.typDecls[obj] = d
Expand Down

0 comments on commit cd66b5a

Please sign in to comment.