refAllDecls Replacement

refAllDecls is a handy function to force analysis of code for the purpose of test discovery. However, there are rumors that it is, in fact, not good, and might be going away.

We thought very hard about this problem at TigerBeetle, and came up with an objectively worse replacement.

No further comment.

2 Likes

Very cool. I wonder if there’s a way to simplify by slicing into @embedFile(@src().file)

We did an equivalent of that initially, but then it wouldn’t be a true quine, loosing cool points!

1 Like

A (maybe related) question from me:
I noticed - using vscode - it is impossible to rename a variable, when not all files are somehow compiled or at least “seen”.
When experimenting in my main.zig and comment away some code and do a rename only the actually compiled parts are touched.
What is a solutiion for that?

(It reminds me of the days of the absolutely never correct working refactoring in Delph, messing up a whole project).

1 Like

I think the quine is fancy, what I am not quite able to determine is whether it has benefits over putting the generator into its own tool with its own test, that runs before the tests that it generates access to.

I guess one benefit would be that you can see generator and result side by side and have a simpler build.zig, but considering that the build system already has handling of multiple and dependent steps, why not use the build-system to handle the generator part (and testing of generator) instead?

I generally try to avoid adding more things to build.zig if possible. zig build test is already a perfectly fine entry point for running this code, so there’s no need to put this into a build system.

What build.zig gives you is extra dependency tracking, but this is fast enough that no dependency tracking is needed. And, even if it were slow, I’d rather add it to our other test visitor that walks every source file, to do all the checks in one pass.

We probably should’ve done this from the start, but then there wouldn’t be a quine!

AFAIK the only solution is 100% test coverage so that all code becomes “active” in the tests.

Zig will only compile “reachable” code, partly because of its compilation strategy, partly because that’s the only way to replace the C preprocessor.

Aha thanks. Cover it all. Understood.

While the function may be removed from std, I don’t see the language changing in a way to prevent you from writing your own refAllDecls. I would have just copied the source into my codebase.