summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/build/maven/scala-actors-pom.xml11
-rw-r--r--src/build/maven/scala-compiler-doc-pom.xml11
-rw-r--r--src/build/maven/scala-compiler-interactive-pom.xml11
-rw-r--r--src/build/maven/scala-compiler-pom.xml13
-rw-r--r--src/build/maven/scala-dist-pom.xml11
-rw-r--r--src/build/maven/scala-library-all-pom.xml11
-rw-r--r--src/build/maven/scala-library-pom.xml11
-rw-r--r--src/build/maven/scala-reflect-pom.xml11
-rw-r--r--src/build/maven/scalap-pom.xml11
-rw-r--r--src/compiler/scala/tools/reflect/quasiquotes/Placeholders.scala37
-rw-r--r--src/compiler/scala/tools/reflect/quasiquotes/Quasiquotes.scala6
-rw-r--r--src/compiler/scala/tools/reflect/quasiquotes/Reifiers.scala40
-rw-r--r--src/interactive/scala/tools/nsc/interactive/ContextTrees.scala16
-rw-r--r--src/reflect/scala/reflect/internal/StdNames.scala51
14 files changed, 89 insertions, 162 deletions
diff --git a/src/build/maven/scala-actors-pom.xml b/src/build/maven/scala-actors-pom.xml
index 424ac2898c..a0ebcecad1 100644
--- a/src/build/maven/scala-actors-pom.xml
+++ b/src/build/maven/scala-actors-pom.xml
@@ -38,17 +38,6 @@
<version>@VERSION@</version>
</dependency>
</dependencies>
- <distributionManagement>
- <repository>
- <id>scala-tools.org</id>
- <url>@RELEASE_REPOSITORY@</url>
- </repository>
- <snapshotRepository>
- <id>scala-tools.org</id>
- <url>@SNAPSHOT_REPOSITORY@</url>
- <uniqueVersion>false</uniqueVersion>
- </snapshotRepository>
- </distributionManagement>
<developers>
<developer>
<id>lamp</id>
diff --git a/src/build/maven/scala-compiler-doc-pom.xml b/src/build/maven/scala-compiler-doc-pom.xml
index 30161d2fea..8572e55b42 100644
--- a/src/build/maven/scala-compiler-doc-pom.xml
+++ b/src/build/maven/scala-compiler-doc-pom.xml
@@ -45,17 +45,6 @@
<version>@PARSER_COMBINATORS_VERSION@</version>
</dependency>
</dependencies>
- <distributionManagement>
- <repository>
- <id>scala-tools.org</id>
- <url>@RELEASE_REPOSITORY@</url>
- </repository>
- <snapshotRepository>
- <id>scala-tools.org</id>
- <url>@SNAPSHOT_REPOSITORY@</url>
- <uniqueVersion>false</uniqueVersion>
- </snapshotRepository>
- </distributionManagement>
<developers>
<developer>
<id>lamp</id>
diff --git a/src/build/maven/scala-compiler-interactive-pom.xml b/src/build/maven/scala-compiler-interactive-pom.xml
index d59f305a9f..ad8192b694 100644
--- a/src/build/maven/scala-compiler-interactive-pom.xml
+++ b/src/build/maven/scala-compiler-interactive-pom.xml
@@ -35,17 +35,6 @@
<version>@VERSION@</version>
</dependency>
</dependencies>
- <distributionManagement>
- <repository>
- <id>scala-tools.org</id>
- <url>@RELEASE_REPOSITORY@</url>
- </repository>
- <snapshotRepository>
- <id>scala-tools.org</id>
- <url>@SNAPSHOT_REPOSITORY@</url>
- <uniqueVersion>false</uniqueVersion>
- </snapshotRepository>
- </distributionManagement>
<developers>
<developer>
<id>lamp</id>
diff --git a/src/build/maven/scala-compiler-pom.xml b/src/build/maven/scala-compiler-pom.xml
index 4a000b27a1..8ca18f6f14 100644
--- a/src/build/maven/scala-compiler-pom.xml
+++ b/src/build/maven/scala-compiler-pom.xml
@@ -39,7 +39,7 @@
<artifactId>scala-reflect</artifactId>
<version>@VERSION@</version>
</dependency>
- <!-- TODO modularize compiler: these dependencies will disappear then the compiler is modularized -->
+ <!-- TODO modularize compiler: these dependencies will disappear when the compiler is modularized -->
<dependency> <!-- for scala-compiler-doc -->
<groupId>org.scala-lang.modules</groupId>
<artifactId>scala-xml_@SCALA_BINARY_VERSION@</artifactId>
@@ -57,17 +57,6 @@
<optional>true</optional>
</dependency>
</dependencies>
- <distributionManagement>
- <repository>
- <id>scala-tools.org</id>
- <url>@RELEASE_REPOSITORY@</url>
- </repository>
- <snapshotRepository>
- <id>scala-tools.org</id>
- <url>@SNAPSHOT_REPOSITORY@</url>
- <uniqueVersion>false</uniqueVersion>
- </snapshotRepository>
- </distributionManagement>
<developers>
<developer>
<id>lamp</id>
diff --git a/src/build/maven/scala-dist-pom.xml b/src/build/maven/scala-dist-pom.xml
index 413da928bb..9a566d231b 100644
--- a/src/build/maven/scala-dist-pom.xml
+++ b/src/build/maven/scala-dist-pom.xml
@@ -51,17 +51,6 @@
<version>@JLINE_VERSION@</version>
</dependency>
</dependencies>
- <distributionManagement>
- <repository>
- <id>scala-tools.org</id>
- <url>@RELEASE_REPOSITORY@</url>
- </repository>
- <snapshotRepository>
- <id>scala-tools.org</id>
- <url>@SNAPSHOT_REPOSITORY@</url>
- <uniqueVersion>false</uniqueVersion>
- </snapshotRepository>
- </distributionManagement>
<developers>
<developer>
<id>lamp</id>
diff --git a/src/build/maven/scala-library-all-pom.xml b/src/build/maven/scala-library-all-pom.xml
index f34a28e79a..b649c8c525 100644
--- a/src/build/maven/scala-library-all-pom.xml
+++ b/src/build/maven/scala-library-all-pom.xml
@@ -75,17 +75,6 @@
<version>@ACTORS_MIGRATION_VERSION@</version>
</dependency>
</dependencies>
- <distributionManagement>
- <repository>
- <id>scala-tools.org</id>
- <url>@RELEASE_REPOSITORY@</url>
- </repository>
- <snapshotRepository>
- <id>scala-tools.org</id>
- <url>@SNAPSHOT_REPOSITORY@</url>
- <uniqueVersion>false</uniqueVersion>
- </snapshotRepository>
- </distributionManagement>
<developers>
<developer>
<id>lamp</id>
diff --git a/src/build/maven/scala-library-pom.xml b/src/build/maven/scala-library-pom.xml
index d40cee2656..78fc05a7c3 100644
--- a/src/build/maven/scala-library-pom.xml
+++ b/src/build/maven/scala-library-pom.xml
@@ -33,17 +33,6 @@
</properties>
<dependencies>
</dependencies>
- <distributionManagement>
- <repository>
- <id>scala-tools.org</id>
- <url>@RELEASE_REPOSITORY@</url>
- </repository>
- <snapshotRepository>
- <id>scala-tools.org</id>
- <url>@SNAPSHOT_REPOSITORY@</url>
- <uniqueVersion>false</uniqueVersion>
- </snapshotRepository>
- </distributionManagement>
<developers>
<developer>
<id>lamp</id>
diff --git a/src/build/maven/scala-reflect-pom.xml b/src/build/maven/scala-reflect-pom.xml
index d0a9c0e274..c21caefcf2 100644
--- a/src/build/maven/scala-reflect-pom.xml
+++ b/src/build/maven/scala-reflect-pom.xml
@@ -38,17 +38,6 @@
<version>@VERSION@</version>
</dependency>
</dependencies>
- <distributionManagement>
- <repository>
- <id>scala-tools.org</id>
- <url>@RELEASE_REPOSITORY@</url>
- </repository>
- <snapshotRepository>
- <id>scala-tools.org</id>
- <url>@SNAPSHOT_REPOSITORY@</url>
- <uniqueVersion>false</uniqueVersion>
- </snapshotRepository>
- </distributionManagement>
<developers>
<developer>
<id>lamp</id>
diff --git a/src/build/maven/scalap-pom.xml b/src/build/maven/scalap-pom.xml
index 88cfce08d8..236ac999fc 100644
--- a/src/build/maven/scalap-pom.xml
+++ b/src/build/maven/scalap-pom.xml
@@ -35,17 +35,6 @@
<version>@VERSION@</version>
</dependency>
</dependencies>
- <distributionManagement>
- <repository>
- <id>scala-tools.org</id>
- <url>@RELEASE_REPOSITORY@</url>
- </repository>
- <snapshotRepository>
- <id>scala-tools.org</id>
- <url>@SNAPSHOT_REPOSITORY@</url>
- <uniqueVersion>false</uniqueVersion>
- </snapshotRepository>
- </distributionManagement>
<developers>
<developer>
<id>lamp</id>
diff --git a/src/compiler/scala/tools/reflect/quasiquotes/Placeholders.scala b/src/compiler/scala/tools/reflect/quasiquotes/Placeholders.scala
index 5669ec731f..825d0c04f3 100644
--- a/src/compiler/scala/tools/reflect/quasiquotes/Placeholders.scala
+++ b/src/compiler/scala/tools/reflect/quasiquotes/Placeholders.scala
@@ -17,7 +17,6 @@ trait Placeholders { self: Quasiquotes =>
// Step 1: Transform Scala source with holes into vanilla Scala source
- lazy val holeMap = new HoleMap()
lazy val posMap = mutable.ListMap[Position, (Int, Int)]()
lazy val code = {
val sb = new StringBuilder()
@@ -58,25 +57,27 @@ trait Placeholders { self: Quasiquotes =>
sb.toString
}
- class HoleMap {
- private var underlying = immutable.SortedMap[String, Hole]()
- private val accessed = mutable.Set[String]()
+ object holeMap {
+ private val underlying = mutable.LinkedHashMap.empty[String, Hole]
+ private val accessed = mutable.Set.empty[String]
def unused: Set[Name] = (underlying.keys.toSet -- accessed).map(TermName(_))
- def contains(key: Name) = underlying.contains(key.toString)
- def apply(key: Name) = {
- val s = key.toString
- accessed += s
- underlying(s)
- }
- def update(key: Name, hole: Hole) = {
+ def contains(key: Name): Boolean = underlying.contains(key.toString)
+ def apply(key: Name): Hole = {
+ val skey = key.toString
+ val value = underlying(skey)
+ accessed += skey
+ value
+ }
+ def update(key: Name, hole: Hole) =
underlying += key.toString -> hole
+ def get(key: Name): Option[Hole] = {
+ val skey = key.toString
+ underlying.get(skey).map { v =>
+ accessed += skey
+ v
+ }
}
- def get(key: Name) = {
- val s = key.toString
- accessed += s
- underlying.get(s)
- }
- def toList = underlying.toList
+ def keysIterator: Iterator[TermName] = underlying.keysIterator.map(TermName(_))
}
// Step 2: Transform vanilla Scala AST into an AST with holes
@@ -179,4 +180,4 @@ trait Placeholders { self: Quasiquotes =>
case _ => None
}
}
-} \ No newline at end of file
+}
diff --git a/src/compiler/scala/tools/reflect/quasiquotes/Quasiquotes.scala b/src/compiler/scala/tools/reflect/quasiquotes/Quasiquotes.scala
index 3e703924e8..396688c437 100644
--- a/src/compiler/scala/tools/reflect/quasiquotes/Quasiquotes.scala
+++ b/src/compiler/scala/tools/reflect/quasiquotes/Quasiquotes.scala
@@ -16,7 +16,7 @@ abstract class Quasiquotes extends Parsers
lazy val (universe: Tree, args, parts, parse, reify, method) = c.macroApplication match {
case Apply(build.SyntacticTypeApplied(Select(Select(Apply(Select(universe0, _), List(Apply(_, parts0))), interpolator0), method0), _), args0) =>
- debug(s"\nparse prefix:\nuniverse=$universe0\nparts=$parts0\ninterpolator=$interpolator0\nmethod=$method0\nargs=$args0\n")
+ debug(s"parse prefix:\nuniverse=$universe0\nparts=$parts0\ninterpolator=$interpolator0\nmethod=$method0\nargs=$args0\n")
val parts1 = parts0.map {
case lit @ Literal(Constant(s: String)) => s -> lit.pos
case part => c.abort(part.pos, "Quasiquotes can only be used with literal strings")
@@ -43,8 +43,8 @@ abstract class Quasiquotes extends Parsers
lazy val universeTypes = new definitions.UniverseDependentTypes(universe)
def expandQuasiquote = {
- debug(s"\nmacro application:\n${c.macroApplication}\n")
- debug(s"\ncode to parse:\n$code\n")
+ debug(s"macro application:\n${c.macroApplication}\n")
+ debug(s"code to parse:\n$code\n")
val tree = parse(code)
debug(s"parsed:\n${showRaw(tree)}\n$tree\n")
val reified = reify(tree)
diff --git a/src/compiler/scala/tools/reflect/quasiquotes/Reifiers.scala b/src/compiler/scala/tools/reflect/quasiquotes/Reifiers.scala
index 273245f7bd..0c73214745 100644
--- a/src/compiler/scala/tools/reflect/quasiquotes/Reifiers.scala
+++ b/src/compiler/scala/tools/reflect/quasiquotes/Reifiers.scala
@@ -29,7 +29,7 @@ trait Reifiers { self: Quasiquotes =>
/** Map that stores freshly generated names linked to the corresponding names in the reified tree.
* This information is used to reify names created by calls to freshTermName and freshTypeName.
*/
- var nameMap = collection.mutable.HashMap.empty[Name, Set[TermName]].withDefault { _ => Set() }
+ val nameMap = collection.mutable.HashMap.empty[Name, Set[TermName]].withDefault { _ => Set() }
/** Wraps expressions into:
* a block which starts with a sequence of vals that correspond
@@ -71,7 +71,7 @@ trait Reifiers { self: Quasiquotes =>
// q"..$freshdefs; $tree"
SyntacticBlock(freshdefs :+ tree)
} else {
- val freevars = holeMap.toList.map { case (name, _) => Ident(name) }
+ val freevars = holeMap.keysIterator.map(Ident(_)).toList
val isVarPattern = tree match { case Bind(name, Ident(nme.WILDCARD)) => true case _ => false }
val cases =
if(isVarPattern) {
@@ -162,7 +162,7 @@ trait Reifiers { self: Quasiquotes =>
reifyBuildCall(nme.SyntacticNew, earlyDefs, parents, selfdef, body)
case SyntacticDefDef(mods, name, tparams, build.ImplicitParams(vparamss, implparams), tpt, rhs) =>
if (implparams.nonEmpty)
- mirrorBuildCall(nme.SyntacticDefDef, reify(mods), reify(name), reify(tparams),
+ mirrorBuildCall(nme.SyntacticDefDef, reify(mods), reify(name), reify(tparams),
reifyBuildCall(nme.ImplicitParams, vparamss, implparams), reify(tpt), reify(rhs))
else
reifyBuildCall(nme.SyntacticDefDef, mods, name, tparams, vparamss, tpt, rhs)
@@ -305,7 +305,7 @@ trait Reifiers { self: Quasiquotes =>
* > reifyMultiCardinalityList(lst) { ... } { ... }
* q"List($foo, $bar) ++ ${holeMap(qq$f3948f9s$1).tree}"
*/
- def reifyMultiCardinalityList[T](xs: List[T])(fill: PartialFunction[T, Tree])(fallback: T => Tree): Tree
+ def reifyMultiCardinalityList(xs: List[Any])(fill: PartialFunction[Any, Tree])(fallback: Any => Tree): Tree
/** Reifies arbitrary list filling ..$x and ...$y holeMap when they are put
* in the correct position. Fallbacks to regular reification for non-high cardinality
@@ -361,10 +361,10 @@ trait Reifiers { self: Quasiquotes =>
}
class ApplyReifier extends Reifier(isReifyingExpressions = true) {
- def reifyMultiCardinalityList[T](xs: List[T])(fill: PartialFunction[T, Tree])(fallback: T => Tree): Tree =
+ def reifyMultiCardinalityList(xs: List[Any])(fill: PartialFunction[Any, Tree])(fallback: Any => Tree): Tree =
if (xs.isEmpty) mkList(Nil)
else {
- def reifyGroup(group: List[T]): Tree = group match {
+ def reifyGroup(group: List[Any]): Tree = group match {
case List(elem) if fill.isDefinedAt(elem) => fill(elem)
case elems => mkList(elems.map(fallback))
}
@@ -403,14 +403,26 @@ trait Reifiers { self: Quasiquotes =>
}
class UnapplyReifier extends Reifier(isReifyingExpressions = false) {
- def reifyMultiCardinalityList[T](xs: List[T])(fill: PartialFunction[T, Tree])(fallback: T => Tree): Tree = xs match {
- case init :+ last if fill.isDefinedAt(last) =>
- init.foldRight[Tree](fill(last)) { (el, rest) =>
- val cons = Select(Select(Select(Ident(nme.scala_), nme.collection), nme.immutable), nme.CONS)
- Apply(cons, List(fallback(el), rest))
- }
- case _ =>
- mkList(xs.map(fallback))
+ private def collection = ScalaDot(nme.collection)
+ private def collectionColonPlus = Select(collection, nme.COLONPLUS)
+ private def collectionCons = Select(Select(collection, nme.immutable), nme.CONS)
+ private def collectionNil = Select(Select(collection, nme.immutable), nme.Nil)
+ // pq"$lhs :+ $rhs"
+ private def append(lhs: Tree, rhs: Tree) = Apply(collectionColonPlus, lhs :: rhs :: Nil)
+ // pq"$lhs :: $rhs"
+ private def cons(lhs: Tree, rhs: Tree) = Apply(collectionCons, lhs :: rhs :: Nil)
+
+ def reifyMultiCardinalityList(xs: List[Any])(fill: PartialFunction[Any, Tree])(fallback: Any => Tree): Tree = {
+ val grouped = group(xs) { (a, b) => !fill.isDefinedAt(a) && !fill.isDefinedAt(b) }
+ def appended(lst: List[Any], init: Tree) = lst.foldLeft(init) { (l, r) => append(l, fallback(r)) }
+ def prepended(lst: List[Any], init: Tree) = lst.foldRight(init) { (l, r) => cons(fallback(l), r) }
+ grouped match {
+ case init :: List(hole) :: last :: Nil if fill.isDefinedAt(hole) => appended(last, prepended(init, fill(hole)))
+ case init :: List(hole) :: Nil if fill.isDefinedAt(hole) => prepended(init, fill(hole))
+ case List(hole) :: last :: Nil if fill.isDefinedAt(hole) => appended(last, fill(hole))
+ case List(hole) :: Nil if fill.isDefinedAt(hole) => fill(hole)
+ case _ => prepended(xs, collectionNil)
+ }
}
override def reifyModifiers(m: Modifiers) =
diff --git a/src/interactive/scala/tools/nsc/interactive/ContextTrees.scala b/src/interactive/scala/tools/nsc/interactive/ContextTrees.scala
index 4f67a22b8f..bf718c27cc 100644
--- a/src/interactive/scala/tools/nsc/interactive/ContextTrees.scala
+++ b/src/interactive/scala/tools/nsc/interactive/ContextTrees.scala
@@ -64,9 +64,12 @@ trait ContextTrees { self: Global =>
def locateContextTree(contexts: Contexts, pos: Position): Option[ContextTree] = {
if (contexts.isEmpty) None
else {
+ // binary search on contexts, loop invar: lo <= hi, recursion metric: `hi - lo`
@tailrec
def loop(lo: Int, hi: Int, previousSibling: Option[ContextTree]): Option[ContextTree] = {
- if (pos properlyPrecedes contexts(lo).pos)
+ // [SI-8239] enforce loop invariant & ensure recursion metric decreases monotonically on every recursion
+ if (lo > hi) previousSibling
+ else if (pos properlyPrecedes contexts(lo).pos)
previousSibling
else if (contexts(hi).pos properlyPrecedes pos)
Some(contexts(hi))
@@ -76,9 +79,18 @@ trait ContextTrees { self: Global =>
if (midpos includes pos)
Some(contexts(mid))
else if (midpos properlyPrecedes pos)
+ // recursion metric: (hi - ((lo + hi)/2 + 1)) < (hi - lo)
+ // since (hi - ((lo + hi)/2 + 1)) - (hi - lo) = lo - ((lo + hi)/2 + 1) < 0
+ // since 2*lo - lo - hi - 2 = lo - hi - 2 < 0
+ // since lo < hi + 2
+ // can violate lo <= hi, hence the lo > hi check at the top [SI-8239]
loop(mid + 1, hi, Some(contexts(mid)))
- else
+ else if (lo != hi) // avoid looping forever (lo == hi violates the recursion metric) [SI-8239]
+ // recursion metric: ((lo + hi)/2) - lo < (hi - lo)
+ // since ((lo + hi)/2) - lo - (hi - lo) = ((lo + hi)/2) - hi < 0
+ // since 2 * (((lo + hi)/2) - hi) = lo - hi < 0 since lo < hi
loop(lo, mid, previousSibling)
+ else previousSibling
}
}
loop(0, contexts.length - 1, None)
diff --git a/src/reflect/scala/reflect/internal/StdNames.scala b/src/reflect/scala/reflect/internal/StdNames.scala
index 28d799ea0c..53475be479 100644
--- a/src/reflect/scala/reflect/internal/StdNames.scala
+++ b/src/reflect/scala/reflect/internal/StdNames.scala
@@ -822,31 +822,32 @@ trait StdNames {
def newLazyValSlowComputeName(lzyValName: Name) = lzyValName append LAZY_SLOW_SUFFIX
// ASCII names for operators
- val ADD = encode("+")
- val AND = encode("&")
- val ASR = encode(">>")
- val CONS = encode("::")
- val DIV = encode("/")
- val EQ = encode("==")
- val EQL = encode("=")
- val GE = encode(">=")
- val GT = encode(">")
- val HASHHASH = encode("##")
- val LE = encode("<=")
- val LSL = encode("<<")
- val LSR = encode(">>>")
- val LT = encode("<")
- val MINUS = encode("-")
- val MOD = encode("%")
- val MUL = encode("*")
- val NE = encode("!=")
- val OR = encode("|")
- val PLUS = ADD // technically redundant, but ADD looks funny with MINUS
- val PLUSPLUS = encode("++")
- val SUB = MINUS // ... as does SUB with PLUS
- val XOR = encode("^")
- val ZAND = encode("&&")
- val ZOR = encode("||")
+ val ADD = encode("+")
+ val AND = encode("&")
+ val ASR = encode(">>")
+ val CONS = encode("::")
+ val COLONPLUS = encode(":+")
+ val DIV = encode("/")
+ val EQ = encode("==")
+ val EQL = encode("=")
+ val GE = encode(">=")
+ val GT = encode(">")
+ val HASHHASH = encode("##")
+ val LE = encode("<=")
+ val LSL = encode("<<")
+ val LSR = encode(">>>")
+ val LT = encode("<")
+ val MINUS = encode("-")
+ val MOD = encode("%")
+ val MUL = encode("*")
+ val NE = encode("!=")
+ val OR = encode("|")
+ val PLUS = ADD // technically redundant, but ADD looks funny with MINUS
+ val PLUSPLUS = encode("++")
+ val SUB = MINUS // ... as does SUB with PLUS
+ val XOR = encode("^")
+ val ZAND = encode("&&")
+ val ZOR = encode("||")
// unary operators
val UNARY_~ = encode("unary_~")