-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
cmd/compile: eliminate base.Pos and ir.CurFunc #19683
Comments
One caveat. If the function in question calls nod, then it might need to accept both I'll send an example CL of this soon, which also introduces Unless, @mdempsky, you dislike this, in which case we need another strategy. :) |
Presumably many functions don't need an extra src.XPos because they can get the info from any of the nodes they are working with? |
@josharian I was thinking about that, and I think we can push the Curfn logic into callers. We don't actually need Curfn for OPACK or OLABEL, just ONAME and for setting IsHiddenClosure. I think ONAME can be handled by refactoring all the The IsHiddenClosure logic can probably just be set as appropriate in closure.go instead. |
@griesemer Yeah, if the position information can be obtained using existing parameters, that's preferable. But there are a lot of helper functions in dcl.go that construct Nodes, though none of their parameters include position information currently. Some of those will probably need to be extended (e.g., newname?), and others can probably just use src.NoPos (e.g., typenod?). |
SGTM. Do you want to tackle this set of things, or shall I? |
@josharian I can look into it. |
CL https://golang.org/cl/38592 mentions this issue. |
CL https://golang.org/cl/38597 mentions this issue. |
@mdempsky nod/Curfn is top of my queue now. Looks like the remaining item there is:
Are you actively working on this? If not, I will start on it. |
@josharian I've got a CL for it, then got side tracked pondering what Node.Addable signifies and whether we could get rid of it. I'll finish up the CL and mail it in just a sec. |
Concurrent compilation requires providing an explicit position and curfn to temp. This implementation of tempAt temporarily continues to use the globals lineno and Curfn, so as not to collide with mdempsky's work for #19683 eliminating the Curfn dependency from func nod. Updates #15756 Updates #19683 Change-Id: Ib3149ca4b0740e9f6eea44babc6f34cdd63028a9 Reviewed-on: https://go-review.googlesource.com/38592 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
CL https://golang.org/cl/38770 mentions this issue. |
Updates #19683 Change-Id: Ic00d5a9807200791cf37553f4f802dbf27beea19 Reviewed-on: https://go-review.googlesource.com/38770 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
CL https://golang.org/cl/38735 mentions this issue. |
CL https://golang.org/cl/39191 mentions this issue. |
newnamel is newname but with no dependency on lineno or Curfn. This makes it suitable for use in a concurrent back end. Use it now to make tempAt global-free. The decision to push the assignment to n.Name.Curfn to the caller of newnamel is based on mdempsky's comments in #19683 that he'd like to do that for callers of newname as well. Passes toolstash-check. No compiler performance impact. Updates #19683 Updates #15756 Change-Id: Idc461a1716916d268c9ff323129830d9a6e4a4d9 Reviewed-on: https://go-review.googlesource.com/39191 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Replace yyerror usages with yyerrorl in function typecheckswitch. Updates #19683. Change-Id: I7188cdecddd2ce4e06b8cee45b57f3765a979405 Reviewed-on: https://go-review.googlesource.com/38597 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
I'm looking into moving const.go to yyerrorl (there are about a dozen func toflt(v Val) Val which takes a Val and cast it to a Mpflt Val. Since those functions
Opinions? |
@ALTree I think either of those options sounds reasonable. I suspect threading src.XPos is a bit simpler. If you're feeling adventurous, you can take a look at how go/constant and go/types handle this. E.g., I notice go/constant's corresponding functions (ToInt, ToFloat, etc) just return an invalid value (Unknown), rather than reporting errors internally. |
Biggest difficulty I'm having right now (looking at typechecking, but @mdempsky wrote:
But I think there's an even more annoying problem: the fact that for
The two Currently exploring the latter option. |
CL https://golang.org/cl/40500 mentions this issue. |
I started down this path here: https://go-review.googlesource.com/c/38735/ It had a more substantial performance hit than I was expecting though. I haven't had a chance to investigate why. (Maybe it's really just due to allocating more Nodes.) Note though that typecheck discards OPARENs, so that solution still loses fine-grained position information for later on in the compiler. @neelance is currently experimenting in the opposite direction: allocating extra ONAME Nodes, but sharing their underlying Name fields. |
Updates golang#19683 Change-Id: Ic00d5a9807200791cf37553f4f802dbf27beea19 Reviewed-on: https://go-review.googlesource.com/38770 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
newnamel is newname but with no dependency on lineno or Curfn. This makes it suitable for use in a concurrent back end. Use it now to make tempAt global-free. The decision to push the assignment to n.Name.Curfn to the caller of newnamel is based on mdempsky's comments in golang#19683 that he'd like to do that for callers of newname as well. Passes toolstash-check. No compiler performance impact. Updates golang#19683 Updates golang#15756 Change-Id: Idc461a1716916d268c9ff323129830d9a6e4a4d9 Reviewed-on: https://go-review.googlesource.com/39191 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Replace yyerror usages with yyerrorl in function typecheckswitch. Updates golang#19683. Change-Id: I7188cdecddd2ce4e06b8cee45b57f3765a979405 Reviewed-on: https://go-review.googlesource.com/38597 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
While looking at the typechecker I noticed pos info for a few errors is not currently tested. They're not hard to find
I uploaded a change that adds pos info tests for error messages in the typecheker for every untested Looking for reviewers. This will be useful regardless of the path for |
This change adds line position tests for several yyerror calls in the typechecker that are currently not tested in any way. Untested yyerror calls were found by replacing them with yerrorl(src.NoXPos, ...) (thus destroying position information in the error), and then running the test suite. No failures means no test coverage for the relevant yyerror call. For #19683 Change-Id: Iedb3d2f02141b332e9bfa76dbf5ae930ad2fddc3 Reviewed-on: https://go-review.googlesource.com/41477 Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
CL https://golang.org/cl/41477 mentions this issue. |
Change https://golang.org/cl/69910 mentions this issue: |
Change https://golang.org/cl/70251 mentions this issue: |
Follow CL 41477 and add two more line position tests for yyerror calls in the typechecker which are currently not tested. Update #19683 Change-Id: Iacd865195a3bfba87d8c22655382af267aba47a9 Reviewed-on: https://go-review.googlesource.com/70251 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Change https://golang.org/cl/80298 mentions this issue: |
typenod is only used for anonymous types, which don't logically have position information. Passes toolstash-check. Updates #19683. Change-Id: I505424ae980b88c7deed5f23502c3cecb3dc0702 Reviewed-on: https://go-review.googlesource.com/80298 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
Change https://golang.org/cl/100335 mentions this issue: |
New tasks include: golang/go#19675 cmd/vet: report uses of -0 in float32/64 context golang/go#19683 cmd/compile: eliminate usages of global lineno golang/go#19670 x/tools/go/ssa: make opaqueType less annoying to use golang/go#19636 encoding/base64: decoding is slow golang/go#23471 x/perf/cmd/benchstat: tips or quickstart for newcomers golang/go#19577 test: errorcheck support for intraline errors golang/go#19490 cmd/vet: reduce the amount of false positives for -shadow mode golang/go#19042 cmd/internal/obj: optimize wrapper method prologue for branch prediction golang/go#19013 cmd/compile: add tool for understanding/debugging SSA rules
Use nodl instead of nod to avoid setting and resetting lineo. Passes toolstash-check. Updates #19683 Change-Id: I6a47a7ba43a11352767029eced29f08dff8501a2 Reviewed-on: https://go-review.googlesource.com/100335 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Change https://golang.org/cl/114875 mentions this issue: |
Change https://golang.org/cl/114915 mentions this issue: |
Also remove lineno from typecheckdeftype since copytype was the only user of it and typecheck uses lineno independently. toolstach-check passed. Updates #19683. Change-Id: I1663fdb8cf519d505cc087c8657dcbff3c8b1a0a Reviewed-on: https://go-review.googlesource.com/114875 Run-TryBot: Yury Smolsky <yury@smolsky.by> Reviewed-by: Robert Griesemer <gri@golang.org>
n.Pos.IsKnown() is not needed because it is performed in setlineno. toolstash-check passed. Updates #19683. Change-Id: I34d6a0e6dc9970679d99e8f3424f289ebf1e86ba Reviewed-on: https://go-review.googlesource.com/114915 Run-TryBot: Yury Smolsky <yury@smolsky.by> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
@mdempsky I'm going to change For me, the later seems to be more meaningful. |
|
If we simultaneously change all instances of Fatalf, then we could just leave it called Fatalf. If we want to do it incrementally, FatalfAt seems fine, and we can rename once the migration is complete. |
Seems a bit easier to do it incrementally. There're other package depend on gc.Fatalf, at least types.Fatalf. There can be more that I don't aware of. Also I see many func/method in types package, example this one does call |
Incremental is totally fine, but FYI cmd is entirely self-contained. As long as "go test cmd" builds and passes, you've found all of them. gofmt -r and golang.org/x/tools/cmd/eg are both very effective for working within cmd.
Fatalf is like panic and never returns. But unlike panic, the compiler doesn't know that Fatalf doesn't return, and callers still need to satisfy type checking, hence the nil return. |
Change https://golang.org/cl/188539 mentions this issue: |
state and ssafn both have their own Fatalf, so use them instead of global Fatalf. Updates #19683 Change-Id: Ie02a961d4285ab0a3f3b8d889a5b498d926ed567 Reviewed-on: https://go-review.googlesource.com/c/go/+/188539 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
state and ssafn both have their own Fatalf, so use them instead of global Fatalf. Updates golang#19683 Change-Id: Ie02a961d4285ab0a3f3b8d889a5b498d926ed567 Reviewed-on: https://go-review.googlesource.com/c/go/+/188539 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
state and ssafn both have their own Fatalf, so use them instead of global Fatalf. Updates golang#19683 Change-Id: Ie02a961d4285ab0a3f3b8d889a5b498d926ed567 Reviewed-on: https://go-review.googlesource.com/c/go/+/188539 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Replace usage of yyerror with yyerrorl in checkdefergo and copytype in typecheck.go. All covered error messages already appear in the tests and the yyerror replacement did not lead to any tests failing. Passes toolstash-check Updates #19683 Change-Id: I735e83bcda7ddc6a14afb22e50200bcbb9192fc4 Reviewed-on: https://go-review.googlesource.com/c/go/+/69910 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This is an umbrella issue for eliminating the global
lineno
variable from package gc. Filing as a HelpWanted issue because I think it's a relatively low-barrier-to-entry issue that people can usefully contribute to the compiler with small incremental improvements.Here's the general algorithm:
Bar
that uses lineno.Bar
andBarl
;Barl
takes an additionalpos src.XPos
parameter, andBar
just callsBarl
withlineno
.Bar
to useBarl
. Ideally, the caller can supply the position information directly (e.g., vian.Pos
or something); but if necessary, just uselineno
and later we'll recursively apply this procedure on the caller function.An example of this is
yyerror
andWarn
now haveyyerrorl
and `Warnl' functions that we're trying to use instead.Note: sometimes uses of lineno should just go away entirely (e.g., CL 38393 / 80c4b53). I suggest pinging here to discuss instances and/or express interest in working on this to avoid duplicating work (e.g., @josharian and I are looking at this in the backend for #15756).
The text was updated successfully, but these errors were encountered: