diff options
author | LE Manh Cuong <cuong.manhle.vn@gmail.com> | 2019-05-04 00:24:53 +0700 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2019-05-21 03:03:01 +0000 |
commit | 2d7cb295fdda94f3d62588b7bb01a4d8b445417a (patch) | |
tree | 995e58f0c16da777a7909a1b5645f6d1a65bfd46 /src/cmd/compile/internal/types/sym.go | |
parent | ab724d43efe7e1a7516c1d13e40b55dca26a61b4 (diff) | |
download | go-2d7cb295fdda94f3d62588b7bb01a4d8b445417a.tar.gz go-2d7cb295fdda94f3d62588b7bb01a4d8b445417a.zip |
cmd/compile: clarify the difference between types.Sym and obj.LSym
Both types.Sym and obj.LSym have the field Name, and that field is
widely used in compiler source. It can lead to confusion that when to
use which one.
So, adding documentation for clarifying the difference between them,
eliminate the confusion, or at least, make the code which use them
clearer for the reader.
See https://github.com/golang/go/issues/31252#issuecomment-481929174
Change-Id: I31f7fc6e4de4cf68f67ab2e3a385a7f451c796f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/175019
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types/sym.go')
-rw-r--r-- | src/cmd/compile/internal/types/sym.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/types/sym.go b/src/cmd/compile/internal/types/sym.go index 13761c7615..2779c368a9 100644 --- a/src/cmd/compile/internal/types/sym.go +++ b/src/cmd/compile/internal/types/sym.go @@ -11,14 +11,20 @@ import ( "unicode/utf8" ) -// Sym represents an object name. Most commonly, this is a Go identifier naming -// an object declared within a package, but Syms are also used to name internal -// synthesized objects. +// Sym represents an object name in a segmented (pkg, name) namespace. +// Most commonly, this is a Go identifier naming an object declared within a package, +// but Syms are also used to name internal synthesized objects. // // As an exception, field and method names that are exported use the Sym // associated with localpkg instead of the package that declared them. This // allows using Sym pointer equality to test for Go identifier uniqueness when // handling selector expressions. +// +// Ideally, Sym should be used for representing Go language constructs, +// while cmd/internal/obj.LSym is used for representing emitted artifacts. +// +// NOTE: In practice, things can be messier than the description above +// for various reasons (historical, convenience). type Sym struct { Importdef *Pkg // where imported definition was found Linkname string // link name |