diff options
author | Martin Odersky <odersky@gmail.com> | 2016-09-15 21:45:26 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-10-02 16:12:28 +0200 |
commit | 53b165e69bb45f424184d02e76c520b67ee0c1d7 (patch) | |
tree | 2b4f6123890b520e69dc14fe297e4a89dd79eb81 /src/dotty | |
parent | bef012d32127e3d256d0ce31e1a2a27f7277f8d8 (diff) | |
download | dotty-53b165e69bb45f424184d02e76c520b67ee0c1d7.tar.gz dotty-53b165e69bb45f424184d02e76c520b67ee0c1d7.tar.bz2 dotty-53b165e69bb45f424184d02e76c520b67ee0c1d7.zip |
Cleanups
Better comments and refactorings that move some things around
so that less modules depend on Inliner.
Diffstat (limited to 'src/dotty')
-rw-r--r-- | src/dotty/tools/dotc/ast/TreeTypeMap.scala | 1 | ||||
-rw-r--r-- | src/dotty/tools/dotc/ast/tpd.scala | 22 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Decorators.scala | 7 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/TyperState.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/TreeTransform.scala | 3 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Inliner.scala | 26 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 2 |
7 files changed, 28 insertions, 35 deletions
diff --git a/src/dotty/tools/dotc/ast/TreeTypeMap.scala b/src/dotty/tools/dotc/ast/TreeTypeMap.scala index 80499cceb..cf529dfda 100644 --- a/src/dotty/tools/dotc/ast/TreeTypeMap.scala +++ b/src/dotty/tools/dotc/ast/TreeTypeMap.scala @@ -6,7 +6,6 @@ import core._ import Types._, Contexts._, Constants._, Names._, Flags._ import SymDenotations._, Symbols._, Annotations._, Trees._, Symbols._ import Denotations._, Decorators._ -import config.Printers.inlining import dotty.tools.dotc.transform.SymUtils._ /** A map that applies three functions and a substitution together to a tree and diff --git a/src/dotty/tools/dotc/ast/tpd.scala b/src/dotty/tools/dotc/ast/tpd.scala index 54005808f..8ba7bc54d 100644 --- a/src/dotty/tools/dotc/ast/tpd.scala +++ b/src/dotty/tools/dotc/ast/tpd.scala @@ -10,6 +10,7 @@ import util.Positions._, Types._, Contexts._, Constants._, Names._, Flags._ import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._, Symbols._ import Denotations._, Decorators._, DenotTransformers._ import collection.mutable +import util.{Property, SourceFile, NoSource} import typer.ErrorReporting._ import scala.annotation.tailrec @@ -921,8 +922,25 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { } } - // ensure that constructors are fully applied? - // ensure that normal methods are fully applied? + /** A key to be used in a context property that tracks enclosing inlined calls */ + private val InlinedCalls = new Property.Key[List[Tree]] + /** A context derived form `ctx` that records `call` as innermost enclosing + * call for which the inlined version is currently processed. + */ + def inlineContext(call: Tree)(implicit ctx: Context): Context = + ctx.fresh.setProperty(InlinedCalls, call :: enclosingInlineds) + + /** All enclosing calls that are currently inlined, from innermost to outermost */ + def enclosingInlineds(implicit ctx: Context): List[Tree] = + ctx.property(InlinedCalls).getOrElse(Nil) + + /** The source file where the symbol of the `@inline` method referred to by `call` + * is defined + */ + def sourceFile(call: Tree)(implicit ctx: Context) = { + val file = call.symbol.sourceFile + if (file != null && file.exists) new SourceFile(file) else NoSource + } } diff --git a/src/dotty/tools/dotc/core/Decorators.scala b/src/dotty/tools/dotc/core/Decorators.scala index 691e0aeba..3bf17730a 100644 --- a/src/dotty/tools/dotc/core/Decorators.scala +++ b/src/dotty/tools/dotc/core/Decorators.scala @@ -7,8 +7,7 @@ import Contexts._, Names._, Phases._, printing.Texts._, printing.Printer, printi import util.Positions.Position, util.SourcePosition import collection.mutable.ListBuffer import dotty.tools.dotc.transform.TreeTransforms._ -import typer.Inliner -import ast.tpd.Tree +import ast.tpd._ import scala.language.implicitConversions import printing.Formatting._ @@ -153,11 +152,11 @@ object Decorators { implicit def sourcePos(pos: Position)(implicit ctx: Context): SourcePosition = { def recur(inlinedCalls: List[Tree], pos: Position): SourcePosition = inlinedCalls match { case inlinedCall :: rest => - Inliner.sourceFile(inlinedCall).atPos(pos).withOuter(recur(rest, inlinedCall.pos)) + sourceFile(inlinedCall).atPos(pos).withOuter(recur(rest, inlinedCall.pos)) case empty => ctx.source.atPos(pos) } - recur(Inliner.enclosingInlineds, pos) + recur(enclosingInlineds, pos) } implicit class StringInterpolators(val sc: StringContext) extends AnyVal { diff --git a/src/dotty/tools/dotc/core/TyperState.scala b/src/dotty/tools/dotc/core/TyperState.scala index 3ed4788ee..7e332b412 100644 --- a/src/dotty/tools/dotc/core/TyperState.scala +++ b/src/dotty/tools/dotc/core/TyperState.scala @@ -123,7 +123,7 @@ extends TyperState(r) { * that were temporarily instantiated in the current typer state are permanently * instantiated instead. * - * A note on merging: A case is in isApplicableSafe.scala. It turns out that this + * A note on merging: An interesting test case is isApplicableSafe.scala. It turns out that this * requires a context merge using the new `&' operator. Sequence of actions: * 1) Typecheck argument in typerstate 1. * 2) Cache argument. diff --git a/src/dotty/tools/dotc/transform/TreeTransform.scala b/src/dotty/tools/dotc/transform/TreeTransform.scala index 40a5cb0bf..52a3ad94e 100644 --- a/src/dotty/tools/dotc/transform/TreeTransform.scala +++ b/src/dotty/tools/dotc/transform/TreeTransform.scala @@ -15,7 +15,6 @@ import dotty.tools.dotc.core.Mode import dotty.tools.dotc.ast.Trees._ import dotty.tools.dotc.core.Decorators._ import dotty.tools.dotc.util.DotClass -import dotty.tools.dotc.typer.Inliner import scala.annotation.tailrec import config.Printers.transforms import scala.util.control.NonFatal @@ -1117,7 +1116,7 @@ object TreeTransforms { if (mutatedInfo eq null) tree else { val bindings = transformSubTrees(tree.bindings, mutatedInfo, cur) - val expansion = transform(tree.expansion, mutatedInfo, cur)(Inliner.inlineContext(tree)) + val expansion = transform(tree.expansion, mutatedInfo, cur)(inlineContext(tree)) goInlined(cpy.Inlined(tree)(tree.call, bindings, expansion), mutatedInfo.nx.nxTransInlined(cur)) } case tree: TypeTree => diff --git a/src/dotty/tools/dotc/typer/Inliner.scala b/src/dotty/tools/dotc/typer/Inliner.scala index fd551bc39..f0464c764 100644 --- a/src/dotty/tools/dotc/typer/Inliner.scala +++ b/src/dotty/tools/dotc/typer/Inliner.scala @@ -21,25 +21,21 @@ import transform.ExplicitOuter import Inferencing.fullyDefinedType import config.Printers.inlining import ErrorReporting.errorTree -import util.{Property, SourceFile, NoSource} import collection.mutable import transform.TypeUtils._ object Inliner { import tpd._ - /** A key to be used in a context property that tracks enclosing inlined calls */ - private val InlinedCalls = new Property.Key[List[Tree]] // to be used in context - /** Adds accessors accessors for all non-public term members accessed * from `tree`. Non-public type members are currently left as they are. * This means that references to a private type will lead to typing failures * on the code when it is inlined. Less than ideal, but hard to do better (see below). - * + * * @return If there are accessors generated, a thicket consisting of the rewritten `tree` * and all accessors, otherwise the original tree. */ - def makeInlineable(tree: Tree)(implicit ctx: Context) = { + private def makeInlineable(tree: Tree)(implicit ctx: Context) = { /** A tree map which inserts accessors for all non-public term members accessed * from inlined code. Accesors are collected in the `accessors` buffer. @@ -250,24 +246,6 @@ object Inliner { tpd.seq(inlined.bindings, reposition.transform(inlined.expansion)) } - /** A context derived form `ctx` that records `call` as innermost enclosing - * call for which the inlined version is currently processed. - */ - def inlineContext(call: Tree)(implicit ctx: Context): Context = - ctx.fresh.setProperty(InlinedCalls, call :: enclosingInlineds) - - /** All enclosing calls that are currently inlined, from innermost to outermost */ - def enclosingInlineds(implicit ctx: Context): List[Tree] = - ctx.property(InlinedCalls).getOrElse(Nil) - - /** The source file where the symbol of the `@inline` method referred to by `call` - * is defined - */ - def sourceFile(call: Tree)(implicit ctx: Context) = { - val file = call.symbol.sourceFile - if (file != null && file.exists) new SourceFile(file) else NoSource - } - /** The qualifier part of a Select, Ident, or SelectFromTypeTree tree. * For an Ident, this is the `This` of the current class. (TODO: use elsewhere as well?) */ diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index f9fca117d..fb7f26f36 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -949,7 +949,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit def typedInlined(tree: untpd.Inlined, pt: Type)(implicit ctx: Context): Inlined = { val (exprCtx, bindings1) = typedBlockStats(tree.bindings) - val expansion1 = typed(tree.expansion, pt)(Inliner.inlineContext(tree.call)(exprCtx)) + val expansion1 = typed(tree.expansion, pt)(inlineContext(tree.call)(exprCtx)) assignType(cpy.Inlined(tree)(tree.call, bindings1.asInstanceOf[List[MemberDef]], expansion1), bindings1, expansion1) } |