Skip to content

Commit ec4c54d

Browse files
committed
Drop implicit FlagConjunction -> FlagSet conversion
and don't overload `is`. FlagConjunction tests are now called `isAll`.
1 parent 7ebf5f9 commit ec4c54d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+97
-99
lines changed

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
255255
case t: TypeApply if (t.fun.symbol == Predef_classOf) =>
256256
av.visit(name, t.args.head.tpe.classSymbol.denot.info.toTypeKind(bcodeStore)(innerClasesStore).toASMType)
257257
case t: tpd.RefTree =>
258-
if (t.symbol.denot.owner.is(Flags.JavaEnum)) {
258+
if (t.symbol.denot.owner.isAll(Flags.JavaEnum)) {
259259
val edesc = innerClasesStore.typeDescriptor(t.tpe.asInstanceOf[bcodeStore.int.Type]) // the class descriptor of the enumeration class.
260260
val evalue = t.symbol.name.mangledString // value the actual enumeration value.
261261
av.visitEnum(name, edesc, evalue)
@@ -476,7 +476,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
476476
// unrelated change.
477477
ctx.base.settings.YnoGenericSig.value
478478
|| sym.is(Flags.Artifact)
479-
|| sym.is(Flags.LiftedMethod)
479+
|| sym.isAll(Flags.LiftedMethod)
480480
|| sym.is(Flags.Bridge)
481481
)
482482

@@ -688,13 +688,13 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
688688
def isBottomClass: Boolean = (sym ne defn.NullClass) && (sym ne defn.NothingClass)
689689
def isBridge: Boolean = sym is Flags.Bridge
690690
def isArtifact: Boolean = sym is Flags.Artifact
691-
def hasEnumFlag: Boolean = sym is Flags.JavaEnum
691+
def hasEnumFlag: Boolean = sym.isAll(Flags.JavaEnum)
692692
def hasAccessBoundary: Boolean = sym.accessBoundary(defn.RootClass) ne defn.RootClass
693693
def isVarargsMethod: Boolean = sym is Flags.JavaVarargs
694694
def isDeprecated: Boolean = false
695695
def isMutable: Boolean = sym is Flags.Mutable
696696
def hasAbstractFlag: Boolean =
697-
(sym is Flags.Abstract) || (sym is Flags.JavaInterface) || (sym is Flags.Trait)
697+
(sym is Flags.Abstract) || (sym.isAll(Flags.JavaInterface)) || (sym is Flags.Trait)
698698
def hasModuleFlag: Boolean = sym is Flags.Module
699699
def isSynchronized: Boolean = sym is Flags.Synchronized
700700
def isNonBottomSubClass(other: Symbol): Boolean = sym.derivesFrom(other)

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ object desugar {
158158
val vdef @ ValDef(name, tpt, rhs) = transformQuotedPatternName(vdef0)
159159
val mods = vdef.mods
160160
val setterNeeded =
161-
(mods is Mutable) && ctx.owner.isClass && (!(mods is PrivateLocal) || (ctx.owner is Trait))
161+
(mods is Mutable) && ctx.owner.isClass && (!mods.isAll(PrivateLocal) || (ctx.owner is Trait))
162162
if (setterNeeded) {
163163
// TODO: copy of vdef as getter needed?
164164
// val getter = ValDef(mods, name, tpt, rhs) withPos vdef.pos?
@@ -181,7 +181,7 @@ object desugar {
181181

182182
def makeImplicitParameters(tpts: List[Tree], implicitFlag: FlagSet, forPrimaryConstructor: Boolean = false)(implicit ctx: Context): List[ValDef] =
183183
for (tpt <- tpts) yield {
184-
val paramFlags: FlagSet = if (forPrimaryConstructor) PrivateLocalParamAccessor else Param
184+
val paramFlags: FlagSet = if (forPrimaryConstructor) PrivateLocalParamAccessor.toFlags else Param
185185
val epname = EvidenceParamName.fresh()
186186
ValDef(epname, tpt, EmptyTree).withFlags(paramFlags | implicitFlag)
187187
}
@@ -402,7 +402,7 @@ object desugar {
402402
val tparamReferenced = typeParamIsReferenced(
403403
enumClass.typeParams, originalTparams, originalVparamss, parents)
404404
if (originalTparams.isEmpty && (parents.isEmpty || tparamReferenced))
405-
derivedEnumParams.map(tdef => tdef.withFlags(tdef.mods.flags | PrivateLocal))
405+
derivedEnumParams.map(tdef => tdef.withFlags(tdef.mods.flags | PrivateLocal.toFlags))
406406
else originalTparams
407407
}
408408
else originalTparams
@@ -1015,7 +1015,7 @@ object desugar {
10151015
case _ =>
10161016
val tmpName = UniqueName.fresh()
10171017
val patMods =
1018-
mods & Lazy | Synthetic | (if (ctx.owner.isClass) PrivateLocal else EmptyFlags)
1018+
mods & Lazy | Synthetic | (if (ctx.owner.isClass) PrivateLocal.toFlags else EmptyFlags)
10191019
val firstDef =
10201020
ValDef(tmpName, TypeTree(), matchExpr)
10211021
.withSpan(pat.span.union(rhs.span)).withMods(patMods)

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ object Trees {
863863
class EmptyValDef[T >: Untyped] extends ValDef[T](
864864
nme.WILDCARD, genericEmptyTree[T], genericEmptyTree[T])(NoSource) with WithoutTypeOrPos[T] {
865865
myTpe = NoType.asInstanceOf[T]
866-
setMods(untpd.Modifiers(PrivateLocal))
866+
setMods(untpd.Modifiers(PrivateLocal.toFlags))
867867
override def isEmpty: Boolean = true
868868
override def withSpan(span: Span) = throw new AssertionError("Cannot change span of EmptyValDef")
869869
}

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
180180
mods: List[Mod] = Nil) {
181181

182182
def is(fs: FlagSet): Boolean = flags is fs
183-
def is(fc: FlagConjunction): Boolean = flags is fc
184-
def is(fc: FlagSet, butNot: FlagSet): Boolean = flags.is(fc, butNot = butNot)
183+
def is(fs: FlagSet, butNot: FlagSet): Boolean = flags.is(fs, butNot = butNot)
184+
def isAll(fc: FlagConjunction): Boolean = flags.isAll(fc)
185185

186186
def | (fs: FlagSet): Modifiers = withFlags(flags | fs)
187187
def & (fs: FlagSet): Modifiers = withFlags(flags & fs)
@@ -407,7 +407,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
407407
makeConstructor(Nil, Nil)
408408

409409
def makeSelfDef(name: TermName, tpt: Tree)(implicit ctx: Context): ValDef =
410-
ValDef(name, tpt, EmptyTree).withFlags(PrivateLocal)
410+
ValDef(name, tpt, EmptyTree).withFlags(PrivateLocal.toFlags)
411411

412412
def makeTupleOrParens(ts: List[Tree])(implicit ctx: Context): Tree = ts match {
413413
case t :: Nil => Parens(t)
@@ -429,7 +429,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
429429
vdef.withMods(mods | Param)
430430
}
431431

432-
def makeSyntheticParameter(n: Int = 1, tpt: Tree = null, flags: FlagSet = SyntheticTermParam)(implicit ctx: Context): ValDef =
432+
def makeSyntheticParameter(n: Int = 1, tpt: Tree = null, flags: FlagSet = SyntheticTermParam.toFlags)(implicit ctx: Context): ValDef =
433433
ValDef(nme.syntheticParamName(n), if (tpt == null) TypeTree() else tpt, EmptyTree)
434434
.withFlags(flags)
435435

compiler/src/dotty/tools/dotc/config/JavaPlatform.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class JavaPlatform extends Platform {
3939

4040
/** Is the SAMType `cls` also a SAM under the rules of the JVM? */
4141
def isSam(cls: ClassSymbol)(implicit ctx: Context): Boolean =
42-
cls.is(NoInitsTrait) &&
42+
cls.isAll(NoInitsTrait) &&
4343
cls.superClass == defn.ObjectClass &&
4444
cls.directlyInheritedTraits.forall(_.is(NoInits)) &&
4545
!ExplicitOuter.needsOuterIfReferenced(cls) &&

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class Definitions {
319319
Object_finalize, Object_notify, Object_notifyAll, Object_wait, Object_waitL, Object_waitLI)
320320

321321
lazy val AnyKindClass: ClassSymbol = {
322-
val cls = ctx.newCompleteClassSymbol(ScalaPackageClass, tpnme.AnyKind, AbstractFinal | Permanent, Nil)
322+
val cls = ctx.newCompleteClassSymbol(ScalaPackageClass, tpnme.AnyKind, AbstractFinal.toFlags | Permanent, Nil)
323323
if (!ctx.settings.YnoKindPolymorphism.value) {
324324
// Enable kind-polymorphism by exposing scala.AnyKind
325325
cls.entered
@@ -342,11 +342,11 @@ class Definitions {
342342
MethodType(List(ThrowableType), NothingType))
343343

344344
lazy val NothingClass: ClassSymbol = enterCompleteClassSymbol(
345-
ScalaPackageClass, tpnme.Nothing, AbstractFinal, List(AnyClass.typeRef))
345+
ScalaPackageClass, tpnme.Nothing, AbstractFinal.toFlags, List(AnyClass.typeRef))
346346
def NothingType: TypeRef = NothingClass.typeRef
347347
lazy val RuntimeNothingModuleRef: TermRef = ctx.requiredModuleRef("scala.runtime.Nothing")
348348
lazy val NullClass: ClassSymbol = enterCompleteClassSymbol(
349-
ScalaPackageClass, tpnme.Null, AbstractFinal, List(ObjectClass.typeRef))
349+
ScalaPackageClass, tpnme.Null, AbstractFinal.toFlags, List(ObjectClass.typeRef))
350350
def NullType: TypeRef = NullClass.typeRef
351351
lazy val RuntimeNullModuleRef: TermRef = ctx.requiredModuleRef("scala.runtime.Null")
352352

compiler/src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ object Denotations {
11041104
final def filterDisjoint(denots: PreDenotation)(implicit ctx: Context): SingleDenotation =
11051105
if (denots.exists && denots.matches(this)) NoDenotation else this
11061106
def filterWithFlags(required: FlagConjunction, excluded: FlagSet)(implicit ctx: Context): SingleDenotation =
1107-
if (required.isEmpty && excluded.isEmpty || compatibleWith(required, excluded)) this else NoDenotation
1107+
if (required.toFlags.isEmpty && excluded.isEmpty || compatibleWith(required, excluded)) this else NoDenotation
11081108

11091109
type AsSeenFromResult = SingleDenotation
11101110
protected def computeAsSeenFrom(pre: Type)(implicit ctx: Context): SingleDenotation = {
@@ -1124,7 +1124,7 @@ object Denotations {
11241124
case symd: SymDenotation => symd
11251125
case _ => symbol.denot
11261126
}
1127-
symd.is(required) && !symd.is(excluded)
1127+
symd.isAll(required) && !symd.is(excluded)
11281128
}
11291129
}
11301130

compiler/src/dotty/tools/dotc/core/Flags.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ object Flags {
5656
/** Does this flag set have all of the flags in given flag conjunction?
5757
* Pre: The intersection of the typeflags of both sets must be non-empty.
5858
*/
59-
def is(flags: FlagConjunction): Boolean = {
59+
def isAll(flags: FlagConjunction): Boolean = {
6060
val fs = bits & flags.bits
6161
((fs & KINDFLAGS) != 0 || flags.bits == 0) &&
6262
(fs >>> TYPESHIFT) == (flags.bits >>> TYPESHIFT)
@@ -66,7 +66,7 @@ object Flags {
6666
* and at the same time contain none of the flags in the `butNot` set?
6767
* Pre: The intersection of the typeflags of both sets must be non-empty.
6868
*/
69-
def is(flags: FlagConjunction, butNot: FlagSet): Boolean = is(flags) && !is(butNot)
69+
def isAll(flags: FlagConjunction, butNot: FlagSet): Boolean = isAll(flags) && !is(butNot)
7070

7171
def isEmpty: Boolean = (bits & ~KINDFLAGS) == 0
7272

@@ -129,8 +129,9 @@ object Flags {
129129
* `x is fc` tests whether `x` contains all flags in `fc`.
130130
*/
131131
case class FlagConjunction(bits: Long) {
132-
def flagsString: String = FlagSet(bits).flagsString
133-
def | (fs: FlagSet): FlagConjunction = FlagConjunction((FlagSet(bits) | fs).bits)
132+
def toFlags = FlagSet(bits)
133+
def flagsString: String = toFlags.flagsString
134+
def | (fs: FlagSet): FlagConjunction = FlagConjunction((toFlags | fs).bits)
134135
}
135136

136137
def termFlagConjunction(x: Long) = FlagConjunction(TERMS | x)
@@ -731,7 +732,4 @@ object Flags {
731732
final val SyntheticTypeParam: FlagConjunction = allOf(Synthetic, TypeParam)
732733
final val SyntheticCase: FlagConjunction = allOf(Synthetic, Case)
733734
final val SyntheticOpaque: FlagConjunction = allOf(Synthetic, Opaque)
734-
735-
implicit def conjToFlagSet(conj: FlagConjunction): FlagSet =
736-
FlagSet(conj.bits)
737735
}

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,14 @@ object SymDenotations {
195195
(if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags) is (fs, butNot)
196196

197197
/** Has this denotation all of the flags in `fs` set? */
198-
final def is(fs: FlagConjunction)(implicit ctx: Context): Boolean =
199-
(if (isCurrent(fs)) myFlags else flags) is fs
198+
final def isAll(fs: FlagConjunction)(implicit ctx: Context): Boolean =
199+
(if (isCurrent(fs.toFlags)) myFlags else flags).isAll(fs)
200200

201201
/** Has this denotation all of the flags in `fs` set, whereas none of the flags
202202
* in `butNot` are set?
203203
*/
204204
final def is(fs: FlagConjunction, butNot: FlagSet)(implicit ctx: Context): Boolean =
205-
(if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags) is (fs, butNot)
205+
(if (isCurrent(fs.toFlags) && isCurrent(butNot)) myFlags else flags).isAll(fs, butNot)
206206

207207
/** The type info, or, if symbol is not yet completed, the completer */
208208
final def infoOrCompleter: Type = myInfo
@@ -544,7 +544,7 @@ object SymDenotations {
544544
def isOpaqueAlias(implicit ctx: Context): Boolean = is(Opaque, butNot = Synthetic)
545545

546546
/** Is this symbol the companion of an opaque alias type? */
547-
def isOpaqueCompanion(implicit ctx: Context): Boolean = is(OpaqueModule)
547+
def isOpaqueCompanion(implicit ctx: Context): Boolean = isAll(OpaqueModule)
548548

549549
/** Is this symbol a synthetic opaque type inside an opaque companion object? */
550550
def isOpaqueHelper(implicit ctx: Context): Boolean = is(SyntheticOpaque, butNot = Module)
@@ -1220,7 +1220,7 @@ object SymDenotations {
12201220
final def accessBoundary(base: Symbol)(implicit ctx: Context): Symbol = {
12211221
val fs = flags
12221222
if (fs is Private) owner
1223-
else if (fs is StaticProtected) defn.RootClass
1223+
else if (fs.isAll(StaticProtected)) defn.RootClass
12241224
else if (privateWithin.exists && !ctx.phase.erasedTypes) privateWithin
12251225
else if (fs is Protected) base
12261226
else defn.RootClass

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,11 @@ trait Symbols { this: Context =>
296296
/** Create a new skolem symbol. This is not the same as SkolemType, even though the
297297
* motivation (create a singleton referencing to a type) is similar.
298298
*/
299-
def newSkolem(tp: Type): TermSymbol = newSymbol(defn.RootClass, nme.SKOLEM, SyntheticArtifact | NonMember | Permanent, tp)
299+
def newSkolem(tp: Type): TermSymbol = newSymbol(defn.RootClass, nme.SKOLEM, SyntheticArtifact.toFlags | NonMember | Permanent, tp)
300300

301301
def newErrorSymbol(owner: Symbol, name: Name, msg: => Message): Symbol = {
302302
val errType = ErrorType(msg)
303-
newSymbol(owner, name, SyntheticArtifact,
303+
newSymbol(owner, name, SyntheticArtifact.toFlags,
304304
if (name.isTypeName) TypeAlias(errType) else errType)
305305
}
306306

0 commit comments

Comments
 (0)