Skip to content

Commit 8739bbc

Browse files
committed
Distinguish between Implicit and Implied flags
We need that for pretty printing, and generally, to distinguish the two styles for implicits.
1 parent 8726cf7 commit 8739bbc

20 files changed

+37
-31
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,6 @@ object desugar {
344344
val isObject = mods.is(Module)
345345
val isCaseClass = mods.is(Case) && !isObject
346346
val isCaseObject = mods.is(Case) && isObject
347-
val isImplicit = mods.is(Implicit)
348-
val isInstance = isImplicit && mods.mods.exists(_.isInstanceOf[Mod.Instance])
349347
val isEnum = mods.isEnumClass && !mods.is(Module)
350348
def isEnumCase = mods.isEnumCase
351349
val isValueClass = parents.nonEmpty && isAnyVal(parents.head)
@@ -666,7 +664,7 @@ object desugar {
666664
// synthetic implicit C[Ts](p11: T11, ..., p1N: T1N) ... (pM1: TM1, ..., pMN: TMN): C[Ts] =
667665
// new C[Ts](p11, ..., p1N) ... (pM1, ..., pMN) =
668666
val implicitWrappers =
669-
if (!isImplicit)
667+
if (!mods.is(ImplicitOrImplied))
670668
Nil
671669
else if (ctx.owner is Package) {
672670
ctx.error(TopLevelImplicitClass(cdef), cdef.sourcePos)
@@ -676,7 +674,7 @@ object desugar {
676674
ctx.error(ImplicitCaseClass(cdef), cdef.sourcePos)
677675
Nil
678676
}
679-
else if (arity != 1 && !isInstance) {
677+
else if (arity != 1 && !mods.is(Implied)) {
680678
ctx.error(ImplicitClassPrimaryConstructorArity(), cdef.sourcePos)
681679
Nil
682680
}
@@ -690,7 +688,7 @@ object desugar {
690688
// implicit wrapper is typechecked in same scope as constructor, so
691689
// we can reuse the constructor parameters; no derived params are needed.
692690
DefDef(className.toTermName, constrTparams, defParamss, classTypeRef, creatorExpr)
693-
.withMods(companionMods | Synthetic | Implicit | Final)
691+
.withMods(companionMods | mods.flags & ImplicitOrImplied | Synthetic | Final)
694692
.withSpan(cdef.span) :: Nil
695693
}
696694

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

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

153153
case class Enum()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Enum)
154154

155-
case class Instance()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Implicit)
155+
case class Instance()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Implied)
156156
}
157157

158158
/** Modifiers and annotations for definitions

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ object Flags {
384384
/** Symbol is a Java default method */
385385
final val DefaultMethod: FlagSet = termFlag(38, "<defaultmethod>")
386386

387+
final val Implied: FlagSet = commonFlag(39, "implied")
388+
387389
/** Symbol is an enum class or enum case (if used with case) */
388390
final val Enum: FlagSet = commonFlag(40, "<enum>")
389391

