Skip to content

Commit c59e7aa

Browse files
committed
Simplify tracking of inlined positions
This makes the workaround for the missing JSR-45 support slightly less precise.
1 parent 767e24e commit c59e7aa

File tree

5 files changed

+26
-38
lines changed

5 files changed

+26
-38
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,11 +1242,9 @@ object Trees {
12421242
protected def skipTransform(tree: Tree)(using Context): Boolean = false
12431243

12441244
/** For untyped trees, this is just the identity.
1245-
* For typed trees, a context derived form `ctx` that records `call` as the
1246-
* innermost enclosing call for which the inlined version is currently
1247-
* processed.
1245+
* For typed trees, this record the position of an enclosing inlined positions
12481246
*/
1249-
protected def inlineContext(call: Tree)(using Context): Context = ctx
1247+
protected def inlineContext(pos: SrcPos)(using Context): Context = ctx
12501248

12511249
abstract class TreeMap(val cpy: TreeCopier = inst.cpy) { self =>
12521250
def transform(tree: Tree)(using Context): Tree = {

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import typer.ProtoTypes
77
import transform.SymUtils._
88
import transform.TypeUtils._
99
import core._
10-
import util.Spans._, util.SourcePosition, Types._, Contexts._, Constants._, Names._, Flags._, NameOps._
10+
import util.Spans._, util.SrcPos, Types._, Contexts._, Constants._, Names._, Flags._, NameOps._
1111
import Symbols._, StdNames._, Annotations._, Trees._, Symbols._
1212
import Decorators._, DenotTransformers._
1313
import collection.{immutable, mutable}
@@ -1232,37 +1232,27 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
12321232
}
12331233

12341234
/** A key to be used in a context property that tracks enclosing inlined calls */
1235-
private val InlinedCalls = Property.Key[List[SourcePosition]]()
1235+
private val InlinedCalls = Property.Key[List[SrcPos]]()
12361236

12371237
/** A key to be used in a context property that tracks the number of inlined trees */
12381238
private val InlinedTrees = Property.Key[Counter]()
12391239
final class Counter {
12401240
var count: Int = 0
12411241
}
12421242

1243-
/** Record an enclosing inlined call.
1244-
* EmptyTree calls (for parameters) cancel the next-enclosing call in the list instead of being added to it.
1245-
* We assume parameters are never nested inside parameters.
1246-
*/
1247-
override def inlineContext(call: Tree)(using Context): Context = {
1243+
/** Record an enclosing inlined positions. */
1244+
override def inlineContext(pos: SrcPos)(using Context): Context = {
12481245
// We assume enclosingInlineds is already normalized, and only process the new call with the head.
12491246
val oldIC = enclosingInlineds
1250-
1251-
val newIC =
1252-
if call.isEmpty then
1253-
oldIC match
1254-
case t1 :: ts2 => ts2
1255-
case _ => oldIC
1256-
else
1257-
call.sourcePos :: oldIC
1247+
val newIC = pos :: oldIC
12581248

12591249
val ctx1 = ctx.fresh.setProperty(InlinedCalls, newIC)
12601250
if oldIC.isEmpty then ctx1.setProperty(InlinedTrees, new Counter) else ctx1
12611251
}
12621252

12631253
/** All enclosing calls that are currently inlined, from innermost to outermost.
12641254
*/
1265-
def enclosingInlineds(using Context): List[SourcePosition] =
1255+
def enclosingInlineds(using Context): List[SrcPos] =
12661256
ctx.property(InlinedCalls).getOrElse(Nil)
12671257

12681258
/** Record inlined trees */

compiler/src/dotty/tools/dotc/report.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ object report:
115115
if (ctx.settings.Ydebug.value) warning(msg, pos)
116116

117117
private def addInlineds(pos: SrcPos)(using Context): SourcePosition =
118-
def recur(pos: SourcePosition, inlineds: List[SourcePosition]): SourcePosition = inlineds match
119-
case inlined :: inlineds1 => pos.withOuter(recur(inlined.sourcePos, inlineds1))
118+
def recur(pos: SourcePosition, inlineds: List[SrcPos]): SourcePosition = inlineds match
119+
case inlined :: inlineds1 => pos.sourcePos.withOuter(recur(inlined.sourcePos, inlineds1))
120120
case Nil => pos
121121
recur(pos.sourcePos, tpd.enclosingInlineds)
122122

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
14311431
if suspendable then
14321432
ctx.compilationUnit.suspend() // this throws a SuspendException
14331433

1434-
val evaluatedSplice = inContext(quoted.MacroExpansion.context(inlinedFrom)) {
1434+
val evaluatedSplice = inContext(quoted.MacroExpansion.context(inlinedFrom.sourcePos)) {
14351435
Splicer.splice(body, inlinedFrom, MacroClassLoader.fromContext)
14361436
}
14371437
val inlinedNormailizer = new TreeMap {

tests/run/i4947b.check

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ main1: Test$.main(Test_2.scala:4)
44
main2: Test$.main(Test_2.scala:5)
55
track: Test$.main(Test_2.scala:7)
66
track: Test$.main(Test_2.scala:7)
7-
track: Test$.main(Test_2.scala:8)
8-
track: Test$.main(Test_2.scala:8)
7+
track: Test$.main(Test_2.scala:7)
8+
track: Test$.main(Test_2.scala:7)
99
main3: Test$.main(Test_2.scala:9)
1010
main4: Test$.main(Test_2.scala:10)
1111
track (i = 0): Test$.main(Test_2.scala:13)
@@ -15,22 +15,22 @@ track: Test$.main(Test_2.scala:13)
1515
fact: Test$.main(Test_2.scala:13)
1616
track (i = 2): Test$.main(Test_2.scala:14)
1717
track (i = 2): Test$.main(Test_2.scala:14)
18-
track: Test$.main(Test_2.scala:14)
19-
track: Test$.main(Test_2.scala:14)
20-
fact: Test$.main(Test_2.scala:14)
18+
track: Test$.main(Test_2.scala:13)
19+
track: Test$.main(Test_2.scala:13)
20+
fact: Test$.main(Test_2.scala:13)
2121
main1 (i = -1): Test$.main(Test_2.scala:15)
2222
main2 (i = -1): Test$.main(Test_2.scala:16)
23-
track (i = 1): Test$.main(Test_2.scala:14)
24-
track (i = 1): Test$.main(Test_2.scala:14)
25-
track: Test$.main(Test_2.scala:14)
26-
track: Test$.main(Test_2.scala:14)
27-
fact: Test$.main(Test_2.scala:14)
23+
track (i = 1): Test$.main(Test_2.scala:13)
24+
track (i = 1): Test$.main(Test_2.scala:13)
25+
track: Test$.main(Test_2.scala:13)
26+
track: Test$.main(Test_2.scala:13)
27+
fact: Test$.main(Test_2.scala:13)
2828
main1 (i = -1): Test$.main(Test_2.scala:15)
2929
main2 (i = -1): Test$.main(Test_2.scala:16)
30-
track (i = 0): Test$.main(Test_2.scala:14)
31-
track (i = 0): Test$.main(Test_2.scala:14)
32-
track: Test$.main(Test_2.scala:14)
33-
track: Test$.main(Test_2.scala:14)
34-
fact: Test$.main(Test_2.scala:14)
30+
track (i = 0): Test$.main(Test_2.scala:13)
31+
track (i = 0): Test$.main(Test_2.scala:13)
32+
track: Test$.main(Test_2.scala:13)
33+
track: Test$.main(Test_2.scala:13)
34+
fact: Test$.main(Test_2.scala:13)
3535
main1 (i = -1): Test$.main(Test_2.scala:15)
3636
main2 (i = -1): Test$.main(Test_2.scala:16)

0 commit comments

Comments
 (0)