Skip to content

Commit b106101

Browse files
committed
Make FlagConjunction an alias of FlagSet
Drop .toFlags conversion
1 parent 082fc61 commit b106101

File tree

15 files changed

+36
-44
lines changed

15 files changed

+36
-44
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ object desugar {
182182

183183
def makeImplicitParameters(tpts: List[Tree], implicitFlag: FlagSet, forPrimaryConstructor: Boolean = false)(implicit ctx: Context): List[ValDef] =
184184
for (tpt <- tpts) yield {
185-
val paramFlags: FlagSet = if (forPrimaryConstructor) PrivateLocalParamAccessor.toFlags else Param
185+
val paramFlags: FlagSet = if (forPrimaryConstructor) PrivateLocalParamAccessor else Param
186186
val epname = EvidenceParamName.fresh()
187187
ValDef(epname, tpt, EmptyTree).withFlags(paramFlags | implicitFlag)
188188
}
@@ -403,7 +403,7 @@ object desugar {
403403
val tparamReferenced = typeParamIsReferenced(
404404
enumClass.typeParams, originalTparams, originalVparamss, parents)
405405
if (originalTparams.isEmpty && (parents.isEmpty || tparamReferenced))
406-
derivedEnumParams.map(tdef => tdef.withFlags(tdef.mods.flags | PrivateLocal.toFlags))
406+
derivedEnumParams.map(tdef => tdef.withFlags(tdef.mods.flags | PrivateLocal))
407407
else originalTparams
408408
}
409409
else originalTparams
@@ -974,7 +974,7 @@ object desugar {
974974
case _ =>
975975
val tmpName = UniqueName.fresh()
976976
val patMods =
977-
mods & Lazy | Synthetic | (if (ctx.owner.isClass) PrivateLocal.toFlags else EmptyFlags)
977+
mods & Lazy | Synthetic | (if (ctx.owner.isClass) PrivateLocal else EmptyFlags)
978978
val firstDef =
979979
ValDef(tmpName, TypeTree(), matchExpr)
980980
.withSpan(pat.span.union(rhs.span)).withMods(patMods)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ object DesugarEnums {
286286
val toStringDef = toStringMethLit(name.toString)
287287
val impl1 = cpy.Template(impl)(body = List(ordinalDef, toStringDef) ++ registerCall)
288288
.withAttachment(ExtendsSingletonMirror, ())
289-
val vdef = ValDef(name, TypeTree(), New(impl1)).withMods(mods | EnumValue.toFlags)
289+
val vdef = ValDef(name, TypeTree(), New(impl1)).withMods(mods | EnumValue)
290290
flatTree(scaffolding ::: vdef :: Nil).withSpan(span)
291291
}
292292
}
@@ -302,7 +302,7 @@ object DesugarEnums {
302302
else {
303303
val (tag, scaffolding) = nextOrdinal(CaseKind.Simple)
304304
val creator = Apply(Ident(nme.DOLLAR_NEW), List(Literal(Constant(tag)), Literal(Constant(name.toString))))
305-
val vdef = ValDef(name, enumClassRef, creator).withMods(mods | EnumValue.toFlags)
305+
val vdef = ValDef(name, enumClassRef, creator).withMods(mods | EnumValue)
306306
flatTree(scaffolding ::: vdef :: Nil).withSpan(span)
307307
}
308308
}

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

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
415415
makeConstructor(Nil, Nil)
416416

417417
def makeSelfDef(name: TermName, tpt: Tree)(implicit ctx: Context): ValDef =
418-
ValDef(name, tpt, EmptyTree).withFlags(PrivateLocal.toFlags)
418+
ValDef(name, tpt, EmptyTree).withFlags(PrivateLocal)
419419

420420
def makeTupleOrParens(ts: List[Tree])(implicit ctx: Context): Tree = ts match {
421421
case t :: Nil => Parens(t)
@@ -437,7 +437,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
437437
vdef.withMods(mods | Param)
438438
}
439439

440-
def makeSyntheticParameter(n: Int = 1, tpt: Tree = null, flags: FlagSet = SyntheticTermParam.toFlags)(implicit ctx: Context): ValDef =
440+
def makeSyntheticParameter(n: Int = 1, tpt: Tree = null, flags: FlagSet = SyntheticTermParam)(implicit ctx: Context): ValDef =
441441
ValDef(nme.syntheticParamName(n), if (tpt == null) TypeTree() else tpt, EmptyTree)
442442
.withFlags(flags)
443443

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

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

327327
@threadUnsafe lazy val AnyKindClass: ClassSymbol = {
328-
val cls = ctx.newCompleteClassSymbol(ScalaPackageClass, tpnme.AnyKind, AbstractFinal.toFlags | Permanent, Nil)
328+
val cls = ctx.newCompleteClassSymbol(ScalaPackageClass, tpnme.AnyKind, AbstractFinal | Permanent, Nil)
329329
if (!ctx.settings.YnoKindPolymorphism.value) {
330330
// Enable kind-polymorphism by exposing scala.AnyKind
331331
cls.entered
@@ -348,11 +348,11 @@ class Definitions {
348348
MethodType(List(ThrowableType), NothingType))
349349

350350
@threadUnsafe lazy val NothingClass: ClassSymbol = enterCompleteClassSymbol(
351-
ScalaPackageClass, tpnme.Nothing, AbstractFinal.toFlags, List(AnyClass.typeRef))
351+
ScalaPackageClass, tpnme.Nothing, AbstractFinal, List(AnyClass.typeRef))
352352
def NothingType: TypeRef = NothingClass.typeRef
353353
@threadUnsafe lazy val RuntimeNothingModuleRef: TermRef = ctx.requiredModuleRef("scala.runtime.Nothing")
354354
@threadUnsafe lazy val NullClass: ClassSymbol = enterCompleteClassSymbol(
355-
ScalaPackageClass, tpnme.Null, AbstractFinal.toFlags, List(ObjectClass.typeRef))
355+
ScalaPackageClass, tpnme.Null, AbstractFinal, List(ObjectClass.typeRef))
356356
def NullType: TypeRef = NullClass.typeRef
357357
@threadUnsafe lazy val RuntimeNullModuleRef: TermRef = ctx.requiredModuleRef("scala.runtime.Null")
358358

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ object Denotations {
11091109
final def filterDisjoint(denots: PreDenotation)(implicit ctx: Context): SingleDenotation =
11101110
if (denots.exists && denots.matches(this)) NoDenotation else this
11111111
def filterWithFlags(required: FlagConjunction, excluded: FlagSet)(implicit ctx: Context): SingleDenotation =
1112-
if (required.toFlags.isEmpty && excluded.isEmpty || compatibleWith(required, excluded)) this else NoDenotation
1112+
if (required.isEmpty && excluded.isEmpty || compatibleWith(required, excluded)) this else NoDenotation
11131113

11141114
type AsSeenFromResult = SingleDenotation
11151115
protected def computeAsSeenFrom(pre: Type)(implicit ctx: Context): SingleDenotation = {

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,8 @@ object Flags {
135135

136136
def termFlagSet(x: Long) = FlagSet(TERMS | x)
137137

138-
/** A class representing flag sets that should be tested
139-
* conjunctively. I.e. for a flag conjunction `fc`,
140-
* `x is fc` tests whether `x` contains all flags in `fc`.
141-
*/
142-
case class FlagConjunction(bits: Long) {
143-
def toFlags = FlagSet(bits)
144-
def flagsString: String = toFlags.flagsString
145-
def | (fs: FlagSet): FlagConjunction = FlagConjunction((toFlags | fs).bits)
146-
}
147-
138+
type FlagConjunction = FlagSet
139+
def FlagConjunction(bits: Long) = FlagSet(bits)
148140
def termFlagConjunction(x: Long) = FlagConjunction(TERMS | x)
149141

150142
private final val TYPESHIFT = 2

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,13 @@ object SymDenotations {
208208

209209
/** Has this denotation all of the flags in `fs` set? */
210210
final def isAllOf(fs: FlagConjunction)(implicit ctx: Context): Boolean =
211-
(if (isCurrent(fs.toFlags)) myFlags else flags).isAllOf(fs)
211+
(if (isCurrent(fs)) myFlags else flags).isAllOf(fs)
212212

213213
/** Has this denotation all of the flags in `fs` set, whereas none of the flags
214214
* in `butNot` are set?
215215
*/
216216
final def isAllOf(fs: FlagConjunction, butNot: FlagSet)(implicit ctx: Context): Boolean =
217-
(if (isCurrent(fs.toFlags) && isCurrent(butNot)) myFlags else flags).isAllOf(fs, butNot)
217+
(if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags).isAllOf(fs, butNot)
218218

219219
/** The type info, or, if symbol is not yet completed, the completer */
220220
final def infoOrCompleter: Type = myInfo

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.toFlags | NonMember | Permanent, tp)
299+
def newSkolem(tp: Type): TermSymbol = newSymbol(defn.RootClass, nme.SKOLEM, SyntheticArtifact | NonMember | Permanent, tp)
300300

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

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ class ClassfileParser(
185185
if (isEnum) {
186186
instanceScope.toList.map(_.ensureCompleted())
187187
staticScope.toList.map(_.ensureCompleted())
188-
classRoot.setFlag(Flags.JavaEnum.toFlags)
189-
moduleRoot.setFlag(Flags.JavaEnum.toFlags)
188+
classRoot.setFlag(Flags.JavaEnum)
189+
moduleRoot.setFlag(Flags.JavaEnum)
190190
}
191191

192192
result
@@ -276,7 +276,7 @@ class ClassfileParser(
276276
if (!enumClass.exists)
277277
ctx.warning(s"no linked class for java enum $sym in ${sym.owner}. A referencing class file might be missing an InnerClasses entry.")
278278
else {
279-
if (!enumClass.is(Flags.Sealed)) enumClass.setFlag(Flags.AbstractSealed.toFlags)
279+
if (!enumClass.is(Flags.Sealed)) enumClass.setFlag(Flags.AbstractSealed)
280280
enumClass.addAnnotation(Annotation.Child(sym))
281281
}
282282
}
@@ -555,7 +555,7 @@ class ClassfileParser(
555555
if (ctx.debug && ctx.verbose)
556556
println("" + sym + "; signature = " + sig + " type = " + newType)
557557
case tpnme.SyntheticATTR =>
558-
sym.setFlag(Flags.SyntheticArtifact.toFlags)
558+
sym.setFlag(Flags.SyntheticArtifact)
559559
case tpnme.BridgeATTR =>
560560
sym.setFlag(Flags.Bridge)
561561
case tpnme.DeprecatedATTR =>

compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ object JavaParsers {
120120
// This also avoids clashes between the constructor parameter names and member names.
121121
if (needsDummyConstr) {
122122
stats1 = constr1 :: stats1
123-
constr1 = makeConstructor(List(scalaDot(tpnme.Unit)), tparams, Flags.JavaDefined | Flags.PrivateLocal.toFlags)
123+
constr1 = makeConstructor(List(scalaDot(tpnme.Unit)), tparams, Flags.JavaDefined | Flags.PrivateLocal)
124124
}
125125
Template(constr1.asInstanceOf[DefDef], parents, Nil, EmptyValDef, stats1)
126126
}
@@ -401,7 +401,7 @@ object JavaParsers {
401401
throw new RuntimeException
402402
}
403403

404-
def typeParams(flags: FlagSet = Flags.JavaDefined | Flags.PrivateLocal.toFlags | Flags.Param): List[TypeDef] =
404+
def typeParams(flags: FlagSet = Flags.JavaDefined | Flags.PrivateLocal | Flags.Param): List[TypeDef] =
405405
if (in.token == LT) {
406406
in.nextToken()
407407
val tparams = repsep(() => typeParam(flags), COMMA)
@@ -711,7 +711,7 @@ object JavaParsers {
711711
val iface = atSpan(start, nameOffset) {
712712
TypeDef(
713713
name,
714-
makeTemplate(parents, body, tparams, false)).withMods(mods | Flags.Trait | Flags.JavaInterface.toFlags | Flags.Abstract)
714+
makeTemplate(parents, body, tparams, false)).withMods(mods | Flags.Trait | Flags.JavaInterface | Flags.Abstract)
715715
}
716716
addCompanionObject(statics, iface)
717717
}
@@ -835,7 +835,7 @@ object JavaParsers {
835835
Select(New(javaLangDot(tpnme.Enum)), nme.CONSTRUCTOR), List(enumType)), Nil)
836836
val enumclazz = atSpan(start, nameOffset) {
837837
TypeDef(name,
838-
makeTemplate(superclazz :: interfaces, body, List(), true)).withMods(mods | Flags.JavaEnum.toFlags)
838+
makeTemplate(superclazz :: interfaces, body, List(), true)).withMods(mods | Flags.JavaEnum)
839839
}
840840
addCompanionObject(consts ::: statics ::: predefs, enumclazz)
841841
}
@@ -854,7 +854,7 @@ object JavaParsers {
854854
skipAhead()
855855
accept(RBRACE)
856856
}
857-
ValDef(name.toTermName, enumType, unimplementedExpr).withMods(Modifiers(Flags.JavaEnum.toFlags | Flags.StableRealizable | Flags.JavaDefined | Flags.JavaStatic))
857+
ValDef(name.toTermName, enumType, unimplementedExpr).withMods(Modifiers(Flags.JavaEnum | Flags.StableRealizable | Flags.JavaDefined | Flags.JavaStatic))
858858
}
859859
}
860860

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,7 @@ object Parsers {
16031603
case USCORE =>
16041604
val start = in.skipToken()
16051605
val pname = WildcardParamName.fresh()
1606-
val param = ValDef(pname, TypeTree(), EmptyTree).withFlags(SyntheticTermParam.toFlags)
1606+
val param = ValDef(pname, TypeTree(), EmptyTree).withFlags(SyntheticTermParam)
16071607
.withSpan(Span(start))
16081608
placeholderParams = param :: placeholderParams
16091609
atSpan(start) { Ident(pname) }
@@ -2172,7 +2172,7 @@ object Parsers {
21722172
val start = in.offset
21732173
val mods =
21742174
annotsAsMods() | {
2175-
if (ownerKind == ParamOwner.Class) Param | PrivateLocal.toFlags
2175+
if (ownerKind == ParamOwner.Class) Param | PrivateLocal
21762176
else Param
21772177
} | {
21782178
if (ownerKind == ParamOwner.Def) EmptyFlags
@@ -2237,7 +2237,7 @@ object Parsers {
22372237
if (!(mods.flags &~ (ParamAccessor | Inline | impliedMods.flags)).isEmpty)
22382238
syntaxError("`val' or `var' expected")
22392239
if (firstClause && ofCaseClass) mods
2240-
else mods | PrivateLocal.toFlags
2240+
else mods | PrivateLocal
22412241
}
22422242
}
22432243
else {
@@ -2757,7 +2757,7 @@ object Parsers {
27572757
/** EnumCase = `case' (id ClassConstr [`extends' ConstrApps] | ids)
27582758
*/
27592759
def enumCase(start: Offset, mods: Modifiers): DefTree = {
2760-
val mods1 = mods | EnumCase.toFlags
2760+
val mods1 = mods | EnumCase
27612761
in.skipCASE()
27622762

27632763
atSpan(start, nameStart) {
@@ -2816,9 +2816,9 @@ object Parsers {
28162816
}
28172817
else {
28182818
newLineOptWhenFollowedBy(LBRACE)
2819-
val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal.toFlags))
2819+
val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal))
28202820
val vparamss1 = vparamss.map(_.map(vparam =>
2821-
vparam.withMods(vparam.mods &~ Param | ParamAccessor | PrivateLocal.toFlags)))
2821+
vparam.withMods(vparam.mods &~ Param | ParamAccessor | PrivateLocal)))
28222822
val templ = templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil)
28232823
if (tparams.isEmpty && vparamss.isEmpty) ModuleDef(name, templ)
28242824
else TypeDef(name.toTypeName, templ)

compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.
17221722
def Flags_ParamAccessor: Flags = core.Flags.ParamAccessor
17231723
def Flags_Enum: Flags = core.Flags.Enum
17241724
def Flags_ModuleClass: Flags = core.Flags.ModuleClass
1725-
def Flags_PrivateLocal: Flags = core.Flags.PrivateLocal.toFlags
1725+
def Flags_PrivateLocal: Flags = core.Flags.PrivateLocal
17261726
def Flags_Package: Flags = core.Flags.Package
17271727

17281728
//

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
258258
var inlineFlag = InlineProxy
259259
if (paramtp.hasAnnotation(defn.InlineParamAnnot)) inlineFlag |= Inline
260260
val (bindingFlags, bindingType) =
261-
if (isByName) (InlineByNameProxy.toFlags.toTermFlags, ExprType(argtpe.widen))
261+
if (isByName) (InlineByNameProxy.toTermFlags, ExprType(argtpe.widen))
262262
else (inlineFlag, argtpe.widen)
263263
val boundSym = newSym(name, bindingFlags, bindingType).asTerm
264264
val binding = {

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ class Namer { typer: Typer =>
532532
def addEnumConstants(mdef: DefTree, sym: Symbol)(implicit ctx: Context): Unit = mdef match {
533533
case vdef: ValDef if (isEnumConstant(vdef)) =>
534534
val enumClass = sym.owner.linkedClass
535-
if (!enumClass.is(Sealed)) enumClass.setFlag(Flags.AbstractSealed.toFlags)
535+
if (!enumClass.is(Sealed)) enumClass.setFlag(Flags.AbstractSealed)
536536
addChild(enumClass, sym)
537537
case _ =>
538538
}

0 commit comments

Comments
 (0)