Skip to content

Commit eab1a5d

Browse files
aykevldeadprogram
authored andcommitted
reflect, runtime: remove *UnsafePointer wrappers for functions
This was needed in the past because LLVM used typed pointers and there was a mismatch between pointer types. But we've dropped support for typed pointers a while ago so now we can remove these wrappers. This is just a cleanup, it shouldn't have any practical effect.
1 parent f188eaf commit eab1a5d

File tree

3 files changed

+14
-82
lines changed

3 files changed

+14
-82
lines changed

src/reflect/value.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -646,10 +646,10 @@ func (v Value) Slice3(i, j, k int) Value {
646646
panic("unimplemented: (reflect.Value).Slice3()")
647647
}
648648

649-
//go:linkname maplen runtime.hashmapLenUnsafePointer
649+
//go:linkname maplen runtime.hashmapLen
650650
func maplen(p unsafe.Pointer) int
651651

652-
//go:linkname chanlen runtime.chanLenUnsafePointer
652+
//go:linkname chanlen runtime.chanLen
653653
func chanlen(p unsafe.Pointer) int
654654

655655
// Len returns the length of this value for slices, strings, arrays, channels,
@@ -671,7 +671,7 @@ func (v Value) Len() int {
671671
}
672672
}
673673

674-
//go:linkname chancap runtime.chanCapUnsafePointer
674+
//go:linkname chancap runtime.chanCap
675675
func chancap(p unsafe.Pointer) int
676676

677677
// Cap returns the capacity of this value for arrays, channels and slices.
@@ -965,13 +965,13 @@ func (v Value) MapKeys() []Value {
965965
return keys
966966
}
967967

968-
//go:linkname hashmapStringGet runtime.hashmapStringGetUnsafePointer
968+
//go:linkname hashmapStringGet runtime.hashmapStringGet
969969
func hashmapStringGet(m unsafe.Pointer, key string, value unsafe.Pointer, valueSize uintptr) bool
970970

971-
//go:linkname hashmapBinaryGet runtime.hashmapBinaryGetUnsafePointer
971+
//go:linkname hashmapBinaryGet runtime.hashmapBinaryGet
972972
func hashmapBinaryGet(m unsafe.Pointer, key, value unsafe.Pointer, valueSize uintptr) bool
973973

974-
//go:linkname hashmapInterfaceGet runtime.hashmapInterfaceGetUnsafePointer
974+
//go:linkname hashmapInterfaceGet runtime.hashmapInterfaceGet
975975
func hashmapInterfaceGet(m unsafe.Pointer, key interface{}, value unsafe.Pointer, valueSize uintptr) bool
976976

