Skip to content

Commit ca2dbe5

Browse files
committed
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.
1 parent a3b3341 commit ca2dbe5

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/compiler/scala/tools/nsc/typechecker/Macros.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,7 @@ trait Macros extends FastTrack with MacroRuntimes with Traces with Helpers {
635635

636636
if (isBlackbox(expandee)) {
637637
val expanded1 = atPos(enclosingMacroPosition.focus)(Typed(expanded0, TypeTree(innerPt)))
638-
val expanded2 = typecheck("blackbox typecheck #1", expanded1, innerPt)
639-
typecheck("blackbox typecheck #2", expanded1, outerPt)
638+
typecheck("blackbox typecheck", expanded1, outerPt)
640639
} else {
641640
val expanded1 = expanded0
642641
val expanded2 = typecheck("whitebox typecheck #1", expanded1, outerPt)

0 commit comments

Comments
 (0)