Skip to content

Infer private[this] #7411

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 10 commits into from
Oct 21, 2019
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/WorklistAlgorithm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import scala.collection.mutable
trait WorklistAlgorithm {
type Elem
class WList {
private[this] var list: List[Elem] = Nil
private var list: List[Elem] = Nil
def isEmpty = list.isEmpty
def nonEmpty = !isEmpty
def push(e: Elem): Unit = { list = e :: list }
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/CoreBTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ final class CoreBTypesProxy[BTFS <: BTypesFromSymbols[_ <: BackendInterface]](va
import bTypes._
import bTypes.int._

private[this] var _coreBTypes: CoreBTypes[bTypes.type] = _
private var _coreBTypes: CoreBTypes[bTypes.type] = _
def setBTypes(coreBTypes: CoreBTypes[BTFS]): Unit = {
_coreBTypes = coreBTypes.asInstanceOf[CoreBTypes[bTypes.type]]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,10 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma

private def getGenericSignature(sym: Symbol, owner: Symbol, memberTpe: Type)(implicit ctx: Context): Option[String] =
if (needsGenericSignature(sym)) {
val erasedTypeSym = sym.denot.info.typeSymbol
val erasedTypeSym = TypeErasure.fullErasure(sym.denot.info).typeSymbol
if (erasedTypeSym.isPrimitiveValueClass) {
// Suppress signatures for symbols whose types erase in the end to primitive
// value types. This is needed to fix #7416.
None
} else {
val jsOpt = GenericSignatures.javaSig(sym, memberTpe)
Expand Down
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/backend/jvm/GenBCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class GenBCode extends Phase {
superCallsMap.update(sym, old + calls)
}

private[this] var myOutput: AbstractFile = _
private var myOutput: AbstractFile = _

private def outputDir(implicit ctx: Context): AbstractFile = {
if (myOutput eq null)
Expand Down Expand Up @@ -68,14 +68,14 @@ object GenBCode {

class GenBCodePipeline(val int: DottyBackendInterface)(implicit val ctx: Context) extends BCodeSyncAndTry {

private[this] var tree: Tree = _
private var tree: Tree = _

private[this] val sourceFile: SourceFile = ctx.compilationUnit.source
private val sourceFile: SourceFile = ctx.compilationUnit.source

/** Convert a `dotty.tools.io.AbstractFile` into a
* `dotty.tools.dotc.interfaces.AbstractFile`.
*/
private[this] def convertAbstractFile(absfile: dotty.tools.io.AbstractFile): interfaces.AbstractFile =
private def convertAbstractFile(absfile: dotty.tools.io.AbstractFile): interfaces.AbstractFile =
new interfaces.AbstractFile {
override def name = absfile.name
override def path = absfile.path
Expand All @@ -86,8 +86,8 @@ class GenBCodePipeline(val int: DottyBackendInterface)(implicit val ctx: Context

// class BCodePhase() {

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

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

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class JSCodeGen()(implicit ctx: Context) {
/* See genSuperCall()
* TODO Can we avoid this unscoped var?
*/
private[this] var isModuleInitialized: Boolean = false
private var isModuleInitialized: Boolean = false

private def currentClassType = encodeClassType(currentClassSym)

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/sjs/JSDefinitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ final class JSDefinitions()(implicit ctx: Context) {
@threadUnsafe lazy val Reflect_registerInstantiatableClassR = ReflectModule.requiredMethodRef("registerInstantiatableClass")
def Reflect_registerInstantiatableClass(implicit ctx: Context) = Reflect_registerInstantiatableClassR.symbol

private[this] var allRefClassesCache: Set[Symbol] = _
private var allRefClassesCache: Set[Symbol] = _
def allRefClasses(implicit ctx: Context): Set[Symbol] = {
if (allRefClassesCache == null) {
val baseNames = List("Object", "Boolean", "Character", "Byte", "Short",
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/backend/sjs/JSPositions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class JSPositions()(implicit ctx: Context) {
implicit def implicitSourcePos2irPos(implicit sourcePos: SourcePosition): ir.Position =
sourceAndSpan2irPos(sourcePos.source, sourcePos.span)

private[this] object span2irPosCache { // scalastyle:ignore
private object span2irPosCache { // scalastyle:ignore
import dotty.tools.dotc.util._

private[this] var lastDotcSource: SourceFile = null
private[this] var lastIRSource: ir.Position.SourceFile = null
private var lastDotcSource: SourceFile = null
private var lastIRSource: ir.Position.SourceFile = null

def toIRSource(dotcSource: SourceFile): ir.Position.SourceFile = {
if (dotcSource != lastDotcSource) {
Expand All @@ -49,7 +49,7 @@ class JSPositions()(implicit ctx: Context) {
lastIRSource
}

private[this] def convert(dotcSource: SourceFile): ir.Position.SourceFile = {
private def convert(dotcSource: SourceFile): ir.Position.SourceFile = {
dotcSource.file.file match {
case null =>
new java.net.URI(
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 @@ -12,7 +12,7 @@ import scala.annotation.internal.sharable
*/
object Bench extends Driver {

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

private def ntimes(n: Int)(op: => Reporter): Reporter =
(0 until n).foldLeft(emptyReporter)((_, _) => op)
Expand Down
18 changes: 9 additions & 9 deletions compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
* for type checking.
* imports For each element of RootImports, an import context
*/
protected[this] def rootContext(implicit ctx: Context): Context = {
protected def rootContext(implicit ctx: Context): Context = {
ctx.initialize()(ctx)
ctx.base.setPhasePlan(comp.phases)
val rootScope = new MutableScope
Expand All @@ -59,19 +59,19 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
defn.RootImportFns.foldLeft(start.setRun(this))(addImport)
}

private[this] var compiling = false
private var compiling = false

private[this] var myCtx = rootContext(ictx)
private var myCtx = rootContext(ictx)

/** The context created for this run */
def runContext: Context = myCtx

protected[this] implicit def ctx: Context = myCtx
protected implicit def ctx: Context = myCtx
assert(ctx.runId <= Periods.MaxPossibleRunId)

private[this] var myUnits: List[CompilationUnit] = _
private[this] var myUnitsCached: List[CompilationUnit] = _
private[this] var myFiles: Set[AbstractFile] = _
private var myUnits: List[CompilationUnit] = _
private var myUnitsCached: List[CompilationUnit] = _
private var myFiles: Set[AbstractFile] = _

/** The compilation units currently being compiled, this may return different
* results over time.
Expand All @@ -94,10 +94,10 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
}

/** The source files of all late entered symbols, as a set */
private[this] var lateFiles = mutable.Set[AbstractFile]()
private var lateFiles = mutable.Set[AbstractFile]()

/** Actions that need to be performed at the end of the current compilation run */
private[this] var finalizeActions = mutable.ListBuffer[() => Unit]()
private var finalizeActions = mutable.ListBuffer[() => Unit]()

def compile(fileNames: List[String]): Unit = try {
val sources = fileNames.map(ctx.getSource(_))
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,14 @@ object desugar {
* ==>
* def x: Int = expr
* def x_=($1: <TypeTree()>): Unit = ()
*
* Generate the setter only for non-private class members and all trait members.
*/
def valDef(vdef0: ValDef)(implicit ctx: Context): Tree = {
val vdef @ ValDef(name, tpt, rhs) = transformQuotedPatternName(vdef0)
val mods = vdef.mods
val setterNeeded =
mods.is(Mutable) && ctx.owner.isClass && (!mods.isAllOf(PrivateLocal) || ctx.owner.is(Trait))
mods.is(Mutable) && ctx.owner.isClass && (!mods.is(Private) || ctx.owner.is(Trait))
if (setterNeeded) {
// TODO: copy of vdef as getter needed?
// val getter = ValDef(mods, name, tpt, rhs) withPos vdef.pos?
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/ast/PluggableTransformers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ object PluggableTransformers {
abstract class PluggableTransformer[T] extends TreeTransformer[T, Context] {
type PluginOp[-N <: Tree[T]] = N => Tree[T]

private[this] var _ctx: Context = _
private[this] var _oldTree: Tree[T] = _
private var _ctx: Context = _
private var _oldTree: Tree[T] = _

protected implicit def ctx: Context = _ctx
protected def oldTree: Tree[T] = _oldTree
Expand Down Expand Up @@ -44,7 +44,7 @@ object PluggableTransformers {

val EmptyPlugin = new Plugins

private[this] var _plugins: Plugins = EmptyPlugin
private var _plugins: Plugins = EmptyPlugin

override def plugins: Plugins = _plugins

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/Positioned.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import java.io.{ PrintWriter }
*/
abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Product with Cloneable {

private[this] var myUniqueId: Int = _
private[this] var mySpan: Span = _
private var myUniqueId: Int = _
private var mySpan: Span = _

/** A unique identifier. Among other things, used for determining the source file
* component of the position.
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 @@ -309,7 +309,7 @@ object Trees {
trait DefTree[-T >: Untyped] extends DenotingTree[T] {
type ThisTree[-T >: Untyped] <: DefTree[T]

private[this] var myMods: untpd.Modifiers = null
private var myMods: untpd.Modifiers = null

private[dotc] def rawMods: untpd.Modifiers =
if (myMods == null) untpd.EmptyModifiers else myMods
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
trait TreeProvider {
protected def computeRootTrees(implicit ctx: Context): List[Tree]

private[this] var myTrees: List[Tree] = null
private var myTrees: List[Tree] = null

/** Get trees defined by this provider. Cache them if -Yretain-trees is set. */
def rootTrees(implicit ctx: Context): 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 @@ -276,7 +276,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
*/
abstract class DerivedTypeTree(implicit @constructorOnly src: SourceFile) extends TypeTree {

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

/** The watched tree; used only for printing */
def watched: Tree = myWatched
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ case class AggregateClassPath(aggregates: Seq[ClassPath]) extends ClassPath {
case Some(x) => x
}
}
private[this] val packageIndex: collection.mutable.Map[String, Seq[ClassPath]] = collection.mutable.Map()
private val packageIndex: collection.mutable.Map[String, Seq[ClassPath]] = collection.mutable.Map()
private def aggregatesForPackage(pkg: String): Seq[ClassPath] = packageIndex.synchronized {
packageIndex.getOrElseUpdate(pkg, aggregates.filter(_.hasPackage(pkg)))
}
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[this] var currentClassPath: Option[ClassPath] = None
private 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[this] var outputDirs: List[(AbstractFile, AbstractFile)] = Nil
private var outputDirs: List[(AbstractFile, AbstractFile)] = Nil

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

/** Add a destination directory for sources found under srcdir.
* Both directories should exits.
Expand Down
8 changes: 4 additions & 4 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 OutputTag: ClassTag[AbstractFile] = ClassTag(classOf[AbstractFile])

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

override def toString: String = 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[this] var changed: Boolean = false
private var changed: Boolean = false

def withAbbreviation(abbrv: String): Setting[T] =
copy(aliases = aliases :+ abbrv)(idx)
Expand Down Expand Up @@ -193,7 +193,7 @@ object Settings {

class SettingGroup {

private[this] val _allSettings = new ArrayBuffer[Setting[?]]
private val _allSettings = new ArrayBuffer[Setting[?]]
def allSettings: Seq[Setting[?]] = _allSettings.toSeq

def defaultState: SettingsState = new SettingsState(allSettings map (_.default))
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ object Annotations {
override def symbol(implicit ctx: Context): Symbol
def complete(implicit ctx: Context): Tree

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

case class LazyBodyAnnotation(private var bodyExpr: Context => Tree) extends BodyAnnotation {
// TODO: Make `bodyExpr` an IFT once #6865 os in bootstrap
private[this] var evaluated = false
private[this] var myBody: Tree = _
private var evaluated = false
private var myBody: Tree = _
def tree(implicit ctx: Context): Tree = {
if (evaluated) assert(myBody != null)
else {
Expand Down Expand Up @@ -127,7 +127,7 @@ object Annotations {
/** Create an annotation where the symbol and the tree are computed lazily. */
def deferredSymAndTree(symf: (given Context) => Symbol)(treeFn: (given Context) => Tree)(implicit ctx: Context): Annotation =
new LazyAnnotation {
private[this] var mySym: Symbol = _
private var mySym: Symbol = _

override def symbol(implicit ctx: Context): Symbol = {
if (mySym == null || mySym.defRunId != ctx.runId) {
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Comments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object Comments {
*/
class ContextDocstrings {

private[this] val _docstrings: MutableSymbolMap[Comment] = newMutableSymbolMap
private val _docstrings: MutableSymbolMap[Comment] = newMutableSymbolMap

val templateExpander: CommentExpander = new CommentExpander

Expand Down Expand Up @@ -93,7 +93,7 @@ object Comments {
* def foo: A = ???
* }}}
*/
private[this] def decomposeUseCase(body: String, span: Span, start: Int, end: Int)(implicit ctx: Context): UseCase = {
private def decomposeUseCase(body: String, span: Span, start: Int, end: Int)(implicit ctx: Context): UseCase = {
def subPos(start: Int, end: Int) =
if (span == NoSpan) NoSpan
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ trait ConstraintHandling[AbstractContext] {
protected def constraint: Constraint
protected def constraint_=(c: Constraint): Unit

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

/** If the constraint is frozen we cannot add new bounds to the constraint. */
protected var frozenConstraint: Boolean = 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.{default, typr}

trait ConstraintRunInfo { self: Run =>
private[this] var maxSize = 0
private[this] var maxConstraint: Constraint = _
private var maxSize = 0
private var maxConstraint: Constraint = _
def recordConstraintSize(c: Constraint, size: Int): Unit =
if (size > maxSize) {
maxSize = size
Expand Down
Loading