Skip to content

Commit 954c25b

Browse files
committed
Add isInlineCall to TreeInfo
1 parent 72f3ab6 commit 954c25b

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

compiler/src/dotty/tools/dotc/CompilationUnit.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,8 @@ object CompilationUnit {
6666
def traverse(tree: Tree)(implicit ctx: Context): Unit = {
6767
if (tree.symbol.isQuote)
6868
containsQuotes = true
69-
tree match {
70-
case _: tpd.RefTree | _: Trees.GenericApply[_] if Inliner.isInlineable(tree) =>
71-
containsInline = true
72-
case _ =>
73-
}
69+
if (tpd.isInlineCall(tree))
70+
containsInline = true
7471
traverseChildren(tree)
7572
}
7673
}

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package ast
55
import core._
66
import Flags._, Trees._, Types._, Contexts._
77
import Names._, StdNames._, NameOps._, Symbols._
8-
import typer.ConstFold
8+
import typer.{ConstFold, Inliner}
99
import reporting.trace
1010

1111
import scala.annotation.tailrec
@@ -759,6 +759,14 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
759759
false
760760
}
761761

762+
/** Is this call a call to a method that is marked as Inline */
763+
def isInlineCall(arg: Tree)(implicit ctx: Context): Boolean = arg match {
764+
case _: RefTree | _: GenericApply[_] =>
765+
!arg.tpe.widenDealias.isInstanceOf[MethodicType] && Inliner.isInlineable(arg)
766+
case _ =>
767+
false
768+
}
769+
762770
/** Structural tree comparison (since == on trees is reference equality).
763771
* For the moment, only Ident, Select, Literal, Apply and TypeApply are supported
764772
*/

compiler/src/dotty/tools/dotc/transform/InlineCalls.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class InlineCalls extends MacroTransform { thisPhase =>
2424

2525
class InlineCallsTransformer extends Transformer {
2626
override def transform(tree: Tree)(implicit ctx: Context): Tree = tree match {
27-
case _: RefTree | _: GenericApply[_] if !tree.tpe.widenDealias.isInstanceOf[MethodicType] && Inliner.isInlineable(tree) && !ctx.reporter.hasErrors =>
27+
case tree if isInlineCall(tree) && !ctx.reporter.hasErrors =>
2828
val tree2 = super.transform(tree) // transform arguments before inlining (inline arguments and constant fold arguments)
2929
transform(Inliner.inlineCall(tree2, tree.tpe.widen))
3030
case _: MemberDef =>

0 commit comments

Comments
 (0)