File tree 6 files changed +19
-7
lines changed
compiler/src/dotty/tools/dotc
6 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -56,9 +56,6 @@ class CompilationUnit protected (val source: SourceFile) {
56
56
*/
57
57
var needsQuotePickling : Boolean = false
58
58
59
- /** A structure containing a temporary map for generating inline accessors */
60
- val inlineAccessors : InlineAccessors = new InlineAccessors
61
-
62
59
var suspended : Boolean = false
63
60
var suspendedAtInliningPhase : Boolean = false
64
61
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import SymUtils._
15
15
import NameKinds ._
16
16
import dotty .tools .dotc .ast .tpd
17
17
import typer .Implicits .SearchFailureType
18
+ import typer .PrepareInlineable
18
19
19
20
import scala .collection .mutable
20
21
import dotty .tools .dotc .core .Annotations ._
Original file line number Diff line number Diff line change @@ -26,6 +26,19 @@ import dotty.tools.dotc.transform.TreeMapWithStages._
26
26
object PrepareInlineable {
27
27
import tpd ._
28
28
29
+ private val InlineAccessorsKey = new Property .Key [InlineAccessors ]
30
+
31
+ def initContext (ctx : Context ): Context =
32
+ ctx.fresh.setProperty(InlineAccessorsKey , new InlineAccessors )
33
+
34
+ def makeInlineable (tree : Tree )(using Context ): Tree =
35
+ ctx.property(InlineAccessorsKey ).get.makeInlineable(tree)
36
+
37
+ def addAccessorDefs (cls : Symbol , body : List [Tree ])(using Context ): List [Tree ] =
38
+ ctx.property(InlineAccessorsKey ) match
39
+ case Some (inlineAccessors) => inlineAccessors.addAccessorDefs(cls, body)
40
+ case _ => body
41
+
29
42
class InlineAccessors extends AccessProxies {
30
43
31
44
/** If an inline accessor name wraps a unique inline name, this is taken as indication
@@ -251,7 +264,7 @@ object PrepareInlineable {
251
264
if inlined.isInlineMethod then
252
265
inlinedBody = dropInlineIfError(inlined,
253
266
checkInlineMethod(inlined,
254
- ctx.compilationUnit.inlineAccessors .makeInlineable(inlinedBody)))
267
+ PrepareInlineable .makeInlineable(inlinedBody)))
255
268
inlining.println(i " Body to inline for $inlined: $inlinedBody" )
256
269
inlinedBody
257
270
})
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ trait QuotesAndSplices {
70
70
}
71
71
72
72
private def makeInlineable (tree : Tree )(using Context ): Tree =
73
- ctx.compilationUnit.inlineAccessors .makeInlineable(tree)
73
+ PrepareInlineable .makeInlineable(tree)
74
74
75
75
/** Translate `${ t: Expr[T] }` into expression `t.splice` while tracking the quotation level in the context */
76
76
def typedSplice (tree : untpd.Splice , pt : Type )(using Context ): Tree = {
Original file line number Diff line number Diff line change @@ -2461,7 +2461,7 @@ class Typer extends Namer
2461
2461
// 4. Polymorphic type defs override nothing.
2462
2462
2463
2463
protected def addAccessorDefs (cls : Symbol , body : List [Tree ])(using Context ): List [Tree ] =
2464
- ctx.compilationUnit.inlineAccessors .addAccessorDefs(cls, body)
2464
+ PrepareInlineable .addAccessorDefs(cls, body)
2465
2465
2466
2466
/** If this is a real class, make sure its first parent is a
2467
2467
* constructor call. Cannot simply use a type. Overridden in ReTyper.
Original file line number Diff line number Diff line change @@ -81,7 +81,8 @@ class TyperPhase(addRootImports: Boolean = true) extends Phase {
81
81
override def runOn (units : List [CompilationUnit ])(using Context ): List [CompilationUnit ] =
82
82
val unitContexts =
83
83
for unit <- units yield
84
- val newCtx = ctx.fresh.setPhase(this .start).setCompilationUnit(unit)
84
+ val newCtx0 = ctx.fresh.setPhase(this .start).setCompilationUnit(unit)
85
+ val newCtx = PrepareInlineable .initContext(newCtx0)
85
86
report.inform(s " typing ${unit.source}" )
86
87
if (addRootImports)
87
88
newCtx.withRootImports
You can’t perform that action at this time.
0 commit comments