Skip to content

Commit 891a96a

Browse files
committed
Check if needs inline only for RefTree and GenericApply trees
1 parent 53d69cd commit 891a96a

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,14 +1254,8 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
12541254
super.ensureAccessible(tpe, superAccess, pos)
12551255
}
12561256

1257-
override def typed(tree: untpd.Tree, pt: Type = WildcardType)(using Context): Tree =
1258-
val tree1 = super.typed(tree, pt)
1259-
if Inliner.needsInlining(tree1)
1260-
then Inliner.inlineCall(tree1)
1261-
else tree1
1262-
12631257
override def typedIdent(tree: untpd.Ident, pt: Type)(using Context): Tree =
1264-
tryInlineArg(tree.asInstanceOf[tpd.Tree]) `orElse` super.typedIdent(tree, pt)
1258+
inlineIfNeeded(tryInlineArg(tree.asInstanceOf[tpd.Tree]) `orElse` super.typedIdent(tree, pt))
12651259

12661260
override def typedSelect(tree: untpd.Select, pt: Type)(using Context): Tree = {
12671261
assert(tree.hasType, tree)
@@ -1273,7 +1267,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
12731267
else
12741268
val res = resMaybeReduced
12751269
ensureAccessible(res.tpe, tree.qualifier.isInstanceOf[untpd.Super], tree.srcPos)
1276-
res
1270+
inlineIfNeeded(res)
12771271
}
12781272

12791273
override def typedIf(tree: untpd.If, pt: Type)(using Context): Tree =
@@ -1310,14 +1304,14 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
13101304
val expanded = expandMacro(res.args.head, tree.span)
13111305
typedExpr(expanded) // Inline calls and constant fold code generated by the macro
13121306
case res =>
1313-
res
1307+
inlineIfNeeded(res)
13141308
}
13151309
if res.symbol == defn.QuotedRuntime_exprQuote then
13161310
ctx.compilationUnit.needsQuotePickling = true
13171311
res
13181312

13191313
override def typedTypeApply(tree: untpd.TypeApply, pt: Type)(using Context): Tree =
1320-
constToLiteral(betaReduce(super.typedTypeApply(tree, pt)))
1314+
inlineIfNeeded(constToLiteral(betaReduce(super.typedTypeApply(tree, pt))))
13211315

13221316
override def typedMatch(tree: untpd.Match, pt: Type)(using Context): Tree =
13231317
val tree1 =
@@ -1376,6 +1370,10 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
13761370
/** True if this inline typer has already issued errors */
13771371
override def hasInliningErrors(using Context) = ctx.reporter.errorCount > initialErrorCount
13781372

1373+
private def inlineIfNeeded(tree: Tree)(using Context): Tree =
1374+
if Inliner.needsInlining(tree) then Inliner.inlineCall(tree)
1375+
else tree
1376+
13791377
}
13801378

13811379
/** Drop any side-effect-free bindings that are unused in expansion or other reachable bindings.

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3406,8 +3406,7 @@ class Typer extends Namer
34063406
val meth = methPart(tree).symbol
34073407
if meth.isAllOf(DeferredInline) && !Inliner.inInlineMethod then
34083408
errorTree(tree, i"Deferred inline ${meth.showLocated} cannot be invoked")
3409-
else if Inliner.needsInlining(tree)
3410-
then
3409+
else if Inliner.needsInlining(tree) then
34113410
tree.tpe <:< wildApprox(pt)
34123411
val errorCount = ctx.reporter.errorCount
34133412
val inlined = Inliner.inlineCall(tree)

0 commit comments

Comments
 (0)