Stream: compiler development

Topic: zig compiler - dbg


view this post on Zulip Richard Feldman (Feb 19 2025 at 22:28):

I think we need dbg to be a keyword rather than using dispatch after all

view this post on Zulip Richard Feldman (Feb 19 2025 at 22:29):

the problem is, if I use it in a call chain like foo.dbg().bar() then it's obvious that dbg returns whatever you give it

view this post on Zulip Richard Feldman (Feb 19 2025 at 22:30):

but then if I use it as a standalone statement like foo.dbg() then I'll get a warning because it doesn't evaluate to {}

view this post on Zulip Richard Feldman (Feb 19 2025 at 22:30):

so then either I need to write _ = foo.dbg() or else we have to make an exception for dbg

view this post on Zulip Richard Feldman (Feb 19 2025 at 22:31):

on top of which, in general it's weird to have it look like a normal pure function because it doesn't get optimized away like pure functions are allowed to be

view this post on Zulip Richard Feldman (Feb 19 2025 at 22:31):

I think it's usual enough that it just makes more sense to be a keyword

view this post on Zulip Richard Feldman (Feb 19 2025 at 22:32):

so I think we should do:

dbg foo

works like expect foo as a statement

view this post on Zulip Richard Feldman (Feb 19 2025 at 22:32):

or return foo

view this post on Zulip Richard Feldman (Feb 19 2025 at 22:33):

and then if you want it in a call chain, we allow foo->dbg.bar()

view this post on Zulip Richard Feldman (Feb 19 2025 at 22:34):

(or whatever we end up using for the non-dispatch call chain; I'm default assuming -> but that could change)

view this post on Zulip Richard Feldman (Feb 19 2025 at 22:35):

:thinking: I suppose we could also allow ->expect and even ->return if desired

view this post on Zulip Anthony Bullard (Feb 19 2025 at 23:01):

I'm glad you say this, because this is how I've implemented dbg so far in the compiler :rofl:


Last updated: Jul 06 2025 at 12:14 UTC