Skip to content

Replace private var by private[this] var where possible #3241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/sjs/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class JSCodeGen()(implicit ctx: Context) {
/* See genSuperCall()
* TODO Can we avoid this unscoped var?
*/
private var isModuleInitialized: Boolean = false
private[this] var isModuleInitialized: Boolean = false

private def currentClassType = encodeClassType(currentClassSym)

Expand Down
2 changes: 1 addition & 1 deletion compiler/sjs/backend/sjs/ScopedVar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import language.implicitConversions
class ScopedVar[A](init: A) {
import ScopedVar.Assignment

private var value = init
private[this] var value = init

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

Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/backend/jvm/GenBCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter

// class BCodePhase() {

private var bytecodeWriter : BytecodeWriter = null
private var mirrorCodeGen : JMirrorBuilder = null
private var beanInfoCodeGen : JBeanInfoBuilder = null
private[this] var bytecodeWriter : BytecodeWriter = null
private[this] var mirrorCodeGen : JMirrorBuilder = null
private[this] var beanInfoCodeGen : JBeanInfoBuilder = null

/* ---------------- q1 ---------------- */

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/Bench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import reporting.Reporter
*/
object Bench extends Driver {

@sharable private var numRuns = 1
@sharable private[this] var numRuns = 1

private def ntimes(n: Int)(op: => Reporter): Reporter =
(emptyReporter /: (0 until n)) ((_, _) => op)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object Trees {
/** Property key for trees with documentation strings attached */
val DocComment = new Property.Key[Comment]

@sharable private var nextId = 0 // for debugging
@sharable private[this] var nextId = 0 // for debugging

type LazyTree = AnyRef /* really: Tree | Lazy[Tree] */
type LazyTreeList = AnyRef /* really: List[Tree] | Lazy[List[Tree]] */
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
*/
abstract class DerivedTypeTree extends TypeTree {

private var myWatched: Tree = EmptyTree
private[this] var myWatched: Tree = EmptyTree

/** The watched tree; used only for printing */
def watched: Tree = myWatched
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/config/JavaPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import transform.ExplicitOuter, transform.SymUtils._

class JavaPlatform extends Platform {

private var currentClassPath: Option[ClassPath] = None
private[this] var currentClassPath: Option[ClassPath] = None

def classPath(implicit ctx: Context): ClassPath = {
if (currentClassPath.isEmpty)
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/config/OutputDirs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import io._
*/
class OutputDirs {
/** Pairs of source directory - destination directory. */
private var outputDirs: List[(AbstractFile, AbstractFile)] = Nil
private[this] var outputDirs: List[(AbstractFile, AbstractFile)] = Nil

/** If this is not None, the output location where all
* classes should go.
*/
private var singleOutDir: Option[AbstractFile] = None
private[this] var singleOutDir: Option[AbstractFile] = None

/** Add a destination directory for sources found under srcdir.
* Both directories should exits.
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/config/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ object Settings {
val DirectoryTag = ClassTag(classOf[Directory])

class SettingsState(initialValues: Seq[Any]) {
private var values = ArrayBuffer(initialValues: _*)
private var _wasRead: Boolean = false
private[this] var values = ArrayBuffer(initialValues: _*)
private[this] var _wasRead: Boolean = false

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

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

private var changed: Boolean = false
private[this] var changed: Boolean = false

def withAbbreviation(abbrv: String): Setting[T] =
copy(aliases = aliases :+ abbrv)(idx)
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object Annotations {
override def symbol(implicit ctx: Context): Symbol
def complete(implicit ctx: Context): Tree

private var myTree: Tree = null
private[this] var myTree: Tree = null
def tree(implicit ctx: Context) = {
if (myTree == null) myTree = complete(ctx)
myTree
Expand All @@ -62,8 +62,8 @@ object Annotations {
}

case class LazyBodyAnnotation(private var bodyExpr: Context => Tree) extends BodyAnnotation {
private var evaluated = false
private var myBody: Tree = _
private[this] var evaluated = false
private[this] var myBody: Tree = _
def tree(implicit ctx: Context) = {
if (evaluated) assert(myBody != null)
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ trait ConstraintHandling {
val state: TyperState
import state.constraint

private var addConstraintInvocations = 0
private[this] var addConstraintInvocations = 0

/** If the constraint is frozen we cannot add new bounds to the constraint. */
protected var frozenConstraint = false
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/ConstraintRunInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import Contexts._
import config.Printers.typr

trait ConstraintRunInfo { self: RunInfo =>
private var maxSize = 0
private var maxConstraint: Constraint = _
private[this] var maxSize = 0
private[this] var maxConstraint: Constraint = _
def recordConstraintSize(c: Constraint, size: Int) =
if (size > maxSize) {
maxSize = size
Expand Down
24 changes: 12 additions & 12 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ object Contexts {
/** An optional diagostics buffer than is used by some checking code
* to provide more information in the buffer if it exists.
*/
private var _diagnostics: Option[StringBuilder] = _
private[this] var _diagnostics: Option[StringBuilder] = _
protected def diagnostics_=(diagnostics: Option[StringBuilder]) = _diagnostics = diagnostics
def diagnostics: Option[StringBuilder] = _diagnostics

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

Expand All @@ -175,14 +175,14 @@ object Contexts {
def freshNames: FreshNameCreator = _freshNames

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

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

private var _typeComparer: TypeComparer = _
private[this] var _typeComparer: TypeComparer = _
protected def typeComparer_=(typeComparer: TypeComparer) = _typeComparer = typeComparer
def typeComparer: TypeComparer = {
if (_typeComparer.ctx ne this)
Expand Down Expand Up @@ -224,7 +224,7 @@ object Contexts {
}

/** The history of implicit searches that are currently active */
private var _searchHistory: SearchHistory = null
private[this] var _searchHistory: SearchHistory = null
protected def searchHistory_= (searchHistory: SearchHistory) = _searchHistory = searchHistory
def searchHistory: SearchHistory = _searchHistory

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

/** This context at given phase.
* This method will always return a phase period equal to phaseId, thus will never return squashed phases
Expand Down Expand Up @@ -268,7 +268,7 @@ object Contexts {
/** If -Ydebug is on, the top of the stack trace where this context
* was created, otherwise `null`.
*/
private var creationTrace: Array[StackTraceElement] = _
private[this] var creationTrace: Array[StackTraceElement] = _

private def setCreationTrace() =
if (this.settings.YtraceContextCreation.value)
Expand Down Expand Up @@ -393,7 +393,7 @@ object Contexts {

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

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

/** The platform */
def platform: Platform = {
Expand Down Expand Up @@ -670,7 +670,7 @@ object Contexts {
// Test that access is single threaded

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

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

class GADTMap(initBounds: SimpleIdentityMap[Symbol, TypeBounds]) extends util.DotClass {
private var myBounds = initBounds
private[this] var myBounds = initBounds
def setBounds(sym: Symbol, b: TypeBounds): Unit =
myBounds = myBounds.updated(sym, b)
def bounds = myBounds
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -950,8 +950,8 @@ class Definitions {

/** This class would also be obviated by the implicit function type design */
class PerRun[T](generate: Context => T) {
private var current: RunId = NoRunId
private var cached: T = _
private[this] var current: RunId = NoRunId
private[this] var cached: T = _
def apply()(implicit ctx: Context): T = {
if (current != ctx.runId) {
cached = generate(ctx)
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1122,9 +1122,9 @@ object Denotations {
*/
def filterExcluded(excluded: FlagSet)(implicit ctx: Context): PreDenotation

private var cachedPrefix: Type = _
private var cachedAsSeenFrom: AsSeenFromResult = _
private var validAsSeenFrom: Period = Nowhere
private[this] var cachedPrefix: Type = _
private[this] var cachedAsSeenFrom: AsSeenFromResult = _
private[this] var validAsSeenFrom: Period = Nowhere
type AsSeenFromResult <: PreDenotation

/** The denotation with info(s) as seen from prefix type */
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Names.scala
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ object Names {
def underlying: TermName = unsupported("underlying")

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

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

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

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

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

/** The hash of a name made of from characters cs[offset..offset+len-1]. */
private def hashValue(cs: Array[Char], offset: Int, len: Int): Int =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
upperMap.foreachBinding((_, paramss) => paramss.foreach(_.foreach(checkClosedType(_, "upper"))))
}

private var myUninstVars: mutable.ArrayBuffer[TypeVar] = _
private[this] var myUninstVars: mutable.ArrayBuffer[TypeVar] = _

/** The uninstantiated typevars of this constraint */
def uninstVars: collection.Seq[TypeVar] = {
Expand Down
20 changes: 10 additions & 10 deletions compiler/src/dotty/tools/dotc/core/Phases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,16 @@ object Phases {

def exists: Boolean = true

private var myPeriod: Period = Periods.InvalidPeriod
private var myBase: ContextBase = null
private var myErasedTypes = false
private var myFlatClasses = false
private var myRefChecked = false
private var mySymbolicRefs = false
private var myLabelsReordered = false

private var mySameMembersStartId = NoPhaseId
private var mySameParentsStartId = NoPhaseId
private[this] var myPeriod: Period = Periods.InvalidPeriod
private[this] var myBase: ContextBase = null
private[this] var myErasedTypes = false
private[this] var myFlatClasses = false
private[this] var myRefChecked = false
private[this] var mySymbolicRefs = false
private[this] var myLabelsReordered = false

private[this] var mySameMembersStartId = NoPhaseId
private[this] var mySameParentsStartId = NoPhaseId

/** The sequence position of this phase in the given context where 0
* is reserved for NoPhase and the first real phase is at position 1.
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Scopes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ object Scopes {

/** the hash table
*/
private var hashTable: Array[ScopeEntry] = null
private[this] var hashTable: Array[ScopeEntry] = null

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

/** The synthesizer to be used, or `null` if no synthesis is done on this scope */
private var synthesize: SymbolSynthesizer = null
Expand Down
16 changes: 8 additions & 8 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1874,9 +1874,9 @@ object SymDenotations {
def apply(sym: Symbol) = this
def apply(module: TermSymbol, modcls: ClassSymbol) = this

private var myDecls: Scope = EmptyScope
private var mySourceModuleFn: Context => Symbol = NoSymbolFn
private var myModuleClassFn: Context => Symbol = NoSymbolFn
private[this] var myDecls: Scope = EmptyScope
private[this] var mySourceModuleFn: Context => Symbol = NoSymbolFn
private[this] var myModuleClassFn: Context => Symbol = NoSymbolFn

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

private var locked = false
private[this] var locked = false

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

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

private def resize(size: Int) = {
val classIds1 = new Array[Int](size)
Expand Down Expand Up @@ -2182,5 +2182,5 @@ object SymDenotations {
def baseClasses: List[ClassSymbol] = classes
}

@sharable private var indent = 0 // for completions printing
@sharable private[this] var indent = 0 // for completions printing
}
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class SymbolLoaders {
override def sourceModule(implicit ctx: Context) = _sourceModule
def description(implicit ctx: Context) = "package loader " + sourceModule.fullName

private var enterFlatClasses: Option[Context => Unit] = None
private[this] var enterFlatClasses: Option[Context => Unit] = None

Stats.record("package scopes")

Expand Down
Loading