aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/syntax/nodes.go
AgeCommit message (Collapse)Author
2021-01-21[dev.typeparams] cmd/compile: use nil instead of syntax.ImplicitOneRobert Griesemer
Represent x++/-- as x +=/-= with the RHS of the assignment being nil rather than syntax.ImplicitOne. Dependent code already had to check for syntax.ImplicitOne, but then shared some existing code for regular assignment operations. Now always handle this case fully explicit, which simplifies the code. Change-Id: I28c7918153c27cbbf97b041d0c85ff027c58687c Reviewed-on: https://go-review.googlesource.com/c/go/+/285172 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-15[dev.typeparams] cmd/compile/internal/types2: don't crash if import path is ↵Robert Griesemer
missing In package syntax: - fix parser appendGroup to not add nil entries - non-string paths are syntax errors per the spec; report in parser - document ImportDecl.Path invariants In package types2: - guard against absent paths In package gc: - guard against absent paths Fixes #43190. Change-Id: Ic6a06f6a96b7f519feaa1ceaf4376fc5ab0f0129 Reviewed-on: https://go-review.googlesource.com/c/go/+/278114 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-14[dev.typeparams] cmd/compile/internal/syntax: export NewName and use itRobert Griesemer
Most syntax.Nodes are allocated in one place and there didn't seem a need to provide factory methods - so as a matter of API design, all nodes are "naked", without any constructors. However, Name nodes are frequently used/replaced and also are created as helper nodes in clients (types2). Make an exception and export NewName. Change-Id: I4b5c499d65bba74592dea68b0936c118b3edaca7 Reviewed-on: https://go-review.googlesource.com/c/go/+/277572 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2020-11-25[dev.typeparams] merge dev.regabi 41f3af9d04 into dev.typeparamsRuss Cox
This brings in the new ir.Node interface, replacing *gc.Node. Change-Id: I82c623655eee08d77d623babf22ec4d91f9aa3cd
2020-11-25[dev.regabi] cmd/compile: remove uses of dummyRuss Cox
Per https://developers.google.com/style/inclusive-documentation, since we are editing some of this code anyway and it is easier to put the cleanup in a separate CL. Change-Id: Ib6b851f43f9cc0a57676564477d4ff22abb1cee5 Reviewed-on: https://go-review.googlesource.com/c/go/+/273106 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-10-14[dev.typeparams] cmd/compile/internal/syntax: always use IndexExpr node for ↵Robert Griesemer
type instantiation Per @mdempsky's suggestion: Instead of representing a type instantiation T[P] by an IndexExpr node, and a type instantiation with multiple type arguments T[P1, P2] by a CallExpr node with special Brackets flag, always use an IndexExpr. Use a ListExpr as index in the (less common) case of multiple type arguments. This removes the need for the CallExpr.Brackets field and cleans up the parser code around type instantiations. Backport of syntax package changes from https://golang.org/cl/262020. Change-Id: I32e8bc4eafac5b3ef2e7eb40fa8c790a5a905b69 Reviewed-on: https://go-review.googlesource.com/c/go/+/262137 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-10-13[dev.typeparams] cmd/compile/internal/syntax: prepare syntax nodes for type ↵Robert Griesemer
parameters - add TParamList fields to TypeDecl, FuncDecl - also: change File.Lines to File.EOF so we have the actual file end position Change-Id: Ia345f888080a884f7ac5cefd8bff3d80e4a59cdc Reviewed-on: https://go-review.googlesource.com/c/go/+/261657 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-04-21cmd/compile: detect and diagnose invalid //go: directive placementRuss Cox
Thie CL changes cmd/compile/internal/syntax to give the gc half of the compiler more control over pragma handling, so that it can prepare better errors, diagnose misuse, and so on. Before, the API between the two was hard-coded as a uint16. Now it is an interface{}. This should set us up better for future directives. In addition to the split, this CL emits a "misplaced compiler directive" error for any directive that is in a place where it has no effect. I've certainly been confused in the past by adding comments that were doing nothing and not realizing it. This should help avoid that kind of confusion. The rule, now applied consistently, is that a //go: directive must appear on a line by itself immediately before the declaration specifier it means to apply to. See cmd/compile/doc.go for precise text and test/directive.go for examples. This may cause some code to stop compiling, but that code was broken. For example, this code formerly applied the //go:noinline to f (not c) but now will fail to compile: //go:noinline const c = 1 func f() {} Change-Id: Ieba9b8d90a27cfab25de79d2790a895cefe5296f Reviewed-on: https://go-review.googlesource.com/c/go/+/228578 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2019-08-29cmd/compile/internal/syntax: add BasicLit.Bad field for lexical errorsRobert Griesemer
The new (internal) field scanner.bad indicates whether a syntax error occurred while scanning a literal; the corresponding scanner.lit string may be syntactically incorrect in that case. Store the value of scanner.bad together with the scanner.lit in BasicLit. Clean up error handling so that all syntactic errors use one of the scanner's error reporting methods which also set scanner.bad. Make use of the new field in a few places where we used to track a prior error separately. Preliminary step towards fixing #32133 in a comprehensive manner. Change-Id: I4d79ad6e3b50632dd5fb3fc32ca3df0598ee77b4 Reviewed-on: https://go-review.googlesource.com/c/go/+/192278 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-04-03cmd/compile/internal/syntax: update a couple of commentsRobert Griesemer
Change-Id: Ie84d0e61697922c1e808d815fb7d9aec694ee8e9 Reviewed-on: https://go-review.googlesource.com/104615 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-04-03cmd/compile: better handling of incorrect type switchesRobert Griesemer
Don't report errors if we don't have a correct type switch guard; instead ignore it and leave it to the type-checker to report the error. This leads to better error messages concentrating on the type switch guard rather than errors around (confusing) syntactic details. Also clean up some code setting up AssertExpr (they never have a nil Type field) and remove some incorrect TODOs. Fixes #24470. Change-Id: I69512f36e0417e3b5ea9c8856768e04b19d654a8 Reviewed-on: https://go-review.googlesource.com/103615 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-02-26cmd/compile/internal/syntax: remove dependency on cmd/internal/srcRobert Griesemer
For dependency reasons, the data structure implementing source positions in the compiler is in cmd/internal/src. It contains highly compiler specific details (e.g. inlining index). This change introduces a parallel but simpler position representation, defined in the syntax package, which removes that package's dependency on cmd/internal/src, and also removes the need to deal with certain filename-specific operations (defined by the needs of the compiler) in the syntax package. As a result, the syntax package becomes again a compiler- independent, stand-alone package that at some point might replace (or augment) the existing top-level go/* syntax-related packages. Additionally, line directives that update column numbers are now correctly tracked through the syntax package, with additional tests added. (The respective changes also need to be made in cmd/internal/src; i.e., the compiler accepts but still ignores column numbers in line directives.) This change comes at the cost of a new position translation step, but that step is cheap because it only needs to do real work if the position base changed (i.e., if there is a new file, or new line directive). There is no noticeable impact on overall compiler performance measured with `compilebench -count 5 -alloc`: name old time/op new time/op delta Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5) Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5) GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5) Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5) SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5) Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5) GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5) Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5) Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5) XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5) StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5) name old user-time/op new user-time/op delta Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5) Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5) GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5) Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4) SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5) Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5) GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5) Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5) Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5) XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5) name old alloc/op new alloc/op delta Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5) Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5) GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5) Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5) SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5) Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5) GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5) Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5) Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5) XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5) name old allocs/op new allocs/op delta Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5) Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5) GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5) Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5) SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5) Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5) GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5) Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5) Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5) XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5) name old text-bytes new text-bytes delta HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal) CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal) name old data-bytes new data-bytes delta HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal) CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal) name old exe-bytes new exe-bytes delta HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal) CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal) Passes toolstash compare. For #22662. Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da Reviewed-on: https://go-review.googlesource.com/94515 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-02-15cmd/compile/internal/syntax: fix syntax.Parse doc string, improved testsRobert Griesemer
1) Fix the doc string for syntax.Parse: The returned AST is always nil if there was an error and an error handler is missing. 2) Adjust the syntax Print and Dump tests such that they print and dump the AST even in the presence of errors. Change-Id: If658eabdcc83f578d815070bc65d1a5f6cfaddfc Reviewed-on: https://go-review.googlesource.com/94157 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-21cmd/compile/internal/syntax: compute BranchStmt.Target statementsRobert Griesemer
- Add new BranchStmt.Target field: It's the destination for break, continue, or goto statements. - When parsing with CheckBranches enabled, set the BranchStmt.Target field. We get the information practically for free from the branch checker, so keep it for further use. - Fix a couple of comments. - This could use a test, but the new Target field is currently not used, and writing a test is tedious w/o a general tree visitor. Do it later. For now, visually verified output from syntax dump. Change-Id: Id691d89efab514ad885e19ac9759506106579520 Reviewed-on: https://go-review.googlesource.com/40988 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-03-25cmd/compile/internal/syntax: always construct a correct syntax treeRobert Griesemer
- parser creates sensible nodes in case of syntax errors instead of nil - a new BadExpr node is used in places where we can't do better - fixed error message for incorrect type switch guard - minor cleanups Fixes #19663. Change-Id: I028394c6db9cba7371f0e417ebf93f594659786a Reviewed-on: https://go-review.googlesource.com/38653 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-03-22cmd/compile/internal/syntax: replace inlined statement lists with ↵Robert Griesemer
syntax.BlockStmt This simplifies the code and removes a premature optimization. It increases the amount of allocated syntax.Node space by ~0.4% for parsing all of std lib, which is negligible. Before the change (best of 5 runs): $ go test -run StdLib -fast parsed 1517022 lines (3394 files) in 793.487886ms (1911840 lines/s) allocated 387.086Mb (267B/line, 487.828Mb/s) After the change (best of 5 runs): $ go test -run StdLib -fast parsed 1516911 lines (3392 files) in 805.028655ms (1884294 lines/s) allocated 388.466Mb (268B/line, 482.549Mb/s) Change-Id: Id19d6210fdc62393862ba3b04913352d95c599be Reviewed-on: https://go-review.googlesource.com/38439 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-03-22cmd/compile/internal/syntax: add position info for { and } bracesRobert Griesemer
This change adds position information for { and } braces in the source. There's a 1.9% increase in memory use for syntax.Nodes, which is negligible relative to overall compiler memory consumption. Parsing the std library (using syntax package only) and memory consumption before this change (fastest of 5 runs): $ go test -run StdLib -fast parsed 1516827 lines (3392 files) in 780.612335ms (1943124 lines/s) allocated 379.903Mb (486.673Mb/s) After this change (fastest of 5 runs): $ go test -run StdLib -fast parsed 1517022 lines (3394 files) in 793.487886ms (1911840 lines/s) allocated 387.086Mb (267B/line, 487.828Mb/s) While not an exact apples-to-apples comparison (the syntax package has changed and is also parsed), the overall impact is small. Also: Small improvements to nodes_test.go. Change-Id: Ib8a7f90bbe79de33d83684e33b1bf8dbc32e644a Reviewed-on: https://go-review.googlesource.com/38435 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-03-16cmd/compile/internal/syntax: track column position at function endMatthew Dempsky
Fixes #19576. Change-Id: I11034fb08e989f6eb7d54bde873b92804223598d Reviewed-on: https://go-review.googlesource.com/38291 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-15cmd/compile/internal/syntax: establish principled position informationRobert Griesemer
Until now, the parser set the position for each Node to the position of the first token belonging to that node. For compatibility with the now defunct gc parser, in many places that position information was modified when the gcCompat flag was set (which it was, by default). Furthermore, in some places, position information was not set at all. This change removes the gcCompat flag and all associated code, and sets position information for all nodes in a more principled way, as proposed by mdempsky (see #16943 for details). Specifically, the position of a node may not be at the very beginning of the respective production. For instance for an Operation `a + b`, the position associated with the node is the position of the `+`. Thus, for `a + b + c` we now get different positions for the two additions. This change does not pass toolstash -cmp because position information recorded in export data and pcline tables is different. There are no other functional changes. Added test suite testing the position of all nodes. Fixes #16943. Change-Id: I3fc02bf096bc3b3d7d2fa655dfd4714a1a0eb90c Reviewed-on: https://go-review.googlesource.com/37017 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-02-01all: merge dev.inline into masterRuss Cox
Change-Id: I7715581a04e513dcda9918e853fa6b1ddc703770
2017-01-10[dev.typealias] cmd/compile: recognize type aliases but complain for now ↵Robert Griesemer
(not yet supported) Added test file. For #18130. Change-Id: Ifcfd7cd1acf9dd6a2f4f3d85979d232bb6b8c6b1 Reviewed-on: https://go-review.googlesource.com/34988 Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-01-09[dev.inline] cmd/internal/src: replace src.Pos with syntax.PosRobert Griesemer
This replaces the src.Pos LineHist-based position tracking with the syntax.Pos implementation and updates all uses. The LineHist table is not used anymore - the respective code is still there but should be removed eventually. CL forthcoming. Passes toolstash -cmp when comparing to the master repo (with the exception of a couple of swapped assembly instructions, likely due to different instruction scheduling because the line-based sorting has changed; though this is won't affect correctness). The sizes of various important compiler data structures have increased significantly (see the various sizes_test.go files); this is probably the reason for an increase of compilation times (to be addressed). Here are the results of compilebench -count 5, run on a "quiet" machine (no apps running besides a terminal): name old time/op new time/op delta Template 256ms ± 1% 280ms ±15% +9.54% (p=0.008 n=5+5) Unicode 132ms ± 1% 132ms ± 1% ~ (p=0.690 n=5+5) GoTypes 891ms ± 1% 917ms ± 2% +2.88% (p=0.008 n=5+5) Compiler 3.84s ± 2% 3.99s ± 2% +3.95% (p=0.016 n=5+5) MakeBash 47.1s ± 1% 47.2s ± 2% ~ (p=0.841 n=5+5) name old user-ns/op new user-ns/op delta Template 309M ± 1% 326M ± 2% +5.18% (p=0.008 n=5+5) Unicode 165M ± 1% 168M ± 4% ~ (p=0.421 n=5+5) GoTypes 1.14G ± 2% 1.18G ± 1% +3.47% (p=0.008 n=5+5) Compiler 5.00G ± 1% 5.16G ± 1% +3.12% (p=0.008 n=5+5) Change-Id: I241c4246cdff627d7ecb95cac23060b38f9775ec Reviewed-on: https://go-review.googlesource.com/34273 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-12-09[dev.inline] cmd/compile/internal/syntax: use syntax.Pos for all external ↵Robert Griesemer
positions - use syntax.Pos in syntax.Error (rather than line, col) - use syntax.Pos in syntax.PragmaHandler (rather than just line) - update uses - better documentation in various places Also: - make Pos methods use Pos receiver (rather than *Pos) Reviewed in and cherry-picked from https://go-review.googlesource.com/#/c/33891/. With minor adjustments to noder.go to make merge compile. Change-Id: I5507cea6c2be46a7677087c1aeb69382d31033eb Reviewed-on: https://go-review.googlesource.com/34236 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-12-09[dev.inline] cmd/compile/internal/syntax: process //line pragmas in scannerRobert Griesemer
Reviewed in and cherry-picked from https://go-review.googlesource.com/#/c/33764/. Minor adjustment in noder.go to make merge compile again. Change-Id: Ib5029b52b59944f207b0f2438c8a5aa576eb25b8 Reviewed-on: https://go-review.googlesource.com/34233 Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-12-09[dev.inline] cmd/compile/internal/syntax: introduce general position info ↵Robert Griesemer
for nodes Reviewed in and cherry-picked from https://go-review.googlesource.com/#/c/33758/. Minor adjustments in noder.go to fix merge. Change-Id: Ibe429e327c7f8554f8ac205c61ce3738013aed98 Reviewed-on: https://go-review.googlesource.com/34231 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-11-29cmd/compile/internal/syntax: remove unused node fieldRobert Griesemer
The doc field is not yet used - remove it for now (we may end up with a different solution for 1.9). This reduces memory consumption for parsing all of std lib by about 40MB and makes parsing slightly faster. Change-Id: Iafb00b9c7f1be9c66fdfb29096d3da5049b2fcf5 Reviewed-on: https://go-review.googlesource.com/33661 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-11-05cmd/go/internal/syntax: reintroduce reverted commentsRobert Griesemer
These comments were originally introduced together with the changes for alias declarations, and then reverted when we backed out alias support. Reintroduce them. Change-Id: I3ef2c4f4672d6af8a900f5d73df273edf28d1a14 Reviewed-on: https://go-review.googlesource.com/32826 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-11-05Revert "cmd/compile/internal/syntax: support for alias declarations"Robert Griesemer
This reverts commit 32db3f2756324616b7c856ac9501deccc2491239. Reason: Decision to back out current alias implementation. For #16339. Change-Id: Ib05e3d96041d8347e49cae292f66bec791a1fdc8 Reviewed-on: https://go-review.googlesource.com/32825 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-10-25cmd/compile: simplify parsing of type aliasesRobert Griesemer
Change-Id: Ia86841cf84bc17ff6ecc6e5ac4cec86384a0da00 Reviewed-on: https://go-review.googlesource.com/31719 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-10-15cmd/compile: add go:notinheap type pragmaAustin Clements
This adds a //go:notinheap pragma for declarations of types that must not be heap allocated. We ensure these rules by disallowing new(T), make([]T), append([]T), or implicit allocation of T, by disallowing conversions to notinheap types, and by propagating notinheap to any struct or array that contains notinheap elements. The utility of this pragma is that we can eliminate write barriers for writes to pointers to go:notinheap types, since the write barrier is guaranteed to be a no-op. This will let us mark several scheduler and memory allocator structures as go:notinheap, which will let us disallow write barriers in the scheduler and memory allocator much more thoroughly and also eliminate some problematic hybrid write barriers. This also makes go:nowritebarrierrec and go:yeswritebarrierrec much more powerful. Currently we use go:nowritebarrier all over the place, but it's almost never what you actually want: when write barriers are illegal, they're typically illegal for a whole dynamic scope. Partly this is because go:nowritebarrier has been around longer, but it's also because go:nowritebarrierrec couldn't be used in situations that had no-op write barriers or where some nested scope did allow write barriers. go:notinheap eliminates many no-op write barriers and go:yeswritebarrierrec makes it possible to opt back in to write barriers, so these two changes will let us use go:nowritebarrierrec far more liberally. This updates #13386, which is about controlling pointers from non-GC'd memory to GC'd memory. That would require some additional pragma (or pragmas), but could build on this pragma. Change-Id: I6314f8f4181535dd166887c9ec239977b54940bd Reviewed-on: https://go-review.googlesource.com/30939 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-16cmd/compile/internal/syntax: support for alias declarationsRobert Griesemer
Permits parsing of alias declarations with -newparser const/type/var/func T => p.T but the compiler will reject it with an error. For now this also accepts type T = p.T so we can experiment with a type-alias only scenario. - renamed _Arrow token to _Larrow (<-) - introduced _Rarrow token (=>) - introduced AliasDecl node - extended scanner to accept _Rarrow - extended parser and printer to handle alias declarations Change-Id: I0170d10a87df8255db9186d466b6fd405228c38e Reviewed-on: https://go-review.googlesource.com/29355 Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-31cmd/compile: handle pragmas immediately with -newparser=1Matthew Dempsky
Instead of saving all pragmas and processing them after parsing is finished, process them immediately during scanning like the current lexer does. This is a bit unfortunate because it means we can't use syntax.ParseFile to concurrently parse files yet, but it fixes how we report syntax errors in the presence of //line pragmas. While here, add a bunch more gcCompat entries to syntax/parser.go to get "go build -toolexec='toolstash -cmp' std cmd" passing. There are still a few remaining cases only triggered building unit tests, but this seems like a nice checkpoint. Change-Id: Iaf3bbcf2849857a460496f31eea228e0c585ce13 Reviewed-on: https://go-review.googlesource.com/28226 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-08-19cmd/compile/internal/syntax: expose additional information for gcMatthew Dempsky
gc needs access to line offsets for Nodes. It also needs access to the end line offset for function bodies so it knows what line number to use for things like implicit returns and defer executions. Lastly, include an extra bool to distinguish between simple and full slice expressions. This is redundant in valid parse trees, but needed by gc for producing complete warnings in invalid inputs. Change-Id: I64baf334a35c72336d26fa6755c67eb9d6f4e93c Reviewed-on: https://go-review.googlesource.com/27196 Reviewed-by: Robert Griesemer <gri@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-18cmd/compile/internal/syntax: fast Go syntax trees, initial commit.Robert Griesemer
Syntax tree nodes, scanner, parser, basic printers. Builds syntax trees for entire Go std lib at a rate of ~1.8M lines/s in warmed up state (MacMini, 2.3 GHz Intel Core i7, 8GB RAM): $ go test -run StdLib -fast parsed 1074617 lines (2832 files) in 579.66364ms (1853863 lines/s) allocated 282.212Mb (486.854Mb/s) PASS Change-Id: Ie26d9a7bf4e5ff07457aedfcc9b89f0eba72ae3f Reviewed-on: https://go-review.googlesource.com/27195 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Robert Griesemer <gri@golang.org>