Skip to content

Proposal: @compileLogsOn and @compileLogsOff #590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
PavelVozenilek opened this issue Nov 6, 2017 · 0 comments
Closed

Proposal: @compileLogsOn and @compileLogsOff #590

PavelVozenilek opened this issue Nov 6, 2017 · 0 comments
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@PavelVozenilek
Copy link

tl;dr:

@compileLogsOn;

   @compileLog(...);
   ...
   @compileLog(...);
   ...

@compileLogsOff;


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:

  1. adds one indentation level to the log calls,
  2. is not standardized so every 3pp library will have their own log activation constant(s),
  3. even if standardized it would be just one big on/off switch for the whole application, not very useful.

My proposal:

  1. By default @compileLog are not active. This allows original implementors, the most knowledgeable people about the details, to insert logs w/o fear.

  2. 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.

  3. A usual debugging strategy then would be to enable all logs inside main, review the complete output, select the interesting part(s) and place on/off hints there (plus remove the on hint from the main). This way log output gets restricted to interesting part(s) of the code.

  4. If format of logs changes to this (miscellaneous thoughts from PavelVozenilek #548 (comment)):

| logged text 1 (file1/line1)
| logged text 2 (file2/line2)
| logged text 3 (file3/line3)

then it should be easier to spot interesting places. With current style it is rather confusing.

  1. Possibly, to distinguish log supporting code, there could be compile time flag:
if (@compileLogsAreEnabled) {
   .... complex calculations in comptime
  @compileLog(...);
}

  1. 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.

@andrewrk andrewrk added this to the 0.3.0 milestone Nov 7, 2017
@andrewrk andrewrk added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Dec 3, 2017
@andrewrk andrewrk modified the milestones: 0.3.0, 0.4.0 Feb 28, 2018
@andrewrk andrewrk modified the milestones: 0.4.0, 0.3.0 Sep 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

2 participants