aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/export_debuglog_test.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2024-07-23 15:39:51 -0400
committerAustin Clements <austin@google.com>2024-07-30 13:10:56 +0000
commit548158c4a57580e8c8bd0e9b2f91d03b31efa879 (patch)
tree7c2aae9436d9413b5a8f0768d8ba1aa3dd9fd354 /src/runtime/export_debuglog_test.go
parenteb6743d9d7dd48f785e48b1967f405658a6444d7 (diff)
downloadgo-548158c4a57580e8c8bd0e9b2f91d03b31efa879.tar.xz
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 <carlos@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/runtime/export_debuglog_test.go')
-rw-r--r--src/runtime/export_debuglog_test.go6
1 files changed, 5 insertions, 1 deletions
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) }