Skip to content

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

Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -498,7 +498,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
// unrelated change.
Copy link
Contributor

Choose a reason for hiding this comment

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

I am against merging this as is. I believe the original version is both clearer and more efficient. Computing | on the fly as a cost, that's why we created all these flag set. Doing several flag tests in a row also has a cost. On the other hand, testing against a FlagConjunction with is is fast and does not require boxing.

ctx.base.settings.YnoGenericSig.value
|| sym.is(Flags.Artifact)
|| sym.is(Flags.allOf(Flags.Method, Flags.Lifted))
|| sym.isBoth(Flags.Method, and = Flags.Lifted)
|| sym.is(Flags.Bridge)
)

Expand Down Expand Up @@ -679,7 +679,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
def isConstructor: Boolean = toDenot(sym).isConstructor
def isAnonymousFunction: Boolean = toDenot(sym).isAnonymousFunction
def isMethod: Boolean = sym is Flags.Method
def isPublic: Boolean = sym.flags.is(Flags.EmptyFlags, Flags.Private | Flags.Protected)
def isPublic: Boolean = sym.flags.is(Flags.EmptyFlags, butNot=Flags.Private | Flags.Protected)
def isSynthetic: Boolean = sym is Flags.Synthetic
def isPackageClass: Boolean = sym is Flags.PackageClass
def isModuleClass: Boolean = sym is Flags.ModuleClass
Expand Down Expand Up @@ -716,7 +716,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
def isDeprecated: Boolean = false
def isMutable: Boolean = sym is Flags.Mutable
def hasAbstractFlag: Boolean =
(sym is Flags.Abstract) || (sym is Flags.JavaInterface) || (sym is Flags.Trait)
(sym is Flags.Abstract) || (sym is Flags.Trait)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

