Proposal: @compileLogsOn and @compileLogsOff #590
Labels
proposal
This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone
tl;dr:
Using
@compileLog
always stops the compilation in its early phase. People would need to remove these logs after they are done with their compile-time troubles. This means that valuable insight in form of relevant and properly placed log statements gets lost.A workaround is to use compile time
if
to activate these logs on demand, but this solution:My proposal:
By default
@compileLog
are not active. This allows original implementors, the most knowledgeable people about the details, to insert logs w/o fear.Logs could be activated at any place by
@compileLogsOn
. At any place they could be deactivated by@compileLogsOff
. All these activations and deactivations would be outputted (file/line/on-or-off-info) in the same stream as the logs. They also stop the compilation (like@compileLog
does now). This will ensure that after debugging session nothing will be forgotten inside.A usual debugging strategy then would be to enable all logs inside
main
, review the complete output, select the interesting part(s) and placeon
/off
hints there (plus remove theon
hint from themain
). This way log output gets restricted to interesting part(s) of the code.If format of logs changes to this (miscellaneous thoughts from PavelVozenilek #548 (comment)):
then it should be easier to spot interesting places. With current style it is rather confusing.
A hypothetical feature is to limit number of outputted lines. Say a big table with ten thousand of rows is calculated during compile-time. One may look for an easy way to see just few first few rows, not everything.
@compileLogsOn(20); // meaning: output only the first 20 logs, until the next @compileLogsOff
Programmer hit with a compile-time problem will not be forced to touch or recreate complicated log statements, he will instead use simple hints.
If Zig ever gets advanced IDE with the ability to use debugger during compile-time these "always present" logs would be handy.
The text was updated successfully, but these errors were encountered: