Calculate the arguments to pass to a macro implementation when expanding the provided tree.
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.
Requested runtime if macro implementation can be loaded successfully from either of the mirrors,
null
otherwise.
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)
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.
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.
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
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.
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.
Typechecked rhs of the given macro definition if everything is okay. EmptyTree if an error occurs.
(macros: StringAdd).self
(macros: StringFormat).self
(macros: ArrowAssoc[Macros]).x
(Since version 2.10.0) Use leftOfArrow
instead
(macros: Ensuring[Macros]).x
(Since version 2.10.0) Use resultOfEnsuring
instead
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))