diff --git a/src/internal/reflectlite/value.go b/src/internal/reflectlite/value.go index 0cccfe9d8..31015cbd2 100644 --- a/src/internal/reflectlite/value.go +++ b/src/internal/reflectlite/value.go @@ -1686,12 +1686,6 @@ type funcHeader struct { Code unsafe.Pointer } -type SliceHeader struct { - Data uintptr - Len intw - Cap intw -} - // Slice header that matches the underlying structure. Used for when we switch // to a precise GC, which needs to know exactly where pointers live. type sliceHeader struct { @@ -1700,11 +1694,6 @@ type sliceHeader struct { cap uintptr } -type StringHeader struct { - Data uintptr - Len intw -} - // Like sliceHeader, this type is used internally to make sure pointer and // non-pointer fields match those of actual strings. type stringHeader struct { @@ -1716,9 +1705,7 @@ type stringHeader struct { // See https://github.com/tinygo-org/tinygo/pull/4156 // and https://github.com/tinygo-org/tinygo/issues/1284. var ( - _ [unsafe.Sizeof([]byte{})]byte = [unsafe.Sizeof(SliceHeader{})]byte{} _ [unsafe.Sizeof([]byte{})]byte = [unsafe.Sizeof(sliceHeader{})]byte{} - _ [unsafe.Sizeof("")]byte = [unsafe.Sizeof(StringHeader{})]byte{} _ [unsafe.Sizeof("")]byte = [unsafe.Sizeof(stringHeader{})]byte{} ) diff --git a/src/internal/reflectlite/intw.go b/src/reflect/intw.go similarity index 92% rename from src/internal/reflectlite/intw.go rename to src/reflect/intw.go index 4dd197cef..20fbd4341 100644 --- a/src/internal/reflectlite/intw.go +++ b/src/reflect/intw.go @@ -1,6 +1,6 @@ //go:build !avr -package reflectlite +package reflect // intw is an integer type, used in places where an int is typically required, // except architectures where the size of an int != word size. diff --git a/src/internal/reflectlite/intw_avr.go b/src/reflect/intw_avr.go similarity index 92% rename from src/internal/reflectlite/intw_avr.go rename to src/reflect/intw_avr.go index 24b437777..8f294eeee 100644 --- a/src/internal/reflectlite/intw_avr.go +++ b/src/reflect/intw_avr.go @@ -1,6 +1,6 @@ //go:build avr -package reflectlite +package reflect // intw is an integer type, used in places where an int is typically required, // except architectures where the size of an int != word size. diff --git a/src/internal/reflectlite/intw_test.go b/src/reflect/intw_test.go similarity index 97% rename from src/internal/reflectlite/intw_test.go rename to src/reflect/intw_test.go index b235b88f4..1014a9ae4 100644 --- a/src/internal/reflectlite/intw_test.go +++ b/src/reflect/intw_test.go @@ -1,6 +1,6 @@ //go:build !avr -package reflectlite_test +package reflect_test import ( "reflect" diff --git a/src/reflect/value.go b/src/reflect/value.go index 26f3657cd..fe41f2d18 100644 --- a/src/reflect/value.go +++ b/src/reflect/value.go @@ -226,3 +226,24 @@ func (v Value) Recv() (x Value, ok bool) { func NewAt(typ Type, p unsafe.Pointer) Value { panic("unimplemented: reflect.New()") } + +// Deprecated: Use unsafe.Slice or unsafe.SliceData instead. +type SliceHeader struct { + Data uintptr + Len intw + Cap intw +} + +// Deprecated: Use unsafe.String or unsafe.StringData instead. +type StringHeader struct { + Data uintptr + Len intw +} + +// Verify SliceHeader and StringHeader sizes. +// See https://github.com/tinygo-org/tinygo/pull/4156 +// and https://github.com/tinygo-org/tinygo/issues/1284. +var ( + _ [unsafe.Sizeof([]byte{})]byte = [unsafe.Sizeof(SliceHeader{})]byte{} + _ [unsafe.Sizeof("")]byte = [unsafe.Sizeof(StringHeader{})]byte{} +)