Damian Gryski
b044d27dff
reflect: move StructField.Anonymous field to match upstream location
2023-03-15 00:13:08 +01:00
Damian Gryski
6768af91e7
reflect: TypeOf(nil) should be nil
2023-03-14 23:58:27 +01:00
Damian Gryski
a366c014c7
reflect: call decomposeInterface() directly in TypeOf()
2023-03-14 09:53:45 -07:00
Damian Gryski
584a2718d0
reflect: add type check to Value.Field()
2023-03-14 09:53:00 -07:00
Damian Gryski
069c397975
reflect: fix off-by-one in Zero sizing
...
Without this, pointers wouldn't be set to nil. Add some tests.
2023-03-14 09:42:51 -07:00
Damian Gryski
e0aee1f23c
reflect: Type.AssignableTo(): you can assign anything to interface{}
2023-03-14 17:07:23 +01:00
Damian Gryski
ad9f790dfc
reflect: set Index field in Field()
2023-03-14 17:04:24 +01:00
Damian Gryski
04412cba0e
reflect: add stub for StructOf()
2023-03-14 16:54:44 +01:00
Damian Gryski
3b2763896f
reflect: add stubs for Method(), CanConvert(), ArrayOf()
2023-03-14 16:54:44 +01:00
Damian Gryski
fb394c7685
reflect: add UnsafeAddr()
2023-03-14 16:53:57 +01:00
Damian Gryski
a52cad3825
reflect: fix Addr() indirect value/flags and add tests.
2023-03-14 16:49:05 +01:00
Damian Gryski
69e5c5088d
reflect: add support for remaining map types
2023-03-10 16:28:22 -08:00
Damian Gryski
6a45b73fcb
compiler, reflect: replace package and name length with null-byte termination
2023-03-08 09:38:49 -08:00
Damian Gryski
2de64d3f4e
compiler, reflect: add Type.PkgPath
2023-03-08 09:38:49 -08:00
Damian Gryski
2a821d2a66
reflect: improve Value.String()
2023-03-08 09:38:49 -08:00
Damian Gryski
90af41d089
reflect: add Type.String()
2023-03-08 09:38:49 -08:00
Damian Gryski
7654d86d2c
compiler, reflect: add support for named types
2023-03-08 09:38:49 -08:00
Damian Gryski
f9b6f8339b
reflect: ensure all ValueError panics have Kind fields
2023-03-03 10:18:32 -08:00
Damian Gryski
0ff243e5e2
reflect: add OverflowFloat(), OverflowInt(), OverflowUint()
2023-03-03 10:18:32 -08:00
Damian Gryski
79930a209c
reflect: add Addr()
2023-03-03 10:18:32 -08:00
Damian Gryski
bbc79ee40a
reflect: add Zero()
2023-03-03 10:18:32 -08:00
Damian Gryski
960a0b79bf
reflect: add SetLen()
2023-03-03 10:18:32 -08:00
Damian Gryski
e4ef6f85ac
reflect: allow nil rawType to call Kind()
2023-03-03 10:18:32 -08:00
Damian Gryski
3a3de8a778
reflect: add pointerTo()
2023-03-03 10:18:32 -08:00
Ayke van Laethem
4ec1e58aa6
all: use unsafe.Add instead of unsafe.Pointer(uintptr(...) + ...)
...
We have an optimization for this specific pattern, but it's really just
a hack. With the addition of unsafe.Add in Go 1.17 we can directly
specify the intent instead and eventually remove this special case.
The code is also easier to read.
2023-03-03 16:55:13 +01:00
Damian Gryski
d98c0afbab
reflect: add Bytes()
2023-03-03 05:21:02 -08:00
Damian Gryski
12e3d1d81d
reflect: add Copy()
2023-03-03 05:21:02 -08:00
Damian Gryski
a7e3cf0826
reflect: add Slice3()
2023-03-03 05:21:02 -08:00
Damian Gryski
43a4b256bd
reflect: add Slice()
2023-03-03 05:21:02 -08:00
Damian Gryski
5cc5f11b58
reflect: add MakeSlice()
2023-03-03 05:21:02 -08:00
Damian Gryski
836689fdd2
reflect: add Append()
2023-03-03 05:21:02 -08:00
Damian Gryski
1cce1ea423
reflect: uncomment some DeepEqual tests that now pass
2023-02-28 13:10:40 -08:00
Damian Gryski
a2bb1d3805
reflect: add MapKeys()
2023-02-28 13:10:40 -08:00
Damian Gryski
c4dadbaaab
reflect: add MakeMap()
2023-02-28 13:10:40 -08:00
Damian Gryski
828c3169ab
reflect: add SetMapIndex()
2023-02-28 13:10:40 -08:00
Damian Gryski
f6ee470eda
reflect: add MapRange/MapIter
2023-02-28 13:10:40 -08:00
Damian Gryski
d0f4702f8b
reflect: add MapIndex()
2023-02-28 13:10:40 -08:00
Damian Gryski
9541525402
reflect: add Type.Elem() and Type.Key() for Maps
2023-02-28 13:10:40 -08:00
Damian Gryski
60a93e8e2d
compiler, reflect: add map key and element type info
2023-02-28 13:10:40 -08:00
Ayke van Laethem
4e8453167f
all: refactor reflect package
...
This is a big commit that changes the way runtime type information is stored in
the binary. Instead of compressing it and storing it in a number of sidetables,
it is stored similar to how the Go compiler toolchain stores it (but still more
compactly).
This has a number of advantages:
* It is much easier to add new features to reflect support. They can simply
be added to these structs without requiring massive changes (especially in
the reflect lowering pass).
* It removes the reflect lowering pass, which was a large amount of hard to
understand and debug code.
* The reflect lowering pass also required merging all LLVM IR into one
module, which is terrible for performance especially when compiling large
amounts of code. See issue 2870 for details.
* It is (probably!) easier to reason about for the compiler.
The downside is that it increases code size a bit, especially when reflect is
involved. I hope to fix some of that in later patches.
2023-02-17 22:54:34 +01:00
Damian Gryski
86f125cf72
reflect: track flags when size changes from fits-in-pointer to not
...
Fixes #3328
2022-12-07 23:11:40 +01:00
Julia Ogris
c759e6fc2d
reflect: Add Value.IsZero() method
...
Add Value.IsZero() with tests, largely copied from the Go source code.
The tests were altered to remove the parts calling `Zero()` as that is
still unimplemented in tinygo, and to remove a test that tries to catch
a panic which is not supported on wasi.
A new case for `UnsafePointer` in `Value.IsNil()` was required for
unsafe.Pointer tests to pass.
Link: https://cs.opensource.google/go/go/+/refs/tags/go1.19.3:src/reflect/value.go;l=1568
Link: https://cs.opensource.google/go/go/+/refs/tags/go1.19.3:src/reflect/all_test.go;l=1322
Co-authored-by: Cam Hutchison <camh@xdna.net>
2022-11-21 14:51:22 +01:00
Anuraag Agrawal
62594004c6
Stub out reflect.Type FieldByIndex
2022-10-26 12:06:08 +02:00
Ayke van Laethem
e955aa1941
reflect: implement CanInterface and fix string Index()
...
This commit fixes two related issues:
1. CanInterface was unimplemented. It now uses the same check as is
used in Interface() itself.
This issue led to https://github.com/tinygo-org/tinygo/issues/3033
2. Allow making an interface out of a string char element.
Doing this in one commit (instead of two) because they are shown to be
correct with the same tests.
2022-09-01 21:42:22 +02:00
Ayke van Laethem
c7a23183e8
all: format code according to Go 1.19 rules
...
Go 1.19 started reformatting code in a way that makes it more obvious
how it will be rendered on pkg.go.dev. It gets it almost right, but not
entirely. Therefore, I had to modify some of the comments so that they
are formatted correctly.
2022-08-04 12:18:32 +02:00
Ayke van Laethem
4262f0ff1f
compiler: really define runtime.mem* as LLVM intrinsic wrappers
...
This makes it possible to //go:linkname them from other places, like in
the reflect package. And is in my opinion a much cleaner solution.
2022-06-24 11:10:24 +02:00
Ayke van Laethem
caf405b01d
reflect: add Value.UnsafePointer method
...
This was added in Go 1.18.
2022-06-12 01:08:02 +02:00
Elliott Sales de Andrade
f159573975
Add reflect.Value.FieldByIndexErr stub
2022-03-24 06:31:02 +01:00
Elliott Sales de Andrade
836ab95192
Rename reflect.Ptr to reflect.Pointer
...
This was done in plain Go for 1.18:
17910ed4ff
2022-03-18 15:27:28 +01:00
Kyle Conroy
cfed3f0213
fix: Add stubs for more missing reflect methods
...
With these methods stubbed out, the text/template package can be
imported. These changes also allow code generated by protoc to compile.
2022-02-24 12:32:40 -05:00