977977
func (v Value) MapIndex(key Value) Value {
@@ -1018,7 +1018,7 @@ func (v Value) MapIndex(key Value) Value {
10181018
//go:linkname hashmapNewIterator runtime.hashmapNewIterator
10191019
func hashmapNewIterator() unsafe.Pointer
10201020

1021-
//go:linkname hashmapNext runtime.hashmapNextUnsafePointer
1021+
//go:linkname hashmapNext runtime.hashmapNext
10221022
func hashmapNext(m unsafe.Pointer, it unsafe.Pointer, key, value unsafe.Pointer) bool
10231023

10241024
func (v Value) MapRange() *MapIter {
@@ -1786,22 +1786,22 @@ func (v Value) Grow(n int) {
17861786
slice.cap = newslice.cap
17871787
}
17881788

1789-
//go:linkname hashmapStringSet runtime.hashmapStringSetUnsafePointer
1789+
//go:linkname hashmapStringSet runtime.hashmapStringSet
17901790
func hashmapStringSet(m unsafe.Pointer, key string, value unsafe.Pointer)
17911791

1792-
//go:linkname hashmapBinarySet runtime.hashmapBinarySetUnsafePointer
1792+
//go:linkname hashmapBinarySet runtime.hashmapBinarySet
17931793
func hashmapBinarySet(m unsafe.Pointer, key, value unsafe.Pointer)
17941794

1795-
//go:linkname hashmapInterfaceSet runtime.hashmapInterfaceSetUnsafePointer
1795+
//go:linkname hashmapInterfaceSet runtime.hashmapInterfaceSet
17961796
func hashmapInterfaceSet(m unsafe.Pointer, key interface{}, value unsafe.Pointer)
17971797

1798-
//go:linkname hashmapStringDelete runtime.hashmapStringDeleteUnsafePointer
1798+
//go:linkname hashmapStringDelete runtime.hashmapStringDelete
17991799
func hashmapStringDelete(m unsafe.Pointer, key string)
18001800

1801-
//go:linkname hashmapBinaryDelete runtime.hashmapBinaryDeleteUnsafePointer
1801+
//go:linkname hashmapBinaryDelete runtime.hashmapBinaryDelete
18021802
func hashmapBinaryDelete(m unsafe.Pointer, key unsafe.Pointer)
18031803

1804-
//go:linkname hashmapInterfaceDelete runtime.hashmapInterfaceDeleteUnsafePointer
1804+
//go:linkname hashmapInterfaceDelete runtime.hashmapInterfaceDelete
18051805
func hashmapInterfaceDelete(m unsafe.Pointer, key interface{})
18061806

18071807
func (v Value) SetMapIndex(key, elem Value) {
@@ -1930,7 +1930,7 @@ func (v Value) FieldByNameFunc(match func(string) bool) Value {
19301930
return Value{}
19311931
}
19321932

1933-
//go:linkname hashmapMake runtime.hashmapMakeUnsafePointer
1933+
//go:linkname hashmapMake runtime.hashmapMake
19341934
func hashmapMake(keySize, valueSize uintptr, sizeHint uintptr, alg uint8) unsafe.Pointer
19351935

19361936
// MakeMapWithSize creates a new map with the specified type and initial space

src/runtime/chan.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,6 @@ func chanLen(c *channel) int {
148148
return int(c.bufUsed)
149149
}
150150

151-
// wrapper for use in reflect
152-
func chanLenUnsafePointer(p unsafe.Pointer) int {
153-
c := (*channel)(p)
154-
return chanLen(c)
155-
}
156-
157151
// Return the capacity of this chan, called from the cap builtin.
158152
// A nil chan is defined as having capacity 0.
159153
//
@@ -165,12 +159,6 @@ func chanCap(c *channel) int {
165159
return int(c.bufSize)
166160
}
167161

168-
// wrapper for use in reflect
169-
func chanCapUnsafePointer(p unsafe.Pointer) int {
170-
c := (*channel)(p)
171-
return chanCap(c)
172-
}
173-
174162
// resumeRX resumes the next receiver and returns the destination pointer.
175163
// If the ok value is true, then the caller is expected to store a value into this pointer.
176164
func (ch *channel) resumeRX(ok bool) unsafe.Pointer {

src/runtime/hashmap.go

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ func hashmapMake(keySize, valueSize uintptr, sizeHint uintptr, alg uint8) *hashm
8787
}
8888
}
8989

90-
func hashmapMakeUnsafePointer(keySize, valueSize uintptr, sizeHint uintptr, alg uint8) unsafe.Pointer {
91-
return (unsafe.Pointer)(hashmapMake(keySize, valueSize, sizeHint, alg))
92-
}
93-
9490
// Remove all entries from the map, without actually deallocating the space for
9591
// it. This is used for the clear builtin, and can be used to reuse a map (to
9692
// avoid extra heap allocations).
@@ -178,10 +174,6 @@ func hashmapLen(m *hashmap) int {
178174
return int(m.count)
179175
}
180176

181-
func hashmapLenUnsafePointer(m unsafe.Pointer) int {
182-
return hashmapLen((*hashmap)(m))
183-
}
184-
185177
//go:inline
186178
func hashmapBucketSize(m *hashmap) uintptr {
187179
return unsafe.Sizeof(hashmapBucket{}) + uintptr(m.keySize)*8 + uintptr(m.valueSize)*8
@@ -268,10 +260,6 @@ func hashmapSet(m *hashmap, key unsafe.Pointer, value unsafe.Pointer, hash uint3
268260
*emptySlotTophash = tophash
269261
}
270262

271-
func hashmapSetUnsafePointer(m unsafe.Pointer, key unsafe.Pointer, value unsafe.Pointer, hash uint32) {
272-
hashmapSet((*hashmap)(m), key, value, hash)
273-
}
274-
275263
// hashmapInsertIntoNewBucket creates a new bucket, inserts the given key and
276264
// value into the bucket, and returns a pointer to this bucket.
277265
func hashmapInsertIntoNewBucket(m *hashmap, key, value unsafe.Pointer, tophash uint8) *hashmapBucket {
@@ -352,10 +340,6 @@ func hashmapGet(m *hashmap, key, value unsafe.Pointer, valueSize uintptr, hash u
352340
return false
353341
}
354342

355-
func hashmapGetUnsafePointer(m unsafe.Pointer, key, value unsafe.Pointer, valueSize uintptr, hash uint32) bool {
356-
return hashmapGet((*hashmap)(m), key, value, valueSize, hash)
357-
}
358-
359343
// Delete a given key from the map. No-op when the key does not exist in the
360344
// map.
361345
//
@@ -456,10 +440,6 @@ func hashmapNext(m *hashmap, it *hashmapIterator, key, value unsafe.Pointer) boo
456440
}
457441
}
458442

459-
func hashmapNextUnsafePointer(m unsafe.Pointer, it unsafe.Pointer, key, value unsafe.Pointer) bool {
460-
return hashmapNext((*hashmap)(m), (*hashmapIterator)(it), key, value)
461-
}
462-
463443
// Hashmap with plain binary data keys (not containing strings etc.).
464444
func hashmapBinarySet(m *hashmap, key, value unsafe.Pointer) {
465445
if m == nil {
@@ -469,10 +449,6 @@ func hashmapBinarySet(m *hashmap, key, value unsafe.Pointer) {
469449
hashmapSet(m, key, value, hash)
470450
}
471451

472-
func hashmapBinarySetUnsafePointer(m unsafe.Pointer, key, value unsafe.Pointer) {
473-
hashmapBinarySet((*hashmap)(m), key, value)
474-
}
475-
476452
func hashmapBinaryGet(m *hashmap, key, value unsafe.Pointer, valueSize uintptr) bool {
477453
if m == nil {
478454
memzero(value, uintptr(valueSize))
@@ -482,10 +458,6 @@ func hashmapBinaryGet(m *hashmap, key, value unsafe.Pointer, valueSize uintptr)
482458
return hashmapGet(m, key, value, valueSize, hash)
483459
}
484460

485-
func hashmapBinaryGetUnsafePointer(m unsafe.Pointer, key, value unsafe.Pointer, valueSize uintptr) bool {
486-
return hashmapBinaryGet((*hashmap)(m), key, value, valueSize)
487-
}
488-
489461
func hashmapBinaryDelete(m *hashmap, key unsafe.Pointer) {
490462
if m == nil {
491463
return
@@ -494,10 +466,6 @@ func hashmapBinaryDelete(m *hashmap, key unsafe.Pointer) {
494466
hashmapDelete(m, key, hash)
495467
}
496468

497-
func hashmapBinaryDeleteUnsafePointer(m unsafe.Pointer, key unsafe.Pointer) {
498-
hashmapBinaryDelete((*hashmap)(m), key)
499-
}
500-
501469
// Hashmap with string keys (a common case).
502470

503471
func hashmapStringEqual(x, y unsafe.Pointer, n uintptr) bool {
@@ -522,10 +490,6 @@ func hashmapStringSet(m *hashmap, key string, value unsafe.Pointer) {
522490
hashmapSet(m, unsafe.Pointer(&key), value, hash)
523491
}
524492

525-
func hashmapStringSetUnsafePointer(m unsafe.Pointer, key string, value unsafe.Pointer) {
526-
hashmapStringSet((*hashmap)(m), key, value)
527-
}
528-
529493
func hashmapStringGet(m *hashmap, key string, value unsafe.Pointer, valueSize uintptr) bool {
530494
if m == nil {
531495
memzero(value, uintptr(valueSize))
@@ -535,10 +499,6 @@ func hashmapStringGet(m *hashmap, key string, value unsafe.Pointer, valueSize ui
535499
return hashmapGet(m, unsafe.Pointer(&key), value, valueSize, hash)
536500
}
537501

538-
func hashmapStringGetUnsafePointer(m unsafe.Pointer, key string, value unsafe.Pointer, valueSize uintptr) bool {
539-
return hashmapStringGet((*hashmap)(m), key, value, valueSize)
540-
}
541-
542502
func hashmapStringDelete(m *hashmap, key string) {
543503
if m == nil {
544504
return
@@ -547,10 +507,6 @@ func hashmapStringDelete(m *hashmap, key string) {
547507
hashmapDelete(m, unsafe.Pointer(&key), hash)
548508
}
549509

550-
func hashmapStringDeleteUnsafePointer(m unsafe.Pointer, key string) {
551-
hashmapStringDelete((*hashmap)(m), key)
552-
}
553-
554510
// Hashmap with interface keys (for everything else).
555511

556512
// This is a method that is intentionally unexported in the reflect package. It
@@ -654,10 +610,6 @@ func hashmapInterfaceSet(m *hashmap, key interface{}, value unsafe.Pointer) {
654610
hashmapSet(m, unsafe.Pointer(&key), value, hash)
655611
}
656612

657-
func hashmapInterfaceSetUnsafePointer(m unsafe.Pointer, key interface{}, value unsafe.Pointer) {
658-
hashmapInterfaceSet((*hashmap)(m), key, value)
659-
}
660-
661613
func hashmapInterfaceGet(m *hashmap, key interface{}, value unsafe.Pointer, valueSize uintptr) bool {
662614
if m == nil {
663615
memzero(value, uintptr(valueSize))
@@ -667,18 +619,10 @@ func hashmapInterfaceGet(m *hashmap, key interface{}, value unsafe.Pointer, valu
667619
return hashmapGet(m, unsafe.Pointer(&key), value, valueSize, hash)
668620
}
669621

670-
func hashmapInterfaceGetUnsafePointer(m unsafe.Pointer, key interface{}, value unsafe.Pointer, valueSize uintptr) bool {
671-
return hashmapInterfaceGet((*hashmap)(m), key, value, valueSize)
672-
}
673-
674622
func hashmapInterfaceDelete(m *hashmap, key interface{}) {
675623
if m == nil {
676624
return
677625
}
678626
hash := hashmapInterfaceHash(key, m.seed)
679627
hashmapDelete(m, unsafe.Pointer(&key), hash)
680628
}
681-
682-
func hashmapInterfaceDeleteUnsafePointer(m unsafe.Pointer, key interface{}) {
683-
hashmapInterfaceDelete((*hashmap)(m), key)
684-
}

0 commit comments

Comments
 (0)