scala.tools.nsc.typechecker

Macros

trait Macros extends FastTrack with Traces

Code to deal with macros, namely with: * Compilation of macro definitions * Expansion of macro applications

Say we have in a class C:

def foo[T](xs: List[T]): T = macro fooBar

Then fooBar needs to point to a static method of the following form:

def fooBar[T: c.WeakTypeTag] // type tag annotation is optional (c: scala.reflect.macros.Context) (xs: c.Expr[List[T]]) : c.Expr[T] = { ... }

Then, if foo is called in qual.foo[Int](elems), where qual: D, the macro application is expanded to a reflective invocation of fooBar with parameters:

(simpleMacroContext{ type PrefixType = D; val prefix = qual }) (Expr(elems)) (TypeTag(Int))

Self Type
Analyzer
Source
Macros.scala
Linear Supertypes
Known Subclasses
Type Hierarchy Learn more about scaladoc diagrams
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Macros
  2. Traces
  3. FastTrack
  4. AnyRef
  5. Any
Implicitly
  1. by any2stringadd
  2. by any2stringfmt
  3. by any2ArrowAssoc
  4. by any2Ensuring
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. case class FastTrackEntry(sym: nsc.Global.Symbol, expander: (FastTrack.this)#FastTrackExpander) extends Product with Serializable

    Definition Classes
    FastTrack
  2. type FastTrackExpander = PartialFunction[(Analyzer.MacroContext, Global.Tree), Global.Tree]

    Definition Classes
    FastTrack
  3. case class MacroArgs(c: Analyzer.MacroContext, others: List[Any]) extends Product with Serializable

    Calculate the arguments to pass to a macro implementation when expanding the provided tree.

  4. type MacroRuntime = (Analyzer.MacroArgs) ⇒ Any

    Produces a function that can be used to invoke macro implementation for a given macro definition: 1) Looks up macro implementation symbol in this universe.

    Produces a function that can be used to invoke macro implementation for a given macro definition: 1) Looks up macro implementation symbol in this universe. 2) Loads its enclosing class from the macro classloader. 3) Loads the companion of that enclosing class from the macro classloader. 4) Resolves macro implementation within the loaded companion.

    returns

    Requested runtime if macro implementation can be loaded successfully from either of the mirrors, null otherwise.

  5. class MacroTyper extends Analyzer.MacroErrors

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. def +(other: String): String

    Implicit information
    This member is added by an implicit conversion from Macros to StringAdd performed by method any2stringadd in scala.Predef.
    Definition Classes
    StringAdd
  5. def ->[B](y: B): (Macros, B)

    Implicit information
    This member is added by an implicit conversion from Macros to ArrowAssoc[Macros] performed by method any2ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  6. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  7. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  8. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  9. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  10. def computeMacroDefTypeFromMacroImpl(macroDdef: Global.DefDef, macroImpl: Global.Symbol): Global.Type

  11. def enclosingMacroPosition: Position

  12. def ensuring(cond: (Macros) ⇒ Boolean, msg: ⇒ Any): Macros

    Implicit information
    This member is added by an implicit conversion from Macros to Ensuring[Macros] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  13. def ensuring(cond: (Macros) ⇒ Boolean): Macros

    Implicit information
    This member is added by an implicit conversion from Macros to Ensuring[Macros] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  14. def ensuring(cond: Boolean, msg: ⇒ Any): Macros

    Implicit information
    This member is added by an implicit conversion from Macros to Ensuring[Macros] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  15. def ensuring(cond: Boolean): Macros

    Implicit information
    This member is added by an implicit conversion from Macros to Ensuring[Macros] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  16. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  17. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  18. lazy val fastTrack: Map[Global.Symbol, Analyzer.FastTrackEntry]

    Definition Classes
    FastTrack
  19. implicit def fastTrackEntry2MacroRuntime(entry: Analyzer.FastTrackEntry): (Analyzer.MacroArgs) ⇒ Any

    Definition Classes
    FastTrack
  20. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  21. def formatted(fmtstr: String): String

    Implicit information
    This member is added by an implicit conversion from Macros to StringFormat performed by method any2stringfmt in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  22. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  23. def globalSettings: Settings

    Definition Classes
    MacrosTraces
  24. var hasPendingMacroExpansions: Boolean

    Without any restrictions on macro expansion, macro applications will expand at will, and when type inference is involved, expansions will end up using yet uninferred type params.

    Without any restrictions on macro expansion, macro applications will expand at will, and when type inference is involved, expansions will end up using yet uninferred type params.

    For some macros this might be ok (thanks to TreeTypeSubstituter that replaces the occurrences of undetparams with their inferred values), but in general case this won't work. E.g. for reification simple substitution is not enough - we actually need to re-reify inferred types.

    Luckily, there exists a very simple way to fix the problem: delay macro expansion until everything is inferred. Here are the exact rules. Macro application gets delayed if any of its subtrees contain: 1) type vars (tpe.isInstanceOf[TypeVar]) // [Eugene] this check is disabled right now, because TypeVars seem to be created from undetparams anyways 2) undetparams (sym.isTypeParameter && !sym.isSkolem)

  25. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  26. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  27. lazy val macroClassloader: ClassLoader

    Macro classloader that is used to resolve and run macro implementations.

    Macro classloader that is used to resolve and run macro implementations. Loads classes from from -cp (aka the library classpath). Is also capable of detecting REPL and reusing its classloader.

  28. val macroDebugLite: Boolean

    Definition Classes
    Traces
  29. val macroDebugVerbose: Boolean

    Definition Classes
    Traces
  30. def macroExpand(typer: Analyzer.Typer, expandee: Global.Tree, mode: Int = EXPRmode, pt: Global.Type = WildcardType): Global.Tree

    Performs macro expansion: 1) Checks whether the expansion needs to be delayed (see mustDelayMacroExpansion) 2) Loads macro implementation using macroMirror 3) Synthesizes invocation arguments for the macro implementation 4) Checks that the result is a tree bound to this universe 5) Typechecks the result against the return type of the macro definition

    Performs macro expansion: 1) Checks whether the expansion needs to be delayed (see mustDelayMacroExpansion) 2) Loads macro implementation using macroMirror 3) Synthesizes invocation arguments for the macro implementation 4) Checks that the result is a tree bound to this universe 5) Typechecks the result against the return type of the macro definition

    If -Ymacro-debug-lite is enabled, you will get basic notifications about macro expansion along with macro expansions logged in the form that can be copy/pasted verbatim into REPL.

    If -Ymacro-debug-verbose is enabled, you will get detailed log of how exactly this function performs class loading and method resolution in order to load the macro implementation. The log will also include other non-trivial steps of macro expansion.

    returns

    the expansion result if the expansion has been successful, the fallback method invocation if the expansion has been unsuccessful, but there is a fallback, the expandee unchanged if the expansion has been delayed, the expandee fully expanded if the expansion has been delayed before and has been expanded now, the expandee with an error marker set if the expansion has been cancelled due malformed arguments or implementation the expandee with an error marker set if there has been an error

  31. def macroExpandAll(typer: Analyzer.Typer, expandee: Global.Tree): Global.Tree

    Performs macro expansion on all subtrees of a given tree.

    Performs macro expansion on all subtrees of a given tree. Innermost macros are expanded first, outermost macros are expanded last. See the documentation for macroExpand for more information.

  32. final def macroLogLite(msg: ⇒ Any): Unit

    Definition Classes
    Traces
    Annotations
    @inline()
  33. final def macroLogVerbose(msg: ⇒ Any): Unit

    Definition Classes
    Traces
    Annotations
    @inline()
  34. val macroTraceLite: SimpleTracer

    Definition Classes
    Traces
  35. val macroTraceVerbose: SimpleTracer

    Definition Classes
    Traces
  36. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  37. final def notify(): Unit

    Definition Classes
    AnyRef
  38. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  39. def notifyUndetparamsAdded(newUndets: List[Global.Symbol]): Unit

  40. def notifyUndetparamsInferred(undetNoMore: List[Global.Symbol], inferreds: List[Global.Type]): Unit

  41. def openMacros: collection.immutable.List[Context { val universe: Macros.this.global.type }]

  42. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  43. def toString(): String

    Definition Classes
    AnyRef → Any
  44. def typedMacroBody(typer: Analyzer.Typer, macroDdef: Global.DefDef): Global.Tree

    Verifies that the body of a macro def typechecks to a reference to a static public non-overloaded method, and that that method is signature-wise compatible with the given macro definition.

    Verifies that the body of a macro def typechecks to a reference to a static public non-overloaded method, and that that method is signature-wise compatible with the given macro definition.

    returns

    Typechecked rhs of the given macro definition if everything is okay. EmptyTree if an error occurs.

  45. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  46. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  47. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  48. def [B](y: B): (Macros, B)

    Implicit information
    This member is added by an implicit conversion from Macros to ArrowAssoc[Macros] performed by method any2ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Shadowed Implict Value Members

  1. val self: Any

    Implicit information
    This member is added by an implicit conversion from Macros to StringAdd performed by method any2stringadd in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (macros: StringAdd).self
    Definition Classes
    StringAdd
  2. val self: Any

    Implicit information
    This member is added by an implicit conversion from Macros to StringFormat performed by method any2stringfmt in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (macros: StringFormat).self
    Definition Classes
    StringFormat

Deprecated Value Members

  1. def x: Macros

    Implicit information
    This member is added by an implicit conversion from Macros to ArrowAssoc[Macros] performed by method any2ArrowAssoc in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (macros: ArrowAssoc[Macros]).x
    Definition Classes
    ArrowAssoc
    Annotations
    @deprecated
    Deprecated

    (Since version 2.10.0) Use leftOfArrow instead

  2. def x: Macros

    Implicit information
    This member is added by an implicit conversion from Macros to Ensuring[Macros] performed by method any2Ensuring in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (macros: Ensuring[Macros]).x
    Definition Classes
    Ensuring
    Annotations
    @deprecated
    Deprecated

    (Since version 2.10.0) Use resultOfEnsuring instead

Inherited from Traces

Inherited from FastTrack

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd from Macros to StringAdd

Inherited by implicit conversion any2stringfmt from Macros to StringFormat

Inherited by implicit conversion any2ArrowAssoc from Macros to ArrowAssoc[Macros]

Inherited by implicit conversion any2Ensuring from Macros to Ensuring[Macros]

Ungrouped