Skip to content

Commit a257ac2

Browse files
authored
Merge pull request #6910 from dotty-staging/refactor-delegate-flags
Refactor Delegate flags
2 parents 4bfafbf + a1dc168 commit a257ac2

File tree

105 files changed

+368
-380
lines changed

Some content is hidden

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

105 files changed

+368
-380
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ object desugar {
480480
if (enumCases.isEmpty)
481481
ctx.error("Enumerations must constain at least one case", namePos)
482482
val enumCompanionRef = TermRefTree()
483-
val enumImport = Import(importDelegate = false, enumCompanionRef, enumCases.flatMap(caseIds))
483+
val enumImport = Import(importGiven = false, enumCompanionRef, enumCases.flatMap(caseIds))
484484
(enumImport :: enumStats, enumCases, enumCompanionRef)
485485
}
486486
else (stats, Nil, EmptyTree)
@@ -750,7 +750,7 @@ object desugar {
750750
// synthetic implicit C[Ts](p11: T11, ..., p1N: T1N) ... (pM1: TM1, ..., pMN: TMN): C[Ts] =
751751
// new C[Ts](p11, ..., p1N) ... (pM1, ..., pMN) =
752752
val implicitWrappers =
753-
if (!mods.isOneOf(DelegateOrImplicit))
753+
if (!mods.isOneOf(GivenOrImplicit))
754754
Nil
755755
else if (ctx.owner.is(Package)) {
756756
ctx.error(TopLevelImplicitClass(cdef), cdef.sourcePos)
@@ -764,7 +764,7 @@ object desugar {
764764
ctx.error(ImplicitCaseClass(cdef), cdef.sourcePos)
765765
Nil
766766
}
767-
else if (arity != 1 && !mods.is(Delegate)) {
767+
else if (arity != 1 && !mods.is(Given)) {
768768
ctx.error(ImplicitClassPrimaryConstructorArity(), cdef.sourcePos)
769769
Nil
770770
}
@@ -778,7 +778,7 @@ object desugar {
778778
// implicit wrapper is typechecked in same scope as constructor, so
779779
// we can reuse the constructor parameters; no derived params are needed.
780780
DefDef(className.toTermName, constrTparams, defParamss, classTypeRef, creatorExpr)
781-
.withMods(companionMods | mods.flags.toTermFlags & DelegateOrImplicit | Synthetic | Final)
781+
.withMods(companionMods | mods.flags.toTermFlags & GivenOrImplicit | Synthetic | Final)
782782
.withSpan(cdef.span) :: Nil
783783
}
784784

@@ -1177,14 +1177,14 @@ object desugar {
11771177
*/
11781178
def packageDef(pdef: PackageDef)(implicit ctx: Context): PackageDef = {
11791179
def isWrappedType(stat: TypeDef): Boolean =
1180-
!stat.isClassDef || stat.mods.isOneOf(DelegateOrImplicit)
1180+
!stat.isClassDef || stat.mods.isOneOf(GivenOrImplicit)
11811181
val wrappedTypeNames = pdef.stats.collect {
11821182
case stat: TypeDef if isWrappedType(stat) => stat.name
11831183
}
11841184
def needsObject(stat: Tree) = stat match {
11851185
case _: ValDef | _: PatDef | _: DefDef | _: Export => true
11861186
case stat: ModuleDef =>
1187-
stat.mods.isOneOf(DelegateOrImplicit) ||
1187+
stat.mods.isOneOf(GivenOrImplicit) ||
11881188
wrappedTypeNames.contains(stat.name.stripModuleClassSuffix.toTypeName)
11891189
case stat: TypeDef => isWrappedType(stat)
11901190
case _ => false

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ object TreeInfo {
874874
/** The expression has no side effects */
875875
val Pure: PurityLevel = new PurityLevel(3)
876876

877-
/** Running the expression a second time has no side effects. Delegate by `Pure`. */
877+
/** Running the expression a second time has no side effects. Implied by `Pure`. */
878878
val Idempotent: PurityLevel = new PurityLevel(1)
879879

880880
val Impure: PurityLevel = new PurityLevel(0)

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ object Trees {
754754
def unforced: LazyTree[T] = preRhs
755755
protected def force(x: Tree[T @uncheckedVariance]): Unit = preRhs = x
756756

757-
override def disableOverlapChecks = rawMods.is(Delegate)
757+
override def disableOverlapChecks = rawMods.is(Given)
758758
// disable order checks for implicit aliases since their given clause follows
759759
// their for clause, but the two appear swapped in the DefDef.
760760
}
@@ -800,7 +800,7 @@ object Trees {
800800
* where a selector is either an untyped `Ident`, `name` or
801801
* an untyped thicket consisting of `name` and `rename`.
802802
*/
803-
case class Import[-T >: Untyped] private[ast] (importDelegate: Boolean, expr: Tree[T], selectors: List[Tree[Untyped]])(implicit @constructorOnly src: SourceFile)
803+
case class Import[-T >: Untyped] private[ast] (importGiven: Boolean, expr: Tree[T], selectors: List[Tree[Untyped]])(implicit @constructorOnly src: SourceFile)
804804
extends DenotingTree[T] {
805805
type ThisTree[-T >: Untyped] = Import[T]
806806
}
@@ -1188,9 +1188,9 @@ object Trees {
11881188
case tree: Template if (constr eq tree.constr) && (parents eq tree.parents) && (derived eq tree.derived) && (self eq tree.self) && (body eq tree.unforcedBody) => tree
11891189
case tree => finalize(tree, untpd.Template(constr, parents, derived, self, body)(sourceFile(tree)))
11901190
}
1191-
def Import(tree: Tree)(importDelegate: Boolean, expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import = tree match {
1192-
case tree: Import if (importDelegate == tree.importDelegate) && (expr eq tree.expr) && (selectors eq tree.selectors) => tree
1193-
case _ => finalize(tree, untpd.Import(importDelegate, expr, selectors)(sourceFile(tree)))
1191+
def Import(tree: Tree)(importGiven: Boolean, expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import = tree match {
1192+
case tree: Import if (importGiven == tree.importGiven) && (expr eq tree.expr) && (selectors eq tree.selectors) => tree
1193+
case _ => finalize(tree, untpd.Import(importGiven, expr, selectors)(sourceFile(tree)))
11941194
}
11951195
def PackageDef(tree: Tree)(pid: RefTree, stats: List[Tree])(implicit ctx: Context): PackageDef = tree match {
11961196
case tree: PackageDef if (pid eq tree.pid) && (stats eq tree.stats) => tree
@@ -1331,8 +1331,8 @@ object Trees {
13311331
cpy.TypeDef(tree)(name, transform(rhs))
13321332
case tree @ Template(constr, parents, self, _) if tree.derived.isEmpty =>
13331333
cpy.Template(tree)(transformSub(constr), transform(tree.parents), Nil, transformSub(self), transformStats(tree.body))
1334-
case Import(importDelegate, expr, selectors) =>
1335-
cpy.Import(tree)(importDelegate, transform(expr), selectors)
1334+
case Import(importGiven, expr, selectors) =>
1335+
cpy.Import(tree)(importGiven, transform(expr), selectors)
13361336
case PackageDef(pid, stats) =>
13371337
cpy.PackageDef(tree)(transformSub(pid), transformStats(stats)(localCtx))
13381338
case Annotated(arg, annot) =>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
333333
Block(cdef :: Nil, New(cls.typeRef, Nil))
334334
}
335335

336-
def Import(importDelegate: Boolean, expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import =
337-
ta.assignType(untpd.Import(importDelegate, expr, selectors), ctx.newImportSymbol(ctx.owner, expr))
336+
def Import(importGiven: Boolean, expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import =
337+
ta.assignType(untpd.Import(importGiven, expr, selectors), ctx.newImportSymbol(ctx.owner, expr))
338338

339339
def PackageDef(pid: RefTree, stats: List[Tree])(implicit ctx: Context): PackageDef =
340340
ta.assignType(untpd.PackageDef(pid, stats), pid)

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,6 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
165165
case class Lazy()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Lazy)
166166

167167
case class Inline()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Inline)
168-
169-
case class Delegate()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Delegate)
170168
}
171169

172170
/** Modifiers and annotations for definitions
@@ -341,7 +339,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
341339
def Template(constr: DefDef, parents: List[Tree], derived: List[Tree], self: ValDef, body: LazyTreeList)(implicit src: SourceFile): Template =
342340
if (derived.isEmpty) new Template(constr, parents, self, body)
343341
else new DerivingTemplate(constr, parents ++ derived, self, body, derived.length)
344-
def Import(importDelegate: Boolean, expr: Tree, selectors: List[Tree])(implicit src: SourceFile): Import = new Import(importDelegate, expr, selectors)
342+
def Import(importGiven: Boolean, expr: Tree, selectors: List[Tree])(implicit src: SourceFile): Import = new Import(importGiven, expr, selectors)
345343
def PackageDef(pid: RefTree, stats: List[Tree])(implicit src: SourceFile): PackageDef = new PackageDef(pid, stats)
346344
def Annotated(arg: Tree, annot: Tree)(implicit src: SourceFile): Annotated = new Annotated(arg, annot)
347345

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

Lines changed: 3 additions & 3 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.DelegateOrGivenOrImplicit
16+
import Flags.GivenOrImplicit
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(DelegateOrGivenOrImplicit)
217+
try owner.thisType.implicitMembers(GivenOrImplicit)
218218
catch {
219219
case ex: CyclicReference => Nil
220220
}
@@ -404,7 +404,7 @@ object Contexts {
404404
case _ => None
405405
}
406406
ctx.fresh.setImportInfo(
407-
ImportInfo(sym, imp.selectors, impNameOpt, imp.importDelegate))
407+
ImportInfo(sym, imp.selectors, impNameOpt, imp.importGiven))
408408
}
409409

410410
/** Does current phase use an erased types interpretation? */

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ object Flags {
2222

2323
type Flag = opaques.Flag
2424

25-
delegate FlagOps {
25+
given FlagOps {
2626

2727
def (x: FlagSet) bits: Long = opaques.toBits(x)
2828

@@ -338,8 +338,6 @@ object Flags {
338338
/** Symbol is a Java default method */
339339
val (_, DefaultMethod @ _, _) = newFlags(38, "<defaultmethod>")
340340

341-
val (Delegate @ _, _, _) = newFlags(39, "delegate")
342-
343341
/** Symbol is an enum class or enum case (if used with case) */
344342
val (Enum @ _, _, _) = newFlags(40, "<enum>")
345343

@@ -421,7 +419,7 @@ object Flags {
421419

422420
/** Flags representing source modifiers */
423421
private val CommonSourceModifierFlags: FlagSet =
424-
commonFlags(Private, Protected, Final, Case, Implicit, Delegate, Given, Override, JavaStatic)
422+
commonFlags(Private, Protected, Final, Case, Implicit, Given, Override, JavaStatic)
425423

426424
val TypeSourceModifierFlags: FlagSet =
427425
CommonSourceModifierFlags.toTypeFlags | Abstract | Sealed | Opaque
@@ -443,7 +441,7 @@ object Flags {
443441
HigherKinded, Param, ParamAccessor,
444442
Scala2ExistentialCommon, Mutable, Opaque, Touched, JavaStatic,
445443
OuterOrCovariant, LabelOrContravariant, CaseAccessor,
446-
Extension, NonMember, Implicit, Given, Delegate, Permanent, Synthetic,
444+
Extension, NonMember, Implicit, Given, Permanent, Synthetic,
447445
SuperAccessorOrScala2x, Inline)
448446

449447
/** Flags that are not (re)set when completing the denotation, or, if symbol is
@@ -502,14 +500,14 @@ object Flags {
502500

503501
/** Flags that can apply to a module val */
504502
val RetainedModuleValFlags: FlagSet = RetainedModuleValAndClassFlags |
505-
Override | Final | Method | Implicit | Delegate | Lazy |
503+
Override | Final | Method | Implicit | Given | Lazy |
506504
Accessor | AbsOverride | StableRealizable | Captured | Synchronized | Erased
507505

508506
/** Flags that can apply to a module class */
509507
val RetainedModuleClassFlags: FlagSet = RetainedModuleValAndClassFlags | Enum
510508

511509
/** Flags retained in export forwarders */
512-
val RetainedExportFlags = Delegate | Given | Implicit | Extension
510+
val RetainedExportFlags = Given | Implicit | Extension
513511

514512
// ------- Other flag sets -------------------------------------
515513

@@ -528,10 +526,6 @@ object Flags {
528526
val DeferredOrLazyOrMethod: FlagSet = Deferred | Lazy | Method
529527
val DeferredOrTermParamOrAccessor: FlagSet = Deferred | ParamAccessor | TermParam // term symbols without right-hand sides
530528
val DeferredOrTypeParam: FlagSet = Deferred | TypeParam // type symbols without right-hand sides
531-
val DelegateOrGiven: FlagSet = Delegate | Given
532-
val DelegateOrGivenOrImplicit: FlagSet = Delegate | Given | Implicit
533-
val DelegateOrGivenOrImplicitVal: FlagSet = DelegateOrGivenOrImplicit.toTermFlags
534-
val DelegateOrImplicit: FlagSet = Delegate | Implicit
535529
val EnumValue: FlagSet = Enum | JavaStatic | StableRealizable // A Scala enum value
536530
val StableOrErased: FlagSet = Erased | StableRealizable // Assumed to be pure
537531
val ExtensionMethod: FlagSet = Extension | Method
@@ -540,6 +534,7 @@ object Flags {
540534
val EffectivelyFinalFlags: FlagSet = Final | Private
541535
val FinalOrSealed: FlagSet = Final | Sealed
542536
val GivenOrImplicit: FlagSet = Given | Implicit
537+
val GivenOrImplicitVal: FlagSet = GivenOrImplicit.toTermFlags
543538
val InlineOrProxy: FlagSet = Inline | InlineProxy // An inline method or inline argument proxy */
544539
val InlineMethod: FlagSet = Inline | Method
545540
val InlineParam: FlagSet = Inline | Param
@@ -570,7 +565,7 @@ object Flags {
570565
val Scala2Trait: FlagSet = Scala2x | Trait
571566
val SyntheticArtifact: FlagSet = Synthetic | Artifact
572567
val SyntheticCase: FlagSet = Synthetic | Case
573-
val SyntheticDelegateMethod: FlagSet = Synthetic | Delegate | Method
568+
val SyntheticGivenMethod: FlagSet = Synthetic | Given | Method
574569
val SyntheticModule: FlagSet = Synthetic | Module
575570
val SyntheticOpaque: FlagSet = Synthetic | Opaque
576571
val SyntheticTermParam: FlagSet = Synthetic | TermParam

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.isOneOf(DelegateOrGivenOrImplicit)) {
412+
if (e.sym.isOneOf(GivenOrImplicit)) {
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
@@ -1980,7 +1980,7 @@ object SymDenotations {
19801980
if (keepOnly eq implicitFilter)
19811981
if (this.is(Package)) Iterator.empty
19821982
// implicits in package objects are added by the overriding `memberNames` in `PackageClassDenotation`
1983-
else info.decls.iterator.filter(_.isOneOf(DelegateOrGivenOrImplicit))
1983+
else info.decls.iterator.filter(_.isOneOf(GivenOrImplicit))
19841984
else info.decls.iterator
19851985
for (sym <- ownSyms) maybeAdd(sym.name)
19861986
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.isOneOf(DelegateOrGivenOrImplicit, butNot = Method) && cycleSym.owner.isTerm)
145+
else if (cycleSym.isOneOf(GivenOrImplicit, butNot = Method) && cycleSym.owner.isTerm)
146146
CyclicReferenceInvolvingImplicit(cycleSym)
147147
else
148148
CyclicReferenceInvolving(denot)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,12 +789,12 @@ object Types {
789789
}
790790

791791
/** The set of implicit term members of this type
792-
* @param kind A subset of {Implicit, Delegate} that specifies what kind of implicit should
792+
* @param kind A subset of {Implicit, Given} that specifies what kind of implicit should
793793
* be returned
794794
*/
795795
final def implicitMembers(kind: FlagSet)(implicit ctx: Context): List[TermRef] = track("implicitMembers") {
796796
memberDenots(implicitFilter,
797-
(name, buf) => buf ++= member(name).altsWith(_.isOneOf(DelegateOrGivenOrImplicitVal & kind)))
797+
(name, buf) => buf ++= member(name).altsWith(_.isOneOf(GivenOrImplicitVal & kind)))
798798
.toList.map(d => TermRef(this, d.symbol.asTerm))
799799
}
800800

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Standard-Section: "ASTs" TopLevelStat*
5757
Stat = Term
5858
ValOrDefDef
5959
TYPEDEF Length NameRef (type_Term | Template) Modifier* -- modifiers type name (= type | bounds) | moifiers class name template
60-
IMPORT Length [IMPLIED] qual_Term Selector* -- import implied? qual selectors
60+
IMPORT Length [GIVEN] qual_Term Selector* -- import given? qual selectors
6161
ValOrDefDef = VALDEF Length NameRef type_Term rhs_Term? Modifier* -- modifiers val name : type (= rhs)?
6262
DEFDEF Length NameRef TypeParam* Params* returnType_Term rhs_Term?
6363
Modifier* -- modifiers def name [typeparams] paramss : returnType (= rhs)?
@@ -182,7 +182,7 @@ Standard-Section: "ASTs" TopLevelStat*
182182
SEALED -- sealed
183183
CASE -- case (for classes or objects)
184184
IMPLICIT -- implicit
185-
IMPLIED -- implied
185+
GIVEN -- given
186186
ERASED -- erased
187187
LAZY -- lazy
188188
OVERRIDE -- override
@@ -206,7 +206,6 @@ Standard-Section: "ASTs" TopLevelStat*
206206
DEFAULTparameterized -- Method with default parameters (default arguments are separate methods with DEFAULTGETTER names)
207207
STABLE -- Method that is assumed to be stable, i.e. its applications are legal paths
208208
EXTENSION -- An extension method
209-
GIVEN -- A new style implicit parameter, introduced with `given`
210209
PARAMsetter -- The setter part `x_=` of a var parameter `x` which itself is pickled as a PARAM
211210
EXPORTED -- An export forwarder
212211
Annotation
@@ -249,7 +248,7 @@ Standard Section: "Comments" Comment*
249248
object TastyFormat {
250249

251250
final val header: Array[Int] = Array(0x5C, 0xA1, 0xAB, 0x1F)
252-
val MajorVersion: Int = 15
251+
val MajorVersion: Int = 16
253252
val MinorVersion: Int = 0
254253

255254
/** Tags used to serialize names */
@@ -328,9 +327,8 @@ object TastyFormat {
328327
final val OPAQUE = 35
329328
final val EXTENSION = 36
330329
final val GIVEN = 37
331-
final val IMPLIED = 38
332-
final val PARAMsetter = 39
333-
final val EXPORTED = 40
330+
final val PARAMsetter = 38
331+
final val EXPORTED = 39
334332

335333
// Cat. 2: tag Nat
336334

@@ -477,7 +475,7 @@ object TastyFormat {
477475
| SEALED
478476
| CASE
479477
| IMPLICIT
480-
| IMPLIED
478+
| GIVEN
481479
| ERASED
482480
| LAZY
483481
| OVERRIDE
@@ -538,7 +536,6 @@ object TastyFormat {
538536
case SEALED => "SEALED"
539537
case CASE => "CASE"
540538
case IMPLICIT => "IMPLICIT"
541-
case IMPLIED => "IMPLIED"
542539
case ERASED => "ERASED"
543540
case LAZY => "LAZY"
544541
case OVERRIDE => "OVERRIDE"

0 commit comments

Comments
 (0)