Skip to content

Commit 861803c

Browse files
committed
WIP
1 parent 0059d1d commit 861803c

18 files changed

+1022
-516
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,18 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
999999
case _ => None
10001000
case _ => None
10011001
end AssertNotNull
1002+
1003+
object ConstantValue {
1004+
def unapply(tree: Tree)(using Context): Option[Any] =
1005+
tree match
1006+
case Typed(expr, _) => unapply(expr)
1007+
case Inlined(_, Nil, expr) => unapply(expr)
1008+
case Block(Nil, expr) => unapply(expr)
1009+
case _ =>
1010+
tree.tpe.widenTermRefExpr.normalized match
1011+
case ConstantType(Constant(x)) => Some(x)
1012+
case _ => None
1013+
}
10021014
}
10031015

10041016
object TreeInfo {

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ class TreeUnpickler(reader: TastyReader,
830830
else if sym.isInlineMethod && !sym.is(Deferred) then
831831
// The body of an inline method is stored in an annotation, so no need to unpickle it again
832832
new Trees.Lazy[Tree] {
833-
def complete(using Context) = typer.Inliner.bodyToInline(sym)
833+
def complete(using Context) = typer.Inlines.bodyToInline(sym)
834834
}
835835
else
836836
readLater(end, _.readTerm())

compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Types._
1616
import Symbols._
1717
import Names._
1818
import NameOps._
19-
import typer.Inliner
19+
import typer.Inlines
2020
import transform.ValueClasses
2121
import transform.SymUtils._
2222
import dotty.tools.io.File
@@ -657,7 +657,7 @@ private class ExtractAPICollector(using Context) extends ThunkHolder {
657657
*/
658658
def apiAnnotations(s: Symbol, inlineOrigin: Symbol): List[api.Annotation] = {
659659
val annots = new mutable.ListBuffer[api.Annotation]
660-
val inlineBody = Inliner.bodyToInline(s)
660+
val inlineBody = Inlines.bodyToInline(s)
661661
if !inlineBody.isEmpty then
662662
// If the body of an inline def changes, all the reverse dependencies of
663663
// this method need to be recompiled. sbt has no way of tracking method

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import core.Constants._
1919
import core.Definitions._
2020
import core.Annotations.BodyAnnotation
2121
import typer.NoChecking
22-
import typer.Inliner
22+
import typer.Inlines
2323
import typer.ProtoTypes._
2424
import typer.ErrorReporting.errorTree
2525
import typer.Checking.checkValue
@@ -886,7 +886,7 @@ object Erasure {
886886

887887
override def typedInlined(tree: untpd.Inlined, pt: Type)(using Context): Tree =
888888
super.typedInlined(tree, pt) match {
889-
case tree: Inlined => Inliner.dropInlined(tree)
889+
case tree: Inlined => Inlines.dropInlined(tree)
890890
}
891891

892892
override def typedValDef(vdef: untpd.ValDef, sym: Symbol)(using Context): Tree =

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import dotty.tools.dotc.core.Symbols._
88
import dotty.tools.dotc.core.Flags._
99
import dotty.tools.dotc.core.Types._
1010
import dotty.tools.dotc.transform.MegaPhase.MiniPhase
11-
import dotty.tools.dotc.typer.Inliner
11+
import dotty.tools.dotc.typer.Inlines
1212

1313
/** Check that `tree.rhs` can be right hand-side of an `inline` value definition. */
1414
class InlineVals extends MiniPhase:
@@ -31,7 +31,7 @@ class InlineVals extends MiniPhase:
3131
/** Check that `tree.rhs` can be right hand-side of an `inline` value definition. */
3232
private def checkInlineConformant(tree: ValDef)(using Context): Unit = {
3333
if tree.symbol.is(Inline, butNot = DeferredOrTermParamOrAccessor)
34-
&& !Inliner.inInlineMethod
34+
&& !Inlines.inInlineMethod
3535
then
3636
val rhs = tree.rhs
3737
val tpt = tree.tpt

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import SymUtils._
99
import dotty.tools.dotc.ast.tpd
1010

1111
import dotty.tools.dotc.core.StagingContext._
12-
import dotty.tools.dotc.typer.Inliner
12+
import dotty.tools.dotc.typer.Inlines
1313
import dotty.tools.dotc.ast.TreeMapWithImplicits
1414

1515

@@ -43,7 +43,7 @@ class Inlining extends MacroTransform {
4343
traverseChildren(tree)(using StagingContext.quoteContext)
4444
case _: GenericApply if tree.symbol.isExprSplice =>
4545
traverseChildren(tree)(using StagingContext.spliceContext)
46-
case tree: RefTree if !Inliner.inInlineMethod && StagingContext.level == 0 =>
46+
case tree: RefTree if !Inlines.inInlineMethod && StagingContext.level == 0 =>
4747
assert(!tree.symbol.isInlineMethod, tree.show)
4848
case _ =>
4949
traverseChildren(tree)
@@ -64,10 +64,10 @@ class Inlining extends MacroTransform {
6464
else super.transform(tree)
6565
case _: Typed | _: Block =>
6666
super.transform(tree)
67-
case _ if Inliner.needsInlining(tree) =>
67+
case _ if Inlines.needsInlining(tree) =>
6868
val tree1 = super.transform(tree)
6969
if tree1.tpe.isError then tree1
70-
else Inliner.inlineCall(tree1)
70+
else Inlines.inlineCall(tree1)
7171
case _: GenericApply if tree.symbol.isQuote =>
7272
super.transform(tree)(using StagingContext.quoteContext)
7373
case _: GenericApply if tree.symbol.isExprSplice =>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import dotty.tools.dotc.core.Annotations._
2020
import dotty.tools.dotc.core.StdNames._
2121
import dotty.tools.dotc.quoted._
2222
import dotty.tools.dotc.transform.TreeMapWithStages._
23-
import dotty.tools.dotc.typer.Inliner
23+
import dotty.tools.dotc.typer.Inlines
2424

2525
import scala.annotation.constructorOnly
2626

@@ -84,10 +84,10 @@ class PickleQuotes extends MacroTransform {
8484

8585
override def checkPostCondition(tree: Tree)(using Context): Unit =
8686
tree match
87-
case tree: RefTree if !Inliner.inInlineMethod =>
87+
case tree: RefTree if !Inlines.inInlineMethod =>
8888
assert(!tree.symbol.isQuote)
8989
assert(!tree.symbol.isExprSplice)
90-
case _ : TypeDef if !Inliner.inInlineMethod =>
90+
case _ : TypeDef if !Inlines.inInlineMethod =>
9191
assert(!tree.symbol.hasAnnotation(defn.QuotedRuntime_SplicedTypeAnnot),
9292
s"${tree.symbol} should have been removed by PickledQuotes because it has a @quoteTypeTag")
9393
case _ =>
@@ -101,7 +101,7 @@ class PickleQuotes extends MacroTransform {
101101
case Apply(Select(Apply(TypeApply(fn, List(tpt)), List(code)),nme.apply), List(quotes))
102102
if fn.symbol == defn.QuotedRuntime_exprQuote =>
103103
val (contents, codeWithHoles) = makeHoles(code)
104-
val sourceRef = Inliner.inlineCallTrace(ctx.owner, tree.sourcePos)
104+
val sourceRef = Inlines.inlineCallTrace(ctx.owner, tree.sourcePos)
105105
val codeWithHoles2 = Inlined(sourceRef, Nil, codeWithHoles)
106106
val pickled = PickleQuotes(quotes, codeWithHoles2, contents, tpt.tpe, false)
107107
transform(pickled) // pickle quotes that are in the contents

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import dotty.tools.dotc.ast.{Trees, tpd, untpd, desugar}
55
import scala.collection.mutable
66
import core._
77
import dotty.tools.dotc.typer.Checking
8-
import dotty.tools.dotc.typer.Inliner
8+
import dotty.tools.dotc.typer.Inlines
99
import dotty.tools.dotc.typer.VarianceChecker
1010
import typer.ErrorReporting.errorTree
1111
import Types._, Contexts._, Names._, Flags._, DenotTransformers._, Phases._
@@ -282,7 +282,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
282282
if tree.isType then
283283
checkNotPackage(tree)
284284
else
285-
if tree.symbol.is(Inline) && !Inliner.inInlineMethod then
285+
if tree.symbol.is(Inline) && !Inlines.inInlineMethod then
286286
ctx.compilationUnit.needsInlining = true
287287
checkNoConstructorProxy(tree)
288288
tree.tpe match {
@@ -356,7 +356,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
356356
}
357357
case Inlined(call, bindings, expansion) if !call.isEmpty =>
358358
val pos = call.sourcePos
359-
val callTrace = Inliner.inlineCallTrace(call.symbol, pos)(using ctx.withSource(pos.source))
359+
val callTrace = Inlines.inlineCallTrace(call.symbol, pos)(using ctx.withSource(pos.source))
360360
cpy.Inlined(tree)(callTrace, transformSub(bindings), transform(expansion)(using inlineContext(call)))
361361
case templ: Template =>
362362
withNoCheckNews(templ.parents.flatMap(newPart)) {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import dotty.tools.dotc.core.Names._
1818
import dotty.tools.dotc.core.StdNames._
1919
import dotty.tools.dotc.quoted._
2020
import dotty.tools.dotc.transform.TreeMapWithStages._
21-
import dotty.tools.dotc.typer.Inliner
2221

2322
import scala.annotation.constructorOnly
2423

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import dotty.tools.dotc.core.Names._
2222
import dotty.tools.dotc.core.StdNames._
2323
import dotty.tools.dotc.quoted._
2424
import dotty.tools.dotc.transform.TreeMapWithStages._
25-
import dotty.tools.dotc.typer.Inliner
2625
import dotty.tools.dotc.config.ScalaRelease.*
2726

2827
import scala.annotation.constructorOnly

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ trait Checking {
12341234

12351235
/** Check that we are in an inline context (inside an inline method or in inline code) */
12361236
def checkInInlineContext(what: String, pos: SrcPos)(using Context): Unit =
1237-
if !Inliner.inInlineMethod && !ctx.isInlineContext then
1237+
if !Inlines.inInlineMethod && !ctx.isInlineContext then
12381238
report.error(em"$what can only be used in an inline method", pos)
12391239

12401240
/** Check arguments of compiler-defined annotations */

0 commit comments

Comments
 (0)