Skip to content

Commit d00b123

Browse files
committed
Make implicit flags disjoint
Ensure that every symbol has only one of the three flags Implciit, Impled, Given. This is a prerequisite for simplifying the flags in the future.
1 parent 13ac0c4 commit d00b123

File tree

16 files changed

+38
-37
lines changed

16 files changed

+38
-37
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ object desugar {
167167
else vdef
168168
}
169169

170-
def makeImplicitParameters(tpts: List[Tree], contextualFlag: FlagSet = EmptyFlags, forPrimaryConstructor: Boolean = false)(implicit ctx: Context): List[ValDef] =
170+
def makeImplicitParameters(tpts: List[Tree], implicitFlag: FlagSet, forPrimaryConstructor: Boolean = false)(implicit ctx: Context): List[ValDef] =
171171
for (tpt <- tpts) yield {
172172
val paramFlags: FlagSet = if (forPrimaryConstructor) PrivateLocalParamAccessor else Param
173173
val epname = EvidenceParamName.fresh()
174-
ValDef(epname, tpt, EmptyTree).withFlags(paramFlags | Implicit | contextualFlag)
174+
ValDef(epname, tpt, EmptyTree).withFlags(paramFlags | implicitFlag)
175175
}
176176

177177
/** 1. Expand context bounds to evidence params. E.g.,
@@ -207,7 +207,7 @@ object desugar {
207207
val epbuf = new ListBuffer[ValDef]
208208
def desugarContextBounds(rhs: Tree): Tree = rhs match {
209209
case ContextBounds(tbounds, cxbounds) =>
210-
epbuf ++= makeImplicitParameters(cxbounds, forPrimaryConstructor = isPrimaryConstructor)
210+
epbuf ++= makeImplicitParameters(cxbounds, Implicit, forPrimaryConstructor = isPrimaryConstructor)
211211
tbounds
212212
case LambdaTypeTree(tparams, body) =>
213213
cpy.LambdaTypeTree(rhs)(tparams, desugarContextBounds(body))
@@ -310,7 +310,7 @@ object desugar {
310310
meth
311311
case evidenceParams =>
312312
val vparamss1 = meth.vparamss.reverse match {
313-
case (vparams @ (vparam :: _)) :: rvparamss if vparam.mods is Implicit =>
313+
case (vparams @ (vparam :: _)) :: rvparamss if vparam.mods is ImplicitOrGiven =>
314314
((evidenceParams ++ vparams) :: rvparamss).reverse
315315
case _ =>
316316
meth.vparamss :+ evidenceParams
@@ -321,7 +321,7 @@ object desugar {
321321
/** The implicit evidence parameters of `meth`, as generated by `desugar.defDef` */
322322
private def evidenceParams(meth: DefDef)(implicit ctx: Context): List[ValDef] =
323323
meth.vparamss.reverse match {
324-
case (vparams @ (vparam :: _)) :: _ if vparam.mods is Implicit =>
324+
case (vparams @ (vparam :: _)) :: _ if vparam.mods is ImplicitOrGiven =>
325325
vparams.dropWhile(!_.name.is(EvidenceParamName))
326326
case _ =>
327327
Nil
@@ -332,7 +332,7 @@ object desugar {
332332
private def toDefParam(tparam: TypeDef): TypeDef =
333333
tparam.withMods(tparam.rawMods & EmptyFlags | Param)
334334
private def toDefParam(vparam: ValDef): ValDef =
335-
vparam.withMods(vparam.rawMods & (Implicit | Erased) | Param)
335+
vparam.withMods(vparam.rawMods & (ImplicitOrGiven | Erased) | Param)
336336

337337
/** The expansion of a class definition. See inline comments for what is involved */
338338
def classDef(cdef: TypeDef)(implicit ctx: Context): Tree = {
@@ -400,7 +400,7 @@ object desugar {
400400
if (isCaseClass && originalTparams.isEmpty)
401401
ctx.error(CaseClassMissingParamList(cdef), namePos)
402402
ListOfNil
403-
} else if (isCaseClass && originalVparamss.head.exists(_.mods.is(Implicit))) {
403+
} else if (isCaseClass && originalVparamss.head.exists(_.mods.is(ImplicitOrGiven))) {
404404
ctx.error("Case classes should have a non-implicit parameter list", namePos)
405405
ListOfNil
406406
}
@@ -495,7 +495,7 @@ object desugar {
495495
// new C[Ts](paramss)
496496
lazy val creatorExpr = {
497497
val vparamss = constrVparamss match {
498-
case (vparam :: _) :: _ if vparam.mods.is(Implicit) => // add a leading () to match class parameters
498+
case (vparam :: _) :: _ if vparam.mods.is(ImplicitOrGiven) => // add a leading () to match class parameters
499499
Nil :: constrVparamss
500500
case _ =>
501501
constrVparamss
@@ -1177,7 +1177,7 @@ object desugar {
11771177
def makeContextualFunction(formals: List[Type], body: Tree, isErased: Boolean)(implicit ctx: Context): Tree = {
11781178
val mods = if (isErased) Given | Erased else Given
11791179
val params = makeImplicitParameters(formals.map(TypeTree), mods)
1180-
new FunctionWithMods(params, body, Modifiers(Implicit | mods))
1180+
new FunctionWithMods(params, body, Modifiers(mods))
11811181
}
11821182

11831183
/** Add annotation to tree:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
231231

232232
def valueParam(name: TermName, origInfo: Type): TermSymbol = {
233233
val maybeImplicit =
234-
if (tp.isContextual) Implicit | Given
234+
if (tp.isContextual) Given
235235
else if (tp.isImplicitMethod) Implicit
236236
else EmptyFlags
237237
val maybeErased = if (tp.isErasedMethod) Erased else EmptyFlags

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
134134

135135
case class Implicit()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Implicit)
136136

137-
case class Given()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Implicit | Flags.Given)
137+
case class Given()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Given)
138138

139139
case class Erased()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Erased)
140140

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Scopes._
1313
import Uniques._
1414
import ast.Trees._
1515
import ast.untpd
16-
import Flags.ImplicitOrImplied
16+
import Flags.ImplicitOrImpliedOrGiven
1717
import util.{FreshNameCreator, NoSource, SimpleIdentityMap, SourceFile}
1818
import typer.{Implicits, ImportInfo, Inliner, NamerContextOps, SearchHistory, SearchRoot, TypeAssigner, Typer}
1919
import Implicits.ContextualImplicits
@@ -214,7 +214,7 @@ object Contexts {
214214
implicitsCache = {
215215
val implicitRefs: List[ImplicitRef] =
216216
if (isClassDefContext)
217-
try owner.thisType.implicitMembers(ImplicitOrImplied)
217+
try owner.thisType.implicitMembers(ImplicitOrImpliedOrGiven)
218218
catch {
219219
case ex: CyclicReference => Nil
220220
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ object Flags {
487487
HigherKinded.toCommonFlags | Param | ParamAccessor.toCommonFlags |
488488
Scala2ExistentialCommon | MutableOrOpaque | Touched | JavaStatic |
489489
CovariantOrOuter | ContravariantOrLabel | CaseAccessor.toCommonFlags |
490-
Extension.toCommonFlags | NonMember | Implicit | Implied | Permanent | Synthetic |
490+
Extension.toCommonFlags | NonMember | Implicit | Given | Implied | Permanent | Synthetic |
491491
SuperAccessorOrScala2x | Inline
492492

493493
/** Flags that are not (re)set when completing the denotation, or, if symbol is
@@ -589,8 +589,10 @@ object Flags {
589589
final val InlineOrProxy: FlagSet = Inline | InlineProxy
590590

591591
final val ImplicitOrImplied = Implicit | Implied
592+
final val ImplicitOrImpliedOrGiven = Implicit | Implied | Given
593+
final val ImplicitOrGiven = Implicit | Given
592594

593-
final val ImplicitOrImpliedTerm = ImplicitOrImplied.toTermFlags
595+
final val ImplicitOrImpliedOrGivenTerm = ImplicitOrImpliedOrGiven.toTermFlags
594596

595597
/** Assumed to be pure */
596598
final val StableOrErased: FlagSet = StableRealizable | Erased

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ object Scopes {
409409
var irefs = new mutable.ListBuffer[TermRef]
410410
var e = lastEntry
411411
while (e ne null) {
412-
if (e.sym is ImplicitOrImplied) {
412+
if (e.sym is ImplicitOrImpliedOrGiven) {
413413
val d = e.sym.denot
414414
irefs += TermRef(NoPrefix, d.symbol.asTerm).withDenot(d)
415415
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1904,7 +1904,7 @@ object SymDenotations {
19041904
if (keepOnly eq implicitFilter)
19051905
if (this is Package) Iterator.empty
19061906
// implicits in package objects are added by the overriding `memberNames` in `PackageClassDenotation`
1907-
else info.decls.iterator filter (_ is ImplicitOrImplied)
1907+
else info.decls.iterator filter (_ is ImplicitOrImpliedOrGiven)
19081908
else info.decls.iterator
19091909
for (sym <- ownSyms) maybeAdd(sym.name)
19101910
names

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class CyclicReference private (val denot: SymDenotation) extends TypeError {
142142
}
143143
}
144144
// Give up and give generic errors.
145-
else if (cycleSym.is(ImplicitOrImplied, butNot = Method) && cycleSym.owner.isTerm)
145+
else if (cycleSym.is(ImplicitOrImpliedOrGiven, butNot = Method) && cycleSym.owner.isTerm)
146146
CyclicReferenceInvolvingImplicit(cycleSym)
147147
else
148148
CyclicReferenceInvolving(denot)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ object Types {
794794
*/
795795
final def implicitMembers(kind: FlagSet)(implicit ctx: Context): List[TermRef] = track("implicitMembers") {
796796
memberDenots(implicitFilter,
797-
(name, buf) => buf ++= member(name).altsWith(_.is(ImplicitOrImpliedTerm & kind)))
797+
(name, buf) => buf ++= member(name).altsWith(_.is(ImplicitOrImpliedOrGivenTerm & kind)))
798798
.toList.map(d => TermRef(this, d.symbol.asTerm))
799799
}
800800

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ object Parsers {
936936
case MATCH => matchType(EmptyTree, t)
937937
case FORSOME => syntaxError(ExistentialTypesNoLongerSupported()); t
938938
case _ =>
939-
if (imods.is(Implicit) && !t.isInstanceOf[FunctionWithMods])
939+
if (imods.is(ImplicitOrGiven) && !t.isInstanceOf[FunctionWithMods])
940940
syntaxError("Types with implicit keyword can only be function types `implicit (...) => ...`", implicitKwPos(start))
941941
if (imods.is(Erased) && !t.isInstanceOf[FunctionWithMods])
942942
syntaxError("Types with erased keyword can only be function types `erased (...) => ...`", implicitKwPos(start))
@@ -2218,7 +2218,7 @@ object Parsers {
22182218
var initialMods = EmptyModifiers
22192219
if (in.token == GIVEN) {
22202220
in.nextToken()
2221-
initialMods |= Given | Implicit
2221+
initialMods |= Given
22222222
}
22232223
if (in.token == ERASED) {
22242224
in.nextToken()
@@ -2247,16 +2247,15 @@ object Parsers {
22472247
ofCaseClass = ofCaseClass,
22482248
firstClause = firstClause,
22492249
initialMods = initialMods)
2250-
val lastClause =
2251-
params.nonEmpty && params.head.mods.flags.is(Implicit, butNot = Given)
2250+
val lastClause = params.nonEmpty && params.head.mods.flags.is(Implicit)
22522251
params :: (if (lastClause) Nil else recur(firstClause = false, nparams + params.length, isContextual))
22532252
}
22542253
else if (isContextual) {
22552254
val tps = commaSeparated(() => annotType())
22562255
var counter = nparams
22572256
def nextIdx = { counter += 1; counter }
22582257
val paramFlags = if (ofClass) Private | Local | ParamAccessor else Param
2259-
val params = tps.map(makeSyntheticParameter(nextIdx, _, paramFlags | Synthetic | Given | Implicit))
2258+
val params = tps.map(makeSyntheticParameter(nextIdx, _, paramFlags | Synthetic | Given))
22602259
params :: recur(firstClause = false, nparams + params.length, isContextual)
22612260
}
22622261
else Nil
@@ -2450,7 +2449,7 @@ object Parsers {
24502449
if (in.token == THIS) {
24512450
in.nextToken()
24522451
val vparamss = paramClauses()
2453-
if (vparamss.isEmpty || vparamss.head.take(1).exists(_.mods.is(Implicit)))
2452+
if (vparamss.isEmpty || vparamss.head.take(1).exists(_.mods.is(ImplicitOrGiven)))
24542453
in.token match {
24552454
case LBRACKET => syntaxError("no type parameters allowed here")
24562455
case EOF => incompleteInputError(AuxConstructorNeedsNonImplicitParameter())
@@ -2985,7 +2984,7 @@ object Parsers {
29852984
}
29862985
}
29872986

2988-
/** BlockStatSeq ::= { BlockStat semi } [ResultExpr]
2987+
/** BlockStatSeq ::= { BlockStat semi } [Expr]
29892988
* BlockStat ::= Import
29902989
* | Annotations [implicit] [lazy] Def
29912990
* | Annotations LocalModifiers TmplDef

compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
589589
val abs = sym.is(Abstract) || sym.is(Deferred) || absOver
590590
val over = sym.is(Override) || absOver
591591
new api.Modifiers(abs, over, sym.is(Final), sym.is(Sealed),
592-
sym.is(ImplicitOrImplied), sym.is(Lazy), sym.is(Macro), sym.isSuperAccessor)
592+
sym.is(ImplicitOrImpliedOrGiven), sym.is(Lazy), sym.is(Macro), sym.isSuperAccessor)
593593
}
594594

595595
def apiAnnotations(s: Symbol): List[api.Annotation] = {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ trait Checking {
663663
}
664664

665665
/** If `sym` is an implicit conversion, check that implicit conversions are enabled.
666-
* @pre sym.is(Implicit)
666+
* @pre sym.is(ImplicitOrGiven)
667667
*/
668668
def checkImplicitConversionDefOK(sym: Symbol)(implicit ctx: Context): Unit = {
669669
def check(): Unit = {
@@ -694,7 +694,7 @@ trait Checking {
694694
def checkImplicitConversionUseOK(sym: Symbol, posd: Positioned)(implicit ctx: Context): Unit =
695695
if (sym.exists) {
696696
val conv =
697-
if (sym.is(Implicit)) sym
697+
if (sym.is(ImplicitOrGiven)) sym
698698
else {
699699
assert(sym.name == nme.apply)
700700
sym.owner

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ abstract class Lifter {
123123
*
124124
* unless `pre` is idempotent.
125125
*/
126-
def liftPrefix(defs: mutable.ListBuffer[Tree], tree: Tree)(implicit ctx: Context): Tree =
126+
def liftPrefix(defs: mutable.ListBuffer[Tree], tree: Tree)(implicit ctx: Context): Tree =
127127
if (isIdempotentExpr(tree)) tree else lift(defs, tree)
128128
}
129129

@@ -209,7 +209,7 @@ object EtaExpansion extends LiftImpure {
209209
else mt.paramInfos map TypeTree
210210
var paramFlag = Synthetic | Param
211211
if (mt.isContextual) paramFlag |= Given
212-
if (mt.isImplicitMethod) paramFlag |= Implicit
212+
else if (mt.isImplicitMethod) paramFlag |= Implicit
213213
val params = (mt.paramNames, paramTypes).zipped.map((name, tpe) =>
214214
ValDef(name, tpe, EmptyTree).withFlags(paramFlag).withSpan(tree.span.startPos))
215215
var ids: List[Tree] = mt.paramNames map (name => Ident(name).withSpan(tree.span.startPos))
@@ -219,7 +219,7 @@ object EtaExpansion extends LiftImpure {
219219
if (mt.isContextual) body.pushAttachment(ApplyGiven, ())
220220
if (!isLastApplication) body = PostfixOp(body, Ident(nme.WILDCARD))
221221
val fn =
222-
if (mt.isContextual) new untpd.FunctionWithMods(params, body, Modifiers(Implicit | Given))
222+
if (mt.isContextual) new untpd.FunctionWithMods(params, body, Modifiers(Given))
223223
else if (mt.isImplicitMethod) new untpd.FunctionWithMods(params, body, Modifiers(Implicit))
224224
else untpd.Function(params, body)
225225
if (defs.nonEmpty) untpd.Block(defs.toList map (untpd.TypedSplice(_)), fn) else fn

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class ImportInfo(symf: Context => Symbol, val selectors: List[untpd.Tree],
9696
}
9797

9898
private def implicitFlag(implicit ctx: Context) =
99-
if (importImplied || ctx.mode.is(Mode.FindHiddenImplicits)) ImplicitOrImplied
99+
if (importImplied || ctx.mode.is(Mode.FindHiddenImplicits)) ImplicitOrImpliedOrGiven
100100
else Implicit
101101

102102
/** The implicit references imported by this import clause */

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ trait NamerContextOps { this: Context =>
125125
/** if isConstructor, make sure it has one non-implicit parameter list */
126126
def normalizeIfConstructor(termParamss: List[List[Symbol]], isConstructor: Boolean): List[List[Symbol]] =
127127
if (isConstructor &&
128-
(termParamss.isEmpty || termParamss.head.nonEmpty && (termParamss.head.head is Implicit)))
128+
(termParamss.isEmpty || termParamss.head.nonEmpty && (termParamss.head.head is ImplicitOrGiven)))
129129
Nil :: termParamss
130130
else
131131
termParamss
@@ -749,7 +749,7 @@ class Namer { typer: Typer =>
749749

750750
def missingType(sym: Symbol, modifier: String)(implicit ctx: Context): Unit = {
751751
ctx.error(s"${modifier}type of implicit definition needs to be given explicitly", sym.sourcePos)
752-
sym.resetFlag(Implicit)
752+
sym.resetFlag(ImplicitOrGiven)
753753
}
754754

755755
/** The completer of a symbol defined by a member def or import (except ClassSymbols) */
@@ -949,7 +949,7 @@ class Namer { typer: Typer =>
949949

950950
def whyNoForwarder(mbr: SingleDenotation): String = {
951951
val sym = mbr.symbol
952-
if (sym.is(ImplicitOrImplied) != exp.impliedOnly) s"is ${if (exp.impliedOnly) "not " else ""}implied"
952+
if (sym.is(ImplicitOrImpliedOrGiven) != exp.impliedOnly) s"is ${if (exp.impliedOnly) "not " else ""}implied"
953953
else if (!sym.isAccessibleFrom(path.tpe)) "is not accessible"
954954
else if (sym.isConstructor || sym.is(ModuleClass) || sym.is(Bridge)) SKIP
955955
else if (cls.derivesFrom(sym.owner) &&

doc-tool/src/dotty/tools/dottydoc/core/DocImplicitsPhase.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class DocImplicitsPhase extends MiniPhase {
1414

1515
override def transformDefDef(tree: DefDef)(implicit ctx: Context): Tree = {
1616
if (
17-
tree.symbol.is(Flags.Implicit) && // has to have an implicit flag
17+
tree.symbol.is(Flags.ImplicitOrImplied) && // has to have an implicit flag
1818
tree.symbol.owner.isStaticOwner && // owner has to be static (e.g. top-level `object`)
1919
tree.vparamss.length > 0 &&
2020
tree.vparamss(0).length == 1 // should only take one arg, since it has to be a transformation

0 commit comments

Comments
 (0)