Dotty: Add `-Ylog:` option to enable loggers

Created on 17 Aug 2018  路  3Comments  路  Source: lampepfl/dotty

Currently, enabling a logger requires modifying https://github.com/lampepfl/dotty/blob/61cba970fec1017223ceb37da05f241f011c14d4/compiler/src/dotty/tools/dotc/config/Printers.scala, replacing say val exhaustivity: Printer = noPrinter with val exhaustivity: Printer = default.

This is neither documented nor convenient, and we can't ask users to enable it for bugs they struggle minimizing. We should probably add a -Ylog: setting.

tooling help wanted

Most helpful comment

I think a hard requirement is that this feature should not introduce any overhead when no printer is enabled. So two things to keep in mind:

  • Testing a setting's value is slow. Ideally it should be done only once (not each time you log something)
  • Context is the most allocated object in the compiler, so it should be kept small. That's why we have stuff like ContextBase. So you should not mix Printers with Context but with ContextBase

All 3 comments

@Blaisorblade
There are two ways I can think of doing this:

  • Keep Printers an object, and turn every printer field (currently a val) into a def with an implicit Context argument (so we can access the new YlogPrinter flag (Ylog is already taken)).

  • Turn Printers into a trait and move it inside the cake for Context. This is more efficient because the printer fields can remain as vals, but maybe cakes are no longer hip?

Do you have a preference?

I think a hard requirement is that this feature should not introduce any overhead when no printer is enabled. So two things to keep in mind:

  • Testing a setting's value is slow. Ideally it should be done only once (not each time you log something)
  • Context is the most allocated object in the compiler, so it should be kept small. That's why we have stuff like ContextBase. So you should not mix Printers with Context but with ContextBase

There is already a -Ylog option that will print stuff without having to touch the Printers. IIUC the distinction between the two is intentional (for performance reason?), and the Printers logs are meant to be a debugging tool for compiler writers, no something that we want to exposed under a flag.

Was this page helpful?
0 / 5 - 0 ratings