gorm/schema
Jeremy Quirke 8c18714462
Don't call MethodByName with a variable arg (#6602)
Go 1.22 goes somewhat toward addressing the issue using reflect
MethodByName disabling linker deadcode elimination (DCE) and the
resultant large increase in binary size because the linker cannot
prune unused code because it might be reached via reflection.

Go Issue golang/go#62257 reduces the number of incidences of this
problem by leveraging a compiler assist to avoid marking functions
containing calls to MethodByName as ReflectMethods as long as the
arguments are constants.

An analysis of Uber Technologies code base however shows that a number
of transitive imports still contain calls to MethodByName with a
variable argument, including GORM.

In the case of GORM, the solution we are proposing is because the
number of possible methods is finite, we will "unroll" this. This
demonstrably shows that GORM is not longer a problem for DCE.

Before
```
% go version
go version devel go1.22-2f3458a8ce Sat Sep 16 16:26:48 2023 -0700 darwin/arm64
% go  test ./... -ldflags=-dumpdep   2>  >(grep -i -e  '->.*<reflectmethod>')
gorm.io/gorm.(*Statement).BuildCondition -> gorm.io/gorm/schema.ParseWithSpecialTableName <ReflectMethod>
type:reflect.Value <UsedInIface> -> reflect.(*Value).Method <ReflectMethod>
type:reflect.Value <UsedInIface> -> reflect.(*Value).MethodByName <ReflectMethod>
ok  	gorm.io/gorm	(cached)
ok  	gorm.io/gorm/callbacks	(cached)
gorm.io/gorm/clause_test.BenchmarkComplexSelect -> gorm.io/gorm/schema.ParseWithSpecialTableName <ReflectMethod>
type:reflect.Value <UsedInIface> -> reflect.(*Value).Method <ReflectMethod>
type:reflect.Value <UsedInIface> -> reflect.(*Value).MethodByName <ReflectMethod>
?   	gorm.io/gorm/migrator	[no test files]
ok  	gorm.io/gorm/clause	(cached)
ok  	gorm.io/gorm/logger	(cached)
gorm.io/gorm/schema_test.TestAdvancedDataTypeValuerAndSetter -> gorm.io/gorm/schema.ParseWithSpecialTableName <ReflectMethod>
type:reflect.Value <UsedInIface> -> reflect.(*Value).Method <ReflectMethod>
type:reflect.Value <UsedInIface> -> reflect.(*Value).MethodByName <ReflectMethod>
?   	gorm.io/gorm/utils/tests	[no test files]
ok  	gorm.io/gorm/schema	(cached)
ok  	gorm.io/gorm/utils	(cached)
```

After

```
%go version
go version devel go1.22-2f3458a8ce Sat Sep 16 16:26:48 2023 -0700 darwin/arm64
%go  test ./... -ldflags=-dumpdep   2>  >(grep -i -e  '->.*<reflectmethod>')
ok  	gorm.io/gorm	(cached)
ok  	gorm.io/gorm/callbacks	(cached)
?   	gorm.io/gorm/migrator	[no test files]
?   	gorm.io/gorm/utils/tests	[no test files]
ok  	gorm.io/gorm/clause	(cached)
ok  	gorm.io/gorm/logger	(cached)
ok  	gorm.io/gorm/schema	(cached)
ok  	gorm.io/gorm/utils	(cached)
```
2023-10-10 14:50:29 +08:00
..
callbacks_test.go ci: add gofumpt check in reviewdog (#4973) 2022-01-06 15:02:53 +08:00
check.go ci: add gofumpt check in reviewdog (#4973) 2022-01-06 15:02:53 +08:00
check_test.go Rename package name 2020-06-02 09:18:01 +08:00
field.go fix: 🐛 embedded struct test failed with custom datatypes (#6311) 2023-05-15 09:59:26 +08:00
field_test.go Add serializer support (#5078) 2022-02-19 17:02:53 +08:00
index.go fix(schema): field is only unique when there is one unique index (#5974) 2023-01-11 14:05:39 +08:00
index_test.go fix(schema): field is only unique when there is one unique index (#5974) 2023-01-11 14:05:39 +08:00
interfaces.go Add serializer support (#5078) 2022-02-19 17:02:53 +08:00
model_test.go ci: add gofumpt check in reviewdog (#4973) 2022-01-06 15:02:53 +08:00
naming.go max identifier length changed to 63 (#6337) 2023-05-30 10:00:48 +08:00
naming_test.go max identifier length changed to 63 (#6337) 2023-05-30 10:00:48 +08:00
pool.go Remove shared sync pool for Scanner compatibility 2022-04-11 21:37:44 +08:00
relationship.go feat: support embedded preload (#6137) 2023-04-11 13:10:38 +08:00
relationship_test.go max identifier length changed to 63 (#6337) 2023-05-30 10:00:48 +08:00
schema.go Don't call MethodByName with a variable arg (#6602) 2023-10-10 14:50:29 +08:00
schema_helper_test.go feat: support embedded preload (#6137) 2023-04-11 13:10:38 +08:00
schema_test.go Fix: Composite primary key with auto-increment value returns 0 after insert (#6127) 2023-03-10 16:50:03 +08:00
serializer.go Issue 6054: Unscoped not working with PreLoad on Joins (#6058) 2023-02-18 09:06:43 +08:00
utils.go fix schema GetIdentityFieldValuesMap interface or ptr (#6417) 2023-08-19 21:35:14 +08:00
utils_test.go Remove autoincrement tag for join table, close #3217 2020-07-31 18:19:25 +08:00