scala/scala — pull request #3452 by xeno-by (2014-02-01 01:19:58+00:00)
Title: SI-8603 and its sixteen friends

This is a preview version of the pull request that addresses https://issues.scala-lang.org/browse/SI-8063 in parallel with cleaning up reflection API for 2.11 and fixing a bunch of low-hanging bugs.

**Much needed day-to-day APIs**

This pull request brings a number of methods that have been frequently requested by you guys (thanks a lot for your relentless feedback!), including `Type.typeArgs`, `Flag.PARAMACCESSOR` and `Type.companionType`. It also adds new conveniences like `ClassSymbol.isPrimaryConstructor`, `symbolOf[T]` and `typecheck(tree, TYPEmode)` that simplify typical reflection tasks both at compile time and at runtime.

**First-class support for complex macros**

Over the course of Scala 2.10, it's become clear that high-level reflection APIs are insufficient for complex macros (async, sbt, etc) and that those low-level APIs that we put in place anticipating the difficulties aren't enough either. As a result, macro programmers are often forced to perform casts to compiler internals, which not only requires close knowledge of compiler internals, but also makes such macros hard to maintain, as compiler internals can change without notice at any time.

These problems with complex macros are caused by internal implementation details of the macro engine that we've already been trying to address for some time (https://groups.google.com/forum/#!topic/scala-internals/TtCTPlj_qcQ), but we're still not done with the fixes. Hopefully, we'll be able to merge some progress over the course of 2.11.x lifecycle, and by the 2.12.0-final release we'll have this handled, but no promises yet.

In the meanwhile, thanks to precious feedback from Jason Zaugg, we have been able to identify the low-level APIs that should be sufficient to work around the existing problems while we're looking for a definitive fix. We have exposed these APIs under `import c.internal._`, so that there's no longer need to cast to address typical issues arising in complex macros.

Documentation of these techniques is still scarce, but in mid-May @densh and I are going to run the ["Macrology 201" workshop](http://2014.flatmap.no/speakers/burmako.html) at flatMap, so stay tuned if you're interested in that kind of stuff.

**Towards perfect reflection API**

While reflection API has definitely become easier to use during the Scala 2.11 development cycle (quasiquotes, bunch of deprecations of confusing APIs, isolation of low-level APIs in `internal`, thread safety), there's still much work to do.

Among the most pressing issues I would highlight the following five bugs that we're going to take a very good look at for Scala 2.12: [Typechecking is not idempotent](https://issues.scala-lang.org/browse/SI-5464), [Hygiene for tree manipulation](https://issues.scala-lang.org/browse/SI-7823), [Get rid of pervasive casts in the reflection API](https://issues.scala-lang.org/browse/SI-8220), [Better usability for reflective invocations](https://issues.scala-lang.org/browse/SI-8221) and [Toolbox doesn't respect relative imports](https://issues.scala-lang.org/browse/SI-6393).