aboutsummaryrefslogtreecommitdiff
path: root/src/reflect
AgeCommit message (Collapse)Author
2024-01-24reflect: fix isRegularMemory at case ArrayJes Cok
To match cmd/compile/internal/compare.IsRegularMemory, this CL adds code for empty arrays of comparable element type. Change-Id: I205fb9bfda60be6c9aac2d9098ed3f0eb51cd0fa GitHub-Last-Rev: 40db7ed510883633374895271145678a51418426 GitHub-Pull-Request: golang/go#65252 Reviewed-on: https://go-review.googlesource.com/c/go/+/558155 Reviewed-by: Keith Randall <khr@google.com> Run-TryBot: qiulaidongfeng <2645477756@qq.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: qiulaidongfeng <2645477756@qq.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2024-01-23reflect: delete TODO pass safe to packEface don't need to copy if safe==trueqiulaidongfeng
valueInterface not copy result in the follow incorrect behavior w1. x := ValueOf(&v).Elem() r1. iface := Value.Interface() w2. x.Set() or x.SetT() The write operation of W2 will be observed by the read operation of r1, but the existing behavior is not. The valueInterface in deepValueEqual can, in theory, pass safe==true to not copy the object, but there is no benchmark to indicate that the memory allocation has changed, maybe we don't actually need safe==true here. Change-Id: I55c423fd50adac8822a7fdbfe67af89ee223eace GitHub-Last-Rev: 4a6386709817f3ea6055711dd39d2694d58b3043 GitHub-Pull-Request: golang/go#64618 Reviewed-on: https://go-review.googlesource.com/c/go/+/548436 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@golang.org>
2024-01-23reflect: StructOf set abi.TFlagRegularMemoryqiulaidongfeng
Complete a TODO. Change-Id: I791d27266ccee69c371524e298120765f5736cf8 GitHub-Last-Rev: 8878003efa2f9f3d8609b88073c982d21ece774b GitHub-Pull-Request: golang/go#64617 Reviewed-on: https://go-review.googlesource.com/c/go/+/548435 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2023-12-30reflect: fix typo in type.goRenJiangdu
There is no 'of' relationships between float and string. This points to those interfaces with internal type float or string. Change-Id: I14449f00c192e0d3f8270b433ff508978b7fdf17 GitHub-Last-Rev: f301a8aa5294e7669361627c82b2978652cfc14b GitHub-Pull-Request: golang/go#64885 Reviewed-on: https://go-review.googlesource.com/c/go/+/552957 Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Jorropo <jorropo.pgm@gmail.com> Run-TryBot: qiulaidongfeng <2645477756@qq.com> Run-TryBot: Jorropo <jorropo.pgm@gmail.com>
2023-11-22internal/abi, runtime, reflect, cmd: merge maxZero const into internal/abiqiulaidongfeng
For #59670 Change-Id: If38a74ad067a3ea3ff551c0c25c8ef41abec114b GitHub-Last-Rev: fb1f2f3c9f320017627bc3342b061e1e7f6f7fad GitHub-Pull-Request: golang/go#64268 Reviewed-on: https://go-review.googlesource.com/c/go/+/543655 Run-TryBot: qiulaidongfeng <2645477756@qq.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2023-11-21reflect, runtime: add reflect support for regABI on loong64Guoqi Chen
Update #40724 Co-authored-by: Xiaolin Zhao <zhaoxiaolin@loongson.cn> Change-Id: I0549fd1a2192ffb041034ff41bf0cc4be0b1662c Reviewed-on: https://go-review.googlesource.com/c/go/+/521784 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Meidan Li <limeidan@loongson.cn> Reviewed-by: David Chase <drchase@google.com> Auto-Submit: David Chase <drchase@google.com> Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-11-21reflect: tweak logic for 'case Array' in IsZeroJes Cok
For 'case Array' in IsZero, check 'v.flag&flagIndir == 0' in the first place, rename 'array' to 'typ' for consistency, and remove stale comment. Add line breaks for long sentence in isZero. Change-Id: Id06d01fd61eefd205bf4626e6b920ae82b459455 GitHub-Last-Rev: 7225ca3f7b55cbef58387365ed8f3ff104236a06 GitHub-Pull-Request: golang/go#64270 Reviewed-on: https://go-review.googlesource.com/c/go/+/543656 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com> Run-TryBot: Jes Cok <xigua67damn@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2023-11-20src: a/an grammar fixesVille Skyttä
Change-Id: I179b50ae8e73677d4d408b83424afbbfe6aa17a1 GitHub-Last-Rev: 2e2d9c1e45556155d02db4df381b99f2d1bc5c0e GitHub-Pull-Request: golang/go#63478 Reviewed-on: https://go-review.googlesource.com/c/go/+/534015 Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-11-19reflect: optimize Value.IsZero for struct typesqiulaidongfeng
For some types where the zero value is a value where all bits of this type are 0 optimize it. goos: windows goarch: amd64 pkg: reflect cpu: AMD Ryzen 7 7840HS w/ Radeon 780M Graphics │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ IsZero/StructInt_512-16 109.75n ± 0% 72.61n ± 1% -33.84% (p=0.000 n=12) Change-Id: I56de8b95f4d4482068960d6f38938763fa1caa90 GitHub-Last-Rev: c143f0cd7616cb3be52c59879f748e49a3c5cbf1 GitHub-Pull-Request: golang/go#64220 Reviewed-on: https://go-review.googlesource.com/c/go/+/543355 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2023-11-16reflect: uncomment allocation testCherry Mui
We no longer force Value content to escape and the compiler's escape analysis can handle it now. Change-Id: I0628f3241e6ef37dce710c2394725e280790479a Reviewed-on: https://go-review.googlesource.com/c/go/+/542975 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
2023-11-16reflect: remove go121noForceValueEscapeCherry Mui
Before Go 1.21, ValueOf always escapes and a Value's content is always heap allocated. In Go 1.21, we made it no longer always escape, guarded by go121noForceValueEscape. This behavior has been released for some time and there is no issue so far. We can remove the guard now. Change-Id: I81f5366412390f6c63b642f4c7c016da534da76a Reviewed-on: https://go-review.googlesource.com/c/go/+/542795 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-11-16runtime: optimize bulkBarrierPreWrite with allocheadersMichael Anthony Knyszek
Currently bulkBarrierPreWrite follows a fairly slow path wherein it calls typePointersOf, which ends up calling into fastForward. This does some fairly heavy computation to move the iterator forward without any assumptions about where it lands at all. It needs to be completely general to support splitting at arbitrary boundaries, for example for scanning oblets. This means that copying objects during the GC mark phase is fairly expensive, and is a regression from before allocheaders. However, in almost all cases bulkBarrierPreWrite and bulkBarrierPreWriteSrcOnly have perfect type information. We can do a lot better in these cases because we're starting on a type-size boundary, which is exactly what the iterator is built around. This change adds the typePointersOfType method which produces a typePointers iterator from a pointer and a type. This change significantly improves the performance of these bulk write barriers, eliminating some performance regressions that were noticed on the perf dashboard. There are still just a couple cases where we have to use the more general typePointersOf calls, but they're fairly rare; most bulk barriers have perfect type information. This change is tested by the GCInfo tests in the runtime and the GCBits tests in the reflect package via an additional check in getgcmask. Results for tile38 before and after allocheaders. There was previous a regression in the p90, now it's gone. Also, the overall win has been boosted slightly. tile38 $ benchstat noallocheaders.results allocheaders.results name old time/op new time/op delta Tile38QueryLoad 481µs ± 1% 468µs ± 1% -2.71% (p=0.000 n=10+10) name old average-RSS-bytes new average-RSS-bytes delta Tile38QueryLoad 6.32GB ± 1% 6.23GB ± 0% -1.38% (p=0.000 n=9+8) name old peak-RSS-bytes new peak-RSS-bytes delta Tile38QueryLoad 6.49GB ± 1% 6.40GB ± 1% -1.38% (p=0.002 n=10+10) name old peak-VM-bytes new peak-VM-bytes delta Tile38QueryLoad 7.72GB ± 1% 7.64GB ± 1% -1.07% (p=0.007 n=10+10) name old p50-latency-ns new p50-latency-ns delta Tile38QueryLoad 212k ± 1% 205k ± 0% -3.02% (p=0.000 n=10+9) name old p90-latency-ns new p90-latency-ns delta Tile38QueryLoad 622k ± 1% 616k ± 1% -1.03% (p=0.005 n=10+10) name old p99-latency-ns new p99-latency-ns delta Tile38QueryLoad 4.55M ± 2% 4.39M ± 2% -3.51% (p=0.000 n=10+10) name old ops/s new ops/s delta Tile38QueryLoad 12.5k ± 1% 12.8k ± 1% +2.78% (p=0.000 n=10+10) Change-Id: I0a48f848eae8777d0fd6769c3a1fe449f8d9d0a6 Reviewed-on: https://go-review.googlesource.com/c/go/+/542219 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-11-15reflect: optimize Value.IsZero for array typesqiulaidongfeng
For some types where the zero value is a value where all bits of this type are 0 optimize it goos: windows goarch: amd64 pkg: reflect cpu: AMD Ryzen 7 7840HS w/ Radeon 780M Graphics │ std.txt │ new.txt │ │ sec/op │ sec/op vs base │ IsZero/ArrayComparable-16 8.483n ± 0% 8.470n ± 2% ~ (p=0.542 n=10) IsZero/ArrayIncomparable-16 88.13n ± 1% 87.34n ± 2% ~ (p=0.110 n=10) IsZero/StructComparable-16 4.050n ± 2% 4.011n ± 1% ~ (p=0.093 n=10) IsZero/StructIncomparable-16 19.93n ± 1% 19.81n ± 1% ~ (p=0.493 n=10) IsZero/ArrayInt_4-16 4.445n ± 2% 4.478n ± 2% ~ (p=0.306 n=10) IsZero/ArrayInt_1024-16 3381.5n ± 3% 140.8n ± 1% -95.84% (p=0.000 n=10) IsZero/ArrayInt_1024_NoZero-16 1760.50n ± 3% 72.17n ± 1% -95.90% (p=0.000 n=10) IsZero/Struct4Int-16 4.495n ± 3% 4.478n ± 1% ~ (p=0.579 n=10) IsZero/ArrayStruct4Int_1024-16 1404.0n ± 3% 140.5n ± 0% -90.00% (p=0.000 n=10) IsZero/ArrayChanInt_1024-16 3437.0n ± 6% 140.5n ± 1% -95.91% (p=0.000 n=10) geomean 89.94n 27.38n -69.56% Change-Id: I835231a79b9cd89686d44c5b8c2fbe629ccd98ba GitHub-Last-Rev: 3abe118a108faf0070b56ba9098871746daa1ac1 GitHub-Pull-Request: golang/go#63661 Reviewed-on: https://go-review.googlesource.com/c/go/+/536855 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com>
2023-11-09runtime: implement experiment to replace heap bitmap with alloc headersMichael Anthony Knyszek
This change replaces the 1-bit-per-word heap bitmap for most size classes with allocation headers for objects that contain pointers. The header consists of a single pointer to a type. All allocations with headers are treated as implicitly containing one or more instances of the type in the header. As the name implies, headers are usually stored as the first word of an object. There are two additional exceptions to where headers are stored and how they're used. Objects smaller than 512 bytes do not have headers. Instead, a heap bitmap is reserved at the end of spans for objects of this size. A full word of overhead is too much for these small objects. The bitmap is of the same format of the old bitmap, minus the noMorePtrs bits which are unnecessary. All the objects <512 bytes have a bitmap less than a pointer-word in size, and that was the granularity at which noMorePtrs could stop scanning early anyway. Objects that are larger than 32 KiB (which have their own span) have their headers stored directly in the span, to allow power-of-two-sized allocations to not spill over into an extra page. The full implementation is behind GOEXPERIMENT=allocheaders. The purpose of this change is performance. First and foremost, with headers we no longer have to unroll pointer/scalar data at allocation time for most size classes. Small size classes still need some unrolling, but their bitmaps are small so we can optimize that case fairly well. Larger objects effectively have their pointer/scalar data unrolled on-demand from type data, which is much more compactly represented and results in less TLB pressure. Furthermore, since the headers are usually right next to the object and where we're about to start scanning, we get an additional temporal locality benefit in the data cache when looking up type metadata. The pointer/scalar data is now effectively unrolled on-demand, but it's also simpler to unroll than before; that unrolled data is never written anywhere, and for arrays we get the benefit of retreading the same data per element, as opposed to looking it up from scratch for each pointer-word of bitmap. Lastly, because we no longer have a heap bitmap that spans the entire heap, there's a flat 1.5% memory use reduction. This is balanced slightly by some objects possibly being bumped up a size class, but most objects are not tightly optimized to size class sizes so there's some memory to spare, making the header basically free in those cases. See the follow-up CL which turns on this experiment by default for benchmark results. (CL 538217.) Change-Id: I4c9034ee200650d06d8bdecd579d5f7c1bbf1fc5 Reviewed-on: https://go-review.googlesource.com/c/go/+/437955 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-11-02reflect: pass the right element type in verifyGCBitsSliceMichael Anthony Knyszek
Currently verifyGCBitsSlice creates a new array type to represent the slice backing store, but passes the element type as the slice type in this construction. This is incorrect, but the tests currently don't care about it. They will in a follow-up CL, so fix it now. Change-Id: I6ed8a9808ae78c624be316db1566376fa0e12758 Reviewed-on: https://go-review.googlesource.com/c/go/+/537981 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-10-09reflect: compute the median h uniformlyJes Cok
Like sort.Search, use "h := int(uint(i+j) >> 1)" to compute the median h. Change-Id: I62c1e67533657e2b56af872676e5dc4ed4d49c55 GitHub-Last-Rev: cbfba7ee9ab0a0bda371db3ad5e8cc4d5ea91579 GitHub-Pull-Request: golang/go#63439 Reviewed-on: https://go-review.googlesource.com/c/go/+/533595 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-22reflect: remove broken support for embedding of interfaces from StructOf.Dominique Lefevre
When reviewing https://go-review.googlesource.com/c/go/+/522435, Cherry Mui cherryyz@google.com noticed that the implementation of StructOf was broken, and produced junk if an interface was embedded into a struct. For example, StructOf messed up the calling convention for methods of the embedded interface: > The main problem is that the method wrappers created by reflect.MakeFunc > expects to be called with a closure calling convention, with a closure > context passed in the context register. But methods are called with > a different calling convention, without setting the closure register, > because (besides this case) all methods are top level functions. > So there is no way to pass that makefunc closure context. It is curious that StructOf did not break in go 1.17 which introduced the regabi. I've tried to run the following example program, and it fails even in 1.7 which introduced StructOf. As the embedding of interfaces has been broken since forever, let us not perpetuate the complexity that this feature brings, and just remove the support for embedding altogether. The test program: package main import ( "fmt" "reflect" ) type I interface { F() } type T int func (t T) F() { println(t) } func main() { var i I t := reflect.StructOf([]reflect.StructField{ { Anonymous: true, Name: "I", Type: reflect.TypeOf(&i).Elem(), }, }) v := reflect.New(t).Elem() v.Field(0).Set(reflect.ValueOf(T(42))) fmt.Println(v) v.Interface().(interface{ F() }).F() // fatal error } Change-Id: I7b2115c22d66ea4ed746f0f9d22b2c94f604e185 Reviewed-on: https://go-review.googlesource.com/c/go/+/526075 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-09-22all: clean unnecessary casts for test filesJes Cok
This is a follow up of CL 528696. Change-Id: I5b71eabedb12567c4b1b36f7182a3d2b0ed662a5 GitHub-Last-Rev: acaf3ac11c38042ad27b99e1c70a3c9f1a554a15 GitHub-Pull-Request: golang/go#62713 Reviewed-on: https://go-review.googlesource.com/c/go/+/529197 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-01reflect: make Value.IsZero identical to v == zeroJoe Tsai
The upcoming built-in zero value provides an idiomatic way to test for zero by comparing to the zero literal: v == zero. The reflect package is meant to provide a programmatic way to perform operations that the Go language itself provides. Thus, it seems prudent that reflect.ValueOf(&v).Elem().IsZero() is identical to v == zero. This change alters the behavior of Value.IsZero in two concrete ways: * negative zero is identical to zero * blank fields in a struct are ignored Prior to this change, we were already in an inconsistent state due to a regression introduced by CL 411478. The new behavior was already the case for comparable composite types. This change makes it consistent for all other types (in particular incomparable composite types and standalone numbers). Updates #61372 Fixes #61827 Change-Id: Id23fb97eb3b8921417cc75a1d3ead963e22dc3d9 Reviewed-on: https://go-review.googlesource.com/c/go/+/517777 Reviewed-by: Russ Cox <rsc@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-08-02reflect: update Type.FieldByName documentationqiulaidongfeng
Fixes #61495 Change-Id: I9abaf3613c797006b803dcb1dbee16f25ffb7516 Change-Id: I9abaf3613c797006b803dcb1dbee16f25ffb7516 GitHub-Last-Rev: 7bc2cba77286be1bd322ee31eee3e1df3d8761f1 GitHub-Pull-Request: golang/go#61645 Reviewed-on: https://go-review.googlesource.com/c/go/+/514035 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
2023-08-01reflect: make linkable cross-references in documentationKeith Randall
This makes it easier to click around in documentation on pkg.go.dev. Change-Id: Idc67c312bc72c612e660607e5400b43ecc110bc1 Reviewed-on: https://go-review.googlesource.com/c/go/+/514895 Run-TryBot: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-07-31reflect: add TypeForCarl Johnson
Fixes #60088 Change-Id: I7b43d329def22c2524501ba1d6bfc73becc823d1 GitHub-Last-Rev: becd714c4562da4a3280c3a56ebaf246e48e9f37 GitHub-Pull-Request: golang/go#61598 Reviewed-on: https://go-review.googlesource.com/c/go/+/513478 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
2023-07-31reflect: optimize DeepEqual() for mapskorzhao
benchmark old ns/op new ns/op delta BenchmarkMapsDeepEqual-10 235 200 -15.05% benchmark old allocs new allocs delta BenchmarkMapsDeepEqual-10 7 6 -14.29% benchmark old bytes new bytes delta BenchmarkMapsDeepEqual-10 96 48 -50.00% Change-Id: Ifa625ad25524cc9ee438711917606626b33a9597 Reviewed-on: https://go-review.googlesource.com/c/go/+/512576 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org>
2023-07-27reflect: deprecate PtrToqiulaidongfeng
Replace reflect.PtrTo with reflect.PointerTo. Fixes #59599 Change-Id: I49407193e2050543ef983cd637703acc682d9f51 Change-Id: I49407193e2050543ef983cd637703acc682d9f51 GitHub-Last-Rev: 7bc9ccf1dcb4b444406430b451ad4c47c6ec1be2 GitHub-Pull-Request: golang/go#61440 Reviewed-on: https://go-review.googlesource.com/c/go/+/511035 Run-TryBot: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-07-21reflect: panic on recv channel closeMauri de Souza Meneguzzo
It is possible to call reflect.ValueOf(ch).Close() on a recv-only channel, while close(ch) is a compile-time error. Following the same reflect semantics as send and recv this should result in a panic. Fixes #61445 Change-Id: I2a9ee8f45963593a37bd6df4643dd64fb322f9f9 GitHub-Last-Rev: fe2d5e09f5bb5536ac25d1606cf3744fb7a0a4a9 GitHub-Pull-Request: golang/go#61453 Reviewed-on: https://go-review.googlesource.com/c/go/+/511295 Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-06-16reflect: fix ArenaNew to match documentationMichael Anthony Knyszek
Currently ArenaNew expects the type passed in to be a *T and it returns a *T. This does not match the function's documentation. Since this is an experiment, change ArenaNew to match the documentation. This more closely aligns ArenaNew with arena.New. (Takes a type T, returns a *T value.) Note that this is a breaking change. However, as far as pkg.go.dev can tell, there's exactly one package using it in the open source world. Also, add smoke test for the exported API, which is just a wrapper around the internal API. Clearly there's enough room for error here that it should be tested, but we don't need thorough tests at this layer because that already exists in the runtime. We just need to make sure it basically works. Fixes #60528. Change-Id: I673cc4609378380ef80648b0c2eb2928e73f49c9 Reviewed-on: https://go-review.googlesource.com/c/go/+/501860 Run-TryBot: Michael Knyszek <mknyszek@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-05-12reflect: make Value.IsZero not escapeCherry Mui
With CL 408826 reflect.Value not always escape. IsZero still escapes the Value because in some cases it passes the Value pointer to the equal function, which is function pointer. Equal functions are compiler generated and never escapes, but the escape analysis doesn't know. Add noescape to help. Change-Id: Ica397c2be77cac9e8a46d03d70bac385b0aa9e82 Reviewed-on: https://go-review.googlesource.com/c/go/+/441937 Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-05-12reflect: do not escape Value.TypeCherry Mui
Types are either static (for compiler-created types) or heap allocated and always reachable (for reflection-created types, held in the central map). So there is no need to escape types. With CL 408826 reflect.Value does not always escape. Some functions that escapes Value.typ would make the Value escape without this CL. Had to add a special case for the inliner to keep (*Value).Type still inlineable. Change-Id: I7c14d35fd26328347b509a06eb5bd1534d40775f Reviewed-on: https://go-review.googlesource.com/c/go/+/413474 Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-05-12reflect: allow Value be stack allocatedCherry Mui
Currently, reflect.ValueOf forces the referenced object to be heap allocated. This CL makes it possible to be stack allocated. We need to be careful to make sure the compiler's escape analysis can do the right thing, e.g. channel send, map assignment, unsafe pointer conversions. Tests will be added in a later CL. CL 408827 might help ensure the correctness. Change-Id: I8663651370c7c8108584902235062dd2b3f65954 Reviewed-on: https://go-review.googlesource.com/c/go/+/408826 Run-TryBot: Cherry Mui <cherryyz@google.com> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2023-05-12Revert "reflect: change rtype so that it (not *rtype) implements Type"Austin Clements
This reverts CL 487558, which is causing test failures in Google. See b/282133554. Change-Id: Icafa4ffc6aaa24a363abb90b8ae0b0183aca2b89 Reviewed-on: https://go-review.googlesource.com/c/go/+/494410 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Austin Clements <austin@google.com> Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Austin Clements <austin@google.com>
2023-05-11runtime: redefine _type to abi.Type; add rtype for methods.David Chase
Change-Id: I1c478b704d84811caa209006c657dda82d9c4cf9 Reviewed-on: https://go-review.googlesource.com/c/go/+/488435 Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com>
2023-05-11reflect: change rtype so that it (not *rtype) implements TypeDavid Chase
The abi.Type field was changed to *abi.Type, thus the bitwise representation is the same, many casts are now avoided and replace by either rtype{afoo} or rfoo.Type. Change-Id: Ie7643edc714a0e56027c2875498a4dfe989cf7dd Reviewed-on: https://go-review.googlesource.com/c/go/+/487558 Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-05-11reflect: replacing almost all use of *rtype with *abi.TypeDavid Chase
Change-Id: I3601525b10237d828c449c62a3447f66cb6f025e Reviewed-on: https://go-review.googlesource.com/c/go/+/487557 Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-05-10reflect: move funcType to abi/type.goDavid Chase
Change-Id: I381229ba67a39487cdcc60da1c73d33b0a7d494a Reviewed-on: https://go-review.googlesource.com/c/go/+/487556 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: David Chase <drchase@google.com>
2023-05-10reflect: prepare fieldnames for moving to abi/type.goDavid Chase
Change-Id: Ia8e88029d29a1210dc7a321578e61336e235f35a Reviewed-on: https://go-review.googlesource.com/c/go/+/487555 Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2023-05-10internal/abi,reflectlite,reflect,runtime: common up chan typeDavid Chase
Change-Id: I085b61c544b85d70fabb1c0d9fe91207826dd21a Reviewed-on: https://go-review.googlesource.com/c/go/+/484858 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@google.com>
2023-05-10reflect: move more types, constants, functions into internal/abiDavid Chase
Change-Id: Ib9cd15576896225e7c5e6fda11f1a77f6993a91a Reviewed-on: https://go-review.googlesource.com/c/go/+/484857 Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com>
2023-05-10internal/abi: common up ArrayTypeDavid Chase
This refactoring is more problematic because the client package wrap abi.Type, thus the self-referential fields within ArrayType need to be downcast to the client wrappers in several places. It's not clear to me this is worthwhile; this CL is for additional comment, before I attempt similar changes for other self-referential types. Change-Id: I41e517e6d851b32560c41676b91b76d7eb17c951 Reviewed-on: https://go-review.googlesource.com/c/go/+/466236 Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com>
2023-05-10internal/abi: common up Method, Imethod, UncommonType typesDavid Chase
was two commits, the first contained a lot of intermediate work, better this way. Change-Id: I7c5b79ef78b21a85828c8aaf9baeae86bb144db7 Reviewed-on: https://go-review.googlesource.com/c/go/+/463118 Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-05-05internal/abi: refactor (basic) type struct into one definitionDavid Chase
This touches a lot of files, which is bad, but it is also good, since there's N copies of this information commoned into 1. The new files in internal/abi are copied from the end of the stack; ultimately this will all end up being used. Change-Id: Ia252c0055aaa72ca569411ef9f9e96e3d610889e Reviewed-on: https://go-review.googlesource.com/c/go/+/462995 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Carlos Amedee <carlos@golang.org> Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2023-04-10reflect: remove typedmemmovepartial as it is unusedDaniel Martí
It appears to have been unused since https://go.dev/cl/298670 in April 2021, as that change removed its only use. It is always in the git history if it is needed again. Change-Id: Ie55d059c102dfaa75bd253e09d48a4b30f45e941 Reviewed-on: https://go-review.googlesource.com/c/go/+/483136 Reviewed-by: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Michael Pratt <mpratt@google.com>
2023-04-04all: fix misuses of "a" vs "an"cui fliter
Fixes the misuse of "a" vs "an", according to English grammatical expectations and using https://www.a-or-an.com/ Change-Id: I53ac724070e3ff3d33c304483fe72c023c7cda47 Reviewed-on: https://go-review.googlesource.com/c/go/+/480536 Run-TryBot: shuang cui <imcusg@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-04-03reflect: deprecate SliceHeader and StringHeaderRuss Cox
These are replaced by unsafe.String etc, which were added in Go 1.20. Per https://go.dev/wiki/Deprecated, we must wait until Go 1.21 to mark them deprecated. Fixes #56906. Change-Id: I4198c3f3456e9e2031f6c7232842e187e6448892 Reviewed-on: https://go-review.googlesource.com/c/go/+/452762 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Russ Cox <rsc@golang.org>
2023-03-22reflect: add test for interface type NumMethodCuong Manh Le
While at it, also use concrete type for non-interface type test. Change-Id: Ie468c30ee31ba99ef8f9a810d3be851fd37b9b43 Reviewed-on: https://go-review.googlesource.com/c/go/+/478356 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com>
2023-01-30reflect,runtime: add Value.ClearCuong Manh Le
Fixes #55002 Change-Id: I7d0f14cc54f67f2769b51d2efafc4ae3714f0e3d Reviewed-on: https://go-review.googlesource.com/c/go/+/457895 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-23internal/abi,runtime: refactor map constants into one placeDavid Chase
Previously TryBot-tested with bucket bits = 4. Also tested locally with bucket bits = 5. This makes it much easier to change the size of map buckets, and hopefully provides pointers to all the code that in some way depends on details of map layout. Change-Id: I9f6669d1eadd02f182d0bc3f959dc5f385fa1683 Reviewed-on: https://go-review.googlesource.com/c/go/+/462115 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Austin Clements <austin@google.com>
2022-11-29reflect: correct tpoy in commentIan Lance Taylor
Change-Id: I75aef6bf957939fae8b680214f5923dc2713a5cc Reviewed-on: https://go-review.googlesource.com/c/go/+/452935 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org>
2022-11-23reflect: remove deprecation notices from SliceHeader, StringHeaderRuss Cox
There has been no proposal discussion about adding these notices. Also, even if we did decide to add them, then since their replacements are only appearing in Go 1.20, go.dev/wiki/Deprecation says that we should wait until Go 1.22 to add the deprecation notice. Filed #56906 for the proposal discussion. Fixes #56905. Change-Id: If86cce65aa00b4b62b2b18e82503431dcbdbcfed Reviewed-on: https://go-review.googlesource.com/c/go/+/452761 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-23doc/go1.20: finish most standard library TODOsRuss Cox
Change-Id: Id8f074b96d28ae37a3d2d2a52a2b80cc53cd1203 Reviewed-on: https://go-review.googlesource.com/c/go/+/452760 TryBot-Bypass: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-11-09all: add missing copyright headercui fliter
Change-Id: Ia5a090953d324f0f8aa9c1808c88125ad5eb6f98 Reviewed-on: https://go-review.googlesource.com/c/go/+/448955 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Bryan Mills <bcmills@google.com>