Skip to content

Fix/double bindings #115

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 10 commits into from
Apr 8, 2014
Merged
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Run(comp: Compiler)(implicit ctx: Context) {

private def printTree(ctx: Context) = {
val unit = ctx.compilationUnit
println(s"result of $unit after ${ctx.phase}:")
println(s"result of $unit after ${ctx.phase.prev}:")
println(unit.tpdTree.show(ctx))
}

Expand Down
6 changes: 4 additions & 2 deletions src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
untpd.Select(qualifier, tp.name).withType(tp)

def Select(qualifier: Tree, sym: Symbol)(implicit ctx: Context): Select =
untpd.Select(qualifier, sym.name).withType(qualifier.tpe select sym)
untpd.Select(qualifier, sym.name).withType(
TermRef.withSig(qualifier.tpe, sym.name.asTermName, sym.signature, sym.denot))

def SelectWithSig(qualifier: Tree, name: Name, sig: Signature)(implicit ctx: Context) =
untpd.SelectWithSig(qualifier, name, sig)
Expand Down Expand Up @@ -259,10 +260,11 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
/** new C(args) */
def New(tp: Type, args: List[Tree])(implicit ctx: Context): Apply = {
val targs = tp.argTypes
val constr = tp.typeSymbol.primaryConstructor.asTerm
Apply(
Select(
New(tp withoutArgs targs),
TermRef(tp.normalizedPrefix, tp.typeSymbol.primaryConstructor.asTerm))
TermRef.withSig(tp.normalizedPrefix, constr))
.appliedToTypes(targs),
args)
}
Expand Down
7 changes: 7 additions & 0 deletions src/dotty/tools/dotc/config/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ object Config {

final val flagInstantiationToNothing = false

/** Enable noDoubleDef checking if option "-YnoDoubleDefs" is set.
* The reason to have an option as well as the present global switch is
* that the noDoubleDef checking is done in a hotspot, and we do not
* want to incur the overhead of checking an option each time.
*/
final val checkNoDoubleBindings = true

/** Throw an exception if a deep subtype recursion is detected */
final val flagDeepSubTypeRecursions = true

Expand Down
1 change: 1 addition & 0 deletions src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class ScalaSettings extends Settings.SettingGroup {
val Ytyperdebug = BooleanSetting("-Ytyper-debug", "Trace all type assignments.")
val Ypatmatdebug = BooleanSetting("-Ypatmat-debug", "Trace pattern matching translation.")
val Yexplainlowlevel = BooleanSetting("-Yexplainlowlevel", "When explaining type errors, show types at a lower level.")
val YnoDoubleBindings = BooleanSetting("-YnoDoubleBindings", "Assert no namedtype is bound twice (should be enabled only if program is error-free).")

val optimise = BooleanSetting("-optimise", "Generates faster bytecode by applying optimisations to the program") withAbbreviation "-optimize"

Expand Down
3 changes: 1 addition & 2 deletions src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ object Contexts {
private var phasedCtx: Context = _
private var phasedCtxs: Array[Context] = _


/** This context at given phase.
* This method will always return a phase period equal to phaseId, thus will never return squashed phases
*/
Expand All @@ -211,7 +210,7 @@ object Contexts {
final def withPhase(phase: Phase): Context =
withPhase(phase.id)

/** If -Ydebug is on, the top of the stack trace where this context
/** If -Ydebug is on, the top of the stack trace where this context
* was created, otherwise `null`.
*/
private var creationTrace: Array[StackTraceElement] = _
Expand Down
53 changes: 26 additions & 27 deletions src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -273,35 +273,34 @@ object Denotations {

def unionDenot(denot1: SingleDenotation, denot2: SingleDenotation): Denotation =
if (denot1.signature matches denot2.signature) {
val sym1 = denot1.symbol
val sym2 = denot2.symbol
val info1 = denot1.info
val info2 = denot2.info
val sym2 = denot2.symbol
def sym2Accessible = sym2.isAccessibleFrom(pre)
if (info1 <:< info2 && sym2Accessible) denot2
val sameSym = sym1 eq sym2
if (sameSym && info1 <:< info2) denot2
else if (sameSym && info2 <:< info1) denot1
else {
val sym1 = denot1.symbol
def sym1Accessible = sym1.isAccessibleFrom(pre)
if (info2 <:< info1 && sym1Accessible) denot1
else {
val owner2 = if (sym2 ne NoSymbol) sym2.owner else NoSymbol
/** Determine a symbol which is overridden by both sym1 and sym2.
* Preference is given to accessible symbols.
*/
def lubSym(overrides: Iterator[Symbol], previous: Symbol): Symbol =
if (!overrides.hasNext) previous
else {
val candidate = overrides.next
if (owner2 derivesFrom candidate.owner)
if (candidate isAccessibleFrom pre) candidate
else lubSym(overrides, previous orElse candidate)
else
lubSym(overrides, previous)
}
new JointRefDenotation(
lubSym(sym1.allOverriddenSymbols, NoSymbol),
info1 | info2,
denot1.validFor & denot2.validFor)
}
val jointSym =
if (sameSym) sym1
else {
val owner2 = if (sym2 ne NoSymbol) sym2.owner else NoSymbol
/** Determine a symbol which is overridden by both sym1 and sym2.
* Preference is given to accessible symbols.
*/
def lubSym(overrides: Iterator[Symbol], previous: Symbol): Symbol =
if (!overrides.hasNext) previous
else {
val candidate = overrides.next
if (owner2 derivesFrom candidate.owner)
if (candidate isAccessibleFrom pre) candidate
else lubSym(overrides, previous orElse candidate)
else
lubSym(overrides, previous)
}
lubSym(sym1.allOverriddenSymbols, NoSymbol)
}
new JointRefDenotation(jointSym, info1 | info2, denot1.validFor & denot2.validFor)
}
}
else NoDenotation
Expand Down Expand Up @@ -335,7 +334,7 @@ object Denotations {
final def info(implicit ctx: Context) = infoOrCompleter
final def validFor = denot1.validFor & denot2.validFor
final def isType = false
def signature(implicit ctx: Context) = multiHasNot("signature")
final def signature(implicit ctx: Context) = Signature.OverloadedSignature
def atSignature(sig: Signature)(implicit ctx: Context): SingleDenotation =
denot1.atSignature(sig) orElse denot2.atSignature(sig)
def current(implicit ctx: Context): Denotation =
Expand Down
9 changes: 9 additions & 0 deletions src/dotty/tools/dotc/core/NameOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ object NameOps {
implicit class NameDecorator[N <: Name](val name: N) extends AnyVal {
import nme._

def likeTyped(n: Name): N =
(if (name.isTermName) n.toTermName else n.toTypeName).asInstanceOf[N]

def isConstructorName = name == CONSTRUCTOR || name == IMPLCLASS_CONSTRUCTOR
def isExceptionResultName = name startsWith EXCEPTION_RESULT_PREFIX
def isImplClassName = name endsWith IMPL_CLASS_SUFFIX
Expand All @@ -62,6 +65,8 @@ object NameOps {
def isTraitSetterName = isSetterName && (name containsSlice TRAIT_SETTER_SEPARATOR)
def isSingletonName = name endsWith SINGLETON_SUFFIX
def isModuleClassName = name endsWith MODULE_SUFFIX
def isImportName = name startsWith IMPORT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this addition have to do with the present PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks like an oversight or merge problem. The line should be deleted. It's part of another commit that was abandoned.

def isInheritedName = name.head == '(' && name.startsWith(nme.INHERITED)

def isModuleVarName(name: Name): Boolean =
name.stripAnonNumberSuffix endsWith MODULE_VAR_SUFFIX
Expand Down Expand Up @@ -132,6 +137,10 @@ object NameOps {
if (idx < 0) name else (name drop (idx + separator.length)).asInstanceOf[N]
}

def inheritedName: N = likeTyped(nme.INHERITED ++ name)

def revertInherited: N = likeTyped(name.drop(nme.INHERITED.length))

/** Translate a name into a list of simple TypeNames and TermNames.
* In all segments before the last, type/term is determined by whether
* the following separator char is '.' or '#'. The last segment
Expand Down
6 changes: 5 additions & 1 deletion src/dotty/tools/dotc/core/Signature.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dotty.tools.dotc
package core

import Names._, Types._, Contexts._
import Names._, Types._, Contexts._, StdNames._
import transform.Erasure.sigName

/** The signature of a denotation.
Expand Down Expand Up @@ -49,6 +49,10 @@ object Signature {
* a type different from PolyType, MethodType, or ExprType.
*/
val NotAMethod = Signature(List(), EmptyTypeName)

/** The signature of an overloaded denotation.
*/
val OverloadedSignature = Signature(List(tpnme.OVERLOADED), EmptyTypeName)

/** The signature of a method with no parameters and result type `resultType`. */
def apply(resultType: Type, isJava: Boolean)(implicit ctx: Context): Signature =
Expand Down
2 changes: 2 additions & 0 deletions src/dotty/tools/dotc/core/StdNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ object StdNames {
val EXPAND_SEPARATOR: N = "$$"
val IMPL_CLASS_SUFFIX: N = "$class"
val IMPORT: N = "<import>"
val INHERITED: N = "(inherited)" // tag to be used until we have proper name kinds
val INTERPRETER_IMPORT_WRAPPER: N = "$iw"
val INTERPRETER_LINE_PREFIX: N = "line"
val INTERPRETER_VAR_PREFIX: N = "res"
Expand All @@ -109,6 +110,7 @@ object StdNames {
val MODULE_VAR_SUFFIX: N = "$module"
val NAME_JOIN: N = NameTransformer.NAME_JOIN_STRING
val USCORE_PARAM_PREFIX: N = "_$"
val OVERLOADED: N = "<overloaded>"
val PACKAGE: N = "package"
val PACKAGE_CLS: N = "package$"
val PROTECTED_PREFIX: N = "protected$"
Expand Down
6 changes: 5 additions & 1 deletion src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,8 @@ object SymDenotations {

/** The symbol, in class `inClass`, that is overridden by this denotation. */
final def overriddenSymbol(inClass: ClassSymbol)(implicit ctx: Context): Symbol =
matchingSymbol(inClass, owner.thisType)
if ((this is Private) && (owner ne inClass)) NoSymbol
else matchingSymbol(inClass, owner.thisType)

/** All symbols overriden by this denotation. */
final def allOverriddenSymbols(implicit ctx: Context): Iterator[Symbol] =
Expand Down Expand Up @@ -731,6 +732,9 @@ object SymDenotations {
override def termRefWithSig(implicit ctx: Context): TermRef =
TermRef.withSig(owner.thisType, name.asTermName, signature, this)

def nonMemberTermRef(implicit ctx: Context): TermRef =
TermRef.withNonMemberSym(owner.thisType, name.asTermName, symbol.asTerm)

/** The variance of this type parameter or type member as an Int, with
* +1 = Covariant, -1 = Contravariant, 0 = Nonvariant, or not a type parameter
*/
Expand Down
4 changes: 2 additions & 2 deletions src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ trait Symbols { this: Context =>
for (name <- names) {
val tparam = newNakedSymbol[TypeName](NoCoord)
tparamBuf += tparam
trefBuf += TypeRef(owner.thisType, name) withSym tparam
trefBuf += TypeRef(owner.thisType, name).withSym(tparam, Signature.NotAMethod)
}
val tparams = tparamBuf.toList
val bounds = boundsFn(trefBuf.toList)
Expand Down Expand Up @@ -319,7 +319,7 @@ object Symbols {
type ThisName <: Name

private[this] var _id: Int = nextId
//assert(_id != 5859)
//assert(_id != 12325)

/** The unique id of this symbol */
def id = _id
Expand Down
Loading