@@ -460,7 +462,7 @@ object Flags {
460462

461463
/** Flags representing source modifiers */
462464
private val CommonSourceModifierFlags: FlagSet =
463-
commonFlags(Private, Protected, Final, Case, Implicit, Override, JavaStatic)
465+
commonFlags(Private, Protected, Final, Case, Implicit, Implied, Override, JavaStatic)
464466

465467
final val TypeSourceModifierFlags: FlagSet =
466468
CommonSourceModifierFlags.toTypeFlags | Abstract | Sealed | Opaque
@@ -485,7 +487,7 @@ object Flags {
485487
HigherKinded.toCommonFlags | Param | ParamAccessor.toCommonFlags |
486488
Scala2ExistentialCommon | MutableOrOpaque | Touched | JavaStatic |
487489
CovariantOrOuter | ContravariantOrLabel | CaseAccessor.toCommonFlags |
488-
Extension.toCommonFlags | NonMember | ImplicitCommon | Permanent | Synthetic |
490+
Extension.toCommonFlags | NonMember | ImplicitCommon | Implied | Permanent | Synthetic |
489491
SuperAccessorOrScala2x | Inline
490492

491493
/** Flags that are not (re)set when completing the denotation, or, if symbol is
@@ -541,7 +543,7 @@ object Flags {
541543

542544
/** Flags that can apply to a module val */
543545
final val RetainedModuleValFlags: FlagSet = RetainedModuleValAndClassFlags |
544-
Override | Final | Method | Implicit | Lazy |
546+
Override | Final | Method | Implicit | Implied | Lazy |
545547
Accessor | AbsOverride | StableRealizable | Captured | Synchronized | Erased
546548

547549
/** Flags that can apply to a module class */
@@ -586,6 +588,8 @@ object Flags {
586588
/** An inline method or inline argument proxy */
587589
final val InlineOrProxy: FlagSet = Inline | InlineProxy
588590

591+
final val ImplicitOrImplied = Implicit | Implied
592+
589593
/** Assumed to be pure */
590594
final val StableOrErased: FlagSet = StableRealizable | Erased
591595

@@ -601,9 +605,6 @@ object Flags {
601605
/** An inline method */
602606
final val InlineMethod: FlagConjunction = allOf(Inline, Method)
603607

604-
/** An implicit inline method */
605-
final val ImplicitInlineMethod: FlagConjunction = allOf(Inline, Implicit, Method)
606-
607608
/** An inline parameter */
608609
final val InlineParam: FlagConjunction = allOf(Inline, Param)
609610

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package core
99

1010
import Symbols._
1111
import Types.{TermRef, NoPrefix}
12-
import Flags.Implicit
12+
import Flags._
1313
import Names._
1414
import Contexts._
1515
import Denotations._
@@ -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 Implicit) {
412+
if (e.sym is ImplicitOrImplied) {
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,8 +1872,8 @@ object SymDenotations {
18721872
maybeAdd(name)
18731873
val ownSyms =
18741874
if (keepOnly eq implicitFilter)
1875-
if (this is Package) Iterator.empty
1876-
else info.decls.iterator filter (_ is Implicit)
1875+
if (this is Package) Iterator.empty // !!!!
1876+
else info.decls.iterator filter (_ is ImplicitOrImplied)
18771877
else info.decls.iterator
18781878
for (sym <- ownSyms) maybeAdd(sym.name)
18791879
names

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class CyclicReference private (val denot: SymDenotation) extends TypeError {
137137
}
138138
}
139139
// Give up and give generic errors.
140-
else if (cycleSym.is(Implicit, butNot = Method) && cycleSym.owner.isTerm)
140+
else if (cycleSym.is(ImplicitOrImplied, butNot = Method) && cycleSym.owner.isTerm)
141141
CyclicReferenceInvolvingImplicit(cycleSym)
142142
else
143143
CyclicReferenceInvolving(denot)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ object Types {
790790
/** The set of implicit members of this type */
791791
final def implicitMembers(implicit ctx: Context): List[TermRef] = track("implicitMembers") {
792792
memberDenots(implicitFilter,
793-
(name, buf) => buf ++= member(name).altsWith(_ is Implicit))
793+
(name, buf) => buf ++= member(name).altsWith(_ is ImplicitOrImplied))
794794
.toList.map(d => TermRef(this, d.symbol.asTerm))
795795
}
796796

compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ Standard-Section: "ASTs" TopLevelStat*
180180
SEALED
181181
CASE
182182
IMPLICIT
183+
IMPLIED
183184
ERASED
184185
LAZY
185186
OVERRIDE
@@ -324,7 +325,8 @@ object TastyFormat {
324325
final val OPAQUE = 35
325326
final val EXTENSION = 36
326327
final val GIVEN = 37
327-
final val PARAMsetter = 38
328+
final val IMPLIED = 38
329+
final val PARAMsetter = 39
328330

329331
// Cat. 2: tag Nat
330332

@@ -475,6 +477,7 @@ object TastyFormat {
475477
| SEALED
476478
| CASE
477479
| IMPLICIT
480+
| IMPLIED
478481
| ERASED
479482
| LAZY
480483
| OVERRIDE
@@ -535,6 +538,7 @@ object TastyFormat {
535538
case SEALED => "SEALED"
536539
case CASE => "CASE"
537540
case IMPLICIT => "IMPLICIT"
541+
case IMPLIED => "IMPLIED"
538542
case ERASED => "ERASED"
539543
case LAZY => "LAZY"
540544
case OVERRIDE => "OVERRIDE"

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ class TreePickler(pickler: TastyPickler) {
646646
if (flags is Scala2x) writeByte(SCALA2X)
647647
if (isTerm) {
648648
if (flags is Implicit) writeByte(IMPLICIT)
649+
if (flags is Implied) writeByte(IMPLIED)
649650
if (flags is Erased) writeByte(ERASED)
650651
if (flags.is(Lazy, butNot = Module)) writeByte(LAZY)
651652
if (flags is AbsOverride) { writeByte(ABSTRACT); writeByte(OVERRIDE) }

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ class TreeUnpickler(reader: TastyReader,
609609
case SEALED => addFlag(Sealed)
610610
case CASE => addFlag(Case)
611611
case IMPLICIT => addFlag(Implicit)
612+
case IMPLIED => addFlag(Implied)
612613
case ERASED => addFlag(Erased)
613614
case LAZY => addFlag(Lazy)
614615
case OVERRIDE => addFlag(Override)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ object Parsers {
783783
def functionRest(params: List[Tree]): Tree =
784784
atSpan(start, accept(ARROW)) {
785785
val t = typ()
786-
if (imods.is(Implicit | Given | Erased)) new FunctionWithMods(params, t, imods)
786+
if (imods.is(Given | Erased)) new FunctionWithMods(params, t, imods)
787787
else Function(params, t)
788788
}
789789
def funArgTypesRest(first: Tree, following: () => Tree) = {
@@ -817,7 +817,7 @@ object Parsers {
817817
}
818818
openParens.change(LPAREN, -1)
819819
accept(RPAREN)
820-
if (imods.is(Implicit) || isValParamList || in.token == ARROW)
820+
if (isValParamList || in.token == ARROW)
821821
functionRest(ts)
822822
else {
823823
val ts1 =

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
771771
if (ctx.settings.YdebugFlags.value) AnyFlags
772772
else if (suppressKw) PrintableFlags(isType) &~ Private
773773
else PrintableFlags(isType)
774-
if (homogenizedView && mods.flags.isTypeFlags) flagMask &~= Implicit // drop implicit from classes
774+
if (homogenizedView && mods.flags.isTypeFlags) flagMask &~= ImplicitOrImplied // drop implicit/implied from classes
775775
val flags = (if (sym.exists) sym.flags else (mods.flags)) & flagMask
776776
val flagsText = if (flags.isEmpty) "" else keywordStr(flags.toString)
777777
val annotations =

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(Implicit), sym.is(Lazy), sym.is(Macro), sym.isSuperAccessor)
592+
sym.is(ImplicitOrImplied), sym.is(Lazy), sym.is(Macro), sym.isSuperAccessor)
593593
}
594594

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ trait FlagsOpsImpl extends scala.tasty.reflect.FlagsOps with CoreImpl {
2121
def Sealed: Flags = core.Flags.Sealed
2222
def Case: Flags = core.Flags.Case
2323
def Implicit: Flags = core.Flags.Implicit
24+
def Implied = core.Flags.Implied
2425
def Erased: Flags = core.Flags.Erased
2526
def Lazy: Flags = core.Flags.Lazy
2627
def Override: Flags = core.Flags.Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ object Checking {
376376
))
377377
fail(ParamsNoInline(sym.owner))
378378

379-
if (sym.is(ImplicitCommon)) {
379+
if (sym.is(ImplicitCommon | Implied)) {
380380
if (sym.owner.is(Package))
381381
fail(TopLevelCantBeImplicit(sym))
382382
if (sym.isType)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ trait Deriving { this: Typer =>
143143
if (ctx.denotNamed(instanceName).exists) {
144144
if (reportErrors) ctx.error(i"duplicate typeclass derivation for $clsName", pos)
145145
}
146-
else add(newMethod(instanceName, info, pos.span, Implicit))
146+
else add(newMethod(instanceName, info, pos.span, Implied))
147147
}
148148

149149
/** Check derived type tree `derived` for the following well-formedness conditions:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class ImportInfo(symf: Context => Symbol, val selectors: List[untpd.Tree],
102102
} else
103103
for {
104104
renamed <- reverseMapping.keys
105-
denot <- pre.member(reverseMapping(renamed)).altsWith(_ is Implicit)
105+
denot <- pre.member(reverseMapping(renamed)).altsWith(_ is ImplicitOrImplied)
106106
} yield {
107107
val original = reverseMapping(renamed)
108108
val ref = TermRef(pre, original, denot)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
10491049
case Some(x) => x > 1 || x == 1 && !boundSym.is(Method)
10501050
case none => true
10511051
}
1052-
} && !boundSym.is(ImplicitInlineMethod)
1052+
} && !(boundSym.is(InlineMethod) && boundSym.is(ImplicitOrImplied))
10531053

10541054
val inlineBindings = new TreeMap {
10551055
override def transform(t: Tree)(implicit ctx: Context) = t match {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ class Namer { typer: Typer =>
342342
tree match {
343343
case tree: TypeDef if tree.isClassDef =>
344344
val name = checkNoConflict(tree.name).asTypeName
345-
val flags = checkFlags(tree.mods.flags &~ Implicit)
345+
val flags = checkFlags(tree.mods.flags &~ ImplicitOrImplied)
346346
val cls =
347347
createOrRefine[ClassSymbol](tree, name, flags,
348348
cls => adjustIfModule(new ClassCompleter(cls, tree)(ctx), tree),
@@ -954,7 +954,7 @@ class Namer { typer: Typer =>
954954
val ptype = typedAheadType(tpt).tpe appliedTo targs1.tpes
955955
if (ptype.typeParams.isEmpty) ptype
956956
else {
957-
if (denot.is(ModuleClass) && denot.sourceModule.is(Implicit))
957+
if (denot.is(ModuleClass) && denot.sourceModule.is(ImplicitOrImplied))
958958
missingType(denot.symbol, "parent ")(creationContext)
959959
fullyDefinedType(typedAheadExpr(parent).tpe, "class parent", parent.span)
960960
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,7 @@ class Typer extends Namer
14771477
def typedValDef(vdef: untpd.ValDef, sym: Symbol)(implicit ctx: Context): Tree = track("typedValDef") {
14781478
val ValDef(name, tpt, _) = vdef
14791479
completeAnnotations(vdef, sym)
1480-
if (sym is Implicit) checkImplicitConversionDefOK(sym)
1480+
if (sym is ImplicitOrImplied) checkImplicitConversionDefOK(sym)
14811481
val tpt1 = checkSimpleKinded(typedType(tpt))
14821482
val rhs1 = vdef.rhs match {
14831483
case rhs @ Ident(nme.WILDCARD) => rhs withType tpt1.tpe
@@ -1532,7 +1532,7 @@ class Typer extends Namer
15321532
val tparams1 = tparams mapconserve (typed(_).asInstanceOf[TypeDef])
15331533
val vparamss1 = vparamss nestedMapconserve (typed(_).asInstanceOf[ValDef])
15341534
vparamss1.foreach(checkNoForwardDependencies)
1535-
if (sym is Implicit) checkImplicitConversionDefOK(sym)
1535+
if (sym is ImplicitOrImplied) checkImplicitConversionDefOK(sym)
15361536
val tpt1 = checkSimpleKinded(typedType(tpt))
15371537

15381538
var rhsCtx = ctx

0 commit comments

Comments
 (0)