Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d8cd2bb
Convert to using clauses
odersky Jul 9, 2020
717bce7
Convert Symbols to using clauses
odersky Jul 8, 2020
7330e7f
Convert Denotations to using clauses
odersky Jul 8, 2020
86ae3ca
Remove implicit definitions of `ctx` that are not parameters
odersky Jul 9, 2020
1d8cb7c
Change Printers to givens
odersky Jul 9, 2020
9d52399
Change Printers to givens
odersky Jul 9, 2020
d1f2a11
Remove implicit definitions of `ctx` that are not parameters (2)
odersky Jul 9, 2020
017a578
Convert to givens in TypeComparer
odersky Jul 9, 2020
f16fec0
Convert core classes (1)
odersky Jul 9, 2020
0c0d896
Convert core classes (2)
odersky Jul 9, 2020
114e0d2
Convert core classes (3)
odersky Jul 9, 2020
23b19e8
Convert core classes (4)
odersky Jul 9, 2020
50144f4
Convert core classes (5)
odersky Jul 9, 2020
adc75a0
Convert core classes (6)
odersky Jul 9, 2020
a66f8f3
Convert tasty and unpickler classes
odersky Jul 9, 2020
f76b9b6
Convert ast classes
odersky Jul 9, 2020
b935477
Convert config classes
odersky Jul 9, 2020
2ab9a58
Convert parser classes
odersky Jul 9, 2020
e71a167
Convert interactive classes
odersky Jul 9, 2020
f5c30a9
Convert reporting classes
odersky Jul 9, 2020
1ae90ec
Convert transform classes (1)
odersky Jul 9, 2020
7366f5c
Convert transform classes (2)
odersky Jul 9, 2020
1798e29
Convert transform classes (3)
odersky Jul 9, 2020
ce9aa2d
Convert transform classes (4)
odersky Jul 9, 2020
edb4869
Convert other dotc classes (1)
odersky Jul 9, 2020
68e1fea
Convert other dotc classes (2)
odersky Jul 9, 2020
4dc0b9b
Fixes
odersky Jul 10, 2020
d84abfe
Convert tools classes
odersky Jul 9, 2020
682ef6a
Convert repl classes
odersky Jul 10, 2020
6e54aed
Convert test classes (1)
odersky Jul 10, 2020
f71a4b3
Convert test classes (2)
odersky Jul 10, 2020
b76d2e4
Make Contexts.ctx an inline function
odersky Jul 10, 2020
a9c405f
Omit redundant (using ctx)
odersky Jul 10, 2020
f3e03fc
Move atPhase and friends to Contexts
odersky Jul 10, 2020
0ece69a
Use atPhase instead of inContext where possible
odersky Jul 10, 2020
da6829b
Rename Context#phases -> Phases.curPhases
odersky Jul 10, 2020
cd9f05d
Move individual phases to Phases
odersky Jul 10, 2020
165b7d8
Use atPhase instead of passing ctx.withPhase
odersky Jul 10, 2020
5442a4f
Use atPhase for ContextFunctionResults
odersky Jul 10, 2020
1236d8c
Convert remaining instance to atPhase
odersky Jul 10, 2020
159486a
Move plugins to ContextBase
odersky Jul 10, 2020
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
Prev Previous commit
Next Next commit
Convert core classes (1)
  • Loading branch information
