runtime: require explicit GC layouts

This commit is contained in:
Jake Bailey
2026-08-07 10:21:19 -07:00
committed by Ron Evans
parent 1a4cb2032e
commit a7360d5ad3
28 changed files with 279 additions and 108 deletions
+30
View File
@@ -994,6 +994,20 @@ func TestTypeAssertPanic(t *testing.T) {
})
}
type tinyMakeChanElement struct {
ptr *int
text string
}
var tinyMakeChanChurn []*int
//go:noinline
func fillTinyMakeChan(ch chan tinyMakeChanElement) {
value := new(int)
*value = 42
ch <- tinyMakeChanElement{ptr: value, text: "hello"}
}
func TestTinyMakeChan(t *testing.T) {
// Value.Send and Value.Recv are not implemented yet, so the channel is
// exercised through Interface(): that proves MakeChan returns a working
@@ -1027,6 +1041,22 @@ func TestTinyMakeChan(t *testing.T) {
}
})
t.Run("buffered pointers survive GC", func(t *testing.T) {
v := MakeChan(TypeOf(make(chan tinyMakeChanElement)), 1)
ch := v.Interface().(chan tinyMakeChanElement)
fillTinyMakeChan(ch)
runtime.GC()
tinyMakeChanChurn = make([]*int, 128)
for i := range tinyMakeChanChurn {
tinyMakeChanChurn[i] = new(int)
}
got := <-ch
if *got.ptr != 42 || got.text != "hello" {
t.Errorf("<-ch=%v, want {42 hello}", got)
}
})
t.Run("unbuffered", func(t *testing.T) {
v := MakeChan(TypeOf(make(chan string)), 0)
if got, want := v.Cap(), 0; got != want {