scala.tools.nsc.typechecker

Macros

trait Macros extends FastTrack with MacroRuntimes with Traces with Helpers

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
Linear Supertypes
Known Subclasses
Type Hierarchy Learn more about scaladoc diagrams
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Macros
  2. Helpers
  3. Traces
  4. MacroRuntimes
  5. ScalaReflectionRuntimes
  6. JavaReflectionRuntimes
  7. FastTrack
  8. AnyRef
  9. Any
Implicitly
  1. by StringAdd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. final class FastTrackEntry extends ((FastTrack.this)#MacroArgs) ⇒ Any

    Definition Classes
    FastTrack
  2. trait JavaReflectionResolvers extends AnyRef

    Definition Classes
    JavaReflectionRuntimes
  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. case class MacroImplBinding(isBundle: Boolean, className: String, methName: String, signature: List[List[Fingerprint]], targs: List[Global.Tree]) extends Product with Serializable

    Represents all the information that a macro definition needs to know about its implementation.

  5. type MacroRole = typechecker.MacroRole

    Describes the role that the macro expandee is performing.

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

    Abstracts away resolution of macro runtimes.

    Abstracts away resolution of macro runtimes.

    Definition Classes
    MacroRuntimes
  7. class MacroRuntimeResolver extends tools.nsc.typechecker.Analyzer.JavaReflectionResolvers with tools.nsc.typechecker.Analyzer.ScalaReflectionResolvers

    Definition Classes
    MacroRuntimes
  8. trait ScalaReflectionResolvers extends AnyRef

    Definition Classes
    ScalaReflectionRuntimes

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[Macros] performed by method StringAdd 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 ArrowAssoc 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 APPLY_ROLE: typechecker.MacroRole

  9. object MacroImplBinding extends Serializable

    Macro def -> macro impl bindings are serialized into a macroImpl annotation with synthetic content that carries the payload described in MacroImplBinding.

  10. final def UNAPPLY_ROLE: typechecker.MacroRole

  11. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  12. def bindMacroImpl(macroDef: Global.Symbol, macroImplRef: Global.Tree): Unit

  13. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  14. def computeMacroDefTypeFromMacroImplRef(macroDdef: Global.DefDef, macroImplRef: Global.Tree): Global.Type

  15. def decreaseMetalevel(tp: Global.Type): Global.Type

    Decreases metalevel of the type, i.

    Decreases metalevel of the type, i.e. transforms: * c.Expr[T] to T * Anything else to Any

    Definition Classes
    Helpers
    See also

    Metalevels.scala for more information and examples about metalevels

  16. lazy val defaultMacroClassloader: 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.

    When -Xmacro-jit is enabled, we sometimes fallback to on-the-fly compilation of macro implementations, which compiles implementations into a virtual directory (very much like REPL does) and then conjures a classloader mapped to that virtual directory.

    Definition Classes
    MacroRuntimes
  17. def enclosingMacroPosition: Position

  18. 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 Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  19. def ensuring(cond: (Macros) ⇒ Boolean): Macros

    Implicit information
    This member is added by an implicit conversion from Macros to Ensuring[Macros] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  20. 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 Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  21. def ensuring(cond: Boolean): Macros

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

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

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

    A map from a set of pre-established macro symbols to their implementations.

    A map from a set of pre-established macro symbols to their implementations.

    Definition Classes
    FastTrack
  25. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  26. def findMacroClassLoader(): ClassLoader

    Attributes
    protected
  27. def formatted(fmtstr: String): String

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

    Definition Classes
    AnyRef → Any
  29. def globalSettings: Settings

    Definition Classes
    MacrosTraces
  30. 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)

  31. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  32. def increaseMetalevel(pre: Global.Type, tp: Global.Type): Global.Type

    Increases metalevel of the type, i.

    Increases metalevel of the type, i.e. transforms: * T to c.Expr[T]

    Definition Classes
    Helpers
    See also

    Metalevels.scala for more information and examples about metalevels

  33. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  34. def loadMacroImplBinding(macroDef: Global.Symbol): Analyzer.MacroImplBinding

  35. def macroContext(typer: Analyzer.Typer, prefixTree: Global.Tree, expandeeTree: Global.Tree): Analyzer.MacroContext

  36. val macroDebugLite: Boolean

    Definition Classes
    Traces
  37. val macroDebugVerbose: Boolean

    Definition Classes
    Traces
  38. 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.

  39. def macroExpandApply(typer: Analyzer.Typer, expandee: Global.Tree, mode: Mode, pt: Global.Type): Global.Tree

    Expands a term macro used in apply role as M(2)(3) in val x = M(2)(3).

    Expands a term macro used in apply role as M(2)(3) in val x = M(2)(3).

    See also

    MacroExpander

  40. def macroExpandUnapply(typer: Analyzer.Typer, original: Global.Tree, fun: Global.Tree, unapply: Global.Symbol, args: List[Global.Tree], mode: Mode, pt: Global.Type): Global.Tree

    Expands a term macro used in unapply role as u.Quasiquote(StringContext("", "")).q.unapply(x) in case q"$x" => ....

    Expands a term macro used in unapply role as u.Quasiquote(StringContext("", "")).q.unapply(x) in case q"$x" => ....

    See also

    MacroExpander

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

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

    Definition Classes
    Traces
    Annotations
    @inline()
  43. def macroRuntime(macroDef: Global.Symbol): Analyzer.MacroRuntime

    Definition Classes
    MacroRuntimes
  44. final def ne(arg0: AnyRef): Boolean

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

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

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

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

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

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

    Definition Classes
    AnyRef
  51. def toString(): String

    Definition Classes
    AnyRef → Any
  52. def transformTypeTagEvidenceParams(macroImplRef: Global.Tree, transform: (Global.Symbol, Global.Symbol) ⇒ Global.Symbol): List[List[Global.Symbol]]

    Transforms parameters lists of a macro impl.

    Transforms parameters lists of a macro impl. The transform function is invoked only for WeakTypeTag evidence parameters.

    The transformer takes two arguments: a value parameter from the parameter list and a type parameter that is witnesses by the value parameter.

    If the transformer returns a NoSymbol, the value parameter is not included from the result. If the transformer returns something else, this something else is included in the result instead of the value parameter.

    Despite of being highly esoteric, this function significantly simplifies signature analysis. For example, it can be used to strip macroImpl.paramss from the evidences (necessary when checking def <-> impl correspondence) or to streamline creation of the list of macro arguments.

    Definition Classes
    Helpers
  53. 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 or a top-level macro bundle, 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 or a top-level macro bundle, and that that method is signature-wise compatible with the given macro definition.

    returns

    Macro impl reference for the given macro definition if everything is okay. EmptyTree if an error occurs.

  54. final def wait(): Unit

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

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

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

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

Inherited from Helpers

Inherited from Traces

Inherited from MacroRuntimes

Inherited from ScalaReflectionRuntimes

Inherited from JavaReflectionRuntimes

Inherited from FastTrack

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion StringAdd from Macros to StringAdd[Macros]

Inherited by implicit conversion StringFormat from Macros to StringFormat[Macros]

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

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

Ungrouped