Skip to content

Commit

Permalink
Change according to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
noti0na1 committed Feb 24, 2022
1 parent b131f61 commit a20aaf8
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 91 deletions.
6 changes: 2 additions & 4 deletions compiler/src/dotty/tools/dotc/Resident.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ class Resident extends Driver {
nextCtx = rootCtx
line = getLine()
}
if (line.startsWith(quit)) ctx.reporter
else
// split returns non-nullable values
loop((line split "\\s+").asInstanceOf[Array[String]], nextCtx)
if line.startsWith(quit) then ctx.reporter
else loop((line split "\\s+").asInstanceOf[Array[String]], nextCtx)
case None =>
prevCtx.reporter
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
compileSources(sources)
catch
case NonFatal(ex) =>
if units != Nil then report.echo(i"exception occurred while compiling $units%, %")
if units.nonEmpty then report.echo(i"exception occurred while compiling $units%, %")
else report.echo(s"exception occurred while compiling ${files.map(_.name).mkString(", ")}")
throw ex

Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import NameKinds.{TempResultName, OuterSelectName}
import typer.ConstFold

import scala.annotation.tailrec
import scala.collection.mutable.ListBuffer

/** Some creators for typed trees */
object tpd extends Trees.Instance[Type] with TypedTreeInfo {
Expand Down
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -862,10 +862,11 @@ object Contexts {

/** The platform */
def platform: Platform = {
if _platform == null then
val p = _platform
if p == null then
throw new IllegalStateException(
"initialize() must be called before accessing platform")
_platform.uncheckedNN
p
}

protected def newPlatform(using Context): Platform =
Expand Down
36 changes: 20 additions & 16 deletions compiler/src/dotty/tools/dotc/core/Hashable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ import annotation.tailrec
object Hashable {

/** A null terminated list of BindingTypes. We use `null` here for efficiency */
class Binders(val tp: BindingType, val next: Binders | Null)
class SomeBinders(val tp: BindingType, val next: Binders)

type Binders = SomeBinders | Null

/** A null terminated list of pairs of BindingTypes. Used for isomorphism tests. */
class BinderPairs(tp1: BindingType, tp2: BindingType, next: BinderPairs | Null) {
class SomeBinderPairs(tp1: BindingType, tp2: BindingType, next: BinderPairs) {
@tailrec final def matches(t1: Type, t2: Type): Boolean =
(t1 `eq` tp1) && (t2 `eq` tp2) || next != null && next.matches(t1, t2)
}

type BinderPairs = SomeBinderPairs | Null

/** A hash value indicating that the underlying type is not
* cached in uniques.
*/
Expand Down Expand Up @@ -45,24 +49,24 @@ trait Hashable {
protected final def finishHash(hashCode: Int, arity: Int): Int =
avoidSpecialHashes(hashing.finalizeHash(hashCode, arity))

final def typeHash(bs: Binders | Null, tp: Type): Int =
final def typeHash(bs: Binders, tp: Type): Int =
if (bs == null || tp.hashIsStable) tp.hash else tp.computeHash(bs)

def identityHash(bs: Binders | Null): Int = avoidSpecialHashes(System.identityHashCode(this))
def identityHash(bs: Binders): Int = avoidSpecialHashes(System.identityHashCode(this))

protected def finishHash(bs: Binders | Null, seed: Int, arity: Int, tp: Type): Int = {
protected def finishHash(bs: Binders, seed: Int, arity: Int, tp: Type): Int = {
val elemHash = typeHash(bs, tp)
if (elemHash == NotCached) return NotCached
finishHash(hashing.mix(seed, elemHash), arity + 1)
}

protected def finishHash(bs: Binders | Null, seed: Int, arity: Int, tp1: Type, tp2: Type): Int = {
protected def finishHash(bs: Binders, seed: Int, arity: Int, tp1: Type, tp2: Type): Int = {
val elemHash = typeHash(bs, tp1)
if (elemHash == NotCached) return NotCached
finishHash(bs, hashing.mix(seed, elemHash), arity + 1, tp2)
}

protected def finishHash(bs: Binders | Null, seed: Int, arity: Int, tps: List[Type]): Int = {
protected def finishHash(bs: Binders, seed: Int, arity: Int, tps: List[Type]): Int = {
var h = seed
var xs = tps
var len = arity
Expand All @@ -76,7 +80,7 @@ trait Hashable {
finishHash(h, len)
}

protected def finishHash(bs: Binders | Null, seed: Int, arity: Int, tp: Type, tps: List[Type]): Int = {
protected def finishHash(bs: Binders, seed: Int, arity: Int, tp: Type, tps: List[Type]): Int = {
val elemHash = typeHash(bs, tp)
if (elemHash == NotCached) return NotCached
finishHash(bs, hashing.mix(seed, elemHash), arity + 1, tps)
Expand All @@ -86,28 +90,28 @@ trait Hashable {
protected final def doHash(x: Any): Int =
finishHash(hashing.mix(hashSeed, x.hashCode), 1)

protected final def doHash(bs: Binders | Null, tp: Type): Int =
protected final def doHash(bs: Binders, tp: Type): Int =
finishHash(bs, hashSeed, 0, tp)

protected final def doHash(bs: Binders | Null, x1: Any, tp2: Type): Int =
protected final def doHash(bs: Binders, x1: Any, tp2: Type): Int =
finishHash(bs, hashing.mix(hashSeed, x1.hashCode), 1, tp2)

protected final def doHash(bs: Binders | Null, x1: Int, tp2: Type): Int =
protected final def doHash(bs: Binders, x1: Int, tp2: Type): Int =
finishHash(bs, hashing.mix(hashSeed, x1), 1, tp2)

protected final def doHash(bs: Binders | Null, x1: Int, tp2: Type, tp3: Type): Int =
protected final def doHash(bs: Binders, x1: Int, tp2: Type, tp3: Type): Int =
finishHash(bs, hashing.mix(hashSeed, x1), 1, tp2, tp3)

protected final def doHash(bs: Binders | Null, tp1: Type, tp2: Type): Int =
protected final def doHash(bs: Binders, tp1: Type, tp2: Type): Int =
finishHash(bs, hashSeed, 0, tp1, tp2)

protected final def doHash(bs: Binders | Null, x1: Any, tp2: Type, tp3: Type): Int =
protected final def doHash(bs: Binders, x1: Any, tp2: Type, tp3: Type): Int =
finishHash(bs, hashing.mix(hashSeed, x1.hashCode), 1, tp2, tp3)

protected final def doHash(bs: Binders | Null, tp1: Type, tps2: List[Type]): Int =
protected final def doHash(bs: Binders, tp1: Type, tps2: List[Type]): Int =
finishHash(bs, hashSeed, 0, tp1, tps2)

protected final def doHash(bs: Binders | Null, x1: Any, tp2: Type, tps3: List[Type]): Int =
protected final def doHash(bs: Binders, x1: Any, tp2: Type, tps3: List[Type]): Int =
finishHash(bs, hashing.mix(hashSeed, x1.hashCode), 1, tp2, tps3)

protected final def doHash(x1: Int, x2: Int): Int =
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ object TypeErasure {
*/
abstract case class ErasedValueType(tycon: TypeRef, erasedUnderlying: Type)
extends CachedGroundType with ValueType {
override def computeHash(bs: Hashable.Binders | Null): Int = doHash(bs, tycon, erasedUnderlying)
override def computeHash(bs: Hashable.Binders): Int = doHash(bs, tycon, erasedUnderlying)
}

final class CachedErasedValueType(tycon: TypeRef, erasedUnderlying: Type)
Expand Down
Loading

0 comments on commit a20aaf8

Please sign in to comment.