Skip to content

Commit

Permalink
macroExpandApply => macroExpand
Browse files Browse the repository at this point in the history
Back then, when we needed separate macro expanders for both applications
and unapplications, it made sense to have two different methods that
do macro expansions.

However, after @paulp’s upgrade of the pattern matching engine, we no longer
need a dedicated expander for unapply, so I’m removing it and renaming
`macroExpandApply` to just `macroExpand`.
  • Loading branch information
xeno-by committed Dec 30, 2013
1 parent fbbe7cc commit 9737b80
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 21 deletions.
21 changes: 3 additions & 18 deletions src/compiler/scala/tools/nsc/typechecker/Macros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ trait Macros extends FastTrack with MacroRuntimes with Traces with Helpers {
* @param innerPt Expected type that comes from the signature of a macro def, possibly wildcarded to help type inference.
* @see MacroExpander
*/
def macroExpandApply(typer: Typer, expandee: Tree, mode: Mode, outerPt: Type): Tree = {
def macroExpand(typer: Typer, expandee: Tree, mode: Mode, outerPt: Type): Tree = {
object expander extends TermMacroExpander(APPLY_ROLE, typer, expandee, mode, outerPt) {
lazy val innerPt = {
val tp = if (isNullaryInvocation(expandee)) expandee.tpe.finalResultType else expandee.tpe
Expand Down Expand Up @@ -701,29 +701,14 @@ trait Macros extends FastTrack with MacroRuntimes with Traces with Helpers {
else {
forced += delayed
typer.infer.inferExprInstance(delayed, typer.context.extractUndetparams(), outerPt, keepNothings = false)
macroExpandApply(typer, delayed, mode, outerPt)
macroExpand(typer, delayed, mode, outerPt)
}
} else delayed
}
}
expander(expandee)
}

/** Expands a term macro used in unapply role as `u.Quasiquote(StringContext("", "")).q.unapply(x)` in `case q"$x" => ...`.
* @see MacroExpander
*/
def macroExpandUnapply(typer: Typer, original: Tree, fun: Tree, unapply: Symbol, args: List[Tree], mode: Mode, pt: Type) = {
val expandee = treeCopy.Apply(original, gen.mkAttributedSelect(fun, unapply), args)
object expander extends TermMacroExpander(UNAPPLY_ROLE, typer, expandee, mode, pt) {
override def allowedExpansions: String = "unapply trees"
override def allowExpandee(expandee: Tree) = expandee.isInstanceOf[Apply]
private def unsupported(what: String) = abort("unapply macros currently don't support " + what)
override def onFallback(fallback: Tree) = unsupported("fallback")
override def onDelayed(delayed: Tree) = unsupported("advanced interaction with type inference")
}
expander(original)
}

private sealed abstract class MacroStatus(val result: Tree)
private case class Success(expanded: Tree) extends MacroStatus(expanded)
private case class Fallback(fallback: Tree) extends MacroStatus(fallback) { currentRun.seenMacroExpansionsFallingBack = true }
Expand Down Expand Up @@ -871,7 +856,7 @@ trait Macros extends FastTrack with MacroRuntimes with Traces with Helpers {
context.implicitsEnabled = typer.context.implicitsEnabled
context.enrichmentEnabled = typer.context.enrichmentEnabled
context.macrosEnabled = typer.context.macrosEnabled
macroExpandApply(newTyper(context), tree, EXPRmode, WildcardType)
macroExpand(newTyper(context), tree, EXPRmode, WildcardType)
case _ =>
tree
})
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/typechecker/Typers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
if (tree.isType)
adaptType()
else if (mode.typingExprNotFun && treeInfo.isMacroApplication(tree) && !isMacroExpansionSuppressed(tree))
macroExpandApply(this, tree, mode, pt)
macroExpand(this, tree, mode, pt)
else if (mode.typingConstructorPattern)
typedConstructorPattern(tree, pt)
else if (shouldInsertApply(tree))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// see the comments for macroExpandApply.onDelayed for an explanation of what's tested here
// see the comments for macroExpand.onDelayed for an explanation of what's tested here
object Test extends App {
case class Foo(i: Int, s: String, b: Boolean)
def foo[C, L](c: C)(implicit iso: Iso[C, L]): L = iso.to(c)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// see the comments for macroExpandApply.onDelayed for an explanation of what's tested here
// see the comments for macroExpand.onDelayed for an explanation of what's tested here
object Test extends App {
case class Foo(i: Int, s: String, b: Boolean)
def foo[C, L](c: C)(implicit iso: Iso[C, L]): L = iso.to(c)
Expand Down

0 comments on commit 9737b80

Please sign in to comment.