Skip to content

Remove some implicit conversions #4312

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
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ compiler/test/debug/Gen.jar

compiler/before-pickling.txt
compiler/after-pickling.txt
bench/compile.txt
*.dotty-ide-version

*.decompiled.out
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
def getAnnotPickle(jclassName: String, sym: Symbol): Option[Annotation] = None


def getRequiredClass(fullname: String): Symbol = ctx.requiredClass(fullname.toTermName)
def getRequiredClass(fullname: String): Symbol = ctx.requiredClass(fullname)

def getClassIfDefined(fullname: String): Symbol = NoSymbol // used only for android. todo: implement

Expand All @@ -375,12 +375,12 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
}

def requiredClass[T](implicit evidence: ClassTag[T]): Symbol =
ctx.requiredClass(erasureString(evidence.runtimeClass).toTermName)
ctx.requiredClass(erasureString(evidence.runtimeClass))

def requiredModule[T](implicit evidence: ClassTag[T]): Symbol = {
val moduleName = erasureString(evidence.runtimeClass)
val className = if (moduleName.endsWith("$")) moduleName.dropRight(1) else moduleName
ctx.requiredModule(className.toTermName)
ctx.requiredModule(className)
}


Expand Down Expand Up @@ -1193,8 +1193,8 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
val arity = field.meth.tpe.widenDealias.paramTypes.size - _1.size
val returnsUnit = field.meth.tpe.widenDealias.resultType.classSymbol == UnitClass
if (returnsUnit)
ctx.requiredClass(("scala.compat.java8.JProcedure" + arity).toTermName)
else ctx.requiredClass(("scala.compat.java8.JFunction" + arity).toTermName)
ctx.requiredClass(("scala.compat.java8.JProcedure" + arity))
else ctx.requiredClass(("scala.compat.java8.JFunction" + arity))
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
*/
protected[this] def rootContext(implicit ctx: Context): Context = {
ctx.initialize()(ctx)
ctx.setPhasePlan(comp.phases)
ctx.base.setPhasePlan(comp.phases)
val rootScope = new MutableScope
val bootstrap = ctx.fresh
.setPeriod(Period(comp.nextRunId, FirstPhaseId))
Expand Down Expand Up @@ -149,7 +149,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint

protected def compileUnits()(implicit ctx: Context) = Stats.maybeMonitored {
if (!ctx.mode.is(Mode.Interactive)) // IDEs might have multi-threaded access, accesses are synchronized
ctx.checkSingleThreaded()
ctx.base.checkSingleThreaded()

compiling = true

Expand All @@ -158,16 +158,16 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
if (ctx.settings.YtestPickler.value) List("pickler")
else ctx.settings.YstopAfter.value

val pluginPlan = ctx.addPluginPhases(ctx.phasePlan)
val phases = ctx.squashPhases(pluginPlan,
val pluginPlan = ctx.addPluginPhases(ctx.base.phasePlan)
val phases = ctx.base.squashPhases(pluginPlan,
ctx.settings.Yskip.value, ctx.settings.YstopBefore.value, stopAfter, ctx.settings.Ycheck.value)
ctx.usePhases(phases)
ctx.base.usePhases(phases)

def runPhases(implicit ctx: Context) = {
var lastPrintedTree: PrintedTree = NoPrintedTree
val profiler = ctx.profiler

for (phase <- ctx.allPhases)
for (phase <- ctx.base.allPhases)
if (phase.isRunnable)
Stats.trackTime(s"$phase ms ") {
val start = System.currentTimeMillis
Expand Down Expand Up @@ -228,7 +228,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
private def printTree(last: PrintedTree)(implicit ctx: Context): PrintedTree = {
val unit = ctx.compilationUnit
val prevPhase = ctx.phase.prev // can be a mini-phase
val squashedPhase = ctx.squashed(prevPhase)
val squashedPhase = ctx.base.squashed(prevPhase)
val treeString = unit.tpdTree.show(ctx.withProperty(XprintMode, Some(())))

ctx.echo(s"result of $unit after $squashedPhase:")
Expand Down Expand Up @@ -274,4 +274,4 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
myUnits = null
myUnitsCached = null
}
}
}
8 changes: 5 additions & 3 deletions compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ object Trees {
/** The type constructor at the root of the tree */
type ThisTree[T >: Untyped] <: Tree[T]

private[this] var myTpe: T = _
protected var myTpe: T @uncheckedVariance = _

/** Destructively set the type of the tree. This should be called only when it is known that
* it is safe under sharing to do so. One use-case is in the withType method below
Expand All @@ -92,7 +92,7 @@ object Trees {
/** The type of the tree. In case of an untyped tree,
* an UnAssignedTypeException is thrown. (Overridden by empty trees)
*/
def tpe: T @uncheckedVariance = {
final def tpe: T @uncheckedVariance = {
if (myTpe == null)
throw new UnAssignedTypeException(this)
myTpe
Expand Down Expand Up @@ -756,7 +756,6 @@ object Trees {
}

trait WithoutTypeOrPos[-T >: Untyped] extends Tree[T] {
override def tpe: T @uncheckedVariance = NoType.asInstanceOf[T]
override def withTypeUnchecked(tpe: Type) = this.asInstanceOf[ThisTree[Type]]
override def pos = NoPosition
override def setPos(pos: Position) = {}
Expand All @@ -769,6 +768,8 @@ object Trees {
*/
case class Thicket[-T >: Untyped](trees: List[Tree[T]])
extends Tree[T] with WithoutTypeOrPos[T] {
myTpe = NoType.asInstanceOf[T]

type ThisTree[-T >: Untyped] = Thicket[T]
override def isEmpty: Boolean = trees.isEmpty
override def toList: List[Tree[T]] = flatten(trees)
Expand All @@ -787,6 +788,7 @@ object Trees {

class EmptyValDef[T >: Untyped] extends ValDef[T](
nme.WILDCARD, genericEmptyTree[T], genericEmptyTree[T]) with WithoutTypeOrPos[T] {
myTpe = NoType.asInstanceOf[T]
override def isEmpty: Boolean = true
setMods(untpd.Modifiers(PrivateLocal))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ case class AggregateClassPath(aggregates: Seq[ClassPath]) extends ClassPath {
override private[dotty] def list(inPackage: String): ClassPathEntries = {
val (packages, classesAndSources) = aggregates.map { cp =>
try {
cp.list(inPackage)
cp.list(inPackage).toTuple
} catch {
case ex: java.io.IOException =>
val e = new FatalError(ex.getMessage)
Expand Down
8 changes: 2 additions & 6 deletions compiler/src/dotty/tools/dotc/classpath/ClassPath.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ package dotty.tools.dotc.classpath
import dotty.tools.io.AbstractFile
import dotty.tools.io.ClassRepresentation

case class ClassPathEntries(packages: Seq[PackageEntry], classesAndSources: Seq[ClassRepresentation])

object ClassPathEntries {
import scala.language.implicitConversions
// to have working unzip method
implicit def entry2Tuple(entry: ClassPathEntries): (Seq[PackageEntry], Seq[ClassRepresentation]) = (entry.packages, entry.classesAndSources)
case class ClassPathEntries(packages: Seq[PackageEntry], classesAndSources: Seq[ClassRepresentation]) {
def toTuple = (packages, classesAndSources)
}

trait ClassFileEntry extends ClassRepresentation {
Expand Down
41 changes: 28 additions & 13 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,32 @@ object Contexts {
"Context(\n" +
(outersIterator map ( ctx => s" owner = ${ctx.owner}, scope = ${ctx.scope}, import = ${iinfo(ctx)}") mkString "\n")
}

def typerPhase = base.typerPhase
def sbtExtractDependenciesPhase = base.sbtExtractDependenciesPhase
def picklerPhase = base.picklerPhase
def refchecksPhase = base.refchecksPhase
def patmatPhase = base.patmatPhase
def elimRepeatedPhase = base.elimRepeatedPhase
def extensionMethodsPhase = base.extensionMethodsPhase
def explicitOuterPhase = base.explicitOuterPhase
def gettersPhase = base.gettersPhase
def erasurePhase = base.erasurePhase
def elimErasedValueTypePhase = base.elimErasedValueTypePhase
def lambdaLiftPhase = base.lambdaLiftPhase
def flattenPhase = base.flattenPhase
def genBCodePhase = base.genBCodePhase
def phases = base.phases

def settings = base.settings
def definitions = base.definitions
def platform = base.platform
def pendingUnderlying = base.pendingUnderlying
def uniqueNamedTypes = base.uniqueNamedTypes
def uniques = base.uniques
def nextId = base.nextId

def initialize()(implicit ctx: Context) = base.initialize()(ctx)
}

/** A condensed context provides only a small memory footprint over
Expand Down Expand Up @@ -520,7 +546,7 @@ object Contexts {
/** A class defining the initial context with given context base
* and set of possible settings.
*/
private class InitialContext(val base: ContextBase, settings: SettingGroup) extends FreshContext {
private class InitialContext(val base: ContextBase, settingsGroup: SettingGroup) extends FreshContext {
outer = NoContext
period = InitialPeriod
mode = Mode.None
Expand All @@ -529,7 +555,7 @@ object Contexts {
tree = untpd.EmptyTree
typeAssigner = TypeAssigner
moreProperties = Map.empty
store = initialStore.updated(settingsStateLoc, settings.defaultState)
store = initialStore.updated(settingsStateLoc, settingsGroup.defaultState)
typeComparer = new TypeComparer(this)
searchHistory = new SearchHistory(0, Map())
gadt = EmptyGADTMap
Expand Down Expand Up @@ -684,17 +710,6 @@ object Contexts {
else assert(thread == Thread.currentThread(), "illegal multithreaded access to ContextBase")
}

object Context {

/** Implicit conversion that injects all printer operations into a context */
implicit def toPrinter(ctx: Context): Printer = ctx.printer

/** implicit conversion that injects all ContextBase members into a context */
implicit def toBase(ctx: Context): ContextBase = ctx.base

// @sharable val theBase = new ContextBase // !!! DEBUG, so that we can use a minimal context for reporting even in code that normally cannot access a context
}

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

lazy val RootClass: ClassSymbol = ctx.newPackageSymbol(
NoSymbol, nme.ROOT, (root, rootcls) => ctx.rootLoader(root)).moduleClass.asClass
NoSymbol, nme.ROOT, (root, rootcls) => ctx.base.rootLoader(root)).moduleClass.asClass
lazy val RootPackage: TermSymbol = ctx.newSymbol(
NoSymbol, nme.ROOTPKG, PackageCreationFlags, TypeRef(NoPrefix, RootClass))

lazy val EmptyPackageVal = ctx.newPackageSymbol(
RootClass, nme.EMPTY_PACKAGE, (emptypkg, emptycls) => ctx.rootLoader(emptypkg)).entered
RootClass, nme.EMPTY_PACKAGE, (emptypkg, emptycls) => ctx.base.rootLoader(emptypkg)).entered
lazy val EmptyPackageClass = EmptyPackageVal.moduleClass.asClass

/** A package in which we can place all methods that are interpreted specially by the compiler */
lazy val OpsPackageVal = ctx.newCompletePackageSymbol(RootClass, nme.OPS_PACKAGE).entered
lazy val OpsPackageClass = OpsPackageVal.moduleClass.asClass

lazy val ScalaPackageVal = ctx.requiredPackage("scala")
lazy val ScalaPackageVal = ctx.requiredPackage(nme.scala_)
lazy val ScalaMathPackageVal = ctx.requiredPackage("scala.math")
lazy val ScalaPackageClass = {
val cls = ScalaPackageVal.moduleClass.asClass
Expand All @@ -211,8 +211,8 @@ class Definitions {
cls
}
lazy val ScalaPackageObjectRef = ctx.requiredModuleRef("scala.package")
lazy val JavaPackageVal = ctx.requiredPackage("java")
lazy val JavaLangPackageVal = ctx.requiredPackage("java.lang")
lazy val JavaPackageVal = ctx.requiredPackage(nme.java)
lazy val JavaLangPackageVal = ctx.requiredPackage(jnme.JavaLang)
// fundamental modules
lazy val SysPackage = ctx.requiredModule("scala.sys.package")
lazy val Sys_errorR = SysPackage.moduleClass.requiredMethodRef(nme.error)
Expand Down Expand Up @@ -342,11 +342,11 @@ class Definitions {

lazy val Predef_ConformsR = ScalaPredefModule.requiredClass("<:<").typeRef
def Predef_Conforms(implicit ctx: Context) = Predef_ConformsR.symbol
lazy val Predef_conformsR = ScalaPredefModule.requiredMethodRef("$conforms")
lazy val Predef_conformsR = ScalaPredefModule.requiredMethodRef(nme.conforms_)
def Predef_conforms(implicit ctx: Context) = Predef_conformsR.symbol
lazy val Predef_classOfR = ScalaPredefModule.requiredMethodRef("classOf")
lazy val Predef_classOfR = ScalaPredefModule.requiredMethodRef(nme.classOf)
def Predef_classOf(implicit ctx: Context) = Predef_classOfR.symbol
lazy val Predef_undefinedR = ScalaPredefModule.requiredMethodRef("???")
lazy val Predef_undefinedR = ScalaPredefModule.requiredMethodRef(nme.???)
def Predef_undefined(implicit ctx: Context) = Predef_undefinedR.symbol

lazy val ScalaRuntimeModuleRef = ctx.requiredModuleRef("scala.runtime.ScalaRunTime")
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/DenotTransformers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object DenotTransformers {
trait DenotTransformer extends Phase {

/** The last phase during which the transformed denotations are valid */
def lastPhaseId(implicit ctx: Context) = ctx.nextDenotTransformerId(id + 1)
def lastPhaseId(implicit ctx: Context) = ctx.base.nextDenotTransformerId(id + 1)

/** The validity period of the transformed denotations in the given context */
def validFor(implicit ctx: Context): Period =
Expand Down
Loading