scala/scala — pull request #2846 by xeno-by (2013-08-16 21:39:00+00:00)
Title: hooks for plugins to override Global.analyzer

As discussed a couple weeks ago, submitting this to formalize the hacks
that I used in macro paradise for 2.10, so that it continues working
after possible refactorings in 2.11.

One of the strategies to implement this would be to make a list of
functions overridden by the plugin and then to reuse the analyzer
plugins architecture to introduce them as hooks. However:
1) The list is quite big and disparate (Namers.enterSym,
Namers.ensureCompanionObject, Typers.reallyExists, Typers.typed1,
Typers.typedTemplate, Typers.typedBlock, Typers.typedClassDef).
2) The list doesn't correspond to the spirit of analyzer plugins that
modify return types of namer/typer functions rather than override them.
3) There's no guarantee that later on paradise won't need to override
additional functionality of namer/typer, requiring new hacks.

Another strategy lets plugins suggest their own analyzers to the compiler.
It enables augmenting namer/typer with arbitrary functionality, providing
ultimate flexibility. Shortcomings:
1) If multiple plugins want to install their own analyzers, it won't work
(but such situations can be detected and meaningful errors can be reported).
One can argue though, that even if we provided finer-grained API for
such plugins, it wouldn't work anyway, because e.g. it's hard to imagine
several plugins robustly applying their modifications to Namers.enterSym.

None of the outlined two strategies is ideal, however, the second one
makes more sense to me, because shortcoming #3 of the first one seems to
defeat the idea of introducing the hooks into the compiler in the first place.
Therefore this patch implements the second strategy.