odersky committed Jul 9, 2020
commit f16fec06ffe5d7ed98eab23a836df2e27ca60865
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
* imports For each element of RootImports, an import context
*/
protected def rootContext(implicit ctx: Context): Context = {
ctx.initialize()(ctx)
ctx.initialize()
ctx.base.setPhasePlan(comp.phases)
val rootScope = new MutableScope
val bootstrap = ctx.fresh
Expand All @@ -72,7 +72,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
.setTyper(new Typer)
.addMode(Mode.ImplicitsEnabled)
.setTyperState(new TyperState(ctx.typerState))
ctx.initialize()(start) // re-initialize the base context with start
ctx.initialize()(using start) // re-initialize the base context with start
def addImport(ctx: Context, rootRef: ImportInfo.RootRef) =
ctx.fresh.setImportInfo(ImportInfo.rootImport(rootRef))
defn.RootImportFns.foldLeft(start.setRun(this))(addImport)
Expand Down
70 changes: 35 additions & 35 deletions compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ object Annotations {
else tree.tpe.typeSymbol

abstract class Annotation {
def tree(implicit ctx: Context): Tree
def tree(using Context): Tree

def symbol(implicit ctx: Context): Symbol = annotClass(tree)
def symbol(using Context): Symbol = annotClass(tree)

def matches(cls: Symbol)(implicit ctx: Context): Boolean = symbol.derivesFrom(cls)
def matches(cls: Symbol)(using Context): Boolean = symbol.derivesFrom(cls)

def appliesToModule: Boolean = true // for now; see remark in SymDenotations

def derivedAnnotation(tree: Tree)(implicit ctx: Context): Annotation =
def derivedAnnotation(tree: Tree)(using Context): Annotation =
if (tree eq this.tree) this else Annotation(tree)

def arguments(implicit ctx: Context): List[Tree] = ast.tpd.arguments(tree)
def arguments(using Context): List[Tree] = ast.tpd.arguments(tree)

def argument(i: Int)(implicit ctx: Context): Option[Tree] = {
def argument(i: Int)(using Context): Option[Tree] = {
val args = arguments
if (i < args.length) Some(args(i)) else None
}
def argumentConstant(i: Int)(implicit ctx: Context): Option[Constant] =
def argumentConstant(i: Int)(using Context): Option[Constant] =
for (ConstantType(c) <- argument(i) map (_.tpe)) yield c

/** The tree evaluaton is in progress. */
Expand All @@ -41,14 +41,14 @@ object Annotations {
/** The tree evaluation has finished. */
def isEvaluated: Boolean = true

def ensureCompleted(implicit ctx: Context): Unit = tree
def ensureCompleted(using Context): Unit = tree

def sameAnnotation(that: Annotation)(implicit ctx: Context): Boolean =
def sameAnnotation(that: Annotation)(using Context): Boolean =
symbol == that.symbol && tree.sameTree(that.tree)
}

case class ConcreteAnnotation(t: Tree) extends Annotation {
def tree(implicit ctx: Context): Tree = t
def tree(using Context): Tree = t
}

/** The context to use to evaluate an annotation */
Expand Down Expand Up @@ -94,15 +94,15 @@ object Annotations {
* pickling/unpickling and TypeTreeMaps
*/
abstract class BodyAnnotation extends Annotation {
override def symbol(implicit ctx: Context): ClassSymbol = defn.BodyAnnot
override def derivedAnnotation(tree: Tree)(implicit ctx: Context): Annotation =
override def symbol(using Context): ClassSymbol = defn.BodyAnnot
override def derivedAnnotation(tree: Tree)(using Context): Annotation =
if (tree eq this.tree) this else ConcreteBodyAnnotation(tree)
override def arguments(implicit ctx: Context): List[Tree] = Nil
override def ensureCompleted(implicit ctx: Context): Unit = ()
override def arguments(using Context): List[Tree] = Nil
override def ensureCompleted(using Context): Unit = ()
}

class ConcreteBodyAnnotation(body: Tree) extends BodyAnnotation {
def tree(implicit ctx: Context): Tree = body
def tree(using Context): Tree = body
}

abstract class LazyBodyAnnotation extends BodyAnnotation {
Expand Down Expand Up @@ -132,52 +132,52 @@ object Annotations {

def apply(tree: Tree): ConcreteAnnotation = ConcreteAnnotation(tree)

def apply(cls: ClassSymbol)(implicit ctx: Context): Annotation =
def apply(cls: ClassSymbol)(using Context): Annotation =
apply(cls, Nil)

def apply(cls: ClassSymbol, arg: Tree)(implicit ctx: Context): Annotation =
def apply(cls: ClassSymbol, arg: Tree)(using Context): Annotation =
apply(cls, arg :: Nil)

def apply(cls: ClassSymbol, arg1: Tree, arg2: Tree)(implicit ctx: Context): Annotation =
def apply(cls: ClassSymbol, arg1: Tree, arg2: Tree)(using Context): Annotation =
apply(cls, arg1 :: arg2 :: Nil)

def apply(cls: ClassSymbol, args: List[Tree])(implicit ctx: Context): Annotation =
def apply(cls: ClassSymbol, args: List[Tree])(using Context): Annotation =
apply(cls.typeRef, args)

def apply(atp: Type, arg: Tree)(implicit ctx: Context): Annotation =
def apply(atp: Type, arg: Tree)(using Context): Annotation =
apply(atp, arg :: Nil)

def apply(atp: Type, arg1: Tree, arg2: Tree)(implicit ctx: Context): Annotation =
def apply(atp: Type, arg1: Tree, arg2: Tree)(using Context): Annotation =
apply(atp, arg1 :: arg2 :: Nil)

def apply(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation =
def apply(atp: Type, args: List[Tree])(using Context): Annotation =
apply(New(atp, args))

/** Create an annotation where the tree is computed lazily. */
def deferred(sym: Symbol)(treeFn: Context ?=> Tree)(implicit ctx: Context): Annotation =
def deferred(sym: Symbol)(treeFn: Context ?=> Tree)(using Context): Annotation =
new LazyAnnotation {
protected var myTree: Tree | (Context => Tree) = ctx => treeFn(using ctx)
protected var mySym: Symbol | (Context => Symbol) = sym
}

/** Create an annotation where the symbol and the tree are computed lazily. */
def deferredSymAndTree(symFn: Context ?=> Symbol)(treeFn: Context ?=> Tree)(implicit ctx: Context): Annotation =
def deferredSymAndTree(symFn: Context ?=> Symbol)(treeFn: Context ?=> Tree)(using Context): Annotation =
new LazyAnnotation {
protected var mySym: Symbol | (Context => Symbol) = ctx => symFn(using ctx)
protected var myTree: Tree | (Context => Tree) = ctx => treeFn(using ctx)
}

def deferred(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation =
def deferred(atp: Type, args: List[Tree])(using Context): Annotation =
deferred(atp.classSymbol)(New(atp, args))

def deferredResolve(atp: Type, args: List[ast.untpd.Tree])(implicit ctx: Context): Annotation =
def deferredResolve(atp: Type, args: List[ast.untpd.Tree])(using Context): Annotation =
deferred(atp.classSymbol)(ast.untpd.resolveConstructor(atp, args))

/** Extractor for child annotations */
object Child {

/** A deferred annotation to the result of a given child computation */
def later(delayedSym: Context ?=> Symbol, span: Span)(implicit ctx: Context): Annotation = {
def later(delayedSym: Context ?=> Symbol, span: Span)(using Context): Annotation = {
def makeChildLater(using Context) = {
val sym = delayedSym
New(defn.ChildAnnot.typeRef.appliedTo(sym.owner.thisType.select(sym.name, sym)), Nil)
Expand All @@ -187,21 +187,21 @@ object Annotations {
}

/** A regular, non-deferred Child annotation */
def apply(sym: Symbol, span: Span)(implicit ctx: Context): Annotation = later(sym, span)
def apply(sym: Symbol, span: Span)(using Context): Annotation = later(sym, span)

def unapply(ann: Annotation)(implicit ctx: Context): Option[Symbol] =
def unapply(ann: Annotation)(using Context): Option[Symbol] =
if (ann.symbol == defn.ChildAnnot) {
val AppliedType(_, (arg: NamedType) :: Nil) = ann.tree.tpe
Some(arg.symbol)
}
else None
}

def makeSourceFile(path: String)(implicit ctx: Context): Annotation =
def makeSourceFile(path: String)(using Context): Annotation =
apply(defn.SourceFileAnnot, Literal(Constant(path)))
}

def ThrowsAnnotation(cls: ClassSymbol)(implicit ctx: Context): Annotation = {
def ThrowsAnnotation(cls: ClassSymbol)(using Context): Annotation = {
val tref = cls.typeRef
Annotation(defn.ThrowsAnnot.typeRef.appliedTo(tref), Ident(tref))
}
Expand All @@ -211,24 +211,24 @@ object Annotations {
*/
implicit class AnnotInfo(val sym: Symbol) extends AnyVal {

def isDeprecated(implicit ctx: Context): Boolean =
def isDeprecated(using Context): Boolean =
sym.hasAnnotation(defn.DeprecatedAnnot)

def deprecationMessage(implicit ctx: Context): Option[String] =
def deprecationMessage(using Context): Option[String] =
for {
annot <- sym.getAnnotation(defn.DeprecatedAnnot)
arg <- annot.argumentConstant(0)
}
yield arg.stringValue

def migrationVersion(implicit ctx: Context): Option[Try[ScalaVersion]] =
def migrationVersion(using Context): Option[Try[ScalaVersion]] =
for {
annot <- sym.getAnnotation(defn.MigrationAnnot)
arg <- annot.argumentConstant(1)
}
yield ScalaVersion.parse(arg.stringValue)

def migrationMessage(implicit ctx: Context): Option[Try[ScalaVersion]] =
def migrationMessage(using Context): Option[Try[ScalaVersion]] =
for {
annot <- sym.getAnnotation(defn.MigrationAnnot)
arg <- annot.argumentConstant(0)
Expand Down
18 changes: 9 additions & 9 deletions compiler/src/dotty/tools/dotc/core/CheckRealizable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,30 @@ object CheckRealizable {

object NotConcrete extends Realizability(" is not a concrete type")

class NotFinal(sym: Symbol)(implicit ctx: Context)
class NotFinal(sym: Symbol)(using Context)
extends Realizability(i" refers to nonfinal $sym")

class HasProblemBounds(name: Name, info: Type)(implicit ctx: Context)
class HasProblemBounds(name: Name, info: Type)(using Context)
extends Realizability(i" has a member $name with possibly conflicting bounds ${info.bounds.lo} <: ... <: ${info.bounds.hi}")

class HasProblemBaseArg(typ: Type, argBounds: TypeBounds)(implicit ctx: Context)
class HasProblemBaseArg(typ: Type, argBounds: TypeBounds)(using Context)
extends Realizability(i" has a base type $typ with possibly conflicting parameter bounds ${argBounds.lo} <: ... <: ${argBounds.hi}")

class HasProblemBase(base1: Type, base2: Type)(implicit ctx: Context)
class HasProblemBase(base1: Type, base2: Type)(using Context)
extends Realizability(i" has conflicting base types $base1 and $base2")

class HasProblemField(fld: SingleDenotation, problem: Realizability)(implicit ctx: Context)
class HasProblemField(fld: SingleDenotation, problem: Realizability)(using Context)
extends Realizability(i" has a member $fld which is not a legal path\nsince ${fld.symbol.name}: ${fld.info}${problem.msg}")

class ProblemInUnderlying(tp: Type, problem: Realizability)(implicit ctx: Context)
class ProblemInUnderlying(tp: Type, problem: Realizability)(using Context)
extends Realizability(i"s underlying type ${tp}${problem.msg}") {
assert(problem != Realizable)
}

def realizability(tp: Type)(implicit ctx: Context): Realizability =
def realizability(tp: Type)(using Context): Realizability =
new CheckRealizable().realizability(tp)

def boundsRealizability(tp: Type)(implicit ctx: Context): Realizability =
def boundsRealizability(tp: Type)(using Context): Realizability =
new CheckRealizable().boundsRealizability(tp)

private val LateInitializedFlags = Lazy | Erased
Expand All @@ -61,7 +61,7 @@ object CheckRealizable {
* In general, a realizable type can have multiple inhabitants, hence it need not be stable (in the sense of
* Type.isStable).
*/
class CheckRealizable(implicit ctx: Context) {
class CheckRealizable(using Context) {
import CheckRealizable._

/** A set of all fields that have already been checked. Used
Expand Down
26 changes: 13 additions & 13 deletions compiler/src/dotty/tools/dotc/core/Comments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ object Comments {
* @param f The expansion function.
* @return The expanded comment, with the `usecases` populated.
*/
def expand(f: String => String)(implicit ctx: Context): Comment = {
def expand(f: String => String)(using Context): Comment = {
val expandedComment = f(raw)
val useCases = Comment.parseUsecases(expandedComment, span)
Comment(span, raw, Some(expandedComment), useCases)
Expand All @@ -76,7 +76,7 @@ object Comments {
def apply(span: Span, raw: String): Comment =
Comment(span, raw, None, Nil)

private def parseUsecases(expandedComment: String, span: Span)(implicit ctx: Context): List[UseCase] =
private def parseUsecases(expandedComment: String, span: Span)(using Context): List[UseCase] =
if (!isDocComment(expandedComment))
Nil
else
Expand All @@ -92,7 +92,7 @@ object Comments {
* def foo: A = ???
* }}}
*/
private def decomposeUseCase(body: String, span: Span, start: Int, end: Int)(implicit ctx: Context): UseCase = {
private def decomposeUseCase(body: String, span: Span, start: Int, end: Int)(using Context): UseCase = {
def subPos(start: Int, end: Int) =
if (span == NoSpan) NoSpan
else {
Expand All @@ -115,7 +115,7 @@ object Comments {
}

object UseCase {
def apply(code: String, codePos: Span)(implicit ctx: Context): UseCase = {
def apply(code: String, codePos: Span)(using Context): UseCase = {
val tree = {
val tree = new Parser(SourceFile.virtual("<usecase>", code)).localDef(codePos.start)
tree match {
Expand All @@ -140,7 +140,7 @@ object Comments {
import dotc.config.Printers.dottydoc
import scala.collection.mutable

def expand(sym: Symbol, site: Symbol)(implicit ctx: Context): String = {
def expand(sym: Symbol, site: Symbol)(using Context): String = {
val parent = if (site != NoSymbol) site else sym
defineVariables(parent)
expandedDocComment(sym, parent)
Expand All @@ -154,7 +154,7 @@ object Comments {
* of the same string are done, which is
* interpreted as a recursive variable definition.
*/
def expandedDocComment(sym: Symbol, site: Symbol, docStr: String = "")(implicit ctx: Context): String = {
def expandedDocComment(sym: Symbol, site: Symbol, docStr: String = "")(using Context): String = {
// when parsing a top level class or module, use the (module-)class itself to look up variable definitions
val parent = if ((sym.is(Flags.Module) || sym.isClass) && site.is(Flags.Package)) sym
else site
Expand All @@ -177,7 +177,7 @@ object Comments {
docStr.replaceAll("""\{@inheritDoc\p{Zs}*\}""", "@inheritdoc")

/** The cooked doc comment of an overridden symbol */
protected def superComment(sym: Symbol)(implicit ctx: Context): Option[String] =
protected def superComment(sym: Symbol)(using Context): Option[String] =
allInheritedOverriddenSymbols(sym).iterator map (x => cookedDocComment(x)) find (_ != "")

private val cookedDocComments = newMutableSymbolMap[String]
Expand All @@ -187,7 +187,7 @@ object Comments {
* If a symbol does not have a doc comment but some overridden version of it does,
* the doc comment of the overridden version is copied instead.
*/
def cookedDocComment(sym: Symbol, docStr: String = "")(implicit ctx: Context): String = cookedDocComments.getOrElseUpdate(sym, {
def cookedDocComment(sym: Symbol, docStr: String = "")(using Context): String = cookedDocComments.getOrElseUpdate(sym, {
var ownComment =
if (docStr.length == 0) ctx.docCtx.flatMap(_.docstring(sym).map(c => template(c.raw))).getOrElse("")
else template(docStr)
Expand Down Expand Up @@ -342,7 +342,7 @@ object Comments {
out.toString
}

protected def expandVariables(initialStr: String, sym: Symbol, site: Symbol)(implicit ctx: Context): String = {
protected def expandVariables(initialStr: String, sym: Symbol, site: Symbol)(using Context): String = {
val expandLimit = 10

def expandInternal(str: String, depth: Int): String = {
Expand Down Expand Up @@ -394,7 +394,7 @@ object Comments {
expandInternal(initialStr, 0).replace("""\$""", "$")
}

def defineVariables(sym: Symbol)(implicit ctx: Context): Unit = {
def defineVariables(sym: Symbol)(using Context): Unit = {
val Trim = "(?s)^[\\s&&[^\n\r]]*(.*?)\\s*$".r

val raw = ctx.docCtx.flatMap(_.docstring(sym).map(_.raw)).getOrElse("")
Expand All @@ -420,7 +420,7 @@ object Comments {
* @param vble The variable for which a definition is searched
* @param site The class for which doc comments are generated
*/
def lookupVariable(vble: String, site: Symbol)(implicit ctx: Context): Option[String] = site match {
def lookupVariable(vble: String, site: Symbol)(using Context): Option[String] = site match {
case NoSymbol => None
case _ =>
val searchList =
Expand All @@ -437,14 +437,14 @@ object Comments {
* If a symbol does not have a doc comment but some overridden version of it does,
* the position of the doc comment of the overridden version is returned instead.
*/
def docCommentPos(sym: Symbol)(implicit ctx: Context): Span =
def docCommentPos(sym: Symbol)(using Context): Span =
ctx.docCtx.flatMap(_.docstring(sym).map(_.span)).getOrElse(NoSpan)

/** A version which doesn't consider self types, as a temporary measure:
* an infinite loop has broken out between superComment and cookedDocComment
* since r23926.
*/
private def allInheritedOverriddenSymbols(sym: Symbol)(implicit ctx: Context): List[Symbol] =
private def allInheritedOverriddenSymbols(sym: Symbol)(using Context): List[Symbol] =
if (!sym.owner.isClass) Nil
else sym.allOverriddenSymbols.toList.filter(_ != NoSymbol) //TODO: could also be `sym.owner.allOverrid..`
//else sym.owner.ancestors map (sym overriddenSymbol _) filter (_ != NoSymbol)
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Constants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object Constants {
def isNonUnitAnyVal: Boolean = BooleanTag <= tag && tag <= DoubleTag
def isAnyVal: Boolean = UnitTag <= tag && tag <= DoubleTag

def tpe(implicit ctx: Context): Type = tag match {
def tpe(using Context): Type = tag match {
case UnitTag => defn.UnitType
case BooleanTag => defn.BooleanType
case ByteTag => defn.ByteType
Expand Down Expand Up @@ -150,7 +150,7 @@ object Constants {

/** Convert constant value to conform to given type.
*/
def convertTo(pt: Type)(implicit ctx: Context): Constant = {
def convertTo(pt: Type)(using Context): Constant = {
def classBound(pt: Type): Type = pt.dealias.stripTypeVar match {
case tref: TypeRef if !tref.symbol.isClass && tref.info.exists =>
classBound(tref.info.bounds.lo)
Expand Down
Loading