Skip to content

Cherry picks from #4512 #4722

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 4 commits into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
def superInterfaces: List[Symbol] = {
val directlyInheritedTraits = decorateSymbol(sym).directlyInheritedTraits
val directlyInheritedTraitsSet = directlyInheritedTraits.toSet
val allBaseClasses = directlyInheritedTraits.iterator.flatMap(_.symbol.asClass.baseClasses.drop(1)).toSet
val allBaseClasses = directlyInheritedTraits.iterator.flatMap(_.asClass.baseClasses.drop(1)).toSet
val superCalls = superCallsMap.getOrElse(sym, Set.empty)
val additional = (superCalls -- directlyInheritedTraitsSet).filter(_.is(Flags.Trait))
// if (additional.nonEmpty)
Expand Down
19 changes: 5 additions & 14 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ class Definitions {
lazy val Product_productPrefixR = ProductClass.requiredMethodRef(nme.productPrefix)
def Product_productPrefix(implicit ctx: Context) = Product_productPrefixR.symbol
lazy val LanguageModuleRef = ctx.requiredModule("scala.language")
def LanguageModuleClass(implicit ctx: Context) = LanguageModuleRef.symbol.moduleClass.asClass
def LanguageModuleClass(implicit ctx: Context) = LanguageModuleRef.moduleClass.asClass
lazy val NonLocalReturnControlType: TypeRef = ctx.requiredClassRef("scala.runtime.NonLocalReturnControl")
lazy val SelectableType: TypeRef = ctx.requiredClassRef("scala.Selectable")

Expand All @@ -635,19 +635,13 @@ class Definitions {

lazy val QuotedExprType = ctx.requiredClassRef("scala.quoted.Expr")
def QuotedExprClass(implicit ctx: Context) = QuotedExprType.symbol.asClass

lazy val QuotedExprModuleType = ctx.requiredModuleRef("scala.quoted.Expr")
def QuotedExprModule(implicit ctx: Context) = QuotedExprModuleType.symbol
def QuotedExprModule(implicit ctx: Context) = QuotedExprClass.companionModule
lazy val QuotedExpr_applyR = QuotedExprModule.requiredMethodRef(nme.apply)
def QuotedExpr_apply(implicit ctx: Context) = QuotedExpr_applyR.symbol

lazy val QuotedExpr_spliceR = QuotedExprClass.requiredMethod(nme.UNARY_~)
def QuotedExpr_~(implicit ctx: Context) = QuotedExpr_spliceR.symbol
lazy val QuotedExpr_runR = QuotedExprClass.requiredMethodRef(nme.run)
def QuotedExpr_run(implicit ctx: Context) = QuotedExpr_runR.symbol
lazy val QuotedExpr_~ = QuotedExprClass.requiredMethod(nme.UNARY_~)

lazy val QuotedExprsModule = ctx.requiredModule("scala.quoted.Exprs")
def QuotedExprsClass(implicit ctx: Context) = QuotedExprsModule.symbol.asClass
def QuotedExprsClass(implicit ctx: Context) = QuotedExprsModule.asClass

lazy val QuotedTypeType = ctx.requiredClassRef("scala.quoted.Type")
def QuotedTypeClass(implicit ctx: Context) = QuotedTypeType.symbol.asClass
Expand All @@ -668,10 +662,7 @@ class Definitions {
def Unpickler_unpickleType = ctx.requiredMethod("scala.runtime.quoted.Unpickler.unpickleType")

lazy val TastyTopLevelSpliceModule = ctx.requiredModule("scala.tasty.TopLevelSplice")
def TastyTopLevelSpliceModuleClass(implicit ctx: Context) = TastyTopLevelSpliceModule.symbol.asClass

lazy val TastyTopLevelSplice_compilationTopLevelSpliceR = TastyTopLevelSpliceModule.requiredMethod("tastyContext")
def TastyTopLevelSplice_compilationTopLevelSplice(implicit ctx: Context) = TastyTopLevelSplice_compilationTopLevelSpliceR.symbol
lazy val TastyTopLevelSplice_compilationTopLevelSplice = TastyTopLevelSpliceModule.requiredMethod("tastyContext")

lazy val EqType = ctx.requiredClassRef("scala.Eq")
def EqClass(implicit ctx: Context) = EqType.symbol.asClass
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -580,13 +580,13 @@ object SymDenotations {
myFlags.is(ModuleClass) && (myFlags.is(PackageClass) || isStatic)

/** Is this denotation defined in the same scope and compilation unit as that symbol? */
final def isCoDefinedWith(that: Symbol)(implicit ctx: Context) =
(this.effectiveOwner == that.effectiveOwner) &&
final def isCoDefinedWith(other: Symbol)(implicit ctx: Context) =
(this.effectiveOwner == other.effectiveOwner) &&
( !(this.effectiveOwner is PackageClass)
|| this.unforcedIsAbsent || that.unforcedIsAbsent
|| this.unforcedIsAbsent || other.unforcedIsAbsent
|| { // check if they are defined in the same file(or a jar)
val thisFile = this.symbol.associatedFile
val thatFile = that.symbol.associatedFile
val thatFile = other.associatedFile
( thisFile == null
|| thatFile == null
|| thisFile.path == thatFile.path // Cheap possibly wrong check, then expensive normalization
Expand Down
11 changes: 9 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -564,14 +564,22 @@ object Symbols {
* Overridden in ClassSymbol
*/
def associatedFile(implicit ctx: Context): AbstractFile =
if (lastDenot == null) null else lastDenot.topLevelClass.symbol.associatedFile
if (lastDenot == null) null else lastDenot.topLevelClass.associatedFile

/** The class file from which this class was generated, null if not applicable. */
final def binaryFile(implicit ctx: Context): AbstractFile = {
val file = associatedFile
if (file != null && file.extension == "class") file else null
}

/** A trap to avoid calling x.symbol on something that is already a symbol.
* This would be expanded to `toDenot(x).symbol` which is guaraneteed to be
* the same as `x`.
* With the given setup, all such calls will give implicit-not found errors
*/
final def symbol(implicit ev: DontUseSymbolOnSymbol): Nothing = unsupported("symbol")
type DontUseSymbolOnSymbol

/** The source file from which this class was generated, null if not applicable. */
final def sourceFile(implicit ctx: Context): AbstractFile = {
val file = associatedFile
Expand Down Expand Up @@ -797,5 +805,4 @@ object Symbols {

@inline def newMutableSymbolMap[T]: MutableSymbolMap[T] =
new MutableSymbolMap(new java.util.IdentityHashMap[Symbol, T]())

}
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class ClassfileParser(
setClassInfo(classRoot, classInfo)
setClassInfo(moduleRoot, staticInfo)
} else if (result == Some(NoEmbedded)) {
for (sym <- List(moduleRoot.sourceModule.symbol, moduleRoot.symbol, classRoot.symbol)) {
for (sym <- List(moduleRoot.sourceModule, moduleRoot.symbol, classRoot.symbol)) {
classRoot.owner.asClass.delete(sym)
if (classRoot.owner == defn.ScalaShadowingPackageClass) {
// Symbols in scalaShadowing are also added to scala
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
val owner = if (atEnd) loadingMirror.RootClass else readSymbolRef()

def adjust(denot: Denotation) = {
val denot1 = denot.disambiguate(d => p(d.symbol))
val denot1 = denot.disambiguate(p)
val sym = denot1.symbol
if (denot.exists && !denot1.exists) { // !!!DEBUG
val alts = denot.alternatives map (d => d + ":" + d.info + "/" + d.signature)
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/interactive/Interactive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ object Interactive {
val boundaryCtx = ctx.withOwner(boundary)
def exclude(sym: Symbol) = sym.isAbsent || sym.is(Synthetic) || sym.is(Artifact)
def addMember(name: Name, buf: mutable.Buffer[SingleDenotation]): Unit =
buf ++= prefix.member(name).altsWith(d =>
!exclude(d) && d.symbol.isAccessibleFrom(prefix)(boundaryCtx))
buf ++= prefix.member(name).altsWith(sym =>
!exclude(sym) && sym.isAccessibleFrom(prefix)(boundaryCtx))
prefix.memberDenots(completionsFilter, addMember).map(_.symbol).toList
}
else Nil
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/LambdaLift.scala
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ object LambdaLift {
def traverse(tree: Tree)(implicit ctx: Context) = try { //debug
val sym = tree.symbol

def enclosure = ctx.owner.enclosingMethod.symbol
def enclosure = ctx.owner.enclosingMethod

def narrowTo(thisClass: ClassSymbol) = {
val enclMethod = enclosure
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Mixin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase =>
initName,
Protected | Synthetic | Method,
sym.info,
coord = sym.symbol.coord).enteredAfter(thisPhase))
coord = sym.coord).enteredAfter(thisPhase))
}
}.asTerm

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/TreeExtractors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ object TreeExtractors {
object ValueClassUnbox {
def unapply(t: Tree)(implicit ctx: Context): Option[Tree] = t match {
case Apply(sel @ Select(ref, _), Nil) =>
val d = ref.tpe.widenDealias.typeSymbol.denot
if (isDerivedValueClass(d) && (sel.symbol eq valueClassUnbox(d.asClass))) {
val sym = ref.tpe.widenDealias.typeSymbol
if (isDerivedValueClass(sym) && (sel.symbol eq valueClassUnbox(sym.asClass))) {
Some(ref)
} else
None
Expand Down
20 changes: 10 additions & 10 deletions compiler/src/dotty/tools/dotc/transform/ValueClasses.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package transform
import core._
import Types._
import Symbols._
import SymDenotations._
import Contexts._
import Flags._
import StdNames._
Expand All @@ -13,7 +12,8 @@ import SymUtils._
/** Methods that apply to user-defined value classes */
object ValueClasses {

def isDerivedValueClass(d: SymDenotation)(implicit ctx: Context) = {
def isDerivedValueClass(sym: Symbol)(implicit ctx: Context): Boolean = {
val d = sym.denot
!ctx.settings.XnoValueClasses.value &&
!d.isRefinementClass &&
d.isValueClass &&
Expand All @@ -33,27 +33,27 @@ object ValueClasses {
}

/** The member of a derived value class that unboxes it. */
def valueClassUnbox(d: ClassDenotation)(implicit ctx: Context): Symbol =
def valueClassUnbox(cls: ClassSymbol)(implicit ctx: Context): Symbol =
// (info.decl(nme.unbox)).orElse(...) uncomment once we accept unbox methods
d.classInfo.decls.find(_.is(ParamAccessor))
cls.classInfo.decls.find(_.is(ParamAccessor))

/** For a value class `d`, this returns the synthetic cast from the underlying type to
* ErasedValueType defined in the companion module. This method is added to the module
* and further described in [[ExtensionMethods]].
*/
def u2evt(d: ClassDenotation)(implicit ctx: Context): Symbol =
d.linkedClass.info.decl(nme.U2EVT).symbol
def u2evt(cls: ClassSymbol)(implicit ctx: Context): Symbol =
cls.linkedClass.info.decl(nme.U2EVT).symbol

/** For a value class `d`, this returns the synthetic cast from ErasedValueType to the
* underlying type defined in the companion module. This method is added to the module
* and further described in [[ExtensionMethods]].
*/
def evt2u(d: ClassDenotation)(implicit ctx: Context): Symbol =
d.linkedClass.info.decl(nme.EVT2U).symbol
def evt2u(cls: ClassSymbol)(implicit ctx: Context): Symbol =
cls.linkedClass.info.decl(nme.EVT2U).symbol

/** The unboxed type that underlies a derived value class */
def underlyingOfValueClass(d: ClassDenotation)(implicit ctx: Context): Type =
valueClassUnbox(d).info.resultType
def underlyingOfValueClass(sym: ClassSymbol)(implicit ctx: Context): Type =
valueClassUnbox(sym).info.resultType

/** Whether a value class wraps itself */
def isCyclic(cls: ClassSymbol)(implicit ctx: Context): Boolean = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class InlineLocalObjects(val simplifyPhase: Simplify) extends Optimisation {
case t @ NewCaseClassValDef(fun, args) if newFieldsMapping.contains(t.symbol) =>
val newFields = newFieldsMapping(t.symbol).values.toList
val newFieldsDefs = newFields.zip(args).map { case (nf, arg) =>
val rhs = arg.changeOwnerAfter(t.symbol, nf.symbol, simplifyPhase)
val rhs = arg.changeOwnerAfter(t.symbol, nf, simplifyPhase)
ValDef(nf.asTerm, rhs)
}
val recreate = cpy.ValDef(t)(rhs = fun.appliedToArgs(newFields.map(x => ref(x))))
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Inferencing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ object Inferencing {
case tp: TypeRef =>
val companion = tp.classSymbol.companionModule
if (companion.exists)
companion.termRef.asSeenFrom(tp.prefix, companion.symbol.owner)
companion.termRef.asSeenFrom(tp.prefix, companion.owner)
else NoType
case _ => NoType
}
Expand Down