-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Remove PreName add (almost) all other implicit conversions #4077
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
Changes from 4 commits
1e471b7
2aa965c
57df5b5
163509d
f4e9ccd
a50b2d4
b18fba5
e07a68d
ebe084f
d870b36
c064915
9866c74
27ee9a4
4f119bc
f2fba0b
c01612a
0bed6fd
01cc814
c49d246
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,3 +73,4 @@ compiler/after-pickling.txt | |
*.dotty-ide-version | ||
|
||
*.decompiled.out | ||
bench/compile.txt | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,9 +154,9 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma | |
lazy val Predef_classOf: Symbol = defn.ScalaPredefModule.requiredMethod(nme.classOf) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer we leave PreName, but move the String -> PreName conversion to the companion object of PreName. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That doesn't work as moving it the companion of PreName is not enough to make .toTermName and .toTypeName available on Strings. I guess we could have two implicit conversions, one in PreName's companion and one available by import, but I feel it would just make things worse... Are you sure you don't like this commit as is? In my opinion, completely removing an abstraction from the code base is a clear simplification. The diff might look large but in reality, most of the line changes are about making type more precise by having the TermName/TypeName instead of PreName. The balance sheet in term of added boilerplate is also reasonable: toTermName added: 22 toTypeName added: 12 +4 overloaded methods with String & Name arguments There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still think we should leave PreName. I don't like to have to overload methods, and the problem is, if you are systematic about it (and you should be!) you will end up with a lot more overloaded methods. I realize it's a contentious issue, but then the maxime "when in doubt, don't change it" applies. One other thing: We have to tell everyone working on the compiler that |
||
|
||
lazy val AnnotationRetentionAttr = ctx.requiredClass("java.lang.annotation.Retention") | ||
lazy val AnnotationRetentionSourceAttr = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("SOURCE") | ||
lazy val AnnotationRetentionClassAttr = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("CLASS") | ||
lazy val AnnotationRetentionRuntimeAttr = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("RUNTIME") | ||
lazy val AnnotationRetentionSourceAttr = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("SOURCE".toTermName) | ||
lazy val AnnotationRetentionClassAttr = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("CLASS".toTermName) | ||
lazy val AnnotationRetentionRuntimeAttr = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("RUNTIME".toTermName) | ||
lazy val JavaAnnotationClass = ctx.requiredClass("java.lang.annotation.Annotation") | ||
|
||
def boxMethods: Map[Symbol, Symbol] = defn.ScalaValueClasses().map{x => // @darkdimius Are you sure this should be a def? | ||
|
@@ -366,7 +366,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma | |
def getAnnotPickle(jclassName: String, sym: Symbol): Option[Annotation] = None | ||
|
||
|
||
def getRequiredClass(fullname: String): Symbol = ctx.requiredClass(fullname.toTermName) | ||
def getRequiredClass(fullname: String): Symbol = ctx.requiredClass(fullname) | ||
|
||
def getClassIfDefined(fullname: String): Symbol = NoSymbol // used only for android. todo: implement | ||
|
||
|
@@ -376,12 +376,12 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma | |
} | ||
|
||
def requiredClass[T](implicit evidence: ClassTag[T]): Symbol = | ||
ctx.requiredClass(erasureString(evidence.runtimeClass).toTermName) | ||
ctx.requiredClass(erasureString(evidence.runtimeClass)) | ||
|
||
def requiredModule[T](implicit evidence: ClassTag[T]): Symbol = { | ||
val moduleName = erasureString(evidence.runtimeClass) | ||
val className = if (moduleName.endsWith("$")) moduleName.dropRight(1) else moduleName | ||
ctx.requiredModule(className.toTermName) | ||
ctx.requiredModule(className) | ||
} | ||
|
||
|
||
|
@@ -1193,8 +1193,8 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma | |
val arity = field.meth.tpe.widenDealias.paramTypes.size - _1.size | ||
val returnsUnit = field.meth.tpe.widenDealias.resultType.classSymbol == UnitClass | ||
if (returnsUnit) | ||
ctx.requiredClass(("scala.compat.java8.JProcedure" + arity).toTermName) | ||
else ctx.requiredClass(("scala.compat.java8.JFunction" + arity).toTermName) | ||
ctx.requiredClass("scala.compat.java8.JProcedure" + arity) | ||
else ctx.requiredClass("scala.compat.java8.JFunction" + arity) | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import config.Config | |
import util.common._ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This commit LGTM |
||
import collection.mutable.ListBuffer | ||
import Decorators.SymbolIteratorDecorator | ||
import SymDenotations.LazyType | ||
|
||
/** Denotations represent the meaning of symbols and named types. | ||
* The following diagram shows how the principal types of denotations | ||
|
@@ -171,12 +172,19 @@ object Denotations { | |
* | ||
* @param symbol The referencing symbol, or NoSymbol is none exists | ||
*/ | ||
abstract class Denotation(val symbol: Symbol) extends PreDenotation with printing.Showable { | ||
|
||
abstract class Denotation(val symbol: Symbol, protected var myInfo: Type) extends PreDenotation with printing.Showable { | ||
type AsSeenFromResult <: Denotation | ||
|
||
/** The type info of the denotation, exists only for non-overloaded denotations */ | ||
def info(implicit ctx: Context): Type | ||
/** The type info. | ||
* The info is an instance of TypeType iff this is a type denotation | ||
* Uncompleted denotations set myInfo to a LazyType. | ||
*/ | ||
final def info(implicit ctx: Context): Type = { | ||
def completeInfo = { // Written this way so that `info` is small enough to be inlined | ||
this.asInstanceOf[SymDenotation].completeFrom(myInfo.asInstanceOf[LazyType]); info | ||
} | ||
if (myInfo.isInstanceOf[LazyType]) completeInfo else myInfo | ||
} | ||
|
||
/** The type info, or, if this is a SymDenotation where the symbol | ||
* is not yet completed, the completer | ||
|
@@ -287,13 +295,14 @@ object Denotations { | |
denot.symbol | ||
} | ||
|
||
def requiredMethod(name: PreName)(implicit ctx: Context): TermSymbol = | ||
info.member(name.toTermName).requiredSymbol(_ is Method).asTerm | ||
def requiredMethodRef(name: PreName)(implicit ctx: Context): TermRef = | ||
def requiredMethod(name: TermName)(implicit ctx: Context): TermSymbol = | ||
info.member(name).requiredSymbol(_ is Method).asTerm | ||
|
||
def requiredMethodRef(name: TermName)(implicit ctx: Context): TermRef = | ||
requiredMethod(name).termRef | ||
|
||
def requiredMethod(name: PreName, argTypes: List[Type])(implicit ctx: Context): TermSymbol = { | ||
info.member(name.toTermName).requiredSymbol { x => | ||
def requiredMethod(name: TermName, argTypes: List[Type])(implicit ctx: Context): TermSymbol = { | ||
info.member(name).requiredSymbol { x => | ||
(x is Method) && { | ||
x.info.paramInfoss match { | ||
case paramInfos :: Nil => paramInfos.corresponds(argTypes)(_ =:= _) | ||
|
@@ -302,19 +311,18 @@ object Denotations { | |
} | ||
}.asTerm | ||
} | ||
def requiredMethodRef(name: PreName, argTypes: List[Type])(implicit ctx: Context): TermRef = | ||
|
||
def requiredMethodRef(name: TermName, argTypes: List[Type])(implicit ctx: Context): TermRef = | ||
requiredMethod(name, argTypes).termRef | ||
|
||
def requiredValue(name: PreName)(implicit ctx: Context): TermSymbol = | ||
info.member(name.toTermName).requiredSymbol(_.info.isParameterless).asTerm | ||
def requiredValueRef(name: PreName)(implicit ctx: Context): TermRef = | ||
requiredValue(name).termRef | ||
def requiredValue(name: TermName)(implicit ctx: Context): TermSymbol = | ||
info.member(name).requiredSymbol(_.info.isParameterless).asTerm | ||
|
||
def requiredClass(name: PreName)(implicit ctx: Context): ClassSymbol = | ||
def requiredClass(name: TypeName)(implicit ctx: Context): ClassSymbol = | ||
info.member(name.toTypeName).requiredSymbol(_.isClass).asClass | ||
|
||
def requiredType(name: PreName)(implicit ctx: Context): TypeSymbol = | ||
info.member(name.toTypeName).requiredSymbol(_.isType).asType | ||
def requiredType(name: TypeName)(implicit ctx: Context): TypeSymbol = | ||
info.member(name).requiredSymbol(_.isType).asType | ||
|
||
/** The alternative of this denotation that has a type matching `targetType` when seen | ||
* as a member of type `site`, `NoDenotation` if none exists. | ||
|
@@ -646,7 +654,7 @@ object Denotations { | |
} | ||
|
||
/** A non-overloaded denotation */ | ||
abstract class SingleDenotation(symbol: Symbol) extends Denotation(symbol) { | ||
abstract class SingleDenotation(symbol: Symbol, initInfo: Type) extends Denotation(symbol, initInfo) { | ||
protected def newLikeThis(symbol: Symbol, info: Type): SingleDenotation | ||
|
||
final def name(implicit ctx: Context): Name = symbol.name | ||
|
@@ -1076,34 +1084,32 @@ object Denotations { | |
} | ||
} | ||
|
||
abstract class NonSymSingleDenotation(symbol: Symbol) extends SingleDenotation(symbol) { | ||
def infoOrCompleter: Type | ||
def info(implicit ctx: Context) = infoOrCompleter | ||
abstract class NonSymSingleDenotation(symbol: Symbol, initInfo: Type) extends SingleDenotation(symbol, initInfo) { | ||
def infoOrCompleter: Type = initInfo | ||
def isType = infoOrCompleter.isInstanceOf[TypeType] | ||
} | ||
|
||
class UniqueRefDenotation( | ||
symbol: Symbol, | ||
val infoOrCompleter: Type, | ||
initValidFor: Period) extends NonSymSingleDenotation(symbol) { | ||
initInfo: Type, | ||
initValidFor: Period) extends NonSymSingleDenotation(symbol, initInfo) { | ||
validFor = initValidFor | ||
override def hasUniqueSym: Boolean = true | ||
protected def newLikeThis(s: Symbol, i: Type): SingleDenotation = new UniqueRefDenotation(s, i, validFor) | ||
} | ||
|
||
class JointRefDenotation( | ||
symbol: Symbol, | ||
val infoOrCompleter: Type, | ||
initValidFor: Period) extends NonSymSingleDenotation(symbol) { | ||
initInfo: Type, | ||
initValidFor: Period) extends NonSymSingleDenotation(symbol, initInfo) { | ||
validFor = initValidFor | ||
override def hasUniqueSym = false | ||
protected def newLikeThis(s: Symbol, i: Type): SingleDenotation = new JointRefDenotation(s, i, validFor) | ||
} | ||
|
||
class ErrorDenotation(implicit ctx: Context) extends NonSymSingleDenotation(NoSymbol) { | ||
class ErrorDenotation(implicit ctx: Context) extends NonSymSingleDenotation(NoSymbol, NoType) { | ||
override def exists = false | ||
override def hasUniqueSym = false | ||
def infoOrCompleter = NoType | ||
validFor = Period.allInRun(ctx.runId) | ||
protected def newLikeThis(s: Symbol, i: Type): SingleDenotation = this | ||
} | ||
|
@@ -1185,9 +1191,9 @@ object Denotations { | |
|
||
/** An overloaded denotation consisting of the alternatives of both given denotations. | ||
*/ | ||
case class MultiDenotation(denot1: Denotation, denot2: Denotation) extends Denotation(NoSymbol) with MultiPreDenotation { | ||
case class MultiDenotation(denot1: Denotation, denot2: Denotation) extends Denotation(NoSymbol, NoType) with MultiPreDenotation { | ||
final def infoOrCompleter = multiHasNot("info") | ||
final def info(implicit ctx: Context) = infoOrCompleter | ||
// final def info(implicit ctx: Context) = infoOrCompleter | ||
final def validFor = denot1.validFor & denot2.validFor | ||
final def isType = false | ||
final def hasUniqueSym = false | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit LGTM