Skip to content

Commit 4cd165f

Browse files
committed
Avoid data copies
1 parent 00f0aeb commit 4cd165f

72 files changed

Lines changed: 300 additions & 347 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import scala.tools.asm.tree.*
1919
import tpd.*
2020
import dotty.tools.io.AbstractFile
2121
import dotty.tools.dotc.ast.Positioned
22-
import dotty.tools.dotc.util.NoSourcePosition
22+
import dotty.tools.dotc.util.{NoSourcePosition, SourceFile}
2323
import SymbolUtils.given
2424
import dotty.tools.backend.ScalaPrimitives
2525
import dotty.tools.dotc.interfaces.CompilerCallback
26-
import opt.{OptimizerUtils, CallGraph}
26+
import opt.{CallGraph, OptimizerUtils}
2727

2828
class CodeGen(val primitives: ScalaPrimitives,
2929
val callGraph: Option[CallGraph], val bTypeLoader: BTypeLoader, val knownBTypes: KnownBTypes,
@@ -44,7 +44,6 @@ class CodeGen(val primitives: ScalaPrimitives,
4444
def genClassDef(cd: TypeDef): Unit =
4545
try
4646
val sym = cd.symbol
47-
val sourceFile = ctx.compilationUnit.source.file
4847
val mainClassNode = genClass(cd)
4948
val mirrorClassNode =
5049
if !sym.isTopLevelModuleClass then null
@@ -113,7 +112,7 @@ class CodeGen(val primitives: ScalaPrimitives,
113112
clsFile => {
114113
val className = cls.name.replace('/', '.')
115114
ctx.compilerCallback match
116-
case cb: CompilerCallback => cb.onClassGenerated(sourceFile, clsFile, className)
115+
case cb: CompilerCallback => cb.onClassGenerated(SourceFile.toInterface(sourceFile), clsFile, className)
117116
case null => ()
118117

119118
ctx.withIncCallback: cb =>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Contexts.*
99
import dotty.tools.backend.ScalaPrimitives
1010
import dotty.tools.backend.jvm.opt.{BCodeRepository, BTypesFromClassfile, CallGraph, OptimizerKnownBTypes, OptimizerUtils}
1111
import dotty.tools.dotc.core.Decorators.em
12+
import dotty.tools.dotc.util.SourceFile
1213
import dotty.tools.io.*
1314

1415
import scala.collection.mutable
@@ -137,7 +138,7 @@ class GenBCode extends Phase { self =>
137138
protected def run(using Context): Unit =
138139
codeGen.genUnit()
139140
ctx.compilerCallback match
140-
case cb: CompilerCallback => cb.onSourceCompiled(ctx.source)
141+
case cb: CompilerCallback => cb.onSourceCompiled(SourceFile.toInterface(ctx.source))
141142
case null => ()
142143

143144
override def runOn(units: List[CompilationUnit])(using ctx:Context): List[CompilationUnit] = {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class PostProcessor(bTypeLoader: BTypeLoader, bTypes: KnownBTypes)(using Context
9090
if (name < dupName) ((clsPos, dupPos), (name, dupName))
9191
else ((dupPos, clsPos), (dupName, name))
9292
val locationAddendum =
93-
if pos1.source.path == pos2.source.path then ""
93+
if pos1.source.file.path == pos2.source.file.path then ""
9494
else s" (defined in ${pos2.source.file.name})"
9595
def nicify(name: String): String = name.replace('/', '.')
9696
if name1 == name2 then

compiler/src/dotty/tools/backend/jvm/analysis/AliasingAnalyzer.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,7 @@ object AliasSet {
512512
else {
513513
var newLength = set.length
514514
while (index >= newLength) newLength *= 2
515-
val newSet = new Array[Long](newLength)
516-
Array.copy(set, 0, newSet, 0, set.length)
517-
newSet
515+
Array.copyOf(set, newLength)
518516
}
519517
}
520518

compiler/src/dotty/tools/backend/jvm/opt/LocalOpt.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,7 @@ object LocalOptImpls {
693693
var top = -1
694694
def enq(i: Int): Unit = {
695695
if (top == queue.length - 1) {
696-
val nq = new Array[Int](queue.length * 2)
697-
Array.copy(queue, 0, nq, 0, queue.length)
698-
queue = nq
696+
queue = Array.copyOf(queue, queue.length * 2)
699697
}
700698
top += 1
701699
queue(top) = i

compiler/src/dotty/tools/backend/jvm/opt/MethodMax.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ object MethodMax {
5151

5252
def enq(i: Int): Unit = {
5353
if (top == queue.length - 1) {
54-
val nq = new Array[Int](queue.length * 2)
55-
Array.copy(queue, 0, nq, 0, queue.length)
56-
queue = nq
54+
queue = Array.copyOf(queue, queue.length * 2)
5755
}
5856
top += 1
5957
queue(top) = i

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@ import Contexts.*
66
import SymDenotations.ClassDenotation
77
import Symbols.*
88
import Comments.Comment
9-
import util.{FreshNameCreator, SourceFile, NoSource}
9+
import util.{FreshNameCreator, NoSource, SourceFile}
1010
import util.Spans.Span
1111
import ast.{tpd, untpd}
1212
import tpd.{Tree, TreeTraverser}
13-
import ast.Trees.{Import, Ident}
13+
import ast.Trees.{Ident, Import}
1414
import typer.Nullables
1515
import core.Decorators.*
16-
import config.{SourceVersion, Feature}
16+
import config.{Feature, SourceVersion}
17+
1718
import scala.annotation.internal.sharable
1819
import scala.util.control.NoStackTrace
1920
import transform.MacroAnnotations.isMacroAnnotation
2021

22+
import scala.io.Codec
23+
2124
class CompilationUnit protected (val source: SourceFile, val info: CompilationUnitInfo | Null) {
2225

2326
override def toString: String = source.toString
@@ -146,7 +149,7 @@ object CompilationUnit {
146149
def apply(clsd: ClassDenotation, unpickled: Tree, forceTrees: Boolean)(using Context): CompilationUnit =
147150
val compilationUnitInfo = clsd.symbol.compilationUnitInfo.nn
148151
val file = compilationUnitInfo.associatedFile
149-
apply(SourceFile(file, Array.emptyCharArray), unpickled, forceTrees, compilationUnitInfo)
152+
apply(SourceFile(file, Codec(ctx.settings.encoding.value)), unpickled, forceTrees, compilationUnitInfo)
150153

151154
/** Make a compilation unit, given picked bytes and unpickled tree */
152155
def apply(source: SourceFile, unpickled: Tree, forceTrees: Boolean, info: CompilationUnitInfo)(using Context): CompilationUnit = {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ object Trees {
899899
override def isTerm: Boolean = name.isTermName
900900

901901
override def nameSpan(using Context): Span =
902-
if span.exists then Span(span.start, span.start + name.toString.length) else span
902+
if span.exists then Span(span.start, span.start + name.length) else span
903903
}
904904

905905
/** tree_1 | ... | tree_n */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
13931393

13941394
// convert a numeric with a toXXX method
13951395
def primitiveConversion(tree: Tree, numericCls: Symbol)(using Context): Tree =
1396-
val mname = "to".concat(numericCls.name)
1396+
val mname = termName("to" + numericCls.name)
13971397
val conversion = tree.tpe.member(mname)
13981398
if conversion.symbol.exists then
13991399
tree.select(conversion.symbol.termRef).ensureApplied

compiler/src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ object Contexts {
784784
@tailrec
785785
def originalCompilationUnit: CompilationUnit =
786786
val cu = ctx.compilationUnit
787-
if cu.source.name == SyntaxHighlighting.VirtualSourceName then ctx.outer.originalCompilationUnit
787+
if cu.source.file.name == SyntaxHighlighting.VirtualSourceName then ctx.outer.originalCompilationUnit
788788
else cu
789789

790790
extension (c: Context)
@@ -1093,15 +1093,8 @@ object Contexts {
10931093
private[Contexts] val comparers = new mutable.ArrayBuffer[TypeComparer]
10941094
private[Contexts] var comparersInUse: Int = 0
10951095

1096-
private var charArray = new Array[Char](256)
1097-
10981096
private[dotc] var wConfCache: (List[String], WConf) = uninitialized
10991097

1100-
def sharedCharArray(len: Int): Array[Char] =
1101-
while len > charArray.length do
1102-
charArray = new Array[Char](charArray.length * 2)
1103-
charArray
1104-
11051098
def reset(): Unit =
11061099
uniques.clear()
11071100
uniqueAppliedTypes.clear()

0 commit comments

Comments
 (0)