Calculate the arguments to pass to a macro implementation when expanding the provided tree.
Represents all the information that a macro definition needs to know about its implementation.
Describes the role that the macro expandee is performing.
Abstracts away resolution of macro runtimes.
Abstracts away resolution of macro runtimes.
Macro def -> macro impl bindings are serialized into a macroImpl
annotation
with synthetic content that carries the payload described in MacroImplBinding
.
Decreases metalevel of the type, i.
Decreases metalevel of the type, i.e. transforms: * c.Expr[T] to T * Anything else to Any
Metalevels.scala for more information and examples about metalevels
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.
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.
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)
Increases metalevel of the type, i.
Increases metalevel of the type, i.e. transforms: * T to c.Expr[T]
Metalevels.scala for more information and examples about metalevels
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.
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)
.
MacroExpander
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" => ...
.
MacroExpander
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.
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.
Macro impl reference for the given macro definition if everything is okay. EmptyTree if an error occurs.
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))