Skip to content

Cleanup some uses of Flags combinations #15512

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 1 commit into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ class JSCodeGen()(using genCtx: Context) {

// Term members that are neither methods nor modules are fields
classSym.info.decls.filter { f =>
!f.isOneOf(Method | Module) && f.isTerm
!f.isOneOf(MethodOrModule) && f.isTerm
&& !f.hasAnnotation(jsdefn.JSNativeAnnot)
&& !f.hasAnnotation(jsdefn.JSOptionalAnnot)
&& !f.hasAnnotation(jsdefn.JSExportStaticAnnot)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/sjs/JSEncoding.scala
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ object JSEncoding {
js.StringLiteral(encodeFieldSymAsString(sym))

private def encodeFieldSymAsString(sym: Symbol)(using Context): String = {
require(sym.owner.isClass && sym.isTerm && !sym.isOneOf(Method | Module),
require(sym.owner.isClass && sym.isTerm && !sym.isOneOf(MethodOrModule),
"encodeFieldSym called with non-field symbol: " + sym)

val name0 = sym.javaSimpleName
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
else if (sym.is(Module))
if (sym.moduleClass.isNoInitsRealClass) PurePath else IdempotentPath
else if (sym.is(Lazy)) IdempotentPath
else if sym.isAllOf(Inline | Param) then Impure
else if sym.isAllOf(InlineParam) then Impure
else PurePath
}

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 @@ -288,8 +288,8 @@ class Definitions {
@tu lazy val Any_## : TermSymbol = enterMethod(AnyClass, nme.HASHHASH, ExprType(IntType), Final)
@tu lazy val Any_isInstanceOf: TermSymbol = enterT1ParameterlessMethod(AnyClass, nme.isInstanceOf_, _ => BooleanType, Final)
@tu lazy val Any_asInstanceOf: TermSymbol = enterT1ParameterlessMethod(AnyClass, nme.asInstanceOf_, _.paramRefs(0), Final)
@tu lazy val Any_typeTest: TermSymbol = enterT1ParameterlessMethod(AnyClass, nme.isInstanceOfPM, _ => BooleanType, Final | Synthetic | Artifact)
@tu lazy val Any_typeCast: TermSymbol = enterT1ParameterlessMethod(AnyClass, nme.asInstanceOfPM, _.paramRefs(0), Final | Synthetic | Artifact | StableRealizable)
@tu lazy val Any_typeTest: TermSymbol = enterT1ParameterlessMethod(AnyClass, nme.isInstanceOfPM, _ => BooleanType, Final | SyntheticArtifact)
@tu lazy val Any_typeCast: TermSymbol = enterT1ParameterlessMethod(AnyClass, nme.asInstanceOfPM, _.paramRefs(0), Final | SyntheticArtifact | StableRealizable)
// generated by pattern matcher and explicit nulls, eliminated by erasure

/** def getClass[A >: this.type](): Class[? <: A] */
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2873,7 +2873,7 @@ object Parsers {
if (mods.is(Private) && mods.hasPrivateWithin)
normalize(mods &~ Private)
else if (mods.isAllOf(AbstractOverride))
normalize(addFlag(mods &~ (Abstract | Override), AbsOverride))
normalize(addFlag(mods &~ AbstractOverride, AbsOverride))
else
mods

Expand Down Expand Up @@ -3034,7 +3034,7 @@ object Parsers {
val tps = commaSeparated(funArgType)
var counter = nparams
def nextIdx = { counter += 1; counter }
val paramFlags = if ofClass then Private | Local | ParamAccessor else Param
val paramFlags = if ofClass then LocalParamAccessor else Param
tps.map(makeSyntheticParameter(nextIdx, _, paramFlags | Synthetic | impliedMods.flags))

/** ClsParamClause ::= ‘(’ [‘erased’] ClsParams ‘)’ | UsingClsParamClause
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/ExpandSAMs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class ExpandSAMs extends MiniPhase:
def translateMatch(tree: Match, pfParam: Symbol, cases: List[CaseDef], defaultValue: Tree)(using Context) = {
val selector = tree.selector
val selectorTpe = selector.tpe.widen
val defaultSym = newSymbol(pfParam.owner, nme.WILDCARD, Synthetic | Case, selectorTpe)
val defaultSym = newSymbol(pfParam.owner, nme.WILDCARD, SyntheticCase, selectorTpe)
val defaultCase =
CaseDef(
Bind(defaultSym, Underscore(selectorTpe)),
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,14 @@ object ExplicitOuter {

/** A new param accessor for the outer field in class `cls` */
private def newOuterParamAccessor(cls: ClassSymbol)(using Context) =
newOuterSym(cls, cls, nme.OUTER, Private | Local | ParamAccessor)
newOuterSym(cls, cls, nme.OUTER, LocalParamAccessor)

/** A new outer accessor for class `cls` which is a member of `owner` */
private def newOuterAccessor(owner: ClassSymbol, cls: ClassSymbol)(using Context) = {
val deferredIfTrait = if (owner.is(Trait)) Deferred else EmptyFlags
val outerAccIfOwn = if (owner == cls) OuterAccessor else EmptyFlags
newOuterSym(owner, cls, outerAccName(cls),
Final | Method | StableRealizable | outerAccIfOwn | deferredIfTrait)
Final | StableMethod | outerAccIfOwn | deferredIfTrait)
}

private def outerAccName(cls: ClassSymbol)(using Context): TermName =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class InstrumentCoverage extends MacroTransform with IdentityDenotTransformer:

def isContextual(fun: Apply): Boolean =
val args = fun.args
args.nonEmpty && args.head.symbol.isAllOf(Given | Implicit)
args.nonEmpty && args.head.symbol.isAllOf(GivenOrImplicit)

val fun = tree.fun
val nestedApplyNeedsLift = fun match
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/LambdaLift.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ object LambdaLift:
private def generateProxies()(using Context): Unit =
for owner <- deps.tracked do
val fvs = deps.freeVars(owner).toList
val newFlags = Synthetic | (if (owner.isClass) ParamAccessor | Private else Param)
val newFlags = Synthetic | (if (owner.isClass) PrivateParamAccessor else Param)
report.debuglog(i"free var proxy of ${owner.showLocated}: $fvs%, %")
val freeProxyPairs =
for fv <- fvs yield
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/LazyVals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
}

val retryCase = {
val caseSymbol = newSymbol(methodSymbol, nme.DEFAULT_EXCEPTION_NAME, Synthetic | Case, defn.ThrowableType)
val caseSymbol = newSymbol(methodSymbol, nme.DEFAULT_EXCEPTION_NAME, SyntheticCase, defn.ThrowableType)
val triggerRetry = setFlagState.appliedTo(thiz, offset, initState, fieldId)
CaseDef(
Bind(caseSymbol, ref(caseSymbol)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ParamForwarding extends MiniPhase with IdentityDenotTransformer:
if alias.exists then
sym.copySymDenotation(
name = ParamAccessorName(sym.name),
initFlags = sym.flags | Method | StableRealizable,
initFlags = sym.flags | StableMethod,
info = sym.info.ensureMethodic
).installAfter(thisPhase)
val superAcc =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ object PatternMatcher {
private val initializer = MutableSymbolMap[Tree]()

private def newVar(rhs: Tree, flags: FlagSet, tpe: Type): TermSymbol =
newSymbol(ctx.owner, PatMatStdBinderName.fresh(), Synthetic | Case | flags,
newSymbol(ctx.owner, PatMatStdBinderName.fresh(), SyntheticCase | flags,
sanitize(tpe), coord = rhs.span)
// TODO: Drop Case once we use everywhere else `isPatmatGenerated`.

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/SymUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ object SymUtils:
isCodefined(mt.resultType)
case res =>
self.isCoDefinedGiven(res.typeSymbol)
self.isAllOf(Given | Method) && isCodefined(self.info)
self.isAllOf(GivenMethod) && isCodefined(self.info)

// TODO Scala 3.x: only check for inline vals (no final ones)
def isInlineVal(using Context) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
*
*/
def equalsBody(that: Tree)(using Context): Tree = {
val thatAsClazz = newSymbol(ctx.owner, nme.x_0, Synthetic | Case, clazzType, coord = ctx.owner.span) // x$0
val thatAsClazz = newSymbol(ctx.owner, nme.x_0, SyntheticCase, clazzType, coord = ctx.owner.span) // x$0
def wildcardAscription(tp: Type) = Typed(Underscore(tp), TypeTree(tp))
val pattern = Bind(thatAsClazz, wildcardAscription(AnnotatedType(clazzType, Annotation(defn.UncheckedAnnot)))) // x$0 @ (_: C @unchecked)
// compare primitive fields first, slow equality checks of non-primitive fields can be skipped when primitives differ
Expand Down Expand Up @@ -405,11 +405,11 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
.exists

private def writeReplaceDef(clazz: ClassSymbol)(using Context): TermSymbol =
newSymbol(clazz, nme.writeReplace, Method | Private | Synthetic,
newSymbol(clazz, nme.writeReplace, PrivateMethod | Synthetic,
MethodType(Nil, defn.AnyRefType), coord = clazz.coord).entered.asTerm

private def readResolveDef(clazz: ClassSymbol)(using Context): TermSymbol =
newSymbol(clazz, nme.readResolve, Method | Private | Synthetic,
newSymbol(clazz, nme.readResolve, PrivateMethod | Synthetic,
MethodType(Nil, defn.AnyRefType), coord = clazz.coord).entered.asTerm

/** If this is a static object `Foo`, add the method:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ class ExplicitJSClasses extends MiniPhase with InfoTransformer { thisPhase =>
}

val fieldName = jsclassFieldName(innerJSClass.name.asTypeName)
val fieldFlags = Synthetic | Artifact
val fieldFlags = SyntheticArtifact
val field = newSymbol(cls, fieldName, fieldFlags, defn.AnyRefType, coord = innerJSClass.coord)
addAnnotsIfInJSClass(field)
decls1.enter(field)
Expand All @@ -376,7 +376,7 @@ class ExplicitJSClasses extends MiniPhase with InfoTransformer { thisPhase =>
i"trying to ad-hoc expose objects in non-JS static object ${cls.fullName}")

val getterName = jsobjectGetterNameFor(innerObject)
val getterFlags = Method | Synthetic | Artifact
val getterFlags = Method | SyntheticArtifact
val getter = newSymbol(cls, getterName, getterFlags, ExprType(defn.AnyRefType), coord = innerObject.coord)
addAnnots(getter, innerObject)
decls1.enter(getter)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Deriving.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ trait Deriving {
// If we set the Synthetic flag here widenGiven will widen too far and the
// derived instance will have too low a priority to be selected over a freshly
// derived instance at the summoning site.
val flags = if info.isInstanceOf[MethodOrPoly] then Given | Method else Given | Lazy
val flags = if info.isInstanceOf[MethodOrPoly] then GivenMethod else Given | Lazy
synthetics +=
newSymbol(ctx.owner, instanceName, flags, info, coord = pos.span)
.entered
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ object EtaExpansion extends LiftImpure {
val paramTypes: List[Tree] =
if (isLastApplication && mt.paramInfos.length == xarity) mt.paramInfos map (_ => TypeTree())
else mt.paramInfos map TypeTree
var paramFlag = Synthetic | Param
var paramFlag = SyntheticParam
if (mt.isContextualMethod) paramFlag |= Given
else if (mt.isImplicitMethod) paramFlag |= Implicit
val params = mt.paramNames.lazyZip(paramTypes).map((name, tpe) =>
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ object Inliner {
| Literal(_) =>
true
case Ident(_) =>
isPureRef(tree) || tree.symbol.isAllOf(Inline | Param)
isPureRef(tree) || tree.symbol.isAllOf(InlineParam)
case Select(qual, _) =>
if (tree.symbol.is(Erased)) true
else isPureRef(tree) && apply(qual)
Expand Down Expand Up @@ -969,7 +969,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
case t: ThisType => thisProxy.getOrElse(t.cls, t)
case t: TypeRef => paramProxy.getOrElse(t, mapOver(t))
case t: SingletonType =>
if t.termSymbol.isAllOf(Inline | Param) then apply(t.widenTermRefExpr)
if t.termSymbol.isAllOf(InlineParam) then apply(t.widenTermRefExpr)
else paramProxy.getOrElse(t, mapOver(t))
case t => mapOver(t)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ class Namer { typer: Typer =>
if denot.isClass && !sym.isEnumAnonymClass && !sym.isRefinementClass then
val child = if (denot.is(Module)) denot.sourceModule else denot.symbol
denot.info.parents.foreach { parent => register(child, parent.classSymbol.asClass) }
else if denot.is(CaseVal, butNot = Method | Module) then
else if denot.is(CaseVal, butNot = MethodOrModule) then
assert(denot.is(Enum), denot)
denot.info.classSymbols.foreach { parent => register(denot.symbol, parent) }
end if
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Nullables.scala
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ object Nullables:
@tailrec def recur(s: Symbol): Boolean =
s != NoSymbol
&& s != refOwner
&& (s.isOneOf(Lazy | Method) // not at the rhs of lazy ValDef or in a method (or lambda)
&& (s.isOneOf(MethodOrLazy) // not at the rhs of lazy ValDef or in a method (or lambda)
|| s.isClass // not in a class
|| recur(s.owner))

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ object RefChecks {
"(this rule is designed to prevent ``accidental overrides'')")
else if (other.isStableMember && !member.isStableMember) // (1.5)
overrideError("needs to be a stable, immutable value")
else if (member.is(ModuleVal) && !other.isRealMethod && !other.isOneOf(Deferred | Lazy))
else if (member.is(ModuleVal) && !other.isRealMethod && !other.isOneOf(DeferredOrLazy))
overrideError("may not override a concrete non-lazy value")
else if (member.is(Lazy, butNot = Module) && !other.isRealMethod && !other.is(Lazy) &&
!warnOnMigration(overrideErrorMsg("may not override a non-lazy value"), member.srcPos, version = `3.0`))
Expand Down