Skip to content

Commit 53b165e

Browse files
committed
Cleanups
Better comments and refactorings that move some things around so that less modules depend on Inliner.
1 parent bef012d commit 53b165e

File tree

7 files changed

+28
-35
lines changed

7 files changed

+28
-35
lines changed

src/dotty/tools/dotc/ast/TreeTypeMap.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import core._
66
import Types._, Contexts._, Constants._, Names._, Flags._
77
import SymDenotations._, Symbols._, Annotations._, Trees._, Symbols._
88
import Denotations._, Decorators._
9-
import config.Printers.inlining
109
import dotty.tools.dotc.transform.SymUtils._
1110

1211
/** A map that applies three functions and a substitution together to a tree and

src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import util.Positions._, Types._, Contexts._, Constants._, Names._, Flags._
1010
import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._, Symbols._
1111
import Denotations._, Decorators._, DenotTransformers._
1212
import collection.mutable
13+
import util.{Property, SourceFile, NoSource}
1314
import typer.ErrorReporting._
1415

1516
import scala.annotation.tailrec
@@ -921,8 +922,25 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
921922
}
922923
}
923924

924-
// ensure that constructors are fully applied?
925-
// ensure that normal methods are fully applied?
925+
/** A key to be used in a context property that tracks enclosing inlined calls */
926+
private val InlinedCalls = new Property.Key[List[Tree]]
926927

928+
/** A context derived form `ctx` that records `call` as innermost enclosing
929+
* call for which the inlined version is currently processed.
930+
*/
931+
def inlineContext(call: Tree)(implicit ctx: Context): Context =
932+
ctx.fresh.setProperty(InlinedCalls, call :: enclosingInlineds)
933+
934+
/** All enclosing calls that are currently inlined, from innermost to outermost */
935+
def enclosingInlineds(implicit ctx: Context): List[Tree] =
936+
ctx.property(InlinedCalls).getOrElse(Nil)
937+
938+
/** The source file where the symbol of the `@inline` method referred to by `call`
939+
* is defined
940+
*/
941+
def sourceFile(call: Tree)(implicit ctx: Context) = {
942+
val file = call.symbol.sourceFile
943+
if (file != null && file.exists) new SourceFile(file) else NoSource
944+
}
927945
}
928946

src/dotty/tools/dotc/core/Decorators.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import Contexts._, Names._, Phases._, printing.Texts._, printing.Printer, printi
77
import util.Positions.Position, util.SourcePosition
88
import collection.mutable.ListBuffer
99
import dotty.tools.dotc.transform.TreeTransforms._
10-
import typer.Inliner
11-
import ast.tpd.Tree
10+
import ast.tpd._
1211
import scala.language.implicitConversions
1312
import printing.Formatting._
1413

@@ -153,11 +152,11 @@ object Decorators {
153152
implicit def sourcePos(pos: Position)(implicit ctx: Context): SourcePosition = {
154153
def recur(inlinedCalls: List[Tree], pos: Position): SourcePosition = inlinedCalls match {
155154
case inlinedCall :: rest =>
156-
Inliner.sourceFile(inlinedCall).atPos(pos).withOuter(recur(rest, inlinedCall.pos))
155+
sourceFile(inlinedCall).atPos(pos).withOuter(recur(rest, inlinedCall.pos))
157156
case empty =>
158157
ctx.source.atPos(pos)
159158
}
160-
recur(Inliner.enclosingInlineds, pos)
159+
recur(enclosingInlineds, pos)
161160
}
162161

163162
implicit class StringInterpolators(val sc: StringContext) extends AnyVal {

src/dotty/tools/dotc/core/TyperState.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ extends TyperState(r) {
123123
* that were temporarily instantiated in the current typer state are permanently
124124
* instantiated instead.
125125
*
126-
* A note on merging: A case is in isApplicableSafe.scala. It turns out that this
126+
* A note on merging: An interesting test case is isApplicableSafe.scala. It turns out that this
127127
* requires a context merge using the new `&' operator. Sequence of actions:
128128
* 1) Typecheck argument in typerstate 1.
129129
* 2) Cache argument.

src/dotty/tools/dotc/transform/TreeTransform.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import dotty.tools.dotc.core.Mode
1515
import dotty.tools.dotc.ast.Trees._
1616
import dotty.tools.dotc.core.Decorators._
1717
import dotty.tools.dotc.util.DotClass
18-
import dotty.tools.dotc.typer.Inliner
1918
import scala.annotation.tailrec
2019
import config.Printers.transforms
2120
import scala.util.control.NonFatal
@@ -1117,7 +1116,7 @@ object TreeTransforms {
11171116
if (mutatedInfo eq null) tree
11181117
else {
11191118
val bindings = transformSubTrees(tree.bindings, mutatedInfo, cur)
1120-
val expansion = transform(tree.expansion, mutatedInfo, cur)(Inliner.inlineContext(tree))
1119+
val expansion = transform(tree.expansion, mutatedInfo, cur)(inlineContext(tree))
11211120
goInlined(cpy.Inlined(tree)(tree.call, bindings, expansion), mutatedInfo.nx.nxTransInlined(cur))
11221121
}
11231122
case tree: TypeTree =>

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

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,21 @@ import transform.ExplicitOuter
2121
import Inferencing.fullyDefinedType
2222
import config.Printers.inlining
2323
import ErrorReporting.errorTree
24-
import util.{Property, SourceFile, NoSource}
2524
import collection.mutable
2625
import transform.TypeUtils._
2726

2827
object Inliner {
2928
import tpd._
3029

31-
/** A key to be used in a context property that tracks enclosing inlined calls */
32-
private val InlinedCalls = new Property.Key[List[Tree]] // to be used in context
33-
3430
/** Adds accessors accessors for all non-public term members accessed
3531
* from `tree`. Non-public type members are currently left as they are.
3632
* This means that references to a private type will lead to typing failures
3733
* on the code when it is inlined. Less than ideal, but hard to do better (see below).
38-
*
34+
*
3935
* @return If there are accessors generated, a thicket consisting of the rewritten `tree`
4036
* and all accessors, otherwise the original tree.
4137
*/
42-
def makeInlineable(tree: Tree)(implicit ctx: Context) = {
38+
private def makeInlineable(tree: Tree)(implicit ctx: Context) = {
4339

4440
/** A tree map which inserts accessors for all non-public term members accessed
4541
* from inlined code. Accesors are collected in the `accessors` buffer.
@@ -250,24 +246,6 @@ object Inliner {
250246
tpd.seq(inlined.bindings, reposition.transform(inlined.expansion))
251247
}
252248

253-
/** A context derived form `ctx` that records `call` as innermost enclosing
254-
* call for which the inlined version is currently processed.
255-
*/
256-
def inlineContext(call: Tree)(implicit ctx: Context): Context =
257-
ctx.fresh.setProperty(InlinedCalls, call :: enclosingInlineds)
258-
259-
/** All enclosing calls that are currently inlined, from innermost to outermost */
260-
def enclosingInlineds(implicit ctx: Context): List[Tree] =
261-
ctx.property(InlinedCalls).getOrElse(Nil)
262-
263-
/** The source file where the symbol of the `@inline` method referred to by `call`
264-
* is defined
265-
*/
266-
def sourceFile(call: Tree)(implicit ctx: Context) = {
267-
val file = call.symbol.sourceFile
268-
if (file != null && file.exists) new SourceFile(file) else NoSource
269-
}
270-
271249
/** The qualifier part of a Select, Ident, or SelectFromTypeTree tree.
272250
* For an Ident, this is the `This` of the current class. (TODO: use elsewhere as well?)
273251
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
949949

950950
def typedInlined(tree: untpd.Inlined, pt: Type)(implicit ctx: Context): Inlined = {
951951
val (exprCtx, bindings1) = typedBlockStats(tree.bindings)
952-
val expansion1 = typed(tree.expansion, pt)(Inliner.inlineContext(tree.call)(exprCtx))
952+
val expansion1 = typed(tree.expansion, pt)(inlineContext(tree.call)(exprCtx))
953953
assignType(cpy.Inlined(tree)(tree.call, bindings1.asInstanceOf[List[MemberDef]], expansion1),
954954
bindings1, expansion1)
955955
}

0 commit comments

Comments
 (0)