aboutsummaryrefslogtreecommitdiff
path: root/src/reflect
AgeCommit message (Collapse)Author
2021-01-07Revert "reflect: support multiple keys in struct tags"Ian Lance Taylor
Proposal #40281 was initially accepted, but has now been declined. This CL removes most of the work done to implement it. Specifically this reverts CLs 248341, 274448, 274474, and 278392. For #40281 For #43226 Change-Id: I5a9ebb4d9cb5fb0962434b64c59beb8343030be5 Reviewed-on: https://go-review.googlesource.com/c/go/+/281515 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
2020-12-07reflect: document multiple keys in struct tagsIan Lance Taylor
For #40281 Fixes #42959 Change-Id: Ibc4769fda1592a1373ec720ea30baf319c0a0136 Reviewed-on: https://go-review.googlesource.com/c/go/+/274448 Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2020-11-26reflect: fix Value.Convert for int-to-string conversions (regression)Robert Griesemer
The bug was introduced by https://golang.org/cl/220844. Updates #42792. Fixes #42835. Change-Id: I03065c7526488aded35ef2f800b7162e1606877a Reviewed-on: https://go-review.googlesource.com/c/go/+/273326 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-11-03reflect: update NumMethod doc for interface typeCuong Manh Le
Updates #42123 Change-Id: Ieb43b65c88d15b2475b6f3dd9672c44e7831cc34 Reviewed-on: https://go-review.googlesource.com/c/go/+/264357 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2020-10-30reflect,runtime: use internal ABI for selected ASM routines, attempt 2Than McIntosh
[This is a roll-forward of CL 262319, with a fix for some Darwin test failures]. Change the definitions of selected runtime assembly routines from ABI0 (the default) to ABIInternal. The ABIInternal def is intended to indicate that these functions don't follow the existing Go runtime ABI. In addition, convert the assembly reference to runtime.main (from runtime.mainPC) to ABIInternal. Finally, for functions such as "runtime.duffzero" that are called directly from generated code, make sure that the compiler looks up the correct ABI version. This is intended to support the register abi work, however these changes should not have any issues even when GOEXPERIMENT=regabi is not in effect. Updates #27539, #40724. Change-Id: Idf507f1c06176073563845239e1a54dad51a9ea9 Reviewed-on: https://go-review.googlesource.com/c/go/+/266638 Trust: Than McIntosh <thanm@google.com> Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2020-10-29Revert "reflect,runtime: use internal ABI for selected ASM routines"Than McIntosh
This reverts commit 50af50d136551e2009b2b52e829570536271cdaa. Reason for revert: Causes failures in the runtime package test on Darwin, apparently. Change-Id: I006bc1b3443fa7207e92fb4a93e3fb438d4d3de3 Reviewed-on: https://go-review.googlesource.com/c/go/+/266257 Trust: Than McIntosh <thanm@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-10-29reflect,runtime: use internal ABI for selected ASM routinesThan McIntosh
Change the definitions of selected runtime assembly routines from ABI0 (the default) to ABIInternal. The ABIInternal def is intended to indicate that these functions don't follow the existing Go runtime ABI. In addition, convert the assembly reference to runtime.main (from runtime.mainPC) to ABIInternal. Finally, for functions such as "runtime.duffzero" that are called directly from generated code, make sure that the compiler looks up the correct ABI version. This is intended to support the register abi work, however these changes should not have any issues even when GOEXPERIMENT=regabi is not in effect. Updates #27539, #40724. Change-Id: I9846f8dcaccc95718cf2e61a18b7e924a0677e4c Reviewed-on: https://go-review.googlesource.com/c/go/+/262319 Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-10-28Revert "cmd/compile: split exported/non-exported methods for interface type"Cuong Manh Le
This reverts commit 8f26b57f9afc238bdecb9b7030bc2f4364093885. Reason for revert: break a bunch of code, include standard library. Fixes #42123 Change-Id: Ife90ecbafd2cb395623d1db555fbfc9c1b0098e0 Reviewed-on: https://go-review.googlesource.com/c/go/+/264026 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2020-10-27cmd/compile, runtime: store pointers to go:notinheap types indirectlyKeith Randall
pointers to go:notinheap types should be treated as scalars. That means they shouldn't be stored directly in interfaces, or directly in reflect.Value.ptr. Also be sure to use uintpr to compare such pointers in reflect.DeepEqual. Fixes #42076 Change-Id: I53735f6d434e9c3108d4940bd1bae14c61ef2a74 Reviewed-on: https://go-review.googlesource.com/c/go/+/264480 Trust: Keith Randall <khr@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-10-09cmd/compile: split exported/non-exported methods for interface typeCuong Manh Le
Currently, mhdr/methods is emitted with the same len/cap. There's no way to distinguish between exported and non-exported methods statically. This CL splits mhdr/methods into two parts, use "len" for number of exported methods, and "cap" for all methods. This fixes the bug in issue #22075, which intends to return the number of exported methods but currently return all methods. Note that with this encoding, we still can access either all/exported-only/non-exported-only methods: mhdr[:cap(mhdr)] // all methods mhdr // exported methods mhdr[len(mhdr):cap(mhdr)] // non-exported methods Thank to Matthew Dempsky (@mdempsky) for suggesting this encoding. Fixes #22075 Change-Id: If662adb03ccff27407d55a5578a0ed05a15e7cdd Reviewed-on: https://go-review.googlesource.com/c/go/+/259237 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-10-06reflect: support multiple keys in struct tagsAlexey Vilenskiy
Fixes #40281 Change-Id: Ie624bce3a78a06d7ed71bba1f501e66802dffd13 Reviewed-on: https://go-review.googlesource.com/c/go/+/248341 Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Dmitri Shuralyov <dmitshur@golang.org>
2020-10-02all: drop 387 supportKeith Randall
My last 387 CL. So sad ... ... ... ... not! Fixes #40255 Change-Id: I8d4ddb744b234b8adc735db2f7c3c7b6d8bbdfa4 Reviewed-on: https://go-review.googlesource.com/c/go/+/258957 Trust: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-10-01reflect: add test for variadic reflect.Type.MethodIan Lance Taylor
For #41737 Change-Id: Id065880dd7da54dec1b45662c202aeb7f8397c60 Reviewed-on: https://go-review.googlesource.com/c/go/+/258819 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-09-18reflect: use zero buffer to back the Value returned by ZeroKeith Randall
In the common case (<1KB types), no allocation is required by reflect.Zero. Also use memclr instead of memmove in Set when the source is known to be zero. Fixes #33136 Change-Id: Ic66871930fbb53328032e587153ebd12995ccf55 Reviewed-on: https://go-review.googlesource.com/c/go/+/192331 Trust: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Martin Möhrmann <moehrmann@google.com>
2020-08-18runtime: eliminate scase.kind fieldMatthew Dempsky
Currently, we include a "kind" field on scase to distinguish the three kinds of cases in a select statement: sends, receives, and defaults. This commit removes by kind field by instead arranging for the compiler to always place sends before receives, and to provide their counts separately. It also passes an explicit "block bool" parameter to avoid needing to include a default case in the array. It's safe to shuffle cases like this because the runtime will randomize the order they're polled in anyway. Fixes #40410. Change-Id: Iaeaed4cf7bddd576d78f2c863bd91a03a5c82df2 Reviewed-on: https://go-review.googlesource.com/c/go/+/245125 Reviewed-by: Keith Randall <khr@golang.org>
2020-08-17reflect: remove depth from deepequal recursionKeith Randall
We aren't using it for anything. The visited map will terminate any recursion for us. Change-Id: I36e6bd8e34952123c2ed46323067e42928ec7168 Reviewed-on: https://go-review.googlesource.com/c/go/+/238759 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-08-17runtime: move checkmarks to a separate bitmapAustin Clements
Currently, the GC stores the object marks for checkmarks mode in the heap bitmap using a rather complex encoding: for one word objects, the checkmark is stored in the pointer/scalar bit since one word objects must be pointers; for larger objects, the checkmark is stored in what would be the scan/dead bit for the second word of the object. This encoding made more sense when the runtime used the first scan/dead bit as the regular mark bit, but we moved away from that long ago. This encoding and overloading of the heap bitmap bits causes a great deal of complexity in many parts of the allocator and garbage collector and leads to some subtle bugs like #15903. This CL moves the checkmarks mark bits into their own per-arena bitmap and reclaims the second scan/dead bit as a regular scan/dead bit. I tested this by enabling doubleCheck mode in heapBitsSetType and running in both regular and GODEBUG=gccheckmark=1 mode. Fixes #15903. No performance degradation. (Very slight improvement on a few benchmarks, but it's probably just noise.) name old time/op new time/op delta BiogoIgor 16.6s ± 1% 16.4s ± 1% -0.94% (p=0.000 n=25+24) BiogoKrishna 19.2s ± 3% 19.2s ± 3% ~ (p=0.638 n=23+25) BleveIndexBatch100 6.12s ± 5% 6.17s ± 4% ~ (p=0.170 n=25+25) CompileTemplate 206ms ± 1% 205ms ± 1% -0.43% (p=0.005 n=24+24) CompileUnicode 82.2ms ± 2% 81.5ms ± 2% -0.95% (p=0.001 n=22+22) CompileGoTypes 755ms ± 3% 754ms ± 4% ~ (p=0.715 n=25+25) CompileCompiler 3.73s ± 1% 3.73s ± 1% ~ (p=0.445 n=25+24) CompileSSA 8.67s ± 1% 8.66s ± 1% ~ (p=0.836 n=24+22) CompileFlate 134ms ± 2% 133ms ± 1% -0.66% (p=0.001 n=24+23) CompileGoParser 164ms ± 1% 163ms ± 1% -0.85% (p=0.000 n=24+24) CompileReflect 466ms ± 5% 466ms ± 3% ~ (p=0.863 n=25+25) CompileTar 182ms ± 1% 182ms ± 1% -0.31% (p=0.048 n=24+24) CompileXML 249ms ± 1% 248ms ± 1% -0.32% (p=0.031 n=21+25) CompileStdCmd 10.3s ± 1% 10.3s ± 1% ~ (p=0.459 n=23+23) FoglemanFauxGLRenderRotateBoat 8.66s ± 1% 8.62s ± 1% -0.47% (p=0.000 n=23+24) FoglemanPathTraceRenderGopherIter1 20.3s ± 3% 20.2s ± 2% ~ (p=0.893 n=25+25) GopherLuaKNucleotide 29.7s ± 1% 29.8s ± 2% ~ (p=0.421 n=24+25) MarkdownRenderXHTML 246ms ± 1% 247ms ± 1% ~ (p=0.558 n=25+24) Tile38WithinCircle100kmRequest 779µs ± 4% 779µs ± 3% ~ (p=0.954 n=25+25) Tile38IntersectsCircle100kmRequest 1.02ms ± 3% 1.01ms ± 4% ~ (p=0.658 n=25+25) Tile38KNearestLimit100Request 984µs ± 4% 986µs ± 4% ~ (p=0.627 n=24+25) [Geo mean] 552ms 551ms -0.19% https://perf.golang.org/search?q=upload:20200723.6 Change-Id: Ic703f26a83fb034941dc6f4788fc997d56890dec Reviewed-on: https://go-review.googlesource.com/c/go/+/244539 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Martin Möhrmann <moehrmann@google.com>
2020-08-14reflect: add parentheses to properly bind <- in ChanOf’s stringAlexander Klauer
Adds parentheses so as to properly bind <- to the right most channel. This meant that previously given: ChanOf(<-chan T) it would mistakenly try to look up the type as chan <-chan T instead of chan (<-chan T) Fixes #39897 Change-Id: I8564916055f5fadde3382e41fe8820a1071e5f13 GitHub-Last-Rev: f8f2abe8d4c9e3d1414c89cadca8a16ce5cdeab9 GitHub-Pull-Request: golang/go#39898 Reviewed-on: https://go-review.googlesource.com/c/go/+/240280 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-06-19reflect: zero stack slots before writing to them with write barriersKeith Randall
reflect.assignTo writes to the target using write barriers. Make sure that the memory it is writing to is zeroed, so the write barrier does not read pointers from uninitialized memory. Fixes #39541 Change-Id: Ia64b2cacc193bffd0c1396bbce1dfb8182d4905b Reviewed-on: https://go-review.googlesource.com/c/go/+/238760 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-18reflect: handling flagIndir in DeepEqual potential cyclesIan Lance Taylor
Fixes #39607 Change-Id: Ia7e597e0da8a193a25382cc633a1c6080b4f7cbf Reviewed-on: https://go-review.googlesource.com/c/go/+/238361 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2020-05-04reflect: keep RO flags unchanged in Value.AddrKezhu Wang
Currently, Value.Addr collapses flagRO, which is a combination of flagEmbedRO and flagStickyRO, to flagStickyRO. This causes exported fields of unexported anonymous field from Value.Addr.Elem read only. This commit fix this by keeping all bits of flagRO from origin value in Value.Addr. This should be safe due to following reasons: * Result of Value.Addr is not CanSet because of it is not CanAddr but not flagRO. * Addr.Elem get same flagRO as origin, so it should behave same as origin in CanSet. Fixes #32772. Change-Id: I79e086628c0fb6569a50ce63f3b95916f997eda1 GitHub-Last-Rev: 78e280e6d06865661b5835def74c252c94a92800 GitHub-Pull-Request: golang/go#32787 Reviewed-on: https://go-review.googlesource.com/c/go/+/183937 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-05-01internal/unsafeheader: consolidate stringHeader and sliceHeader declarations ↵Bryan C. Mills
into an internal package The new package "internal/unsafeheader" depends only on "unsafe", and provides declarations equivalent to reflect.StringHeader and reflect.SliceHeader but with Data fields of the proper unsafe.Pointer type (instead of uintptr). Unlike the types it replaces, the "internal/unsafeheader" package has a regression test to ensure that its header types remain equivalent to the declarations provided by the "reflect" package. Since "internal/unsafeheader" has almost no dependencies, it can be used in other low-level packages such as "syscall" and "reflect". This change is based on the corresponding x/sys change in CL 231177. Fixes #37805 Updates #19367 Change-Id: I7a6d93ef8dd6e235bcab94e7c47270aad047af31 Reviewed-on: https://go-review.googlesource.com/c/go/+/231223 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-04-28reflect: reduce allocations for Select with up to 4 casesMartin Möhrmann
Allocate the runcases slice on the stack if the number of select cases is small (up to 4). Found while looking at production profiles of common proto based RPC server framework code in Google which do not have a large number of cases. name old time/op new time/op delta Select/1 147ns ± 2% 120ns ± 6% -18.32% (p=0.000 n=7+10) Select/4 316ns ± 5% 249ns ± 2% -21.23% (p=0.000 n=10+10) Select/8 516ns ± 3% 515ns ± 3% ~ (p=0.858 n=10+9) name old alloc/op new alloc/op delta Select/1 96.0B ± 0% 64.0B ± 0% -33.33% (p=0.000 n=10+10) Select/4 336B ± 0% 208B ± 0% -38.10% (p=0.000 n=10+10) Select/8 672B ± 0% 672B ± 0% ~ (all equal) name old allocs/op new allocs/op delta Select/1 4.00 ± 0% 3.00 ± 0% -25.00% (p=0.000 n=10+10) Select/4 7.00 ± 0% 6.00 ± 0% -14.29% (p=0.000 n=10+10) Select/8 11.0 ± 0% 11.0 ± 0% ~ (all equal) Change-Id: I1687e74fc8e86606a27f03fa8a561bcfb68775d6 Reviewed-on: https://go-review.googlesource.com/c/go/+/230657 Run-TryBot: Martin Möhrmann <moehrmann@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2020-04-22reflect: fix typo on resolveReflectName function documentationKoichi Shiraishi
Change-Id: I250de9db4e8aca6e1069d05c73051571f1712091 Reviewed-on: https://go-review.googlesource.com/c/go/+/229141 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-04-21reflect: disallow invoking methods on unexported embedded fieldsMatthew Dempsky
Given: type u struct{} func (u) M() {} type t struct { u; u2 u } var v = reflect.ValueOf(t{}) Package reflect allows: v.Method(0) // v.M v.Field(0).Method(0) // v.u.M but panics from: v.Field(1).Method(0) // v.u2.M because u2 is not an exported field. However, u is not an exported field either, so this is inconsistent. It seems like this behavior originates from #12367, where it was decided to allow traversing unexported embedded fields to be able to access their exported fields, since package reflect doesn't provide an alternative way to access promoted fields directly. But extending that logic to promoted *methods* was inappropriate, because package reflect's normal method handling logic already handles promoted methods correctly. This CL corrects that mistake. Fixes #38521. Change-Id: If65008965f35927b4e7927cddf8614695288eb19 Reviewed-on: https://go-review.googlesource.com/c/go/+/228902 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-04-21reflect: return user-visible method name in panic stringIan Lance Taylor
This was accidentally broken in CL 166462, which introduce another function in the panicking path without adjusting the argument to runtime.Caller. Change-Id: Ib6f9ed8673fefd458c7a4e3a918c45c5b31ca552 Reviewed-on: https://go-review.googlesource.com/c/go/+/229082 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-04-01reflect: when Converting between float32s, don't lose signal NaNsKeith Randall
Trying this CL again, with a test that skips 387. When converting from float32->float64->float32, any signal NaNs get converted to quiet NaNs. Avoid that so using reflect.Value.Convert between two float32 types keeps the signal bit of NaNs. Skip the test on 387. I don't see any sane way of ensuring that a float load + float store is faithful on that platform. Fixes #36400 Change-Id: Ic316c74ddc155632e40424e207375b5d50dcd853 Reviewed-on: https://go-review.googlesource.com/c/go/+/221792 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2020-02-26all: avoid string(i) where i has type intIan Lance Taylor
Instead use string(r) where r has type rune. This is in preparation for a vet warning for string(i). Updates #32479 Change-Id: Ic205269bba1bd41723950219ecfb67ce17a7aa79 Reviewed-on: https://go-review.googlesource.com/c/go/+/220844 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Akhil Indurti <aindurti@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Toshihiro Shiino <shiino.toshihiro@gmail.com>
2020-02-25Revert "reflect: when Converting between float32s, don't lose signal NaNs"Keith Randall
This reverts commit 7485050c0f55492c0fdfc41f7564f3da37a1a308. Reason for revert: Breaking some builders (387, mips, mips64) Change-Id: I33e5125b7a9a96b55bc5e71880fca4ee30d226a7 Reviewed-on: https://go-review.googlesource.com/c/go/+/220695 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-02-25reflect: when Converting between float32s, don't lose signal NaNsKeith Randall
When converting from float32->float64->float32, any signal NaNs get converted to quiet NaNs. Avoid that so using reflect.Value.Convert between two float32 types keeps the signal bit of NaNs. Update #36400 Change-Id: Ic4dd04c4be7189d2171d12b7e4e8f7cf2fb22bb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/213497 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-02-24reflect: update Select to panic early on excessive input casesMilan Patel
The runtime implementation of select has an upper limit on the number of select cases that are supported in order to maintain low stack memory usage. Rather than support an arbitrary number of select cases, we've opted to panic early with a useful message pointing the user directly at the problem. Fixes #37350 Change-Id: Id129ba281ae120387e681ef96be8adcf89725840 Reviewed-on: https://go-review.googlesource.com/c/go/+/220583 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-01-19reflect: correct riscv64 assemblyJoel Sing
R0 is not a thing in riscv64 assembly - use ZERO (rather than X0) since the rest of this currently uses ABI names. Updates #27532 Change-Id: I28fb68e9f80d05231a07c5921e7062777234e2c5 Reviewed-on: https://go-review.googlesource.com/c/go/+/215437 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-01-18reflect: add support for riscv64Joel Sing
Based on riscv-go port. Update #27532 Change-Id: I791924f71078fd8dfe9c2fc03a3f21a3bc673721 Reviewed-on: https://go-review.googlesource.com/c/go/+/204634 Run-TryBot: Joel Sing <joel@sing.id.au> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2019-12-19reflect: record PkgPath of StructOf argumentsIan Lance Taylor
Fixes #36190 Fixes #36191 Change-Id: I1213ef37b6595af63dbe202a8ade65741caf1356 Reviewed-on: https://go-review.googlesource.com/c/go/+/212001 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-12-10all: fix a number of misuses of the word "an"Daniel Martí
After golang.org/cl/210124, I wondered if the same error had gone unnoticed elsewhere. I quickly spotted another dozen mistakes after reading through the output of: git grep '\<[Aa]n [bcdfgjklmnpqrtvwyz][a-z]' Many results are false positives for acronyms like "an mtime", since it's pronounced "an em-time". However, the total amount of output isn't that large given how simple the grep pattern is. Change-Id: Iaa2ca69e42f4587a9e3137d6c5ed758887906ca6 Reviewed-on: https://go-review.googlesource.com/c/go/+/210678 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Zach Jones <zachj1@gmail.com> Reviewed-by: Robert Griesemer <gri@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-11-22reflect: remove obsolete comment about gobitVectortwo
Change-Id: Ie3495a51ac2021a55e7c1ee43a66d07a5bf2757a GitHub-Last-Rev: b6a6bab3ab840b361021b25cac37eb6891c0fe4b GitHub-Pull-Request: golang/go#35709 Reviewed-on: https://go-review.googlesource.com/c/go/+/207853 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-11-15reflect: factor out special channel assignability rule from ↵go101
haveIdenticalUnderlyingType Go specification says: A value x is assignable to a variable of type T if x is a bidirectional channel value, T is a channel type, x's type V and T have identical element types, and at least one of V or T is not a defined type. However, the current reflection implementation is incorrect which makes "x is assignable to T" even if type V and T are both defined type. The current reflection implementation also mistakes the base types of two non-defined pointer types share the same underlying type when the two base types satisfy the above mentioned special channel assignability rule. Fixes #29469 Change-Id: Ia4b9c4ac47dc8e76a11faef422b2e5c5726b78b3 GitHub-Last-Rev: 487c20a564091a1d2ba5feb95ab5196331c699c2 GitHub-Pull-Request: golang/go#29739 Reviewed-on: https://go-review.googlesource.com/c/go/+/157822 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-10-22reflect: fix unsafe conversions reported by -d=checkptrMatthew Dempsky
The code for generating gcdata was (technically) unsafe. It was also rather repetitive. This CL refactors it a bit and abstracts use of gcdata into a helper gcSlice method. Updates #34972. Change-Id: Ie86d7822eafe263f1d3d150eedf0ec66be1ec85d Reviewed-on: https://go-review.googlesource.com/c/go/+/202582 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-21reflect, internal/reflectlite: set capacity when slicing unsafe pointersMatthew Dempsky
Follow the idiom for allowing -d=checkptr to recognize and verify correctness. Updates #22218. Updates #34972. Change-Id: Ib6001c6f0e6dc535a36bcfaa1ae48e29e0c737f8 Reviewed-on: https://go-review.googlesource.com/c/go/+/202580 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-17cmd/compile: add -d=checkptr to validate unsafe.Pointer rulesMatthew Dempsky
This CL adds -d=checkptr as a compile-time option for adding instrumentation to check that Go code is following unsafe.Pointer safety rules dynamically. In particular, it currently checks two things: 1. When converting unsafe.Pointer to *T, make sure the resulting pointer is aligned appropriately for T. 2. When performing pointer arithmetic, if the result points to a Go heap object, make sure we can find an unsafe.Pointer-typed operand that pointed into the same object. These checks are currently disabled for the runtime, and can also be disabled through a new //go:nocheckptr annotation. The latter is necessary for functions like strings.noescape, which intentionally violate safety rules to workaround escape analysis limitations. Fixes #22218. Change-Id: If5a51273881d93048f74bcff10a3275c9c91da6a Reviewed-on: https://go-review.googlesource.com/c/go/+/162237 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2019-10-10all: remove nacl (part 3, more amd64p32)Brad Fitzpatrick
Part 1: CL 199499 (GOOS nacl) Part 2: CL 200077 (amd64p32 files, toolchain) Part 3: stuff that arguably should've been part of Part 2, but I forgot one of my grep patterns when splitting the original CL up into two parts. This one might also have interesting stuff to resurrect for any future x32 ABI support. Updates #30439 Change-Id: I2b4143374a253a003666f3c69e776b7e456bdb9c Reviewed-on: https://go-review.googlesource.com/c/go/+/200318 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-10-09all: remove the nacl port (part 2, amd64p32 + toolchain)Brad Fitzpatrick
This is part two if the nacl removal. Part 1 was CL 199499. This CL removes amd64p32 support, which might be useful in the future if we implement the x32 ABI. It also removes the nacl bits in the toolchain, and some remaining nacl bits. Updates #30439 Change-Id: I2475d5bb066d1b474e00e40d95b520e7c2e286e1 Reviewed-on: https://go-review.googlesource.com/c/go/+/200077 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-10-09all: remove the nacl port (part 1)Brad Fitzpatrick
You were a useful port and you've served your purpose. Thanks for all the play. A subsequent CL will remove amd64p32 (including assembly files and toolchain bits) and remaining bits. The amd64p32 removal will be separated into its own CL in case we want to support the Linux x32 ABI in the future and want our old amd64p32 support as a starting point. Updates #30439 Change-Id: Ia3a0c7d49804adc87bf52a4dea7e3d3007f2b1cd Reviewed-on: https://go-review.googlesource.com/c/go/+/199499 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-09-28reflect: let StructOf define unexported fieldsDavid Crawshaw
This was missing from the original StructOf CL because I couldn't think of a use for it. Now I can: even with types used entirely by reflect, unexported fields can be set using UnsafeAddr. Change-Id: I5e7e3d81d16e8817cdd69d85796ce33930ef523b Reviewed-on: https://go-review.googlesource.com/c/go/+/85661 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-09-18reflect: give type hints in error messagesJean de Klerk
Currently, if you call various reflect methods you might get a panic with a message like, "reflect: Field of non-struct type". Sometimes it's easy to grok what's going on, but other times you need to laboriously go perform reflect.ValueOf(myType).Kind(). This CL just adds that detail to the error message, saving debuggers the extra step and making the error message more clear. Change-Id: I7e0c211a3001e6b217b828cbcf50518080b5cb1e Reviewed-on: https://go-review.googlesource.com/c/go/+/183097 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-09-11reflect: fix panic in DeepEqual when checking a cycleHuan Du
Before this change, when DeepEqual checks values with cycle, it may panic due to stack overflow. Here is a sample to reproduce the issue. makeCycleMap := func() interface{} { cycleMap := map[string]interface{}{} cycleMap["foo"] = cycleMap return cycleMap } m1 := makeCycleMap() m2 := makeCycleMap() reflect.DeepEqual(m1, m2) // stack overflow The root cause is that DeepEqual fails to cache interface values in visited map, which is used to detect cycle. DeepEqual calls CanAddr to check whether a value should be cached or not. However, all values referenced by interface don't have flagAddr thus all these values are not cached. THe fix is to remove CanAddr calls and use underlying ptr in value directly. As ptr is only read-only in DeepEqual for caching, it's safe to do so. We don't use UnsafeAddr this time, because this method panics when CanAddr returns false. Fixes #33907 Change-Id: I2aa88cc060a2c2192b1d34c129c0aad4bd5597e7 Reviewed-on: https://go-review.googlesource.com/c/go/+/191940 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-09-11reflect: enhance docs for IsZero and IsValidMarko Kungla
Make it clear that IsValid checks that we have valid reflect.Value and not the value of `v` fixes #34152 Change-Id: Ib3d359eeb3a82bf733b9ed17c777fc4c143bc29c Reviewed-on: https://go-review.googlesource.com/c/go/+/193841 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-09-03cmd/compile,runtime: generate hash functions only for types which are map keysKeith Randall
Right now we generate hash functions for all types, just in case they are used as map keys. That's a lot of wasted effort and binary size for types which will never be used as a map key. Instead, generate hash functions only for types that we know are map keys. Just doing that is a bit too simple, since maps with an interface type as a key might have to hash any concrete key type that implements that interface. So for that case, implement hashing of such types at runtime (instead of with generated code). It will be slower, but only for maps with interface types as keys, and maybe only a bit slower as the aeshash time probably dominates the dispatch time. Reorg where we keep the equals and hash functions. Move the hash function from the key type to the map type, saving a field in every non-map type. That leaves only one function in the alg structure, so get rid of that and just keep the equal function in the type descriptor itself. cmd/go now has 10 generated hash functions, instead of 504. Makes cmd/go 1.0% smaller. Update #6853. Speed on non-interface keys is unchanged. Speed on interface keys is ~20% slower: name old time/op new time/op delta MapInterfaceString-8 23.0ns ±21% 27.6ns ±14% +20.01% (p=0.002 n=10+10) MapInterfacePtr-8 19.4ns ±16% 23.7ns ± 7% +22.48% (p=0.000 n=10+8) Change-Id: I7c2e42292a46b5d4e288aaec4029bdbb01089263 Reviewed-on: https://go-review.googlesource.com/c/go/+/191198 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Martin Möhrmann <moehrmann@google.com>
2019-09-02std: remove unused bits of code all over the placeDaniel Martí
Some were never used, and some haven't been used for years. One exception is net/http's readerAndCloser, which was only used in a test. Move it to a test file. While at it, remove a check in regexp that could never fire; the field is an uint32, so it can never be negative. Change-Id: Ia2200f6afa106bae4034045ea8233b452f38747b Reviewed-on: https://go-review.googlesource.com/c/go/+/192621 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-08-27reflect: optimize directlyAssignable to avoid rtype.Name callSergei Zagurskii
directlyAssignable invoked rtype.Name() just to compare its result to empty string. We really only need to check whether rtype has name. It can be done much cheaper, by checking tflagNamed. Benchmark: https://play.golang.org/p/V2BzESPuf2w name old time/op new time/op delta DirectlyAssignable-12 32.7ns ± 6% 6.6ns ± 6% -79.80% (p=0.008 n=5+5) Fixes #32186 Change-Id: I1a2a167dbfddf319fba3015cb6a011bf010f99a8 Reviewed-on: https://go-review.googlesource.com/c/go/+/178518 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>