Skip to content

Commit

Permalink
Merge commit 'refs/pull/467/head'; commit 'refs/pull/468/head'; commi…
Browse files Browse the repository at this point in the history
…t 'refs/pull/469/head'; commit 'refs/pull/470/head' into develop
  • Loading branch information
paulp committed May 3, 2012
4 parents 3694082 + aabe71f + 7a5aaa9 + 4479791 commit aad241e
Show file tree
Hide file tree
Showing 209 changed files with 1,358 additions and 730 deletions.
2 changes: 0 additions & 2 deletions src/compiler/scala/reflect/internal/Definitions.scala
Expand Up @@ -412,8 +412,6 @@ trait Definitions extends reflect.api.StandardDefinitions {
lazy val JavaRepeatedParamClass = specialPolyClass(tpnme.JAVA_REPEATED_PARAM_CLASS_NAME, COVARIANT)(tparam => arrayType(tparam.tpe))
lazy val RepeatedParamClass = specialPolyClass(tpnme.REPEATED_PARAM_CLASS_NAME, COVARIANT)(tparam => seqType(tparam.tpe))

lazy val MarkerCPSTypes = getClassIfDefined("scala.util.continuations.cpsParam")

def isByNameParamType(tp: Type) = tp.typeSymbol == ByNameParamClass
def isScalaRepeatedParamType(tp: Type) = tp.typeSymbol == RepeatedParamClass
def isJavaRepeatedParamType(tp: Type) = tp.typeSymbol == JavaRepeatedParamClass
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/reflect/internal/Flags.scala
Expand Up @@ -260,7 +260,7 @@ class Flags extends ModifierFlags {

/** When a symbol for a default getter is created, it inherits these
* flags from the method with the default. Other flags applied at creation
* time are SYNTHETIC, DEFAULTPARAM, and possibly OVERRIDE.
* time are SYNTHETIC, DEFAULTPARAM, and possibly OVERRIDE, and maybe PRESUPER.
*/
final val DefaultGetterFlags = PRIVATE | PROTECTED | FINAL

Expand Down
5 changes: 1 addition & 4 deletions src/compiler/scala/reflect/internal/Required.scala
Expand Up @@ -5,10 +5,7 @@ import settings.MutableSettings

trait Required { self: SymbolTable =>

type AbstractFileType >: Null <: {
def path: String
def canonicalPath: String
}
type AbstractFileType >: Null <: api.RequiredFile

def picklerPhase: Phase

Expand Down
12 changes: 9 additions & 3 deletions src/compiler/scala/reflect/internal/StdNames.scala
Expand Up @@ -272,6 +272,7 @@ trait StdNames {
val BITMAP_PREFIX = "bitmap$"
val CHECK_IF_REFUTABLE_STRING = "check$ifrefutable$"
val DEFAULT_GETTER_STRING = "$default$"
val DEFAULT_GETTER_INIT_STRING = "$lessinit$greater" // CONSTRUCTOR.encoded, less is more
val DO_WHILE_PREFIX = "doWhile$"
val EVIDENCE_PARAM_PREFIX = "evidence$"
val EXCEPTION_RESULT_PREFIX = "exceptionResult"
Expand Down Expand Up @@ -413,14 +414,19 @@ trait StdNames {
name.subName(0, name.length - SETTER_SUFFIX.length)
}

// Nominally, name$default$N, encoded for <init>
def defaultGetterName(name: Name, pos: Int): TermName = {
val prefix = if (isConstructorName(name)) "init" else name
val prefix = if (isConstructorName(name)) DEFAULT_GETTER_INIT_STRING else name
newTermName(prefix + DEFAULT_GETTER_STRING + pos)
}
// Nominally, name from name$default$N, CONSTRUCTOR for <init>
def defaultGetterToMethod(name: Name): TermName = {
val p = name.pos(DEFAULT_GETTER_STRING)
if (p < name.length) name.toTermName.subName(0, p)
else name.toTermName
if (p < name.length) {
val q = name.toTermName.subName(0, p)
// i.e., if (q.decoded == CONSTRUCTOR.toString) CONSTRUCTOR else q
if (q.toString == DEFAULT_GETTER_INIT_STRING) CONSTRUCTOR else q
} else name.toTermName
}

// If the name ends with $nn where nn are
Expand Down
27 changes: 12 additions & 15 deletions src/compiler/scala/reflect/internal/SymbolTable.scala
Expand Up @@ -280,16 +280,8 @@ abstract class SymbolTable extends api.Universe
object perRunCaches {
import java.lang.ref.WeakReference
import scala.runtime.ScalaRunTime.stringOf
import scala.collection.generic.Clearable

import language.reflectiveCalls

// We can allow ourselves a structural type, these methods
// amount to a few calls per run at most. This does suggest
// a "Clearable" trait may be useful.
private type Clearable = {
def size: Int
def clear(): Unit
}
// Weak references so the garbage collector will take care of
// letting us know when a cache is really out of commission.
private val caches = mutable.HashSet[WeakReference[Clearable]]()
Expand All @@ -298,10 +290,14 @@ abstract class SymbolTable extends api.Universe
println(caches.size + " structures are in perRunCaches.")
caches.zipWithIndex foreach { case (ref, index) =>
val cache = ref.get()
println("(" + index + ")" + (
if (cache == null) " has been collected."
else " has " + cache.size + " entries:\n" + stringOf(cache)
))
cache match {
case xs: Traversable[_] =>
println("(" + index + ")" + (
if (cache == null) " has been collected."
else " has " + xs.size + " entries:\n" + stringOf(xs)
))
case _ =>
}
}
}
// if (settings.debug.value) {
Expand All @@ -315,8 +311,9 @@ abstract class SymbolTable extends api.Universe

def clearAll() = {
if (settings.debug.value) {
val size = caches flatMap (ref => Option(ref.get)) map (_.size) sum;
log("Clearing " + caches.size + " caches totalling " + size + " entries.")
// val size = caches flatMap (ref => Option(ref.get)) map (_.size) sum;
log("Clearing " + caches.size + " caches.")
// totalling " + size + " entries.")
}
caches foreach { ref =>
val cache = ref.get()
Expand Down
41 changes: 28 additions & 13 deletions src/compiler/scala/reflect/internal/Types.scala
Expand Up @@ -6,7 +6,8 @@
package scala.reflect
package internal

import scala.collection.{ mutable, immutable }
import scala.collection.{ mutable, immutable, generic }
import generic.Clearable
import scala.ref.WeakReference
import mutable.ListBuffer
import Flags._
Expand Down Expand Up @@ -97,7 +98,7 @@ trait Types extends api.Types { self: SymbolTable =>
*/
private final val propagateParameterBoundsToTypeVars = sys.props contains "scalac.debug.prop-constraints"

protected val enableTypeVarExperimentals = settings.Xexperimental.value || !settings.XoldPatmat.value
protected val enableTypeVarExperimentals = settings.Xexperimental.value

/** Empty immutable maps to avoid allocations. */
private val emptySymMap = immutable.Map[Symbol, Symbol]()
Expand All @@ -115,7 +116,7 @@ trait Types extends api.Types { self: SymbolTable =>

protected def newUndoLog = new UndoLog

class UndoLog {
class UndoLog extends Clearable {
private type UndoPairs = List[(TypeVar, TypeConstraint)]
private var log: UndoPairs = List()

Expand All @@ -139,7 +140,7 @@ trait Types extends api.Types { self: SymbolTable =>
log ::= ((tv, tv.constr.cloneInternal))
}

private[scala] def clear() {
def clear() {
if (settings.debug.value)
self.log("Clearing " + log.size + " entries from the undoLog.")

Expand Down Expand Up @@ -1609,12 +1610,26 @@ trait Types extends api.Types { self: SymbolTable =>
override def typeConstructor =
copyRefinedType(this, parents map (_.typeConstructor), decls)

/* MO to AM: This is probably not correct
* If they are several higher-kinded parents with different bounds we need
* to take the intersection of their bounds
*/
override def normalize = {
if (isHigherKinded) {
final override def normalize: Type =
if (phase.erasedTypes) normalizeImpl
else {
if (normalized eq null) normalized = normalizeImpl
normalized
}

private var normalized: Type = _
private def normalizeImpl = {
// TODO see comments around def intersectionType and def merge
def flatten(tps: List[Type]): List[Type] = tps flatMap { case RefinedType(parents, ds) if ds.isEmpty => flatten(parents) case tp => List(tp) }
val flattened = flatten(parents).distinct
if (decls.isEmpty && flattened.tail.isEmpty) {
flattened.head
} else if (flattened != parents) {
refinedType(flattened, if (typeSymbol eq NoSymbol) NoSymbol else typeSymbol.owner, decls, NoPosition)
} else if (isHigherKinded) {
// MO to AM: This is probably not correct
// If they are several higher-kinded parents with different bounds we need
// to take the intersection of their bounds
typeFun(
typeParams,
RefinedType(
Expand All @@ -1624,8 +1639,7 @@ trait Types extends api.Types { self: SymbolTable =>
},
decls,
typeSymbol))
}
else super.normalize
} else super.normalize
}

/** A refined type P1 with ... with Pn { decls } is volatile if
Expand Down Expand Up @@ -2898,6 +2912,7 @@ trait Types extends api.Types { self: SymbolTable =>
// existential.
// were we compared to skolems at a higher skolemizationLevel?
// EXPERIMENTAL: value will not be considered unless enableTypeVarExperimentals is true
// see SI-5729 for why this is still experimental
private var encounteredHigherLevel = false
private def shouldRepackType = enableTypeVarExperimentals && encounteredHigherLevel

Expand Down Expand Up @@ -3320,7 +3335,7 @@ trait Types extends api.Types { self: SymbolTable =>
if (phase.erasedTypes)
if (parents.isEmpty) ObjectClass.tpe else parents.head
else {
val clazz = owner.newRefinementClass(NoPosition)
val clazz = owner.newRefinementClass(pos) // TODO: why were we passing in NoPosition instead of pos?
val result = RefinedType(parents, decls, clazz)
clazz.setInfo(result)
result
Expand Down
11 changes: 6 additions & 5 deletions src/compiler/scala/reflect/runtime/AbstractFile.scala
@@ -1,6 +1,7 @@
package scala.reflect.runtime
package scala.reflect
package runtime

class AbstractFile(val jfile: java.io.File) {
def path: String = jfile.getPath()
def canonicalPath: String = jfile.getCanonicalPath()
}
class AbstractFile(val jfile: java.io.File) extends api.RequiredFile {
def path: String = jfile.getPath()
def canonicalPath: String = jfile.getCanonicalPath()
}
12 changes: 9 additions & 3 deletions src/compiler/scala/tools/nsc/Global.scala
Expand Up @@ -354,9 +354,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb
// where I need it, and then an override in Global with the setting.
override protected val etaExpandKeepsStar = settings.etaExpandKeepsStar.value
// Here comes another one...
override protected val enableTypeVarExperimentals = (
settings.Xexperimental.value || !settings.XoldPatmat.value
)
override protected val enableTypeVarExperimentals = settings.Xexperimental.value

// True if -Xscript has been set, indicating a script run.
def isScriptRun = opt.script.isDefined
Expand Down Expand Up @@ -462,6 +460,13 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb
val global: Global.this.type = Global.this
} with Analyzer

// phaseName = "patmat"
object patmat extends {
val global: Global.this.type = Global.this
val runsAfter = List("typer")
val runsRightAfter = Some("typer")
} with PatternMatching

// phaseName = "superaccessors"
object superAccessors extends {
val global: Global.this.type = Global.this
Expand Down Expand Up @@ -682,6 +687,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb
analyzer.namerFactory -> "resolve names, attach symbols to named trees",
analyzer.packageObjects -> "load package objects",
analyzer.typerFactory -> "the meat and potatoes: type the trees",
patmat -> "translate match expressions",
superAccessors -> "add super accessors in traits and nested classes",
extensionMethods -> "add extension methods for inline classes",
pickler -> "serialize symbol tables",
Expand Down
25 changes: 20 additions & 5 deletions src/compiler/scala/tools/nsc/ast/DocComments.scala
Expand Up @@ -383,7 +383,7 @@ trait DocComments { self: Global =>
}

// !!! todo: inherit from Comment?
case class DocComment(raw: String, pos: Position = NoPosition) {
case class DocComment(raw: String, pos: Position = NoPosition, codePos: Position = NoPosition) {

/** Returns:
* template: the doc comment minus all @define and @usecase sections
Expand Down Expand Up @@ -412,7 +412,7 @@ trait DocComments { self: Global =>
val comment = "/** " + raw.substring(commentStart, end) + "*/"
val commentPos = subPos(commentStart, end)

UseCase(DocComment(comment, commentPos), code, codePos)
UseCase(DocComment(comment, commentPos, codePos), code, codePos)
}

private def subPos(start: Int, end: Int) =
Expand Down Expand Up @@ -461,7 +461,18 @@ trait DocComments { self: Global =>
findIn(classes ::: List(pkgs.head, definitions.RootClass))
}

def getType(str: String): Type = {
def getType(_str: String, variable: String): Type = {
/*
* work around the backticks issue suggested by Simon in
* https://groups.google.com/forum/?hl=en&fromgroups#!topic/scala-internals/z7s1CCRCz74
* ideally, we'd have a removeWikiSyntax method in the CommentFactory to completely eliminate the wiki markup
*/
val str =
if (_str.length >= 2 && _str.startsWith("`") && _str.endsWith("`"))
_str.substring(1, _str.length - 2)
else
_str

def getParts(start: Int): List[String] = {
val end = skipIdent(str, start)
if (end == start) List()
Expand All @@ -471,7 +482,11 @@ trait DocComments { self: Global =>
}
}
val parts = getParts(0)
assert(parts.nonEmpty, "parts is empty '" + str + "' in site " + site)
if (parts.isEmpty) {
reporter.error(comment.codePos, "Incorrect variable expansion for " + variable + " in use case. Does the " +
"variable expand to wiki syntax when documenting " + site + "?")
return ErrorType
}
val partnames = (parts.init map newTermName) :+ newTypeName(parts.last)
val (start, rest) = parts match {
case "this" :: _ => (site.thisType, partnames.tail)
Expand All @@ -490,7 +505,7 @@ trait DocComments { self: Global =>
for (alias <- aliases) yield
lookupVariable(alias.name.toString.substring(1), site) match {
case Some(repl) =>
val tpe = getType(repl.trim)
val tpe = getType(repl.trim, alias.name.toString)
if (tpe != NoType) tpe
else {
val alias1 = alias.cloneSymbol(definitions.RootClass, alias.rawflags, newTypeName(repl))
Expand Down
5 changes: 5 additions & 0 deletions src/compiler/scala/tools/nsc/ast/Trees.scala
Expand Up @@ -234,6 +234,11 @@ trait Trees extends reflect.internal.Trees { self: Global =>
}
}

// used when a phase is disabled
object noopTransformer extends Transformer {
override def transformUnit(unit: CompilationUnit): Unit = {}
}

override protected def xtransform(transformer: super.Transformer, tree: Tree): Tree = tree match {
case DocDef(comment, definition) =>
transformer.treeCopy.DocDef(tree, comment, transformer.transform(definition))
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
Expand Up @@ -821,7 +821,7 @@ abstract class GenICode extends SubComponent {
ctx2

case _ =>
abort("Cannot instantiate " + tpt + "of kind: " + generatedType)
abort("Cannot instantiate " + tpt + " of kind: " + generatedType)
}

case Apply(fun @ _, List(expr)) if (definitions.isBox(fun.symbol)) =>
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/scala/tools/nsc/doc/html/page/Template.scala
Expand Up @@ -70,8 +70,7 @@ class Template(universe: doc.Universe, tpl: DocTemplateEntity) extends HtmlPage
<p id="owner">{ templatesToHtml(tpl.inTemplate.toRoot.reverse.tail, xml.Text(".")) }</p>
}

<body class={ if (tpl.isTrait || tpl.isClass || tpl.qualifiedName == "scala.AnyRef") "type" else "value" }
onload={ "sh_highlightDocument('../lib/', '.min.js');" }>
<body class={ if (tpl.isTrait || tpl.isClass || tpl.qualifiedName == "scala.AnyRef") "type" else "value" }>
<div id="definition">
{
tpl.companion match {
Expand Down
Expand Up @@ -454,7 +454,7 @@ function resizeFilterBlock() {
function printAlphabet() {
var html = '<a target="template" href="index/index-_.html">#</a>';
var c;
for (c = 'a'; c < 'z'; c = String.fromCharCode(c.charCodeAt(0) + 1)) {
for (c = 'a'; c <= 'z'; c = String.fromCharCode(c.charCodeAt(0) + 1)) {
html += [
'<a target="template" href="index/index-',
c,
Expand Down
14 changes: 11 additions & 3 deletions src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala
Expand Up @@ -231,9 +231,10 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
Some(makeType(RefinedType(tps, EmptyScope), inTpl))
}
}
val linearization: List[(TemplateEntity, TypeEntity)] = {
sym.ancestors map { ancestor =>
val typeEntity = makeType(sym.info.baseType(ancestor), this)

protected def linearizationFromSymbol(symbol: Symbol) = {
symbol.ancestors map { ancestor =>
val typeEntity = makeType(symbol.info.baseType(ancestor), this)
val tmplEntity = makeTemplate(ancestor) match {
case tmpl: DocTemplateImpl => tmpl registerSubClass this ; tmpl
case tmpl => tmpl
Expand All @@ -242,6 +243,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
}
}

val linearization = linearizationFromSymbol(sym)
def linearizationTemplates = linearization map { _._1 }
def linearizationTypes = linearization map { _._2 }

Expand Down Expand Up @@ -282,6 +284,12 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
abstract class PackageImpl(sym: Symbol, inTpl: => PackageImpl) extends DocTemplateImpl(sym, inTpl) with Package {
override def inTemplate = inTpl
override def toRoot: List[PackageImpl] = this :: inTpl.toRoot
override val linearization = {
val symbol = sym.info.members.find {
s => s.isPackageObject
} getOrElse sym
linearizationFromSymbol(symbol)
}
val packages = members collect { case p: Package => p }
}

Expand Down

0 comments on commit aad241e

Please sign in to comment.