From 548158c4a57580e8c8bd0e9b2f91d03b31efa879 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 23 Jul 2024 15:39:51 -0400 Subject: runtime: switch debuglog from const-toggled to type-toggled Currently, the debuglog build tag controls the dlogEnabled const, and all methods of dlogger first check this const and immediately return if dlog is not enabled. With constant folding and inlining, this makes the whole dlog implementation compile away if it's not enabled. However, we want to be able to test debuglog even when the build tag isn't set. For that to work, we need a different mechanism. This CL changes this mechanism so the debuglog build tag instead controls the type alias for dlogger to be either dloggerImpl or dloggerFake. These two types have the same method set, but one is just stubs. This way, the methods of dloggerImpl don't need to be conditional dlogEnabled, which sets us up to use the now fully-functional dloggerImpl type in the test. I confirmed that this change has no effect on the final size of the cmd/go binary. It does increase the size of the runtime.a file by 0.9% and make the runtime take ever so slightly longer to compile because the compiler can no longer simply eliminate the bodies of the all of dlogger during early deadcode. However, this all gets eliminated by the linker. I consider this worth it to always get build and test coverage of debuglog. Change-Id: I81759e9e1411b7d369a23383a18b022ab7451421 Reviewed-on: https://go-review.googlesource.com/c/go/+/600696 Reviewed-by: Carlos Amedee LUCI-TryBot-Result: Go LUCI --- src/runtime/export_debuglog_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/runtime/export_debuglog_test.go') diff --git a/src/runtime/export_debuglog_test.go b/src/runtime/export_debuglog_test.go index e4b4ab9914..a361c02299 100644 --- a/src/runtime/export_debuglog_test.go +++ b/src/runtime/export_debuglog_test.go @@ -12,7 +12,11 @@ const DebugLogBytes = debugLogBytes const DebugLogStringLimit = debugLogStringLimit -var Dlog = dlog +type Dlogger = dloggerImpl + +func Dlog() *Dlogger { + return dlogImpl() +} func (l *dloggerImpl) End() { l.end() } func (l *dloggerImpl) B(x bool) *dloggerImpl { return l.b(x) } -- cgit v1.3-5-g9baa