From 05cdfbbb5b9b4aced9e504a753a09995b98f570a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Taylor?= Date: Mon, 26 Aug 2024 15:45:30 +0200 Subject: [PATCH] fix sizegen so it handles type aliases (#16650) Signed-off-by: Andres Taylor --- go/mysql/collations/colldata/cached_size.go | 8 -------- go/sqltypes/cached_size.go | 10 +--------- go/tools/sizegen/sizegen.go | 11 ++++++++++- go/vt/proto/query/cached_size.go | 20 -------------------- go/vt/proto/topodata/cached_size.go | 8 -------- go/vt/proto/vttime/cached_size.go | 6 ------ 6 files changed, 11 insertions(+), 52 deletions(-) diff --git a/go/mysql/collations/colldata/cached_size.go b/go/mysql/collations/colldata/cached_size.go index 36167c69d6d..b348baaaed8 100644 --- a/go/mysql/collations/colldata/cached_size.go +++ b/go/mysql/collations/colldata/cached_size.go @@ -19,10 +19,6 @@ package colldata import hack "vitess.io/vitess/go/hack" -type cachedObject interface { - CachedSize(alloc bool) int64 -} - func (cached *eightbitWildcard) CachedSize(alloc bool) int64 { if cached == nil { return int64(0) @@ -63,10 +59,6 @@ func (cached *unicodeWildcard) CachedSize(alloc bool) int64 { if alloc { size += int64(48) } - // field charset vitess.io/vitess/go/mysql/collations/charset/types.Charset - if cc, ok := cached.charset.(cachedObject); ok { - size += cc.CachedSize(true) - } // field pattern []rune { size += hack.RuntimeAllocSize(int64(cap(cached.pattern)) * int64(4)) diff --git a/go/sqltypes/cached_size.go b/go/sqltypes/cached_size.go index 2a488f8450e..632c8249455 100644 --- a/go/sqltypes/cached_size.go +++ b/go/sqltypes/cached_size.go @@ -34,17 +34,9 @@ func (cached *Result) CachedSize(alloc bool) int64 { size += elem.CachedSize(true) } } - // field Rows [][]vitess.io/vitess/go/sqltypes.Value + // field Rows []vitess.io/vitess/go/sqltypes.Row { size += hack.RuntimeAllocSize(int64(cap(cached.Rows)) * int64(24)) - for _, elem := range cached.Rows { - { - size += hack.RuntimeAllocSize(int64(cap(elem)) * int64(32)) - for _, elem := range elem { - size += elem.CachedSize(false) - } - } - } } // field SessionStateChanges string size += hack.RuntimeAllocSize(int64(len(cached.SessionStateChanges))) diff --git a/go/tools/sizegen/sizegen.go b/go/tools/sizegen/sizegen.go index a8fbcb1add4..7ecd50e3d8c 100644 --- a/go/tools/sizegen/sizegen.go +++ b/go/tools/sizegen/sizegen.go @@ -149,7 +149,7 @@ func (sizegen *sizegen) generateType(pkg *types.Package, file *codeFile, named * case *types.Interface: findImplementations(pkg.Scope(), tt, func(tt types.Type) { if _, isStruct := tt.Underlying().(*types.Struct); isStruct { - sizegen.generateKnownType(tt.(*types.Named)) + sizegen.generateTyp(tt) } }) default: @@ -157,6 +157,15 @@ func (sizegen *sizegen) generateType(pkg *types.Package, file *codeFile, named * } } +func (sizegen *sizegen) generateTyp(tt types.Type) { + switch tt := tt.(type) { + case *types.Named: + sizegen.generateKnownType(tt) + case *types.Alias: + sizegen.generateTyp(types.Unalias(tt)) + } +} + func (sizegen *sizegen) generateKnownType(named *types.Named) { pkgInfo := named.Obj().Pkg() file := sizegen.codegen[pkgInfo.Path()] diff --git a/go/vt/proto/query/cached_size.go b/go/vt/proto/query/cached_size.go index 735bd555e55..5b613317294 100644 --- a/go/vt/proto/query/cached_size.go +++ b/go/vt/proto/query/cached_size.go @@ -27,10 +27,6 @@ func (cached *BindVariable) CachedSize(alloc bool) int64 { if alloc { size += int64(96) } - // field unknownFields []byte - { - size += hack.RuntimeAllocSize(int64(cap(cached.unknownFields))) - } // field Value []byte { size += hack.RuntimeAllocSize(int64(cap(cached.Value))) @@ -52,10 +48,6 @@ func (cached *Field) CachedSize(alloc bool) int64 { if alloc { size += int64(160) } - // field unknownFields []byte - { - size += hack.RuntimeAllocSize(int64(cap(cached.unknownFields))) - } // field Name string size += hack.RuntimeAllocSize(int64(len(cached.Name))) // field Table string @@ -78,10 +70,6 @@ func (cached *QueryWarning) CachedSize(alloc bool) int64 { if alloc { size += int64(64) } - // field unknownFields []byte - { - size += hack.RuntimeAllocSize(int64(cap(cached.unknownFields))) - } // field Message string size += hack.RuntimeAllocSize(int64(len(cached.Message))) return size @@ -94,10 +82,6 @@ func (cached *Target) CachedSize(alloc bool) int64 { if alloc { size += int64(96) } - // field unknownFields []byte - { - size += hack.RuntimeAllocSize(int64(cap(cached.unknownFields))) - } // field Keyspace string size += hack.RuntimeAllocSize(int64(len(cached.Keyspace))) // field Shard string @@ -114,10 +98,6 @@ func (cached *Value) CachedSize(alloc bool) int64 { if alloc { size += int64(80) } - // field unknownFields []byte - { - size += hack.RuntimeAllocSize(int64(cap(cached.unknownFields))) - } // field Value []byte { size += hack.RuntimeAllocSize(int64(cap(cached.Value))) diff --git a/go/vt/proto/topodata/cached_size.go b/go/vt/proto/topodata/cached_size.go index d06ebd0d3f0..94b7fc6818c 100644 --- a/go/vt/proto/topodata/cached_size.go +++ b/go/vt/proto/topodata/cached_size.go @@ -27,10 +27,6 @@ func (cached *KeyRange) CachedSize(alloc bool) int64 { if alloc { size += int64(96) } - // field unknownFields []byte - { - size += hack.RuntimeAllocSize(int64(cap(cached.unknownFields))) - } // field Start []byte { size += hack.RuntimeAllocSize(int64(cap(cached.Start))) @@ -49,10 +45,6 @@ func (cached *ThrottledAppRule) CachedSize(alloc bool) int64 { if alloc { size += int64(80) } - // field unknownFields []byte - { - size += hack.RuntimeAllocSize(int64(cap(cached.unknownFields))) - } // field Name string size += hack.RuntimeAllocSize(int64(len(cached.Name))) // field ExpiresAt *vitess.io/vitess/go/vt/proto/vttime.Time diff --git a/go/vt/proto/vttime/cached_size.go b/go/vt/proto/vttime/cached_size.go index e34da16852c..62a6366ba3c 100644 --- a/go/vt/proto/vttime/cached_size.go +++ b/go/vt/proto/vttime/cached_size.go @@ -17,8 +17,6 @@ limitations under the License. package vttime -import hack "vitess.io/vitess/go/hack" - func (cached *Time) CachedSize(alloc bool) int64 { if cached == nil { return int64(0) @@ -27,9 +25,5 @@ func (cached *Time) CachedSize(alloc bool) int64 { if alloc { size += int64(64) } - // field unknownFields []byte - { - size += hack.RuntimeAllocSize(int64(cap(cached.unknownFields))) - } return size }