Skip to content

Micro-optimization: Streamline SymDenotation#info #3245

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 2 commits into from
Oct 4, 2017
Merged
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
25 changes: 12 additions & 13 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ object SymDenotations {
*/
class SymDenotation private[SymDenotations] (
symbol: Symbol,
ownerIfExists: Symbol,
final val maybeOwner: Symbol,
final val name: Name,
initFlags: FlagSet,
initInfo: Type,
Expand All @@ -140,10 +140,7 @@ object SymDenotations {
private[this] var myAnnotations: List[Annotation] = Nil

/** The owner of the symbol; overridden in NoDenotation */
def owner: Symbol = ownerIfExists

/** Same as owner, except returns NoSymbol for NoSymbol */
def maybeOwner: Symbol = if (exists) owner else NoSymbol
def owner: Symbol = maybeOwner

/** The flag set */
final def flags(implicit ctx: Context): FlagSet = { ensureCompleted(); myFlags }
Expand Down Expand Up @@ -178,9 +175,8 @@ object SymDenotations {
else AfterLoadFlags)

/** Has this denotation one of the flags in `fs` set? */
final def is(fs: FlagSet)(implicit ctx: Context) = {
final def is(fs: FlagSet)(implicit ctx: Context) =
(if (isCurrent(fs)) myFlags else flags) is fs
}

/** Has this denotation one of the flags in `fs` set, whereas none of the flags
* in `butNot` are set?
Expand All @@ -202,9 +198,11 @@ object SymDenotations {
* 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 = myInfo match {
case myInfo: LazyType => completeFrom(myInfo); info
case _ => myInfo
final def info(implicit ctx: Context): Type = {
def completeInfo = {
completeFrom(myInfo.asInstanceOf[LazyType]); info
}
if (myInfo.isInstanceOf[LazyType]) completeInfo else myInfo
}

/** The type info, or, if symbol is not yet completed, the completer */
Expand Down Expand Up @@ -455,7 +453,7 @@ object SymDenotations {

/** Is this symbol the root class or its companion object? */
final def isRoot: Boolean =
(name.toTermName == nme.ROOT || name == nme.ROOTPKG) && (owner eq NoSymbol)
(maybeOwner eq NoSymbol) && (name.toTermName == nme.ROOT || name == nme.ROOTPKG)

/** Is this symbol the empty package class or its companion object? */
final def isEmptyPackage(implicit ctx: Context): Boolean =
Expand Down Expand Up @@ -560,11 +558,12 @@ object SymDenotations {

/** Is this denotation static (i.e. with no outer instance)? */
final def isStatic(implicit ctx: Context) =
(this is JavaStatic) || this.exists && owner.isStaticOwner || this.isRoot
(if (maybeOwner eq NoSymbol) isRoot else maybeOwner.isStaticOwner) ||
myFlags.is(JavaStatic)

/** Is this a package class or module class that defines static symbols? */
final def isStaticOwner(implicit ctx: Context): Boolean =
(this is PackageClass) || (this is ModuleClass) && isStatic
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) =
Expand Down