Skip to content

Refactor Delegate flags #6910

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 5 commits into from
Jul 26, 2019
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
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ object desugar {
if (enumCases.isEmpty)
ctx.error("Enumerations must constain at least one case", namePos)
val enumCompanionRef = TermRefTree()
val enumImport = Import(importDelegate = false, enumCompanionRef, enumCases.flatMap(caseIds))
val enumImport = Import(importGiven = false, enumCompanionRef, enumCases.flatMap(caseIds))
(enumImport :: enumStats, enumCases, enumCompanionRef)
}
else (stats, Nil, EmptyTree)
Expand Down Expand Up @@ -750,7 +750,7 @@ object desugar {
// synthetic implicit C[Ts](p11: T11, ..., p1N: T1N) ... (pM1: TM1, ..., pMN: TMN): C[Ts] =
// new C[Ts](p11, ..., p1N) ... (pM1, ..., pMN) =
val implicitWrappers =
if (!mods.isOneOf(DelegateOrImplicit))
if (!mods.isOneOf(GivenOrImplicit))
Nil
else if (ctx.owner.is(Package)) {
ctx.error(TopLevelImplicitClass(cdef), cdef.sourcePos)
Expand All @@ -764,7 +764,7 @@ object desugar {
ctx.error(ImplicitCaseClass(cdef), cdef.sourcePos)
Nil
}
else if (arity != 1 && !mods.is(Delegate)) {
else if (arity != 1 && !mods.is(Given)) {
ctx.error(ImplicitClassPrimaryConstructorArity(), cdef.sourcePos)
Nil
}
Expand All @@ -778,7 +778,7 @@ object desugar {
// implicit wrapper is typechecked in same scope as constructor, so
// we can reuse the constructor parameters; no derived params are needed.
DefDef(className.toTermName, constrTparams, defParamss, classTypeRef, creatorExpr)
.withMods(companionMods | mods.flags.toTermFlags & DelegateOrImplicit | Synthetic | Final)
.withMods(companionMods | mods.flags.toTermFlags & GivenOrImplicit | Synthetic | Final)
.withSpan(cdef.span) :: Nil
}

Expand Down Expand Up @@ -1177,14 +1177,14 @@ object desugar {
*/
def packageDef(pdef: PackageDef)(implicit ctx: Context): PackageDef = {
def isWrappedType(stat: TypeDef): Boolean =
!stat.isClassDef || stat.mods.isOneOf(DelegateOrImplicit)
!stat.isClassDef || stat.mods.isOneOf(GivenOrImplicit)
val wrappedTypeNames = pdef.stats.collect {
case stat: TypeDef if isWrappedType(stat) => stat.name
}
def needsObject(stat: Tree) = stat match {
case _: ValDef | _: PatDef | _: DefDef | _: Export => true
case stat: ModuleDef =>
stat.mods.isOneOf(DelegateOrImplicit) ||
stat.mods.isOneOf(GivenOrImplicit) ||
wrappedTypeNames.contains(stat.name.stripModuleClassSuffix.toTypeName)
case stat: TypeDef => isWrappedType(stat)
case _ => false
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 @@ -874,7 +874,7 @@ object TreeInfo {
/** The expression has no side effects */
val Pure: PurityLevel = new PurityLevel(3)

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

val Impure: PurityLevel = new PurityLevel(0)
Expand Down
14 changes: 7 additions & 7 deletions compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ object Trees {
def unforced: LazyTree[T] = preRhs
protected def force(x: Tree[T @uncheckedVariance]): Unit = preRhs = x

override def disableOverlapChecks = rawMods.is(Delegate)
override def disableOverlapChecks = rawMods.is(Given)
// disable order checks for implicit aliases since their given clause follows
// their for clause, but the two appear swapped in the DefDef.
}
Expand Down Expand Up @@ -800,7 +800,7 @@ object Trees {
* where a selector is either an untyped `Ident`, `name` or
* an untyped thicket consisting of `name` and `rename`.
*/
case class Import[-T >: Untyped] private[ast] (importDelegate: Boolean, expr: Tree[T], selectors: List[Tree[Untyped]])(implicit @constructorOnly src: SourceFile)
case class Import[-T >: Untyped] private[ast] (importGiven: Boolean, expr: Tree[T], selectors: List[Tree[Untyped]])(implicit @constructorOnly src: SourceFile)
extends DenotingTree[T] {
type ThisTree[-T >: Untyped] = Import[T]
}
Expand Down Expand Up @@ -1188,9 +1188,9 @@ object Trees {
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
case tree => finalize(tree, untpd.Template(constr, parents, derived, self, body)(sourceFile(tree)))
}
def Import(tree: Tree)(importDelegate: Boolean, expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import = tree match {
case tree: Import if (importDelegate == tree.importDelegate) && (expr eq tree.expr) && (selectors eq tree.selectors) => tree
case _ => finalize(tree, untpd.Import(importDelegate, expr, selectors)(sourceFile(tree)))
def Import(tree: Tree)(importGiven: Boolean, expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import = tree match {
case tree: Import if (importGiven == tree.importGiven) && (expr eq tree.expr) && (selectors eq tree.selectors) => tree
case _ => finalize(tree, untpd.Import(importGiven, expr, selectors)(sourceFile(tree)))
}
def PackageDef(tree: Tree)(pid: RefTree, stats: List[Tree])(implicit ctx: Context): PackageDef = tree match {
case tree: PackageDef if (pid eq tree.pid) && (stats eq tree.stats) => tree
Expand Down Expand Up @@ -1331,8 +1331,8 @@ object Trees {
cpy.TypeDef(tree)(name, transform(rhs))
case tree @ Template(constr, parents, self, _) if tree.derived.isEmpty =>
cpy.Template(tree)(transformSub(constr), transform(tree.parents), Nil, transformSub(self), transformStats(tree.body))
case Import(importDelegate, expr, selectors) =>
cpy.Import(tree)(importDelegate, transform(expr), selectors)
case Import(importGiven, expr, selectors) =>
cpy.Import(tree)(importGiven, transform(expr), selectors)
case PackageDef(pid, stats) =>
cpy.PackageDef(tree)(transformSub(pid), transformStats(stats)(localCtx))
case Annotated(arg, annot) =>
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
Block(cdef :: Nil, New(cls.typeRef, Nil))
}

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

def PackageDef(pid: RefTree, stats: List[Tree])(implicit ctx: Context): PackageDef =
ta.assignType(untpd.PackageDef(pid, stats), pid)
Expand Down
4 changes: 1 addition & 3 deletions compiler/src/dotty/tools/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
case class Lazy()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Lazy)

case class Inline()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Inline)

case class Delegate()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Delegate)
}

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

Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Scopes._
import Uniques._
import ast.Trees._
import ast.untpd
import Flags.DelegateOrGivenOrImplicit
import Flags.GivenOrImplicit
import util.{FreshNameCreator, NoSource, SimpleIdentityMap, SourceFile}
import typer.{Implicits, ImportInfo, Inliner, NamerContextOps, SearchHistory, SearchRoot, TypeAssigner, Typer}
import Implicits.ContextualImplicits
Expand Down Expand Up @@ -214,7 +214,7 @@ object Contexts {
implicitsCache = {
val implicitRefs: List[ImplicitRef] =
if (isClassDefContext)
try owner.thisType.implicitMembers(DelegateOrGivenOrImplicit)
try owner.thisType.implicitMembers(GivenOrImplicit)
catch {
case ex: CyclicReference => Nil
}
Expand Down Expand Up @@ -404,7 +404,7 @@ object Contexts {
case _ => None
}
ctx.fresh.setImportInfo(
ImportInfo(sym, imp.selectors, impNameOpt, imp.importDelegate))
ImportInfo(sym, imp.selectors, impNameOpt, imp.importGiven))
}

/** Does current phase use an erased types interpretation? */
Expand Down
19 changes: 7 additions & 12 deletions compiler/src/dotty/tools/dotc/core/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object Flags {

type Flag = opaques.Flag

delegate FlagOps {
given FlagOps {

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

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

val (Delegate @ _, _, _) = newFlags(39, "delegate")

/** Symbol is an enum class or enum case (if used with case) */
val (Enum @ _, _, _) = newFlags(40, "<enum>")

Expand Down Expand Up @@ -421,7 +419,7 @@ object Flags {

/** Flags representing source modifiers */
private val CommonSourceModifierFlags: FlagSet =
commonFlags(Private, Protected, Final, Case, Implicit, Delegate, Given, Override, JavaStatic)
commonFlags(Private, Protected, Final, Case, Implicit, Given, Override, JavaStatic)

val TypeSourceModifierFlags: FlagSet =
CommonSourceModifierFlags.toTypeFlags | Abstract | Sealed | Opaque
Expand All @@ -443,7 +441,7 @@ object Flags {
HigherKinded, Param, ParamAccessor,
Scala2ExistentialCommon, Mutable, Opaque, Touched, JavaStatic,
OuterOrCovariant, LabelOrContravariant, CaseAccessor,
Extension, NonMember, Implicit, Given, Delegate, Permanent, Synthetic,
Extension, NonMember, Implicit, Given, Permanent, Synthetic,
SuperAccessorOrScala2x, Inline)

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

/** Flags that can apply to a module val */
val RetainedModuleValFlags: FlagSet = RetainedModuleValAndClassFlags |
Override | Final | Method | Implicit | Delegate | Lazy |
Override | Final | Method | Implicit | Given | Lazy |
Accessor | AbsOverride | StableRealizable | Captured | Synchronized | Erased

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

/** Flags retained in export forwarders */
val RetainedExportFlags = Delegate | Given | Implicit | Extension
val RetainedExportFlags = Given | Implicit | Extension

// ------- Other flag sets -------------------------------------

Expand All @@ -528,10 +526,6 @@ object Flags {
val DeferredOrLazyOrMethod: FlagSet = Deferred | Lazy | Method
val DeferredOrTermParamOrAccessor: FlagSet = Deferred | ParamAccessor | TermParam // term symbols without right-hand sides
val DeferredOrTypeParam: FlagSet = Deferred | TypeParam // type symbols without right-hand sides
val DelegateOrGiven: FlagSet = Delegate | Given
val DelegateOrGivenOrImplicit: FlagSet = Delegate | Given | Implicit
val DelegateOrGivenOrImplicitVal: FlagSet = DelegateOrGivenOrImplicit.toTermFlags
val DelegateOrImplicit: FlagSet = Delegate | Implicit
val EnumValue: FlagSet = Enum | JavaStatic | StableRealizable // A Scala enum value
val StableOrErased: FlagSet = Erased | StableRealizable // Assumed to be pure
val ExtensionMethod: FlagSet = Extension | Method
Expand All @@ -540,6 +534,7 @@ object Flags {
val EffectivelyFinalFlags: FlagSet = Final | Private
val FinalOrSealed: FlagSet = Final | Sealed
val GivenOrImplicit: FlagSet = Given | Implicit
val GivenOrImplicitVal: FlagSet = GivenOrImplicit.toTermFlags
val InlineOrProxy: FlagSet = Inline | InlineProxy // An inline method or inline argument proxy */
val InlineMethod: FlagSet = Inline | Method
val InlineParam: FlagSet = Inline | Param
Expand Down Expand Up @@ -570,7 +565,7 @@ object Flags {
val Scala2Trait: FlagSet = Scala2x | Trait
val SyntheticArtifact: FlagSet = Synthetic | Artifact
val SyntheticCase: FlagSet = Synthetic | Case
val SyntheticDelegateMethod: FlagSet = Synthetic | Delegate | Method
val SyntheticGivenMethod: FlagSet = Synthetic | Given | Method
val SyntheticModule: FlagSet = Synthetic | Module
val SyntheticOpaque: FlagSet = Synthetic | Opaque
val SyntheticTermParam: FlagSet = Synthetic | TermParam
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Scopes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ object Scopes {
var irefs = new mutable.ListBuffer[TermRef]
var e = lastEntry
while (e ne null) {
if (e.sym.isOneOf(DelegateOrGivenOrImplicit)) {
if (e.sym.isOneOf(GivenOrImplicit)) {
val d = e.sym.denot
irefs += TermRef(NoPrefix, d.symbol.asTerm).withDenot(d)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1980,7 +1980,7 @@ object SymDenotations {
if (keepOnly eq implicitFilter)
if (this.is(Package)) Iterator.empty
// implicits in package objects are added by the overriding `memberNames` in `PackageClassDenotation`
else info.decls.iterator.filter(_.isOneOf(DelegateOrGivenOrImplicit))
else info.decls.iterator.filter(_.isOneOf(GivenOrImplicit))
else info.decls.iterator
for (sym <- ownSyms) maybeAdd(sym.name)
names
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeErrors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class CyclicReference private (val denot: SymDenotation) extends TypeError {
}
}
// Give up and give generic errors.
else if (cycleSym.isOneOf(DelegateOrGivenOrImplicit, butNot = Method) && cycleSym.owner.isTerm)
else if (cycleSym.isOneOf(GivenOrImplicit, butNot = Method) && cycleSym.owner.isTerm)
CyclicReferenceInvolvingImplicit(cycleSym)
else
CyclicReferenceInvolving(denot)
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -789,12 +789,12 @@ object Types {
}

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

Expand Down
15 changes: 6 additions & 9 deletions compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Standard-Section: "ASTs" TopLevelStat*
Stat = Term
ValOrDefDef
TYPEDEF Length NameRef (type_Term | Template) Modifier* -- modifiers type name (= type | bounds) | moifiers class name template
IMPORT Length [IMPLIED] qual_Term Selector* -- import implied? qual selectors
IMPORT Length [GIVEN] qual_Term Selector* -- import given? qual selectors
ValOrDefDef = VALDEF Length NameRef type_Term rhs_Term? Modifier* -- modifiers val name : type (= rhs)?
DEFDEF Length NameRef TypeParam* Params* returnType_Term rhs_Term?
Modifier* -- modifiers def name [typeparams] paramss : returnType (= rhs)?
Expand Down Expand Up @@ -182,7 +182,7 @@ Standard-Section: "ASTs" TopLevelStat*
SEALED -- sealed
CASE -- case (for classes or objects)
IMPLICIT -- implicit
IMPLIED -- implied
GIVEN -- given
ERASED -- erased
LAZY -- lazy
OVERRIDE -- override
Expand All @@ -206,7 +206,6 @@ Standard-Section: "ASTs" TopLevelStat*
DEFAULTparameterized -- Method with default parameters (default arguments are separate methods with DEFAULTGETTER names)
STABLE -- Method that is assumed to be stable, i.e. its applications are legal paths
EXTENSION -- An extension method
GIVEN -- A new style implicit parameter, introduced with `given`
PARAMsetter -- The setter part `x_=` of a var parameter `x` which itself is pickled as a PARAM
EXPORTED -- An export forwarder
Annotation
Expand Down Expand Up @@ -249,7 +248,7 @@ Standard Section: "Comments" Comment*
object TastyFormat {

final val header: Array[Int] = Array(0x5C, 0xA1, 0xAB, 0x1F)
val MajorVersion: Int = 15
val MajorVersion: Int = 16
val MinorVersion: Int = 0

/** Tags used to serialize names */
Expand Down Expand Up @@ -328,9 +327,8 @@ object TastyFormat {
final val OPAQUE = 35
final val EXTENSION = 36
final val GIVEN = 37
final val IMPLIED = 38
final val PARAMsetter = 39
final val EXPORTED = 40
final val PARAMsetter = 38
final val EXPORTED = 39

// Cat. 2: tag Nat

Expand Down Expand Up @@ -477,7 +475,7 @@ object TastyFormat {
| SEALED
| CASE
| IMPLICIT
| IMPLIED
| GIVEN
| ERASED
| LAZY
| OVERRIDE
Expand Down Expand Up @@ -538,7 +536,6 @@ object TastyFormat {
case SEALED => "SEALED"
case CASE => "CASE"
case IMPLICIT => "IMPLICIT"
case IMPLIED => "IMPLIED"
case ERASED => "ERASED"
case LAZY => "LAZY"
case OVERRIDE => "OVERRIDE"
Expand Down
Loading