def hasModuleFlag: Boolean = sym is Flags.Module
def isSynchronized: Boolean = sym is Flags.Synchronized
def isNonBottomSubClass(other: Symbol): Boolean = sym.derivesFrom(other)
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ object desugar {
val ValDef(name, tpt, rhs) = vdef
val mods = vdef.mods
val setterNeeded =
(mods is Mutable) && ctx.owner.isClass && (!(mods is PrivateLocal) || (ctx.owner is Trait))
mods.is(Mutable) && ctx.owner.isClass && (!mods.isBoth(Private, and = Local) || ctx.owner.is(Trait))
if (setterNeeded) {
// TODO: copy of vdef as getter needed?
// val getter = ValDef(mods, name, tpt, rhs) withPos vdef.pos?
Expand All @@ -149,7 +149,7 @@ object desugar {

def makeImplicitParameters(tpts: List[Tree], forPrimaryConstructor: Boolean = false)(implicit ctx: Context) =
for (tpt <- tpts) yield {
val paramFlags: FlagSet = if (forPrimaryConstructor) PrivateLocalParamAccessor else Param
val paramFlags: FlagSet = if (forPrimaryConstructor) Private | Local | ParamAccessor else Param
val epname = EvidenceParamName.fresh()
ValDef(epname, tpt, EmptyTree).withFlags(paramFlags | Implicit)
}
Expand Down Expand Up @@ -314,7 +314,7 @@ object desugar {
lazy val derivedEnumParams = enumClass.typeParams.map(derivedTypeParam)
val impliedTparams =
if (isEnumCase && originalTparams.isEmpty)
derivedEnumParams.map(tdef => tdef.withFlags(tdef.mods.flags | PrivateLocal))
derivedEnumParams.map(tdef => tdef.withFlags(tdef.mods.flags | Private | Local))
else
originalTparams
val constrTparams = impliedTparams.map(toDefParam)
Expand Down Expand Up @@ -729,7 +729,7 @@ object desugar {
case _ =>
val tmpName = UniqueName.fresh()
val patMods =
mods & Lazy | Synthetic | (if (ctx.owner.isClass) PrivateLocal else EmptyFlags)
mods & Lazy | Synthetic | (if (ctx.owner.isClass) Private | Local else EmptyFlags)
val firstDef =
ValDef(tmpName, TypeTree(), matchExpr)
.withPos(pat.pos.union(rhs.pos)).withMods(patMods)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ object Trees {
nme.WILDCARD, genericEmptyTree[T], genericEmptyTree[T]) with WithoutTypeOrPos[T] {
myTpe = NoType.asInstanceOf[T]
override def isEmpty: Boolean = true
setMods(untpd.Modifiers(PrivateLocal))
setMods(untpd.Modifiers(Private | Local))
}

@sharable val theEmptyTree: Thicket[Type] = Thicket(Nil)
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
mods: List[Mod] = Nil) extends Positioned with Cloneable {

def is(fs: FlagSet): Boolean = flags is fs
def is(fc: FlagConjunction): Boolean = flags is fc
def isBoth(fc: FlagSet, and: FlagSet): Boolean = flags.isBoth(fc, and)
def is(fc: FlagSet, butNot: FlagSet): Boolean = flags.is(fc, butNot = butNot)

def | (fs: FlagSet): Modifiers = withFlags(flags | fs)
Expand Down Expand Up @@ -349,7 +349,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
makeConstructor(Nil, Nil)

def makeSelfDef(name: TermName, tpt: Tree)(implicit ctx: Context) =
ValDef(name, tpt, EmptyTree).withFlags(PrivateLocal)
ValDef(name, tpt, EmptyTree).withFlags(Private | Local)

def makeTupleOrParens(ts: List[Tree])(implicit ctx: Context) = ts match {
case t :: Nil => Parens(t)
Expand All @@ -365,7 +365,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
ValDef(pname, tpe, EmptyTree).withMods(mods | Param)

def makeSyntheticParameter(n: Int = 1, tpt: Tree = TypeTree())(implicit ctx: Context): ValDef =
ValDef(nme.syntheticParamName(n), tpt, EmptyTree).withFlags(SyntheticTermParam)
ValDef(nme.syntheticParamName(n), tpt, EmptyTree).withFlags(Synthetic | TermParam)

def lambdaAbstract(tparams: List[TypeDef], tpt: Tree)(implicit ctx: Context) =
if (tparams.isEmpty) tpt else LambdaTypeTree(tparams, tpt)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/config/JavaPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class JavaPlatform extends Platform {

/** Is the SAMType `cls` also a SAM under the rules of the JVM? */
def isSam(cls: ClassSymbol)(implicit ctx: Context): Boolean =
cls.is(NoInitsTrait) &&
cls.isBoth(NoInits, and = Trait) &&
cls.superClass == defn.ObjectClass &&
cls.directlyInheritedTraits.forall(_.is(NoInits)) &&
!ExplicitOuter.needsOuterIfReferenced(cls) &&
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,11 @@ class Definitions {
useCompleter = true)

lazy val NothingClass: ClassSymbol = enterCompleteClassSymbol(
ScalaPackageClass, tpnme.Nothing, AbstractFinal, List(AnyClass.typeRef))
ScalaPackageClass, tpnme.Nothing, Abstract | Final, List(AnyClass.typeRef))
def NothingType = NothingClass.typeRef
lazy val RuntimeNothingModuleRef = ctx.requiredModuleRef("scala.runtime.Nothing")
lazy val NullClass: ClassSymbol = enterCompleteClassSymbol(
ScalaPackageClass, tpnme.Null, AbstractFinal, List(ObjectClass.typeRef))
ScalaPackageClass, tpnme.Null, Abstract | Final, List(ObjectClass.typeRef))
def NullType = NullClass.typeRef
lazy val RuntimeNullModuleRef = ctx.requiredModuleRef("scala.runtime.Null")

Expand Down
126 changes: 12 additions & 114 deletions compiler/src/dotty/tools/dotc/core/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package core
import language.implicitConversions

object Flags {

/** A FlagSet represents a set of flags. Flags are encoded as follows:
* The first two bits indicate whether a flagset applies to terms,
* to types, or to both. Bits 2..63 are available for properties
Expand All @@ -15,8 +14,7 @@ object Flags {
*/
case class FlagSet(val bits: Long) extends AnyVal {

/** The union of this flag set and the given flag set
*/
/** The union of this flag set and the given flag set */
def | (that: FlagSet): FlagSet =
if (bits == 0) that
else if (that.bits == 0) this
Expand All @@ -39,6 +37,10 @@ object Flags {

/** Does this flag set have a non-empty intersection with the given flag set?
* This means that both the kind flags and the carrier bits have non-empty intersection.
*
* Note that `.is(flagA | flagB)` returns true if this flag set contains
* EITHER `flagA` OR `flagB`. To test for both conjunction of both flags,
* use `.is(flagA, and = flagB)`.
*/
def is(flags: FlagSet): Boolean = {
val fs = bits & flags.bits
Expand All @@ -48,22 +50,18 @@ object Flags {
/** Does this flag set have a non-empty intersection with the given flag set,
* and at the same time contain none of the flags in the `butNot` set?
*/
def is(flags: FlagSet, butNot: FlagSet): Boolean = is(flags) && !is(butNot)
def is(flags: FlagSet, butNot: FlagSet): Boolean =
is(flags) && !is(butNot)

/** Does this flag set have all of the flags in given flag conjunction?
* Pre: The intersection of the typeflags of both sets must be non-empty.
*/
def is(flags: FlagConjunction): Boolean = {
val fs = bits & flags.bits
(fs & KINDFLAGS) != 0 &&
(fs >>> TYPESHIFT) == (flags.bits >>> TYPESHIFT)
}
/** Does this flag set have both of the given flags? */
def isBoth(flags: FlagSet, and: FlagSet): Boolean =
Copy link
Contributor

Choose a reason for hiding this comment

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

This commit LGTM

is(flags) && is(and)

/** Does this flag set have all of the flags in given flag conjunction?
* and at the same time contain none of the flags in the `butNot` set?
* Pre: The intersection of the typeflags of both sets must be non-empty.
*/
def is(flags: FlagConjunction, butNot: FlagSet): Boolean = is(flags) && !is(butNot)
def isBoth(flags: FlagSet, and: FlagSet, butNot: FlagSet): Boolean =
is(flags) && is(and) && !is(butNot)

def isEmpty = (bits & ~KINDFLAGS) == 0

Expand Down Expand Up @@ -119,14 +117,6 @@ object Flags {
override def toString = flagStrings.mkString(" ")
}

/** A class representing flag sets that should be tested
* conjunctively. I.e. for a flag conjunction `fc`,
* `x is fc` tests whether `x` contains all flags in `fc`.
*/
case class FlagConjunction(bits: Long) {
override def toString = FlagSet(bits).toString
}

private final val TYPESHIFT = 2
private final val TERMindex = 0
private final val TYPEindex = 1
Expand Down Expand Up @@ -179,19 +169,6 @@ object Flags {
flag
}

/** The conjunction of all flags in given flag set */
def allOf(flags1: FlagSet, flags2: FlagSet): FlagConjunction = {
assert(flags1.numFlags == 1 && flags2.numFlags == 1, "Flags.allOf doesn't support flag " + (if (flags1.numFlags != 1) flags1 else flags2))
FlagConjunction((flags1 | flags2).bits)
}

/** The conjunction of all flags in given flag set */
def allOf(flags1: FlagSet, flags2: FlagSet, flags3: FlagSet, flagss: FlagSet*): FlagConjunction = {
val flags0 = allOf(flags1, flags2) | flags3
assert(flags3.numFlags == 1 && flagss.forall(_.numFlags == 1), "Flags.allOf doesn't support flag " + (if (flags3.numFlags != 1) flags3 else flagss.find(_.numFlags != 1)))
FlagConjunction((flags0 | union(flagss: _*)).bits)
}

def commonFlags(flagss: FlagSet*) = union(flagss.map(_.toCommonFlags): _*)

/** The empty flag set */
Expand Down Expand Up @@ -550,18 +527,6 @@ object Flags {
/** Labeled `private`, `final`, or `inline` */
final val PrivateOrFinalOrInline = Private | Final | Inline

/** A private method */
final val PrivateMethod = allOf(Private, Method)

/** A private accessor */
final val PrivateAccessor = allOf(Private, Accessor)

/** An inline method */
final val InlineMethod = allOf(Inline, Method)

/** An inline parameter */
final val InlineParam = allOf(Inline, Param)

/** A term parameter or parameter accessor */
final val TermParamOrAccessor = Param | ParamAccessor

Expand All @@ -583,76 +548,9 @@ object Flags {
/** value that's final or inline */
final val FinalOrInline = Final | Inline

/** A covariant type parameter instance */
final val LocalCovariant = allOf(Local, Covariant)

/** A contravariant type parameter instance */
final val LocalContravariant = allOf(Local, Contravariant)

/** Has defined or inherited default parameters */
final val HasDefaultParams = DefaultParameterized | InheritedDefaultParams

/** Is valid forever */
final val ValidForever = Package | Permanent | Scala2ExistentialCommon

/** A type parameter of a class or trait */
final val ClassTypeParam = allOf(TypeParam, Private)

/** Is a default parameter in Scala 2*/
final val DefaultParameter = allOf(Param, DefaultParameterized)

/** A Scala 2 Macro */
final val Scala2Macro = allOf(Macro, Scala2x)

/** A trait that does not need to be initialized */
final val NoInitsTrait = allOf(Trait, NoInits)

/** A Java interface, potentially with default methods */
final val JavaTrait = allOf(JavaDefined, Trait, NoInits)

/** A Java interface */ // TODO when unpickling, reconstitute from context
final val JavaInterface = allOf(JavaDefined, Trait)

/** A Java companion object */
final val JavaModule = allOf(JavaDefined, Module)

/** A Java companion object */
final val JavaProtected = allOf(JavaDefined, Protected)

/** Labeled private[this] */
final val PrivateLocal = allOf(Private, Local)

/** A private[this] parameter accessor */
final val PrivateLocalParamAccessor = allOf(Private, Local, ParamAccessor)

/** A parameter forwarder */
final val ParamForwarder = allOf(Method, Stable, ParamAccessor)

/** A private[this] parameter */
final val PrivateLocalParam = allOf(Private, Local, Param)

/** A private parameter accessor */
final val PrivateParamAccessor = allOf(Private, ParamAccessor)

/** A local parameter */
final val ParamAndLocal = allOf(Param, Local)

/** Labeled protected[this] */
final val ProtectedLocal = allOf(Protected, Local)

/** Java symbol which is `protected` and `static` */
final val StaticProtected = allOf(JavaDefined, Protected, JavaStatic)

final val AbstractFinal = allOf(Abstract, Final)
final val AbstractSealed = allOf(Abstract, Sealed)
final val SyntheticArtifact = allOf(Synthetic, Artifact)
final val SyntheticModule = allOf(Synthetic, Module)
final val SyntheticTermParam = allOf(Synthetic, TermParam)
final val SyntheticTypeParam = allOf(Synthetic, TypeParam)
final val SyntheticCase = allOf(Synthetic, Case)
final val AbstractAndOverride = allOf(Abstract, Override)
final val Scala2Trait = allOf(Scala2x, Trait)

implicit def conjToFlagSet(conj: FlagConjunction): FlagSet =
FlagSet(conj.bits)
}
41 changes: 28 additions & 13 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -180,25 +180,40 @@ object SymDenotations {
if (myInfo.isInstanceOf[SymbolLoader]) FromStartFlags
else AfterLoadFlags)

/** Has this denotation one of the flags in `fs` set? */
/** Does this denotation have one of the flags in `fs` set? */
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?
/** Does this denotation have at least one of the flags in `fs` set, and
* none of the flags in `butNot` set?
*/
final def is(fs: FlagSet, butNot: FlagSet)(implicit ctx: Context) =
(if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags) is (fs, butNot)
(if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags) is (fs, butNot = butNot)

/** Has this denotation all of the flags in `fs` set? */
final def is(fs: FlagConjunction)(implicit ctx: Context) =
(if (isCurrent(fs)) myFlags else flags) is fs
/** Does this denotation have at least one of the flags in `fs` set,
* and at least one of the flags in `and` set?
*/
final def isBoth(fs: FlagSet, and: FlagSet)(implicit ctx: Context) =
(if (isCurrent(fs) && isCurrent(and)) myFlags else flags) isBoth (fs, and)

/** Has this denotation all of the flags in `fs` set, whereas none of the flags
* in `butNot` are set?
/** Does this denotation have at least one of the flags in `fs` set,
* and at least one of the flags in `and` set,
* and none of the flags in `butNot` set?
*/
final def is(fs: FlagConjunction, butNot: FlagSet)(implicit ctx: Context) =
(if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags) is (fs, butNot)
final def isBoth(fs: FlagSet, and: FlagSet, butNot: FlagSet)(implicit ctx: Context) =
(if (isCurrent(fs) && isCurrent(and) && isCurrent(butNot)) myFlags else flags) isBoth (fs, and = and, butNot = butNot)

/** A type parameter of a class or trait */
final def isClassTypeParam(implicit ctx: Context) =
isBoth(TypeParam, and = Private)

/** A Java interface, potentially with default methods */
final def isJavaTrait(implicit ctx: Context) =
is(JavaDefined) && is(Trait) && is(NoInits)

/** A parameter forwarder */
final def isParamForwarder(implicit ctx: Context) =
is(Method) && is(Stable) && is(ParamAccessor)

/** The type info, or, if symbol is not yet completed, the completer */
final def infoOrCompleter = myInfo
Expand Down Expand Up @@ -770,7 +785,7 @@ object SymDenotations {

def isSkolem: Boolean = name == nme.SKOLEM

def isInlineMethod(implicit ctx: Context): Boolean = is(InlineMethod, butNot = Accessor)
def isInlineMethod(implicit ctx: Context): Boolean = isBoth(Inline, and = Method, butNot = Accessor)

/** ()T and => T types should be treated as equivalent for this symbol.
* Note: For the moment, we treat Scala-2 compiled symbols as loose matching,
Expand Down Expand Up @@ -1113,7 +1128,7 @@ object SymDenotations {
final def accessBoundary(base: Symbol)(implicit ctx: Context): Symbol = {
val fs = flags
if (fs is Private) owner
else if (fs is StaticProtected) defn.RootClass
else if (fs.isBoth(Protected, and = JavaStatic)) defn.RootClass
else if (privateWithin.exists && !ctx.phase.erasedTypes) privateWithin
else if (fs is Protected) base
else defn.RootClass
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,11 @@ trait Symbols { this: Context =>
/** Create a new skolem symbol. This is not the same as SkolemType, even though the
* motivation (create a singleton referencing to a type) is similar.
*/
def newSkolem(tp: Type) = newSymbol(defn.RootClass, nme.SKOLEM, SyntheticArtifact | NonMember | Permanent, tp)
def newSkolem(tp: Type) = newSymbol(defn.RootClass, nme.SKOLEM, Synthetic | Artifact | NonMember | Permanent, tp)

def newErrorSymbol(owner: Symbol, name: Name, msg: => Message) = {
val errType = ErrorType(msg)
newSymbol(owner, name, SyntheticArtifact,
newSymbol(owner, name, Synthetic | Artifact,
if (name.isTypeName) TypeAlias(errType) else errType)
}

Expand Down
Loading