Skip to content

Commit fc45300

Browse files
oderskynicolasstucki
authored andcommitted
Avoid creating source positions in backend interface
1 parent 1a942ea commit fc45300

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import Types._
2121
import Symbols._
2222
import Phases._
2323

24-
import dotty.tools.dotc.util.{SourcePosition, NoSourcePosition}
24+
import dotty.tools.dotc.util
25+
import dotty.tools.dotc.util.Spans
2526
import Decorators._
2627
import tpd._
2728

@@ -41,7 +42,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
4142
type CompilationUnit = dotc.CompilationUnit
4243
type Constant = Constants.Constant
4344
type Literal = tpd.Literal
44-
type Position = SourcePosition
45+
type Position = Spans.Span
4546
type Name = Names.Name
4647
type ClassDef = tpd.TypeDef
4748
type TypeDef = tpd.TypeDef
@@ -77,7 +78,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
7778
type Closure = tpd.Closure
7879

7980
val NoSymbol: Symbol = Symbols.NoSymbol
80-
val NoPosition: Position = NoSourcePosition
81+
val NoPosition: Position = Spans.NoSpan
8182
val EmptyTree: Tree = tpd.EmptyTree
8283

8384

@@ -383,12 +384,14 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
383384
def debuglog(msg: => String): Unit = ctx.debuglog(msg)
384385
def informProgress(msg: String): Unit = ctx.informProgress(msg)
385386
def log(msg: => String): Unit = ctx.log(msg)
386-
def error(pos: SourcePosition, msg: String): Unit = ctx.error(msg, pos)
387-
def warning(pos: SourcePosition, msg: String): Unit = ctx.warning(msg, pos)
387+
def error(pos: Position, msg: String): Unit = ctx.error(msg, sourcePos(pos))
388+
def warning(pos: Position, msg: String): Unit = ctx.warning(msg, sourcePos(pos))
388389
def abort(msg: String): Nothing = {
389390
ctx.error(msg)
390391
throw new RuntimeException(msg)
391392
}
393+
def sourcePos(pos: Position)(implicit ctx: Context): util.SourcePosition =
394+
ctx.source.atSpan(pos)
392395

393396
def emitAsmp: Option[String] = None
394397

@@ -562,7 +565,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
562565

563566
implicit def positionHelper(a: Position): PositionHelper = new PositionHelper {
564567
def isDefined: Boolean = a.exists
565-
def line: Int = a.line + 1
568+
def line: Int = sourcePos(a).line + 1
566569
def finalPosition: Position = a
567570
}
568571

@@ -586,7 +589,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
586589
implicit def treeHelper(a: Tree): TreeHelper = new TreeHelper {
587590
def symbol: Symbol = a.symbol
588591

589-
def pos: Position = a.sourcePos
592+
def pos: Position = a.span
590593

591594
def isEmpty: Boolean = a.isEmpty
592595

@@ -800,15 +803,15 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
800803

801804

802805
def freshLocal(cunit: CompilationUnit, name: String, tpe: Type, pos: Position, flags: Flags): Symbol = {
803-
ctx.newSymbol(sym, name.toTermName, termFlagSet(flags), tpe, NoSymbol, pos.span)
806+
ctx.newSymbol(sym, name.toTermName, termFlagSet(flags), tpe, NoSymbol, pos)
804807
}
805808

806809
def getter(clz: Symbol): Symbol = decorateSymbol(sym).getter
807810
def setter(clz: Symbol): Symbol = decorateSymbol(sym).setter
808811

809812
def moduleSuffix: String = "" // todo: validate that names already have $ suffix
810813
def outputDirectory: AbstractFile = DottyBackendInterface.this.outputDirectory
811-
def pos: Position = sym.sourcePos
814+
def pos: Position = sym.span
812815

813816
def throwsAnnotations: List[Symbol] = Nil
814817

@@ -1104,7 +1107,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
11041107
def _1: Type = field.tpe match {
11051108
case JavaArrayType(elem) => elem
11061109
case _ =>
1107-
error(field.sourcePos, s"JavaSeqArray with type ${field.tpe} reached backend: $field")
1110+
error(field.span, s"JavaSeqArray with type ${field.tpe} reached backend: $field")
11081111
UnspecifiedErrorType
11091112
}
11101113
def _2: List[Tree] = field.elems

0 commit comments

Comments
 (0)