-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile/internal/ir: add IdentExpr #42990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Change https://golang.org/cl/275306 mentions this issue: |
Change https://golang.org/cl/275305 mentions this issue: |
gopherbot
pushed a commit
that referenced
this issue
Dec 4, 2020
Currently, because we use the same *Name to represent both declaration and uses of an object, it's ambiguous what "n1 == n2" means when comparing two Node values. It can mean any of: Are these the same syntactic element? Is n1 a use of declared variable n2? Are n1 and n2 both uses of the same declared variable? We'd like to introduce a new IdentExpr node to replace use of Name within the AST, but that means those three cases need to be handled differently. The first case needs to stay "n1 == n2", but the other cases need to become "n1.Name() == n2" and "n1.Name() == n2.Name()", respectively. ("n1.Name() == n2.Name()" also currently works for the second case, but eventually we'll want to get rid of the Name.Name method.) This CL introduces helper functions SameSource and Uses to handle these cases. It also introduces DeclaredBy, which is another somewhat common case that the next CL introduces uses of. Passes buildall w/ toolstash -cmp. Updates #42990. Change-Id: Ia816c124446e9067645d5820a8163f295968794f Reviewed-on: https://go-review.googlesource.com/c/go/+/275305 Reviewed-by: Russ Cox <rsc@golang.org> Trust: Matthew Dempsky <mdempsky@google.com>
gopherbot
pushed a commit
that referenced
this issue
Dec 4, 2020
Passes buildall w/ toolstash -cmp. Updates #42990. [git-generate] cd src/cmd/compile/internal/gc rf ' ex { import "cmd/compile/internal/ir" var x, stmt ir.Node x.Name() != nil && x.Name().Defn == stmt -> ir.DeclaredBy(x, stmt) x.Name() == nil || x.Name().Defn != stmt -> !ir.DeclaredBy(x, stmt) } ' Change-Id: I222a757296dbcb5d0889d617d221a9d7319f2d74 Reviewed-on: https://go-review.googlesource.com/c/go/+/275306 Reviewed-by: Russ Cox <rsc@golang.org> Trust: Matthew Dempsky <mdempsky@google.com>
Change https://golang.org/cl/277713 mentions this issue: |
gopherbot
pushed a commit
that referenced
this issue
Dec 15, 2020
This CL substantially reworks how imported declarations are handled, and fixes a number of issues with dot imports. In particular: 1. It eliminates the stub ir.Name declarations that are created upfront during import-declaration processing, allowing this to be deferred to when the declarations are actually needed. (Eventually, this can be deferred even further so we never have to create ir.Names w/ ONONAME, but this CL is already invasive/subtle enough.) 2. During noding, we now use ir.Idents to represent uses of imported declarations, including of dot-imported declarations. 3. Unused dot imports are now reported after type checking, so that we can correctly distinguish whether composite literal keys are a simple identifier (struct literals) or expressions (array/slice/map literals) and whether it might be a use of a dot-imported declaration. 4. It changes the "redeclared" error messages to report the previous position information in the same style as other compiler error messages that reference other source lines. Passes buildall w/ toolstash -cmp. Fixes #6428. Fixes #43164. Fixes #43167. Updates #42990. Change-Id: I40a0a780ec40daf5700fbc3cfeeb7300e1055981 Reviewed-on: https://go-review.googlesource.com/c/go/+/277713 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Trust: Matthew Dempsky <mdempsky@google.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently cmd/compile's AST doesn't distinguish between definition and use of an object. This has been a long standing issue that causes bad positions for error messages.
Now that we have more flexibility in AST nodes, we can fix this. My plan is to introduce a new IdentExpr node to represent uses of a named object, while Name will continue represent the declared name itself.
The text was updated successfully, but these errors were encountered: