Skip to content

Commit 13c91f4

Browse files
committed
Cleanups
Better comments and refactorings that move some things around so that less modules depend on Inliner.
1 parent 710791f commit 13c91f4

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
@@ -11,6 +11,7 @@ import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._, Symbols.
1111
import Denotations._, Decorators._, DenotTransformers._
1212
import config.Printers._
1313
import collection.mutable
14+
import util.{Property, SourceFile, NoSource}
1415
import typer.ErrorReporting._
1516

1617
import scala.annotation.tailrec
@@ -945,8 +946,25 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
945946
}
946947
}
947948

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

952+
/** A context derived form `ctx` that records `call` as innermost enclosing
953+
* call for which the inlined version is currently processed.
954+
*/
955+
def inlineContext(call: Tree)(implicit ctx: Context): Context =
956+
ctx.fresh.setProperty(InlinedCalls, call :: enclosingInlineds)
957+
958+
/** All enclosing calls that are currently inlined, from innermost to outermost */
959+
def enclosingInlineds(implicit ctx: Context): List[Tree] =
960+
ctx.property(InlinedCalls).getOrElse(Nil)
961+
962+
/** The source file where the symbol of the `@inline` method referred to by `call`
963+
* is defined
964+
*/
965+
def sourceFile(call: Tree)(implicit ctx: Context) = {
966+
val file = call.symbol.sourceFile
967+
if (file != null && file.exists) new SourceFile(file) else NoSource
968+
}
951969
}
952970

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
@@ -1175,7 +1174,7 @@ object TreeTransforms {
11751174
if (mutatedInfo eq null) tree
11761175
else {
11771176
val bindings = transformSubTrees(tree.bindings, mutatedInfo, cur)
1178-
val expansion = transform(tree.expansion, mutatedInfo, cur)(Inliner.inlineContext(tree))
1177+
val expansion = transform(tree.expansion, mutatedInfo, cur)(inlineContext(tree))
11791178
goInlined(cpy.Inlined(tree)(tree.call, bindings, expansion), mutatedInfo.nx.nxTransInlined(cur))
11801179
}
11811180
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
@@ -920,7 +920,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
920920

921921
def typedInlined(tree: untpd.Inlined, pt: Type)(implicit ctx: Context): Inlined = {
922922
val (exprCtx, bindings1) = typedBlockStats(tree.bindings)
923-
val expansion1 = typed(tree.expansion, pt)(Inliner.inlineContext(tree.call)(exprCtx))
923+
val expansion1 = typed(tree.expansion, pt)(inlineContext(tree.call)(exprCtx))
924924
assignType(cpy.Inlined(tree)(tree.call, bindings1.asInstanceOf[List[MemberDef]], expansion1),
925925
bindings1, expansion1)
926926
}

0 commit comments

Comments
 (0)