2

Since untyped macros are out, the number of macro variants that avoid initial type checking has been diminished.

The rationale in the relevant release doc references both implicit macros and macro annotations as alternatives.

And indeed macro annotations do seem to work as advertised. However, I was unable to find an example of an implicit macro (one I understood at least) or another macro variant being deployed in this situation.

So, once again, the question is: apart from macro annotations, what macro creation methods avoid immediate type checking, and how do they differ in this regard?

The specific use case spurring my investigation is transforming something like this (realized with macro annotations):

{
    @blah
    val x = {
            foo("a")
            bar()
    }
}

Where foo and bar are not defined anywhere in the current scope before the macro application. The intended use case is a DSL. The above example is only given for context, so please don't limit your answers to this scenario.

mikołak
  • 9,605
  • 1
  • 48
  • 70
  • 1
    Implicit macros can provide an alternative to the type-level computation aspect of type macros, but to the best of knowledge they can't be used in an untyped fashion. – Eugene Burmako Jan 27 '14 at 07:39

1 Answers1

3

At the moment (Scala 2.11.0-M8, Macro Paradise 2.0.0-M3), macro annotations implemented in macro pardise is the only macro flavor that doesn't typecheck macro arguments prior to expansion.

There is also an experimental dsl-paradise proposal to extend Scala with scope injection that would allow def macros to be not quite typed in a controlled manner, but it's currently in the early implementation phase, so it's not usable just yet.

The future of untyped macros in official Scala is currently unclear. On the one hand, we recognize that untyped macros are at times useful (e.g. for type providers, scope injection), but, on the other hand, it looks like in their most general form, such macros are more powerful than we would like them to be (see my StrangeLoop talk about philosophy of Scala macros starting from 27:40 and a recent discussion at scala-internals). Therefore future experimentation is required to elaborate on the exact shape in which untyped macros should enter trunk.

Eugene Burmako
  • 13,028
  • 1
  • 46
  • 59
  • Thank you for the comprehensive answer! One supplemental question - are you aware of any plans of *removing* macro annotations from `macro paradise` in their current form, or are they here to stay? – mikołak Jan 27 '14 at 11:18
  • 1
    In general, I try hard to stay compatible. If that can't be helped (like it was with type macros that were banned from inclusion into Scala and therefore had no future), I do my best to provide adequately powerful replacements. Also, as mentioned in http://scalamacros.org/news/2013/08/07/roadmap-for-macro-paradise.html, macro annotations are going to be supported in paradise at least in 2.10 and 2.11. I've recently secured the compiler hooks necessary to implement macro annotations, so there aren't going to be problems with that. – Eugene Burmako Jan 27 '14 at 13:33