Skip to content

Commit 52c46d8

Browse files
committed
Move PrepareInlineable to inlines package
1 parent 4cab4f1 commit 52c46d8

File tree

6 files changed

+44
-42
lines changed

6 files changed

+44
-42
lines changed

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

+39-39
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,45 @@ object Inliner:
9494
false
9595
}
9696
end isElideableExpr
97+
98+
// InlineCopier is a more fault-tolerant copier that does not cause errors when
99+
// function types in applications are undefined. This is necessary since we copy at
100+
// the same time as establishing the proper context in which the copied tree should
101+
// be evaluated. This matters for opaque types, see neg/i14653.scala.
102+
private class InlineCopier() extends TypedTreeCopier:
103+
override def Apply(tree: Tree)(fun: Tree, args: List[Tree])(using Context): Apply =
104+
if fun.tpe.widen.exists then super.Apply(tree)(fun, args)
105+
else untpd.cpy.Apply(tree)(fun, args).withTypeUnchecked(tree.tpe)
106+
107+
// InlinerMap is a TreeTypeMap with special treatment for inlined arguments:
108+
// They are generally left alone (not mapped further, and if they wrap a type
109+
// the type Inlined wrapper gets dropped
110+
private class InlinerMap(
111+
typeMap: Type => Type,
112+
treeMap: Tree => Tree,
113+
oldOwners: List[Symbol],
114+
newOwners: List[Symbol],
115+
substFrom: List[Symbol],
116+
substTo: List[Symbol])(using Context)
117+
extends TreeTypeMap(
118+
typeMap, treeMap, oldOwners, newOwners, substFrom, substTo, InlineCopier()):
119+
120+
override def copy(
121+
typeMap: Type => Type,
122+
treeMap: Tree => Tree,
123+
oldOwners: List[Symbol],
124+
newOwners: List[Symbol],
125+
substFrom: List[Symbol],
126+
substTo: List[Symbol])(using Context) =
127+
new InlinerMap(typeMap, treeMap, oldOwners, newOwners, substFrom, substTo)
128+
129+
override def transformInlined(tree: Inlined)(using Context) =
130+
if tree.call.isEmpty then
131+
tree.expansion match
132+
case expansion: TypeTree => expansion
133+
case _ => tree
134+
else super.transformInlined(tree)
135+
end InlinerMap
97136
end Inliner
98137

99138
/** Produces an inlined version of `call` via its `inlined` method.
@@ -496,45 +535,6 @@ class Inliner(val call: tpd.Tree)(using Context):
496535
def inlinedFromOutside(tree: Tree)(span: Span): Tree =
497536
Inlined(EmptyTree, Nil, tree)(using ctx.withSource(inlinedMethod.topLevelClass.source)).withSpan(span)
498537

499-
// InlineCopier is a more fault-tolerant copier that does not cause errors when
500-
// function types in applications are undefined. This is necessary since we copy at
501-
// the same time as establishing the proper context in which the copied tree should
502-
// be evaluated. This matters for opaque types, see neg/i14653.scala.
503-
class InlineCopier() extends TypedTreeCopier:
504-
override def Apply(tree: Tree)(fun: Tree, args: List[Tree])(using Context): Apply =
505-
if fun.tpe.widen.exists then super.Apply(tree)(fun, args)
506-
else untpd.cpy.Apply(tree)(fun, args).withTypeUnchecked(tree.tpe)
507-
508-
// InlinerMap is a TreeTypeMap with special treatment for inlined arguments:
509-
// They are generally left alone (not mapped further, and if they wrap a type
510-
// the type Inlined wrapper gets dropped
511-
class InlinerMap(
512-
typeMap: Type => Type,
513-
treeMap: Tree => Tree,
514-
oldOwners: List[Symbol],
515-
newOwners: List[Symbol],
516-
substFrom: List[Symbol],
517-
substTo: List[Symbol])(using Context)
518-
extends TreeTypeMap(
519-
typeMap, treeMap, oldOwners, newOwners, substFrom, substTo, InlineCopier()):
520-
521-
override def copy(
522-
typeMap: Type => Type,
523-
treeMap: Tree => Tree,
524-
oldOwners: List[Symbol],
525-
newOwners: List[Symbol],
526-
substFrom: List[Symbol],
527-
substTo: List[Symbol])(using Context) =
528-
new InlinerMap(typeMap, treeMap, oldOwners, newOwners, substFrom, substTo)
529-
530-
override def transformInlined(tree: Inlined)(using Context) =
531-
if tree.call.isEmpty then
532-
tree.expansion match
533-
case expansion: TypeTree => expansion
534-
case _ => tree
535-
else super.transformInlined(tree)
536-
end InlinerMap
537-
538538
// A tree type map to prepare the inlined body for typechecked.
539539
// The translation maps references to `this` and parameters to
540540
// corresponding arguments or proxies on the type and term level. It also changes

compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala renamed to compiler/src/dotty/tools/dotc/inlines/PrepareInlineable.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dotty.tools
22
package dotc
3-
package typer
3+
package inlines
44

55
import dotty.tools.dotc.ast.{Trees, tpd, untpd}
66
import Trees._

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import tpd.tpes
1717
import Variances.alwaysInvariant
1818
import config.{Config, Feature}
1919
import config.Printers.typr
20-
import inlines.Inlines
20+
import inlines.{Inlines, PrepareInlineable}
2121
import parsing.JavaParsers.JavaParser
2222
import parsing.Parsers.Parser
2323
import Annotations._

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

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import dotty.tools.dotc.core.StagingContext._
1515
import dotty.tools.dotc.core.StdNames._
1616
import dotty.tools.dotc.core.Symbols._
1717
import dotty.tools.dotc.core.Types._
18+
import dotty.tools.dotc.inlines.PrepareInlineable
1819
import dotty.tools.dotc.transform.SymUtils._
1920
import dotty.tools.dotc.typer.Implicits._
2021
import dotty.tools.dotc.typer.Inferencing._

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import Inferencing._
2929
import Dynamic.isDynamicExpansion
3030
import EtaExpansion.etaExpand
3131
import TypeComparer.CompareResult
32-
import inlines.Inlines
32+
import inlines.{Inlines, PrepareInlineable}
3333
import util.Spans._
3434
import util.common._
3535
import util.{Property, SimpleIdentityMap, SrcPos}

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

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Symbols._
99
import ImportInfo.withRootImports
1010
import parsing.{Parser => ParserPhase}
1111
import config.Printers.typr
12+
import inlines.PrepareInlineable
1213
import util.Stats._
1314

1415
/**

0 commit comments

Comments
 (0)