]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types: remove Sym.Block and Sym.Lastlineno
authorMatthew Dempsky <mdempsky@google.com>
Mon, 21 Mar 2022 18:24:24 +0000 (11:24 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Mon, 21 Mar 2022 18:58:42 +0000 (18:58 +0000)
These fields were used for tracking the last scope/position that an
identifier was declared, so that we could report redeclaration
errors. However, redeclaration errors are now diagnosed by types2 (and
typecheck.Redeclared was removed in CL 388537), so these fields can be
safely pruned.

Updates #51691.

Change-Id: Ifd5ea3f6795fadb420913298d59287c95e4669a1
Reviewed-on: https://go-review.googlesource.com/c/go/+/394276
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/typecheck/dcl.go
src/cmd/compile/internal/typecheck/syms.go
src/cmd/compile/internal/typecheck/universe.go
src/cmd/compile/internal/types/scope.go
src/cmd/compile/internal/types/sizeof_test.go
src/cmd/compile/internal/types/sym.go

index d1eec6d322e9cb3d0623a8bc6701aecd84b89535..45e7a695abd500fa27ccffdc6b9f6a6eaea89329 100644 (file)
@@ -70,8 +70,6 @@ func Declare(n *ir.Name, ctxt ir.Class) {
                n.SetFrameOffset(0)
        }
 
-       s.Block = types.Block
-       s.Lastlineno = base.Pos
        s.Def = n
        n.Class = ctxt
        if ctxt == ir.PFUNC {
index ed3aaecc5a2a2a777cd748d22eca98f4b65f2ce1..6c2e84680bc23b730c4ebd5b6e94e9744b9c4d0a 100644 (file)
@@ -67,7 +67,6 @@ func Lookup(name string) *types.Sym {
 // but does not make them visible to user code.
 func InitRuntime() {
        base.Timer.Start("fe", "loadsys")
-       types.Block = 1
 
        typs := runtimeTypes()
        for _, d := range &runtimeDecls {
index 204c31b7582f92e0ddccd0828c4770916aac3063..a49bf5793e85ae64db1d0d3e9d9a20e48d8b185f 100644 (file)
@@ -91,14 +91,12 @@ func InitUniverse() {
 
        s = Lookup("_")
        types.BlankSym = s
-       s.Block = -100
        s.Def = NewName(s)
        ir.AsNode(s.Def).SetType(types.Types[types.TBLANK])
        ir.BlankNode = ir.AsNode(s.Def)
        ir.BlankNode.SetTypecheck(1)
 
        s = types.BuiltinPkg.Lookup("_")
-       s.Block = -100
        s.Def = NewName(s)
        ir.AsNode(s.Def).SetType(types.Types[types.TBLANK])
 
@@ -222,6 +220,5 @@ func DeclareUniverse() {
                }
 
                s1.Def = s.Def
-               s1.Block = s.Block
        }
 }
index d7c454f3795e416ce1af5049cfb029f1e5b2a687..e577b7aa532cb1915d7844a700dab580a459efdf 100644 (file)
@@ -6,21 +6,15 @@ package types
 
 import (
        "cmd/compile/internal/base"
-       "cmd/internal/src"
 )
 
 // Declaration stack & operations
 
-var blockgen int32 = 1 // max block number
-var Block int32 = 1    // current block number
-
 // A dsym stores a symbol's shadowed declaration so that it can be
 // restored once the block scope ends.
 type dsym struct {
-       sym        *Sym // sym == nil indicates stack mark
-       def        Object
-       block      int32
-       lastlineno src.XPos // last declaration for diagnostic
+       sym *Sym // sym == nil indicates stack mark
+       def Object
 }
 
 // dclstack maintains a stack of shadowed symbol declarations so that
@@ -31,10 +25,8 @@ var dclstack []dsym
 // it can be shadowed by a new declaration within a nested block scope.
 func Pushdcl(s *Sym) {
        dclstack = append(dclstack, dsym{
-               sym:        s,
-               def:        s.Def,
-               block:      s.Block,
-               lastlineno: s.Lastlineno,
+               sym: s,
+               def: s.Def,
        })
 }
 
@@ -46,14 +38,11 @@ func Popdcl() {
                s := d.sym
                if s == nil {
                        // pop stack mark
-                       Block = d.block
                        dclstack = dclstack[:i-1]
                        return
                }
 
                s.Def = d.def
-               s.Block = d.block
-               s.Lastlineno = d.lastlineno
 
                // Clear dead pointer fields.
                d.sym = nil
@@ -65,11 +54,8 @@ func Popdcl() {
 // Markdcl records the start of a new block scope for declarations.
 func Markdcl() {
        dclstack = append(dclstack, dsym{
-               sym:   nil, // stack mark
-               block: Block,
+               sym: nil, // stack mark
        })
-       blockgen++
-       Block = blockgen
 }
 
 func isDclstackValid() bool {
index d37c1730581c38be38a36d8e067d66deac34b94d..0c46077dfae4eb297cf13b25b17f52a86aa7ef83 100644 (file)
@@ -20,7 +20,7 @@ func TestSizeof(t *testing.T) {
                _32bit uintptr     // size on 32bit platforms
                _64bit uintptr     // size on 64bit platforms
        }{
-               {Sym{}, 44, 72},
+               {Sym{}, 32, 64},
                {Type{}, 64, 112},
                {Map{}, 20, 40},
                {Forward{}, 20, 32},
index fb642f52f881418302738b26d3665f8d2040441f..927ebc453a616f4e411cf7e233d1f6d3804c7215 100644 (file)
@@ -7,7 +7,6 @@ package types
 import (
        "cmd/compile/internal/base"
        "cmd/internal/obj"
-       "cmd/internal/src"
        "unicode"
        "unicode/utf8"
 )
@@ -32,14 +31,15 @@ type Sym struct {
        Pkg  *Pkg
        Name string // object name
 
-       // Def, Block, and Lastlineno are saved and restored by Pushdcl/Popdcl.
-
        // The unique ONAME, OTYPE, OPACK, or OLITERAL node that this symbol is
        // bound to within the current scope. (Most parts of the compiler should
        // prefer passing the Node directly, rather than relying on this field.)
-       Def        Object
-       Block      int32    // blocknumber to catch redeclaration
-       Lastlineno src.XPos // last declaration for diagnostic
+       //
+       // Def is saved and restored by Pushdcl/Popdcl.
+       //
+       // Deprecated: New code should avoid depending on Sym.Def. Add
+       // mdempsky@ as a reviewer for any CLs involving Sym.Def.
+       Def Object
 
        flags bitset8
 }