Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
f8bfa62
compiler, reflect: add map key and element type info
dgryski Feb 15, 2023
cd93cd5
reflect: add MapIndex
dgryski Feb 15, 2023
bba9fde
reflect: add SetMapIndex
dgryski Feb 15, 2023
e44bd0d
reflect: handle indirect values in SetMapIndex
dgryski Feb 15, 2023
da935f8
reflect: handle Type.Key()
dgryski Feb 15, 2023
39fb3a5
reflect: use t.isNamed()
dgryski Feb 15, 2023
d8fa66f
reflect: add MapKeys()
dgryski Feb 15, 2023
635b313
reflect: add MapRange()
dgryski Feb 15, 2023
08487d8
reflect,runtime: remove UnsafePointer wrappers
dgryski Feb 16, 2023
7d6a4fc
reflect: add some slice reflect methods
dgryski Feb 16, 2023
607316f
reflect: flesh out MakeMap for string keys
dgryski Feb 16, 2023
bc0238e
reflect: fix extra pointer in MakeMap
dgryski Feb 20, 2023
010e9ac
reflect: add pointerto() that works with rawTypes
dgryski Feb 20, 2023
bb33d51
reflect: preallocate keys slice in MapKeys()
dgryski Feb 20, 2023
89f8bb7
reflect: use pointer() for accessing map pointer
dgryski Feb 20, 2023
09ee686
reflect: set valueFlagIndirect for slices
dgryski Feb 20, 2023
6ab842d
reflect: simplify MakeSlice() panic logic
dgryski Feb 20, 2023
72fcd2f
reflect: add stubs for channel operations
dgryski Feb 20, 2023
368d9ba
reflect: use ValueError() in SetLen()
dgryski Feb 21, 2023
bc01c04
reflect: fix panic message
dgryski Feb 21, 2023
3701efb
reflect: add OverflowFloat and OverflowUint
dgryski Feb 21, 2023
e125fb6
reflect: better setlen panic message
dgryski Feb 21, 2023
5392f1d
reflect: add binary map keys
dgryski Feb 21, 2023
1be78f5
compiler,reflect: add Name() support
dgryski Feb 21, 2023
1c43d8c
reflect: add FieldByName and FieldByIndex
dgryski Feb 21, 2023
2a3d143
reflect,runtime: add LLVM14 unsafe.Pointer compat wrappers
dgryski Feb 21, 2023
2f401a7
reflect, runtime: a zero reflect.Value in SetMapIndex means delete()
dgryski Feb 21, 2023
a3fd40e
reflect: MapIndex returns Value{} if no key found
dgryski Feb 22, 2023
909208d
reflect: fix SetMapIndex panic messages
dgryski Feb 22, 2023
d805154
reflect: add unit test to cover all the new goodies
dgryski Feb 22, 2023
462b3e2
compiler: update unit tests golden output
dgryski Feb 22, 2023
e56e570
reflect: uncomment a bunch of deep equal tests that now pass
dgryski Feb 22, 2023
6b903a1
reflect: todo++ to handle undef padding bytes
dgryski Feb 22, 2023
8e433c9
targets: bump default-stack-size so testdata/json.go runs
dgryski Feb 23, 2023
6b6bc95
reflect: add MakeMapWithSize and fix MakeMap size hint
dgryski Feb 23, 2023
11fce44
reflect: allow looking up the Kind() field of nil rawtype pointers
dgryski Feb 24, 2023
b903155
reflect: implement FieldByName and FieldByIndex
dgryski Feb 24, 2023
995c03f
reflect: fix flags for MakeSlice()
dgryski Feb 24, 2023
3f6b3f6
reflect: implement Append()
dgryski Feb 24, 2023
b2f2251
reflect: implement Zero()
dgryski Feb 24, 2023
b10163d
reflect: implement Slice()
dgryski Feb 24, 2023
18db66f
reflect: clean up some panic messages
dgryski Feb 24, 2023
c1bfca6
reflect: add Slice3()
dgryski Feb 24, 2023
1ed5d8a
reflect: support Value.Stirng() reporting simple types
dgryski Feb 24, 2023
ff20f2c
reflect: todo++
dgryski Feb 24, 2023
18457d7
reflect: add Bytes() and fix up Copy() to support arrays
dgryski Feb 24, 2023
77d366e
Makefile: more stdlib packages thanks to reflect improvements
dgryski Feb 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ TEST_PACKAGES_FAST = \
net \
net/http/internal/ascii \
net/mail \
net/textproto \
os \
path \
reflect \
Expand All @@ -337,9 +338,11 @@ endif
# compress/lzw appears to hang on wasi
# crypto/hmac fails on wasi, it exits with a "slice out of range" panic
# debug/plan9obj requires os.ReadAt, which is not yet supported on windows
# go/build/constraint requires recover(), which is not yet supported on wasi
# image requires recover(), which is not yet supported on wasi
# io/ioutil requires os.ReadDir, which is not yet supported on windows or wasi
# mime/quotedprintable requires syscall.Faccessat
# mime/multipart hangs on wasi and fails on windows
# strconv requires recover() which is not yet supported on wasi
# text/tabwriter requries recover(), which is not yet supported on wasi
# text/template/parse requires recover(), which is not yet supported on wasi
Expand All @@ -354,8 +357,10 @@ TEST_PACKAGES_LINUX := \
crypto/hmac \
debug/dwarf \
debug/plan9obj \
go/build/constraint \
image \
io/ioutil \
mime/multipart \
mime/quotedprintable \
strconv \
testing/fstest \
Expand Down
19 changes: 17 additions & 2 deletions compiler/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ func (c *compilerContext) getTypeCode(typ types.Type) llvm.Value {
typeFieldTypes = append(typeFieldTypes,
types.NewVar(token.NoPos, nil, "ptrTo", types.Typ[types.UnsafePointer]),
types.NewVar(token.NoPos, nil, "underlying", types.Typ[types.UnsafePointer]),
types.NewVar(token.NoPos, nil, "len", types.Typ[types.Uintptr]),
types.NewVar(token.NoPos, nil, "name", types.NewArray(types.Typ[types.Int8], int64(len(typ.Obj().Name())))),
)
case *types.Chan, *types.Slice:
typeFieldTypes = append(typeFieldTypes,
Expand All @@ -131,6 +133,8 @@ func (c *compilerContext) getTypeCode(typ types.Type) llvm.Value {
case *types.Map:
typeFieldTypes = append(typeFieldTypes,
types.NewVar(token.NoPos, nil, "ptrTo", types.Typ[types.UnsafePointer]),
types.NewVar(token.NoPos, nil, "elementType", types.Typ[types.UnsafePointer]),
types.NewVar(token.NoPos, nil, "keyType", types.Typ[types.UnsafePointer]),
)
case *types.Struct:
typeFieldTypes = append(typeFieldTypes,
Expand Down Expand Up @@ -167,9 +171,18 @@ func (c *compilerContext) getTypeCode(typ types.Type) llvm.Value {
case *types.Basic:
typeFields = []llvm.Value{c.getTypeCode(types.NewPointer(typ))}
case *types.Named:
name := typ.Obj().Name()
var buf []llvm.Value

for _, b := range []byte(name) {
buf = append(buf, llvm.ConstInt(c.ctx.Int8Type(), uint64(b), false))
}

typeFields = []llvm.Value{
c.getTypeCode(types.NewPointer(typ)), // ptrTo
c.getTypeCode(typ.Underlying()), // underlying
c.getTypeCode(types.NewPointer(typ)), // ptrTo
c.getTypeCode(typ.Underlying()), // underlying
llvm.ConstInt(c.uintptrType, uint64(len(name)), false), // length
llvm.ConstArray(c.ctx.Int8Type(), buf),
}
metabyte |= 1 << 5 // "named" flag
case *types.Chan:
Expand All @@ -193,6 +206,8 @@ func (c *compilerContext) getTypeCode(typ types.Type) llvm.Value {
case *types.Map:
typeFields = []llvm.Value{
c.getTypeCode(types.NewPointer(typ)), // ptrTo
c.getTypeCode(typ.Elem()), // elem
c.getTypeCode(typ.Key()), // key
}
case *types.Struct:
typeFields = []llvm.Value{
Expand Down
2 changes: 1 addition & 1 deletion compiler/testdata/interface.ll
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ target triple = "wasm32-unknown-wasi"
@"reflect/types.type:basic:int" = linkonce_odr constant { i8, ptr } { i8 2, ptr @"reflect/types.type:pointer:basic:int" }, align 4
@"reflect/types.type:pointer:basic:int" = linkonce_odr constant { i8, ptr } { i8 21, ptr @"reflect/types.type:basic:int" }, align 4
@"reflect/types.type:pointer:named:error" = linkonce_odr constant { i8, ptr } { i8 21, ptr @"reflect/types.type:named:error" }, align 4
@"reflect/types.type:named:error" = linkonce_odr constant { i8, ptr, ptr } { i8 52, ptr @"reflect/types.type:pointer:named:error", ptr @"reflect/types.type:interface:{Error:func:{}{basic:string}}" }, align 4
@"reflect/types.type:named:error" = linkonce_odr constant { i8, ptr, ptr, i32, [5 x i8] } { i8 52, ptr @"reflect/types.type:pointer:named:error", ptr @"reflect/types.type:interface:{Error:func:{}{basic:string}}", i32 5, [5 x i8] c"error" }, align 4
@"reflect/types.type:interface:{Error:func:{}{basic:string}}" = linkonce_odr constant { i8, ptr } { i8 20, ptr @"reflect/types.type:pointer:interface:{Error:func:{}{basic:string}}" }, align 4
@"reflect/types.type:pointer:interface:{Error:func:{}{basic:string}}" = linkonce_odr constant { i8, ptr } { i8 21, ptr @"reflect/types.type:interface:{Error:func:{}{basic:string}}" }, align 4
@"reflect/types.type:pointer:interface:{String:func:{}{basic:string}}" = linkonce_odr constant { i8, ptr } { i8 21, ptr @"reflect/types.type:interface:{String:func:{}{basic:string}}" }, align 4
Expand Down
24 changes: 12 additions & 12 deletions src/reflect/all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var deepEqualTests = []DeepEqualTest{
{&[3]int{1, 2, 3}, &[3]int{1, 2, 3}, true},
{Basic{1, 0.5}, Basic{1, 0.5}, true},
{error(nil), error(nil), true},
//{map[int]string{1: "one", 2: "two"}, map[int]string{2: "two", 1: "one"}, true},
{map[int]string{1: "one", 2: "two"}, map[int]string{2: "two", 1: "one"}, true},
{fn1, fn2, true},
{[]byte{1, 2, 3}, []byte{1, 2, 3}, true},
{[]MyByte{1, 2, 3}, []MyByte{1, 2, 3}, true},
Expand All @@ -87,10 +87,10 @@ var deepEqualTests = []DeepEqualTest{
{&[3]int{1, 2, 3}, &[3]int{1, 2, 4}, false},
{Basic{1, 0.5}, Basic{1, 0.6}, false},
{Basic{1, 0}, Basic{2, 0}, false},
//{map[int]string{1: "one", 3: "two"}, map[int]string{2: "two", 1: "one"}, false},
//{map[int]string{1: "one", 2: "txo"}, map[int]string{2: "two", 1: "one"}, false},
//{map[int]string{1: "one"}, map[int]string{2: "two", 1: "one"}, false},
//{map[int]string{2: "two", 1: "one"}, map[int]string{1: "one"}, false},
{map[int]string{1: "one", 3: "two"}, map[int]string{2: "two", 1: "one"}, false},
{map[int]string{1: "one", 2: "txo"}, map[int]string{2: "two", 1: "one"}, false},
{map[int]string{1: "one"}, map[int]string{2: "two", 1: "one"}, false},
{map[int]string{2: "two", 1: "one"}, map[int]string{1: "one"}, false},
{nil, 1, false},
{1, nil, false},
{fn1, fn3, false},
Expand All @@ -104,16 +104,16 @@ var deepEqualTests = []DeepEqualTest{
{&[1]float64{math.NaN()}, self{}, true},
{[]float64{math.NaN()}, []float64{math.NaN()}, false},
{[]float64{math.NaN()}, self{}, true},
//{map[float64]float64{math.NaN(): 1}, map[float64]float64{1: 2}, false},
//{map[float64]float64{math.NaN(): 1}, self{}, true},
{map[float64]float64{math.NaN(): 1}, map[float64]float64{1: 2}, false},
{map[float64]float64{math.NaN(): 1}, self{}, true},

// Nil vs empty: not the same.
{[]int{}, []int(nil), false},
{[]int{}, []int{}, true},
{[]int(nil), []int(nil), true},
//{map[int]int{}, map[int]int(nil), false},
//{map[int]int{}, map[int]int{}, true},
//{map[int]int(nil), map[int]int(nil), true},
{map[int]int{}, map[int]int(nil), false},
{map[int]int{}, map[int]int{}, true},
{map[int]int(nil), map[int]int(nil), true},

// Mismatched types
{1, 1.0, false},
Expand All @@ -130,8 +130,8 @@ var deepEqualTests = []DeepEqualTest{
// Possible loops.
{&loopy1, &loopy1, true},
{&loopy1, &loopy2, true},
//{&cycleMap1, &cycleMap2, true},
//{&cycleMap1, &cycleMap3, false},
{&cycleMap1, &cycleMap2, true},
{&cycleMap1, &cycleMap3, false},
}

func TestDeepEqual(t *testing.T) {
Expand Down
Loading