Merge pull request #2361 from retronym/ticket/7337

SI-7337 Error out on missing -d directory.
-Yshow-member-pos, print the positions of members.

Here for instance is a command line which leverages the
output of this option to print the method bodies of all
methods called 'transformInfo' found under src. Given
1500 source files it accomplishes this in four seconds,
thanks to -Ystop-after:parser.

% scalac -Yshow-member-pos sed -Ystop-after:parser \
    $(find src/compiler -name '*.scala') | \
    grep transformInfo | sed 's/ # .*//;' | \
    while read line; do echo "// $line" && gsed -n $line && echo; done

Or more simply, the start/end lines of each member of Random:

% scalac -Yshow-member-pos "" ./src/library/scala/util/Random.scala
./src/library/scala/util/Random.scala
20,134               class Random
 33                  def nextBoolean
 38                  def nextBytes
 43                  def nextDouble
 48                  def nextFloat
 54                  def nextGaussian
 59                  def nextInt
 65                  def nextInt
 70                  def nextLong
 81,89               def nextString
  82,86              def safeChar
   83                val surrogateStart
   84                val res
 94,98               def nextPrintableChar
 [snip]

It makes me sad I'm always in the position of having to hack
the compiler to do this sort of thing. All we need is something
like -Yinsert-phase:Foo where Foo is a class implementing a
(Phase, Tree) => Tree method, and the compiler runs all the
unit.bodies through it after each phase, and then one could
easily accomplish this in the privacy of one's own compiler.
Simplify type bounds.

I started out looking to limit the noise from empty type
bounds, i.e. the endless repetition of

  class A[T >: _root_.scala.Nothing <: _root_.scala.Any]

This led me to be reminded of all the unnecessary and
in fact damaging overreaches which are performed during parsing.
Why should a type parameter for which no bounds are
specified be immediately encoded with this giant tree:

  TypeBounds(
    Select(Select(Ident(nme.ROOTPKG), tpnme.scala_), tpnme.Nothing),
    Select(Select(Ident(nme.ROOTPKG), tpnme.scala_), tpnme.Any)
  )

...which must then be manually recognized as empty type bounds?
Truly, this is madness.

 - It deftly eliminates the possibility of recognizing
   whether the user wrote "class A[T]" or "class A[T >: Nothing]"
   or "class A[T <: Any]" or specified both bounds. The fact
   that these work out the same internally does not imply the
   information should be exterminated even before parsing completes.
 - It burdens everyone who must recognize type bounds trees,
   such as this author
 - It is far less efficient than the obvious encoding
 - It offers literally no advantage whatsoever

Encode empty type bounds as

  TypeBounds(EmptyTree, EmptyTree)

What could be simpler.
Add :kind command to REPL

:kind command diplays the kind of types and type constructors in Scala
syntax notation.

    scala> :kind (Int, Int) => Int
    scala.Function2's kind is F[-A1,-A2,+A3]
SI-7345 Represent the boolean modes in Context in ContextMode.

 - This is a value class in the same spirit of Mode.
 - Code that temporarily changes mode can be simplified
   by saving and restoring this one field.
SI-7345 Rationalize overloads of Context#make

Used default arguments and removed of variations only used
in one place.

I couldn't eliminate them all: one remaining overload avoids
allocating a new context when the scope/owner/tree don't change,
but moving this optimizatin to the primary overload of make breaks
things. This is noted in a TODO comment.
SI-7345 Remove comment that appears obsolete.

Obsolete since ee02ad59c, as best as I can judge.
SI-7345 Use combinator to find next enclosing non-template.
SI-7345 Add Context#isLocal, akin to Symbol#isLocal

Out with the old, in with the new. `isLocal()`, which
has been removed, was unused. `isLocal`, the new entry,
has the same semantics as `Symbol#isLocal`.
SI-7345 Encapsulate warning and error buffers in ReportBuffer.

  - merge `Context#{buffer, warningBuffer}` into `Context#reportBuffer`.
  - only expose immutable copies of the error and warnings buffers
  - Introduce a convenience method, `firstError`.
  - replace `condBufferFlush` more specific methods to retain or
    clear errors by error kind.
SI-7345 Exploit named/default args
  - Collapse overloads of `rootContext`
  - make `atOwner` more concise
SI-7345 More refactoring and documentation in Contexts

  - Use `firstError match {}` rather than `if (c.hasErrors) c.firstError ..`
  - Convert implementation comments to doc comments
  - Add new doc comments
  - Refactor `Context#make` for better readability.
  - Note a few TODOs.
  - Roughly delineate the internal structure of Contexts with comments.
  - Combine `mode` and `state` methods into `contextMode`.
  - Move `isNameInScope` closer to its compadres.
  - Improving alignment, tightening access.
SI-7345 Prefer using a throwaway silent context over buffer flushing.

When we are using a throwaway silent context, we can just let it drift out of
scope and over the horizon, rather than ceremoniously flushing its buffers
on completion.

 - Applied to Scaladoc.
 - Applied to Infer#isApplicableSafe. Less manual error buffer management
   affords greater opportunity to cleanly express the logic.
 - Applied to `typerReportAnyContextErrors`.

The reasoning for the last case is as follows:

 - There were only two callers to `typerReportAnyContextErrors`, and
   they both passed in as `c` a child context of `context`.
 - That child context must share the error reporting mode and buffer
   with `context`.
 - Therefore, extracting an error from `c` and issuing it into `context`
   is a no-op. Because the error buffer is Set, it was harmless.

This part will probably textually conflict with the same change made in
SI-7319, but the end results are identical.
SI-7345 remove unused methods.
SI-7345 Move `inSilentMode` from Infer to Context.
SI-7345 Refactor manual iteration to use foreach.
SI-7345 Produce Context#imports from the context chain

Rather than keeping a List[ImportInfo] around as a field.

This sort of change reduces our bug exposure by structurally
enforcing the invariant that `Context#imports` must mirror
the `outer` chain.

This entails changing a few elements of Contexts from mutable
vars to constructor pararameters, which seems desirable anyway.

We no longer need `makeNewImport`, as `make` now inspects
the provided tree and determines does import specific things
(tracking of used imports / mixin of ImportContext) when
appropriate.

The only wrinkle in this commit is the unfortunate need to pass
`owner = null` in the extends clause of NoContext. I don't see
cleaner way around this.

Applied minor rework to `implicitss` to avoid needlessly re-evaluating
`imports` and `nextOuter`.
SI-7345 Doc and TODO comments around Context.
SI-7345 Remove unneeded warning.

According to Hubert, during normal operation we can start buffering
errors in a context with existing errors. So the warning would be noisy.
SI-7345 Factor out method to clear and restore undetparams.

Also refactored `handleOverloaded` to avoid use of a mutable Buffer