Zulip Chat Archive
Stream: lean4
Topic: output of `dbg_trace` is treated as error in `Delab`
Asei Inoue (Dec 21 2024 at 13:18):
import Lean
open Lean PrettyPrinter Delaborator SubExpr
def foo : Nat → Nat := fun x => x + 1
@[delab app.foo]
def delabFoo : Delab := do
dbg_trace "dbg trace"
`($(mkIdent `fooDelab))
#check (foo)
Asei Inoue (Dec 21 2024 at 13:18):
When the above code is run on VSCode, the output of dbg_trace
seems to be treated as an error.
What is the correct way to do print debugging in Delab
?
Kyle Miller (Dec 21 2024 at 18:34):
You can see the output, right? Is there any problem with it being treated as an error?
Asei Inoue (Dec 21 2024 at 23:16):
I wonder why this is treated as an error.
Asei Inoue (Dec 21 2024 at 23:19):
Is this intended behavior? Is this a bug?
I think the output of dbg_trace should not be treated as an error…
Eric Wieser (Dec 21 2024 at 23:32):
In the web editor the output doesn't seem to appear at all
Asei Inoue (Dec 21 2024 at 23:33):
use VSCode and see output in the terminal window.
Kyle Miller (Dec 21 2024 at 23:50):
dbg_trace
outputs directly to stderr. This is a perfectly fine way to output debug messages.
Eric Wieser (Dec 21 2024 at 23:58):
Isn't there now a mechanism to capture stderr and pipe it to the infoview? I guess delaborators live outside this if so.
Kyle Miller (Dec 22 2024 at 01:30):
Maybe there are other mechanisms too, but the one I know about, docs#IO.FS.withIsolatedStreams (used by #eval
for example), runs the value and yields the entire output at the end.
I think this sort of defeats the purpose of dbg_trace
though, since this means you can't get any debug information until the end of a computation. Plus, there's a larger chance that the logging information will be dropped along the way in case there's an error. You're depending on all the monads in the stack to get the messages to the InfoView, and recall that there have been bugs here before, which makes debugging particularly challenging. (For example, #eval
used to drop all log messages for the MetaM monad until recently. I think docs#Lean.liftCommandElabM too was dropping messages.)
Last updated: May 02 2025 at 03:31 UTC