mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
The closure's type always matches the corresponding function's type, so just use one instance rather than carrying around two. Simplifies construction of closures, rewriting them during walk, and shrinks memory usage. Passes toolstash -cmp. Change-Id: I83b8b8f435b02ab25a30fb7aa15d5ec7ad97189d Reviewed-on: https://go-review.googlesource.com/c/go/+/283152 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@golang.org>
37 lines
804 B
Go
37 lines
804 B
Go
// Copyright 2016 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package ir
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
"unsafe"
|
|
)
|
|
|
|
// Assert that the size of important structures do not change unexpectedly.
|
|
|
|
func TestSizeof(t *testing.T) {
|
|
const _64bit = unsafe.Sizeof(uintptr(0)) == 8
|
|
|
|
var tests = []struct {
|
|
val interface{} // type as a value
|
|
_32bit uintptr // size on 32bit platforms
|
|
_64bit uintptr // size on 64bit platforms
|
|
}{
|
|
{Func{}, 188, 328},
|
|
{Name{}, 116, 208},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
want := tt._32bit
|
|
if _64bit {
|
|
want = tt._64bit
|
|
}
|
|
got := reflect.TypeOf(tt.val).Size()
|
|
if want != got {
|
|
t.Errorf("unsafe.Sizeof(%T) = %d, want %d", tt.val, got, want)
|
|
}
|
|
}
|
|
}
|