Skip to content

Commit

Permalink
Merge pull request #2716 from dotty-staging/fix-#2570-2
Browse files Browse the repository at this point in the history
Fix #2570: Part 3 - The great () insert
  • Loading branch information
odersky committed Jun 23, 2017
2 parents 94e45f4 + b7afd43 commit d1f7968
Show file tree
Hide file tree
Showing 128 changed files with 737 additions and 488 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -70,3 +70,4 @@ compiler/test/debug/Gen.jar

compiler/before-pickling.txt
compiler/after-pickling.txt
*.dotty-ide-version
2 changes: 1 addition & 1 deletion collection-strawman
Submodule collection-strawman updated 60 files
+1 −1 .travis.yml
+24 −3 CONTRIBUTING.md
+6 −0 README.md
+5 −3 benchmarks/memory/src/main/scala/strawman/collection/MemoryFootprint.scala
+90 −0 benchmarks/time/src/main/scala/strawman/collection/immutable/ImmutableArrayBenchmark.scala
+58 −0 benchmarks/time/src/main/scala/strawman/collection/immutable/PrimitiveArrayBenchmark.scala
+58 −0 benchmarks/time/src/main/scala/strawman/collection/immutable/ScalaVectorBenchmark.scala
+2 −2 build.sbt
+2 −1 src/main/scala/strawman/collection/ArrayOps.scala
+1 −1 src/main/scala/strawman/collection/BitSet.scala
+79 −38 src/main/scala/strawman/collection/Factories.scala
+31 −4 src/main/scala/strawman/collection/Iterable.scala
+8 −1 src/main/scala/strawman/collection/Map.scala
+3 −3 src/main/scala/strawman/collection/Seq.scala
+22 −11 src/main/scala/strawman/collection/Set.scala
+30 −16 src/main/scala/strawman/collection/SortedMap.scala
+1 −1 src/main/scala/strawman/collection/SortedOps.scala
+6 −24 src/main/scala/strawman/collection/SortedSet.scala
+5 −5 src/main/scala/strawman/collection/StringOps.scala
+13 −6 src/main/scala/strawman/collection/View.scala
+4 −4 src/main/scala/strawman/collection/immutable/BitSet.scala
+9 −8 src/main/scala/strawman/collection/immutable/HashMap.scala
+5 −6 src/main/scala/strawman/collection/immutable/HashSet.scala
+103 −0 src/main/scala/strawman/collection/immutable/ImmutableArray.scala
+3 −4 src/main/scala/strawman/collection/immutable/LazyList.scala
+15 −16 src/main/scala/strawman/collection/immutable/List.scala
+8 −1 src/main/scala/strawman/collection/immutable/ListMap.scala
+7 −3 src/main/scala/strawman/collection/immutable/ListSet.scala
+10 −17 src/main/scala/strawman/collection/immutable/Map.scala
+1 −1 src/main/scala/strawman/collection/immutable/RedBlackTree.scala
+9 −5 src/main/scala/strawman/collection/immutable/Seq.scala
+6 −8 src/main/scala/strawman/collection/immutable/Set.scala
+16 −2 src/main/scala/strawman/collection/immutable/SortedMap.scala
+1 −4 src/main/scala/strawman/collection/immutable/SortedSet.scala
+16 −14 src/main/scala/strawman/collection/immutable/TreeMap.scala
+7 −7 src/main/scala/strawman/collection/immutable/TreeSet.scala
+1 −1 src/main/scala/strawman/collection/immutable/TrieIterator.scala
+7 −9 src/main/scala/strawman/collection/mutable/ArrayBuffer.scala
+95 −9 src/main/scala/strawman/collection/mutable/BitSet.scala
+5 −5 src/main/scala/strawman/collection/mutable/Builder.scala
+426 −0 src/main/scala/strawman/collection/mutable/FlatHashTable.scala
+20 −6 src/main/scala/strawman/collection/mutable/Growable.scala
+22 −0 src/main/scala/strawman/collection/mutable/GrowableBuilder.scala
+95 −19 src/main/scala/strawman/collection/mutable/HashMap.scala
+63 −30 src/main/scala/strawman/collection/mutable/HashSet.scala
+464 −0 src/main/scala/strawman/collection/mutable/HashTable.scala
+27 −2 src/main/scala/strawman/collection/mutable/Iterable.scala
+9 −7 src/main/scala/strawman/collection/mutable/ListBuffer.scala
+76 −13 src/main/scala/strawman/collection/mutable/Map.scala
+590 −0 src/main/scala/strawman/collection/mutable/RedBlackTree.scala
+10 −7 src/main/scala/strawman/collection/mutable/Seq.scala
+43 −40 src/main/scala/strawman/collection/mutable/Set.scala
+68 −0 src/main/scala/strawman/collection/mutable/Shrinkable.scala
+18 −0 src/main/scala/strawman/collection/mutable/SortedMap.scala
+13 −2 src/main/scala/strawman/collection/mutable/SortedSet.scala
+182 −0 src/main/scala/strawman/collection/mutable/TreeMap.scala
+184 −0 src/main/scala/strawman/collection/mutable/TreeSet.scala
+28 −78 src/main/scala/strawman/collection/package.scala
+57 −1 src/test/scala/strawman/collection/test/Test.scala
+53 −77 src/test/scala/strawman/collection/test/TraverseTest.scala
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Expand Up @@ -69,7 +69,7 @@ object desugar {
val originalOwner = sym.owner
def apply(tp: Type) = tp match {
case tp: NamedType if tp.symbol.exists && (tp.symbol.owner eq originalOwner) =>
val defctx = ctx.outersIterator.dropWhile(_.scope eq ctx.scope).next
val defctx = ctx.outersIterator.dropWhile(_.scope eq ctx.scope).next()
var local = defctx.denotNamed(tp.name).suchThat(_ is ParamOrAccessor).symbol
if (local.exists) (defctx.owner.thisType select local).dealias
else {
Expand Down Expand Up @@ -538,12 +538,12 @@ object desugar {
val cdef1 = addEnumFlags {
val originalTparamsIt = originalTparams.toIterator
val originalVparamsIt = originalVparamss.toIterator.flatten
val tparamAccessors = derivedTparams.map(_.withMods(originalTparamsIt.next.mods))
val tparamAccessors = derivedTparams.map(_.withMods(originalTparamsIt.next().mods))
val caseAccessor = if (isCaseClass) CaseAccessor else EmptyFlags
val vparamAccessors = derivedVparamss match {
case first :: rest =>
first.map(_.withMods(originalVparamsIt.next.mods | caseAccessor)) ++
rest.flatten.map(_.withMods(originalVparamsIt.next.mods))
first.map(_.withMods(originalVparamsIt.next().mods | caseAccessor)) ++
rest.flatten.map(_.withMods(originalVparamsIt.next().mods))
case _ =>
Nil
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/NavigateAST.scala
Expand Up @@ -70,7 +70,7 @@ object NavigateAST {
def pathTo(pos: Position, from: Positioned, skipZeroExtent: Boolean = false)(implicit ctx: Context): List[Positioned] = {
def childPath(it: Iterator[Any], path: List[Positioned]): List[Positioned] = {
while (it.hasNext) {
val path1 = it.next match {
val path1 = it.next() match {
case p: Positioned => singlePath(p, path)
case xs: List[_] => childPath(xs.iterator, path)
case _ => path
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Expand Up @@ -53,7 +53,7 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
def map[R](f: (Symbol, Tree) => R): List[R] = {
val b = List.newBuilder[R]
foreach(b += f(_, _))
b.result
b.result()
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Trees.scala
Expand Up @@ -129,7 +129,7 @@ object Trees {
private def checkChildrenTyped(it: Iterator[Any])(implicit ctx: Context): Unit =
if (!this.isInstanceOf[Import[_]])
while (it.hasNext)
it.next match {
it.next() match {
case x: Ident[_] => // untyped idents are used in a number of places in typed trees
case x: Tree[_] =>
assert(x.hasType || ctx.reporter.errorsReported,
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Expand Up @@ -348,15 +348,15 @@ object Contexts {
*/
def thisCallArgContext: Context = {
assert(owner.isClassConstructor)
val constrCtx = outersIterator.dropWhile(_.outer.owner == owner).next
val constrCtx = outersIterator.dropWhile(_.outer.owner == owner).next()
superOrThisCallContext(owner, constrCtx.scope)
.setTyperState(typerState)
.setGadt(gadt)
}

/** The super- or this-call context with given owner and locals. */
private def superOrThisCallContext(owner: Symbol, locals: Scope): FreshContext = {
var classCtx = outersIterator.dropWhile(!_.isClassDefContext).next
var classCtx = outersIterator.dropWhile(!_.isClassDefContext).next()
classCtx.outer.fresh.setOwner(owner)
.setScope(locals)
.setMode(classCtx.mode | Mode.InSuperCall)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Decorators.scala
Expand Up @@ -37,7 +37,7 @@ object Decorators {
implicit class SymbolIteratorDecorator(val it: Iterator[Symbol]) extends AnyVal {
final def findSymbol(p: Symbol => Boolean): Symbol = {
while (it.hasNext) {
val sym = it.next
val sym = it.next()
if (p(sym)) return sym
}
NoSymbol
Expand Down
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Denotations.scala
Expand Up @@ -408,7 +408,8 @@ object Denotations {

/** Sym preference provided types also override */
def prefer(sym1: Symbol, sym2: Symbol, info1: Type, info2: Type) =
preferSym(sym1, sym2) && info1.overrides(info2)
preferSym(sym1, sym2) &&
info1.overrides(info2, sym1.matchNullaryLoosely || sym2.matchNullaryLoosely)

def handleDoubleDef =
if (preferSym(sym1, sym2)) denot1
Expand Down Expand Up @@ -512,7 +513,7 @@ object Denotations {
def lubSym(overrides: Iterator[Symbol], previous: Symbol): Symbol =
if (!overrides.hasNext) previous
else {
val candidate = overrides.next
val candidate = overrides.next()
if (owner2 derivesFrom candidate.owner)
if (candidate isAccessibleFrom pre) candidate
else lubSym(overrides, previous orElse candidate)
Expand Down Expand Up @@ -779,7 +780,7 @@ object Denotations {
}

if (valid.runId != currentPeriod.runId)
if (exists) initial.bringForward.current
if (exists) initial.bringForward().current
else this
else {
var cur = this
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Phases.scala
Expand Up @@ -28,7 +28,7 @@ trait Phases {
if ((this eq NoContext) || !phase.exists) Nil
else {
val rest = outersIterator.dropWhile(_.phase == phase)
phase :: (if (rest.hasNext) rest.next.phasesStack else Nil)
phase :: (if (rest.hasNext) rest.next().phasesStack else Nil)
}

/** Execute `op` at given phase */
Expand Down
17 changes: 15 additions & 2 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Expand Up @@ -763,6 +763,20 @@ object SymDenotations {

def isInlineMethod(implicit ctx: Context): Boolean = is(InlineMethod, butNot = Accessor)

/** ()T and => T types should be treated as equivalent for this symbol.
* Note: For the moment, we treat Scala-2 compiled symbols as loose matching,
* because the Scala library does not always follow the right conventions.
* Examples are: isWhole(), toInt(), toDouble() in BigDecimal, Numeric, RichInt, ScalaNumberProxy.
*/
def matchNullaryLoosely(implicit ctx: Context): Boolean = {
def test(sym: Symbol) =
sym.is(JavaDefined) ||
sym.owner == defn.AnyClass ||
sym == defn.Object_clone ||
sym.owner.is(Scala2x)
test(symbol) || allOverriddenSymbols.exists(test)
}

// ------ access to related symbols ---------------------------------

/* Modules and module classes are represented as follows:
Expand Down Expand Up @@ -938,7 +952,6 @@ object SymDenotations {
else if (this.isClass) companionNamed(effectiveName.moduleClassName).sourceModule.moduleClass
else NoSymbol


/** Find companion class symbol with given name, or NoSymbol if none exists.
* Three alternative strategies:
* 1. If owner is a class, look in its members, otherwise
Expand All @@ -962,7 +975,7 @@ object SymDenotations {
else if (ctx.scope.lookup(this.name) == symbol)
ctx.scope.lookup(name)
else
companionNamed(name)(ctx.outersIterator.dropWhile(_.scope eq ctx.scope).next)
companionNamed(name)(ctx.outersIterator.dropWhile(_.scope eq ctx.scope).next())

/** Is this symbol the same or a linked class of `sym`? */
final def isLinkedWith(sym: Symbol)(implicit ctx: Context): Boolean =
Expand Down
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TypeOps.scala
Expand Up @@ -518,8 +518,11 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
def dynamicsEnabled =
featureEnabled(defn.LanguageModuleClass, nme.dynamics)

def testScala2Mode(msg: => String, pos: Position) = {
if (scala2Mode) migrationWarning(msg, pos)
def testScala2Mode(msg: => String, pos: Position, rewrite: => Unit = ()) = {
if (scala2Mode) {
migrationWarning(msg, pos)
rewrite
}
scala2Mode
}
}
Expand Down
26 changes: 14 additions & 12 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Expand Up @@ -769,21 +769,23 @@ object Types {
def relaxed_<:<(that: Type)(implicit ctx: Context) =
(this <:< that) || (this isValueSubType that)

/** Is this type a legal type for a member that overrides another
* member of type `that`? This is the same as `<:<`, except that
* the types `()T`, `=> T` and `T` are seen as overriding
* each other.
/** Is this type a legal type for member `sym1` that overrides another
* member `sym2` of type `that`? This is the same as `<:<`, except that
* if `matchLoosely` evaluates to true the types `=> T` and `()T` are seen
* as overriding each other.
*/
final def overrides(that: Type)(implicit ctx: Context) = {
def result(tp: Type): Type = tp match {
case ExprType(_) | MethodType(Nil) => tp.resultType
final def overrides(that: Type, matchLoosely: => Boolean)(implicit ctx: Context): Boolean = {
def widenNullary(tp: Type) = tp match {
case tp @ MethodType(Nil) => tp.resultType
case _ => tp
}
(this frozen_<:< that) || {
val rthat = result(that)
val rthis = result(this)
(rthat.ne(that) || rthis.ne(this)) && (rthis frozen_<:< rthat)
}
((this.widenExpr frozen_<:< that.widenExpr) ||
matchLoosely && {
val this1 = widenNullary(this)
val that1 = widenNullary(that)
((this1 `ne` this) || (that1 `ne` that)) && this1.overrides(this1, matchLoosely = false)
}
)
}

/** Is this type close enough to that type so that members
Expand Down
Expand Up @@ -54,7 +54,7 @@ class ClassfileParser(

def run()(implicit ctx: Context): Option[Embedded] = try {
ctx.debuglog("[class] >> " + classRoot.fullName)
parseHeader
parseHeader()
this.pool = new ConstantPool
parseClass()
} catch {
Expand Down Expand Up @@ -127,7 +127,7 @@ class ClassfileParser(
// might be reassigned by later parseAttributes
val staticInfo = TempClassInfoType(List(), staticScope, moduleRoot.symbol)

enterOwnInnerClasses
enterOwnInnerClasses()

classRoot.setFlag(sflags)
moduleRoot.setFlag(Flags.JavaDefined | Flags.ModuleClassCreationFlags)
Expand Down Expand Up @@ -185,7 +185,7 @@ class ClassfileParser(
}
// skip rest of member for now
in.nextChar // info
skipAttributes
skipAttributes()
}

val memberCompleter = new LazyType {
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/tasty/TastyReader.scala
Expand Up @@ -62,12 +62,12 @@ class TastyReader(val bytes: Array[Byte], start: Int, end: Int, val base: Int =
/** Read a natural number fitting in an Int in big endian format, base 128.
* All but the last digits have bit 0x80 set.
*/
def readNat(): Int = readLongNat.toInt
def readNat(): Int = readLongNat().toInt

/** Read an integer number in 2's complement big endian format, base 128.
* All but the last digits have bit 0x80 set.
*/
def readInt(): Int = readLongInt.toInt
def readInt(): Int = readLongInt().toInt

/** Read a natural number fitting in a Long in big endian format, base 128.
* All but the last digits have bit 0x80 set.
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/JavaScanners.scala
Expand Up @@ -435,7 +435,7 @@ object JavaScanners {
nextChar()
}
if (ch == 'e' || ch == 'E') {
val lookahead = lookaheadReader
val lookahead = lookaheadReader()
lookahead.nextChar()
if (lookahead.ch == '+' || lookahead.ch == '-') {
lookahead.nextChar()
Expand Down Expand Up @@ -475,7 +475,7 @@ object JavaScanners {
}
token = INTLIT
if (base <= 10 && ch == '.') {
val lookahead = lookaheadReader
val lookahead = lookaheadReader()
lookahead.nextChar()
lookahead.ch match {
case '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' |
Expand Down
30 changes: 15 additions & 15 deletions compiler/src/dotty/tools/dotc/parsing/MarkupParserCommon.scala
Expand Up @@ -36,7 +36,7 @@ private[dotty] trait MarkupParserCommon {
*/
protected def xTag(pscope: NamespaceType): (String, AttributesType) = {
val name = xName
xSpaceOpt
xSpaceOpt()

(name, mkAttributes(name, pscope))
}
Expand All @@ -47,7 +47,7 @@ private[dotty] trait MarkupParserCommon {
*/
def xProcInstr: ElementType = {
val n = xName
xSpaceOpt
xSpaceOpt()
xTakeUntil(mkProcInstr(_, n, _), () => tmppos, "?>")
}

Expand Down Expand Up @@ -75,7 +75,7 @@ private[dotty] trait MarkupParserCommon {

private def takeUntilChar(it: Iterator[Char], end: Char): String = {
val buf = new StringBuilder
while (it.hasNext) it.next match {
while (it.hasNext) it.next() match {
case `end` => return buf.toString
case ch => buf append ch
}
Expand All @@ -89,7 +89,7 @@ private[dotty] trait MarkupParserCommon {
if (xName != startName)
errorNoEnd(startName)

xSpaceOpt
xSpaceOpt()
xToken('>')
}

Expand Down Expand Up @@ -136,9 +136,9 @@ private[dotty] trait MarkupParserCommon {
val buf = new StringBuilder
val it = attval.iterator.buffered

while (it.hasNext) buf append (it.next match {
while (it.hasNext) buf append (it.next() match {
case ' ' | '\t' | '\n' | '\r' => " "
case '&' if it.head == '#' => it.next ; xCharRef(it)
case '&' if it.head == '#' => it.next() ; xCharRef(it)
case '&' => attr_unescape(takeUntilChar(it, ';'))
case c => c
})
Expand All @@ -155,11 +155,11 @@ private[dotty] trait MarkupParserCommon {
Utility.parseCharRef(ch, nextch, reportSyntaxError _, truncatedError _)

def xCharRef(it: Iterator[Char]): String = {
var c = it.next
Utility.parseCharRef(() => c, () => { c = it.next }, reportSyntaxError _, truncatedError _)
var c = it.next()
Utility.parseCharRef(() => c, () => { c = it.next() }, reportSyntaxError _, truncatedError _)
}

def xCharRef: String = xCharRef(() => ch, () => nextch)
def xCharRef: String = xCharRef(() => ch, nextch)

/** Create a lookahead reader which does not influence the input */
def lookahead(): BufferedIterator[Char]
Expand Down Expand Up @@ -192,20 +192,20 @@ private[dotty] trait MarkupParserCommon {
}

def xToken(that: Char): Unit = {
if (ch == that) nextch
if (ch == that) nextch()
else xHandleError(that, "'%s' expected instead of '%s'".format(that, ch))
}
def xToken(that: Seq[Char]): Unit = { that foreach xToken }

/** scan [S] '=' [S]*/
def xEQ() = { xSpaceOpt; xToken('='); xSpaceOpt }
def xEQ() = { xSpaceOpt(); xToken('='); xSpaceOpt() }

/** skip optional space S? */
def xSpaceOpt() = while (isSpace(ch) && !eof) nextch
def xSpaceOpt() = while (isSpace(ch) && !eof) nextch()

/** scan [3] S ::= (#x20 | #x9 | #xD | #xA)+ */
def xSpace() =
if (isSpace(ch)) { nextch; xSpaceOpt }
if (isSpace(ch)) { nextch(); xSpaceOpt() }
else xHandleError(ch, "whitespace expected")

/** Apply a function and return the passed value */
Expand Down Expand Up @@ -238,7 +238,7 @@ private[dotty] trait MarkupParserCommon {
truncatedError("") // throws TruncatedXMLControl in compiler

sb append ch
nextch
nextch()
}
unreachable
}
Expand All @@ -251,7 +251,7 @@ private[dotty] trait MarkupParserCommon {
private def peek(lookingFor: String): Boolean =
(lookahead() take lookingFor.length sameElements lookingFor.iterator) && {
// drop the chars from the real reader (all lookahead + orig)
(0 to lookingFor.length) foreach (_ => nextch)
(0 to lookingFor.length) foreach (_ => nextch())
true
}
}

0 comments on commit d1f7968

Please sign in to comment.