Skip to content

Commit b8d1e41

Browse files
authored
Merge pull request #3241 from dotty-staging/private-this-var
Replace `private var` by `private[this] var` where possible
2 parents 7ca9ac3 + 444a189 commit b8d1e41

File tree

76 files changed

+179
-179
lines changed

Some content is hidden

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

76 files changed

+179
-179
lines changed

compiler/sjs/backend/sjs/JSCodeGen.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class JSCodeGen()(implicit ctx: Context) {
7272
/* See genSuperCall()
7373
* TODO Can we avoid this unscoped var?
7474
*/
75-
private var isModuleInitialized: Boolean = false
75+
private[this] var isModuleInitialized: Boolean = false
7676

7777
private def currentClassType = encodeClassType(currentClassSym)
7878

compiler/sjs/backend/sjs/ScopedVar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import language.implicitConversions
55
class ScopedVar[A](init: A) {
66
import ScopedVar.Assignment
77

8-
private var value = init
8+
private[this] var value = init
99

1010
def this()(implicit ev: Null <:< A) = this(ev(null))
1111

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
7777

7878
// class BCodePhase() {
7979

80-
private var bytecodeWriter : BytecodeWriter = null
81-
private var mirrorCodeGen : JMirrorBuilder = null
82-
private var beanInfoCodeGen : JBeanInfoBuilder = null
80+
private[this] var bytecodeWriter : BytecodeWriter = null
81+
private[this] var mirrorCodeGen : JMirrorBuilder = null
82+
private[this] var beanInfoCodeGen : JBeanInfoBuilder = null
8383

8484
/* ---------------- q1 ---------------- */
8585

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import reporting.Reporter
1010
*/
1111
object Bench extends Driver {
1212

13-
@sharable private var numRuns = 1
13+
@sharable private[this] var numRuns = 1
1414

1515
private def ntimes(n: Int)(op: => Reporter): Reporter =
1616
(emptyReporter /: (0 until n)) ((_, _) => op)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ object Trees {
3333
/** Property key for trees with documentation strings attached */
3434
val DocComment = new Property.Key[Comment]
3535

36-
@sharable private var nextId = 0 // for debugging
36+
@sharable private[this] var nextId = 0 // for debugging
3737

3838
type LazyTree = AnyRef /* really: Tree | Lazy[Tree] */
3939
type LazyTreeList = AnyRef /* really: List[Tree] | Lazy[List[Tree]] */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
209209
*/
210210
abstract class DerivedTypeTree extends TypeTree {
211211

212-
private var myWatched: Tree = EmptyTree
212+
private[this] var myWatched: Tree = EmptyTree
213213

214214
/** The watched tree; used only for printing */
215215
def watched: Tree = myWatched

compiler/src/dotty/tools/dotc/config/JavaPlatform.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import transform.ExplicitOuter, transform.SymUtils._
1111

1212
class JavaPlatform extends Platform {
1313

14-
private var currentClassPath: Option[ClassPath] = None
14+
private[this] var currentClassPath: Option[ClassPath] = None
1515

1616
def classPath(implicit ctx: Context): ClassPath = {
1717
if (currentClassPath.isEmpty)

compiler/src/dotty/tools/dotc/config/OutputDirs.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import io._
1212
*/
1313
class OutputDirs {
1414
/** Pairs of source directory - destination directory. */
15-
private var outputDirs: List[(AbstractFile, AbstractFile)] = Nil
15+
private[this] var outputDirs: List[(AbstractFile, AbstractFile)] = Nil
1616

1717
/** If this is not None, the output location where all
1818
* classes should go.
1919
*/
20-
private var singleOutDir: Option[AbstractFile] = None
20+
private[this] var singleOutDir: Option[AbstractFile] = None
2121

2222
/** Add a destination directory for sources found under srcdir.
2323
* Both directories should exits.

compiler/src/dotty/tools/dotc/config/Settings.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ object Settings {
2525
val DirectoryTag = ClassTag(classOf[Directory])
2626

2727
class SettingsState(initialValues: Seq[Any]) {
28-
private var values = ArrayBuffer(initialValues: _*)
29-
private var _wasRead: Boolean = false
28+
private[this] var values = ArrayBuffer(initialValues: _*)
29+
private[this] var _wasRead: Boolean = false
3030

3131
override def toString = s"SettingsState(values: ${values.toList})"
3232

@@ -68,7 +68,7 @@ object Settings {
6868
depends: List[(Setting[_], Any)] = Nil,
6969
propertyClass: Option[Class[_]] = None)(private[Settings] val idx: Int) {
7070

71-
private var changed: Boolean = false
71+
private[this] var changed: Boolean = false
7272

7373
def withAbbreviation(abbrv: String): Setting[T] =
7474
copy(aliases = aliases :+ abbrv)(idx)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ object Annotations {
3838
override def symbol(implicit ctx: Context): Symbol
3939
def complete(implicit ctx: Context): Tree
4040

41-
private var myTree: Tree = null
41+
private[this] var myTree: Tree = null
4242
def tree(implicit ctx: Context) = {
4343
if (myTree == null) myTree = complete(ctx)
4444
myTree
@@ -62,8 +62,8 @@ object Annotations {
6262
}
6363

6464
case class LazyBodyAnnotation(private var bodyExpr: Context => Tree) extends BodyAnnotation {
65-
private var evaluated = false
66-
private var myBody: Tree = _
65+
private[this] var evaluated = false
66+
private[this] var myBody: Tree = _
6767
def tree(implicit ctx: Context) = {
6868
if (evaluated) assert(myBody != null)
6969
else {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ trait ConstraintHandling {
3030
val state: TyperState
3131
import state.constraint
3232

33-
private var addConstraintInvocations = 0
33+
private[this] var addConstraintInvocations = 0
3434

3535
/** If the constraint is frozen we cannot add new bounds to the constraint. */
3636
protected var frozenConstraint = false

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import Contexts._
55
import config.Printers.typr
66

77
trait ConstraintRunInfo { self: RunInfo =>
8-
private var maxSize = 0
9-
private var maxConstraint: Constraint = _
8+
private[this] var maxSize = 0
9+
private[this] var maxConstraint: Constraint = _
1010
def recordConstraintSize(c: Constraint, size: Int) =
1111
if (size > maxSize) {
1212
maxSize = size

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,12 @@ object Contexts {
160160
/** An optional diagostics buffer than is used by some checking code
161161
* to provide more information in the buffer if it exists.
162162
*/
163-
private var _diagnostics: Option[StringBuilder] = _
163+
private[this] var _diagnostics: Option[StringBuilder] = _
164164
protected def diagnostics_=(diagnostics: Option[StringBuilder]) = _diagnostics = diagnostics
165165
def diagnostics: Option[StringBuilder] = _diagnostics
166166

167167
/** The current bounds in force for type parameters appearing in a GADT */
168-
private var _gadt: GADTMap = _
168+
private[this] var _gadt: GADTMap = _
169169
protected def gadt_=(gadt: GADTMap) = _gadt = gadt
170170
def gadt: GADTMap = _gadt
171171

@@ -175,14 +175,14 @@ object Contexts {
175175
def freshNames: FreshNameCreator = _freshNames
176176

177177
/** A map in which more contextual properties can be stored */
178-
private var _moreProperties: Map[Key[Any], Any] = _
178+
private[this] var _moreProperties: Map[Key[Any], Any] = _
179179
protected def moreProperties_=(moreProperties: Map[Key[Any], Any]) = _moreProperties = moreProperties
180180
def moreProperties: Map[Key[Any], Any] = _moreProperties
181181

182182
def property[T](key: Key[T]): Option[T] =
183183
moreProperties.get(key).asInstanceOf[Option[T]]
184184

185-
private var _typeComparer: TypeComparer = _
185+
private[this] var _typeComparer: TypeComparer = _
186186
protected def typeComparer_=(typeComparer: TypeComparer) = _typeComparer = typeComparer
187187
def typeComparer: TypeComparer = {
188188
if (_typeComparer.ctx ne this)
@@ -224,7 +224,7 @@ object Contexts {
224224
}
225225

226226
/** The history of implicit searches that are currently active */
227-
private var _searchHistory: SearchHistory = null
227+
private[this] var _searchHistory: SearchHistory = null
228228
protected def searchHistory_= (searchHistory: SearchHistory) = _searchHistory = searchHistory
229229
def searchHistory: SearchHistory = _searchHistory
230230

@@ -233,8 +233,8 @@ object Contexts {
233233
* phasedCtxs is array that uses phaseId's as indexes,
234234
* contexts are created only on request and cached in this array
235235
*/
236-
private var phasedCtx: Context = _
237-
private var phasedCtxs: Array[Context] = _
236+
private[this] var phasedCtx: Context = _
237+
private[this] var phasedCtxs: Array[Context] = _
238238

239239
/** This context at given phase.
240240
* This method will always return a phase period equal to phaseId, thus will never return squashed phases
@@ -268,7 +268,7 @@ object Contexts {
268268
/** If -Ydebug is on, the top of the stack trace where this context
269269
* was created, otherwise `null`.
270270
*/
271-
private var creationTrace: Array[StackTraceElement] = _
271+
private[this] var creationTrace: Array[StackTraceElement] = _
272272
273273
private def setCreationTrace() =
274274
if (this.settings.YtraceContextCreation.value)
@@ -393,7 +393,7 @@ object Contexts {
393393

394394
/** A condensed context containing essential information of this but
395395
* no outer contexts except the initial context.
396-
private var _condensed: CondensedContext = null
396+
private[this] var _condensed: CondensedContext = null
397397
def condensed: CondensedContext = {
398398
if (_condensed eq outer.condensed)
399399
_condensed = base.initialCtx.fresh
@@ -557,7 +557,7 @@ object Contexts {
557557
val loaders = new SymbolLoaders
558558

559559
/** The platform, initialized by `initPlatform()`. */
560-
private var _platform: Platform = _
560+
private[this] var _platform: Platform = _
561561

562562
/** The platform */
563563
def platform: Platform = {
@@ -670,7 +670,7 @@ object Contexts {
670670
// Test that access is single threaded
671671

672672
/** The thread on which `checkSingleThreaded was invoked last */
673-
@sharable private var thread: Thread = null
673+
@sharable private[this] var thread: Thread = null
674674

675675
/** Check that we are on the same thread as before */
676676
def checkSingleThreaded() =
@@ -695,7 +695,7 @@ object Contexts {
695695
}
696696

697697
class GADTMap(initBounds: SimpleIdentityMap[Symbol, TypeBounds]) extends util.DotClass {
698-
private var myBounds = initBounds
698+
private[this] var myBounds = initBounds
699699
def setBounds(sym: Symbol, b: TypeBounds): Unit =
700700
myBounds = myBounds.updated(sym, b)
701701
def bounds = myBounds

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,8 +950,8 @@ class Definitions {
950950

951951
/** This class would also be obviated by the implicit function type design */
952952
class PerRun[T](generate: Context => T) {
953-
private var current: RunId = NoRunId
954-
private var cached: T = _
953+
private[this] var current: RunId = NoRunId
954+
private[this] var cached: T = _
955955
def apply()(implicit ctx: Context): T = {
956956
if (current != ctx.runId) {
957957
cached = generate(ctx)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,9 +1122,9 @@ object Denotations {
11221122
*/
11231123
def filterExcluded(excluded: FlagSet)(implicit ctx: Context): PreDenotation
11241124

1125-
private var cachedPrefix: Type = _
1126-
private var cachedAsSeenFrom: AsSeenFromResult = _
1127-
private var validAsSeenFrom: Period = Nowhere
1125+
private[this] var cachedPrefix: Type = _
1126+
private[this] var cachedAsSeenFrom: AsSeenFromResult = _
1127+
private[this] var validAsSeenFrom: Period = Nowhere
11281128
type AsSeenFromResult <: PreDenotation
11291129

11301130
/** The denotation with info(s) as seen from prefix type */

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ object Names {
189189
def underlying: TermName = unsupported("underlying")
190190

191191
@sharable // because of synchronized block in `and`
192-
private var derivedNames: AnyRef /* immutable.Map[NameInfo, DerivedName] | j.u.HashMap */ =
192+
private[this] var derivedNames: AnyRef /* immutable.Map[NameInfo, DerivedName] | j.u.HashMap */ =
193193
immutable.Map.empty[NameInfo, DerivedName]
194194

195195
private def getDerived(info: NameInfo): DerivedName /* | Null */= derivedNames match {
@@ -537,15 +537,15 @@ object Names {
537537

538538
/** The number of characters filled. */
539539
@sharable // because it's only mutated in synchronized block of termName
540-
private var nc = 0
540+
private[this] var nc = 0
541541

542542
/** Hashtable for finding term names quickly. */
543543
@sharable // because it's only mutated in synchronized block of termName
544-
private var table = new Array[SimpleName](InitialHashSize)
544+
private[this] var table = new Array[SimpleName](InitialHashSize)
545545

546546
/** The number of defined names. */
547547
@sharable // because it's only mutated in synchronized block of termName
548-
private var size = 1
548+
private[this] var size = 1
549549

550550
/** The hash of a name made of from characters cs[offset..offset+len-1]. */
551551
private def hashValue(cs: Array[Char], offset: Int, len: Int): Int =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
544544
upperMap.foreachBinding((_, paramss) => paramss.foreach(_.foreach(checkClosedType(_, "upper"))))
545545
}
546546

547-
private var myUninstVars: mutable.ArrayBuffer[TypeVar] = _
547+
private[this] var myUninstVars: mutable.ArrayBuffer[TypeVar] = _
548548

549549
/** The uninstantiated typevars of this constraint */
550550
def uninstVars: collection.Seq[TypeVar] = {

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -318,16 +318,16 @@ object Phases {
318318

319319
def exists: Boolean = true
320320

321-
private var myPeriod: Period = Periods.InvalidPeriod
322-
private var myBase: ContextBase = null
323-
private var myErasedTypes = false
324-
private var myFlatClasses = false
325-
private var myRefChecked = false
326-
private var mySymbolicRefs = false
327-
private var myLabelsReordered = false
328-
329-
private var mySameMembersStartId = NoPhaseId
330-
private var mySameParentsStartId = NoPhaseId
321+
private[this] var myPeriod: Period = Periods.InvalidPeriod
322+
private[this] var myBase: ContextBase = null
323+
private[this] var myErasedTypes = false
324+
private[this] var myFlatClasses = false
325+
private[this] var myRefChecked = false
326+
private[this] var mySymbolicRefs = false
327+
private[this] var myLabelsReordered = false
328+
329+
private[this] var mySameMembersStartId = NoPhaseId
330+
private[this] var mySameParentsStartId = NoPhaseId
331331

332332
/** The sequence position of this phase in the given context where 0
333333
* is reserved for NoPhase and the first real phase is at position 1.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,11 @@ object Scopes {
210210

211211
/** the hash table
212212
*/
213-
private var hashTable: Array[ScopeEntry] = null
213+
private[this] var hashTable: Array[ScopeEntry] = null
214214

215215
/** a cache for all elements, to be used by symbol iterator.
216216
*/
217-
private var elemsCache: List[Symbol] = null
217+
private[this] var elemsCache: List[Symbol] = null
218218

219219
/** The synthesizer to be used, or `null` if no synthesis is done on this scope */
220220
private var synthesize: SymbolSynthesizer = null

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,9 +1874,9 @@ object SymDenotations {
18741874
def apply(sym: Symbol) = this
18751875
def apply(module: TermSymbol, modcls: ClassSymbol) = this
18761876

1877-
private var myDecls: Scope = EmptyScope
1878-
private var mySourceModuleFn: Context => Symbol = NoSymbolFn
1879-
private var myModuleClassFn: Context => Symbol = NoSymbolFn
1877+
private[this] var myDecls: Scope = EmptyScope
1878+
private[this] var mySourceModuleFn: Context => Symbol = NoSymbolFn
1879+
private[this] var myModuleClassFn: Context => Symbol = NoSymbolFn
18801880

18811881
/** A proxy to this lazy type that keeps the complete operation
18821882
* but provides fresh slots for scope/sourceModule/moduleClass
@@ -2046,7 +2046,7 @@ object SymDenotations {
20462046
final def isValid(implicit ctx: Context): Boolean =
20472047
cache != null && isValidAt(ctx.phase)
20482048

2049-
private var locked = false
2049+
private[this] var locked = false
20502050

20512051
/** Computing parent member names might force parents, which could invalidate
20522052
* the cache itself. In that case we should cancel invalidation and
@@ -2144,9 +2144,9 @@ object SymDenotations {
21442144

21452145
/** A class to combine base data from parent types */
21462146
class BaseDataBuilder {
2147-
private var classes: List[ClassSymbol] = Nil
2148-
private var classIds = new Array[Int](32)
2149-
private var length = 0
2147+
private[this] var classes: List[ClassSymbol] = Nil
2148+
private[this] var classIds = new Array[Int](32)
2149+
private[this] var length = 0
21502150

21512151
private def resize(size: Int) = {
21522152
val classIds1 = new Array[Int](size)
@@ -2182,5 +2182,5 @@ object SymDenotations {
21822182
def baseClasses: List[ClassSymbol] = classes
21832183
}
21842184

2185-
@sharable private var indent = 0 // for completions printing
2185+
@sharable private[this] var indent = 0 // for completions printing
21862186
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class SymbolLoaders {
150150
override def sourceModule(implicit ctx: Context) = _sourceModule
151151
def description(implicit ctx: Context) = "package loader " + sourceModule.fullName
152152

153-
private var enterFlatClasses: Option[Context => Unit] = None
153+
private[this] var enterFlatClasses: Option[Context => Unit] = None
154154

155155
Stats.record("package scopes")
156156

0 commit comments

Comments
 (0)