How does the dead code elimination work when using args to Printf? If static strings are fed into an empty function, I can imagine it does nothing. However, this I have less of a firm grip upon
dlg.Printf("the thing.Something is %+v", thing.Something())
since surely golang will still call Something, and still call PrintfAnd don't misunderstand me: it's a grave pet peeve of mine to do action inside the args to Printf but I can tell you it's a very common [anti-]pattern so I'd presume your users will want a story for how that interacts with the "disappears completely" claim
In short: You're right - Go will still evaluate argument expressions. In hindsight, I should've made that more obvious, not calling this out initially was an expert blind spot on my part, not an intent to mislead.
If we consider this example:
And look at the disassembly: What disappears is the logging work (formatting, interface/slice plumbing, I/O) and the call itself. Go cannot eliminate calls to functions inside of Printf because they could produce side-effects. Eliminating functions calls like this would be very expensive to do and would clashes with Go's focus on fast compilation times.I'll add a section to the README that explains this. Thanks for pointing it out.
It's easy to show that you're right and that code isn't dead so it can't be eliminated:
prints "unexpected error" twiceThis is a thing I had a little "are you sure?" itch in my brain about, but you've expressed so clearly in four lines of comment, and this is me showing gratitude for the comment and the untangling of my brain.
ETA: Presumably if there was at least an option for passing a closure that would provide a way to address this? Since the closure will only uselessly compile, and not actually uselessly run?
I've added a section to the README that goes into the subtleties of compiletime elimination and what to watch out for to ensure that calls to dlg.Printf can actually be eliminated: https://github.com/vvvvv/dlg?tab=readme-ov-file#true-zero-co...
I'd appreciate any feedback on whether these changes make the behavior more transparent and less misleading.