summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2013-12-10 14:38:13 +0100
committerEugene Burmako <xeno.by@gmail.com>2013-12-10 23:13:01 +0100
commitca2dbe55eb55ec0d5461a62f5783ab1f1ebb4818 (patch)
treed92858a02a6092a49d0c352a5f7215eb5def76e0
parenta3b33419b02cafb7e2c6fed6dd96151859fc7d77 (diff)
downloadscala-ca2dbe55eb55ec0d5461a62f5783ab1f1ebb4818.tar.gz
scala-ca2dbe55eb55ec0d5461a62f5783ab1f1ebb4818.tar.bz2
scala-ca2dbe55eb55ec0d5461a62f5783ab1f1ebb4818.zip
drops the redundant typecheck of blackbox expansions
While fixing the problem with the order of typechecks for whitebox expansions, I realized that we’re doing redundant work when expanding blackbox macros. Concretely, typechecking blackbox expansions looked as follows: val expanded1 = atPos(enclosingMacroPosition.focus)(Typed(expanded0, TypeTree(innerPt))) val expanded2 = typecheck("blackbox typecheck #1", expanded1, innerPt) typecheck("blackbox typecheck #2", expanded1, outerPt) Or, if we reformulate it using quasiquotes (temporarily not taking positions into account, since they aren’t important here): val expanded2 = typed(q”$expanded: $innerPt”, innerPt) typed(expanded2, outerPt) In this formulation, it becomes apparent that the first typecheck is redundant. If something is ascribed with some type, then typechecking the ascription against that type does nothing useful. This is also highlights one of the reasons why it would be really nice to have quasiquotes used in the compiler. With them, it’s easy to notice things that would otherwise remain buried behind swaths of boilerplate.
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Macros.scala3
1 files changed, 1 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala
index 5a67feee69..a18068f2e0 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala
@@ -635,8 +635,7 @@ trait Macros extends FastTrack with MacroRuntimes with Traces with Helpers {
if (isBlackbox(expandee)) {
val expanded1 = atPos(enclosingMacroPosition.focus)(Typed(expanded0, TypeTree(innerPt)))
- val expanded2 = typecheck("blackbox typecheck #1", expanded1, innerPt)
- typecheck("blackbox typecheck #2", expanded1, outerPt)
+ typecheck("blackbox typecheck", expanded1, outerPt)
} else {
val expanded1 = expanded0
val expanded2 = typecheck("whitebox typecheck #1", expanded1, outerPt)