Skip to content

Update to new context function and arguments syntax #8238

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
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
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/CompilationUnit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CompilationUnit protected (val source: SourceFile) {

var suspended: Boolean = false

def suspend()(given ctx: Context): Nothing =
def suspend()(using ctx: Context): Nothing =
if !suspended then
if (ctx.settings.XprintSuspension.value)
ctx.echo(i"suspended: $this")
Expand All @@ -57,7 +57,7 @@ class CompilationUnit protected (val source: SourceFile) {
* that can be tracked for being not null to the list of spans of assignments
* to these variables.
*/
def assignmentSpans(given Context): Map[Int, List[Span]] =
def assignmentSpans(using Context): Map[Int, List[Span]] =
if myAssignmentSpans == null then myAssignmentSpans = Nullables.assignmentSpans
myAssignmentSpans
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ object desugar {
*/

def makeExtensionDef(mdef: Tree, tparams: List[TypeDef], leadingParams: List[ValDef],
givenParamss: List[List[ValDef]])(given ctx: Context): Tree = {
givenParamss: List[List[ValDef]])(using ctx: Context): Tree = {
val allowed = "allowed here, since collective parameters are given"
mdef match {
case mdef: DefDef =>
Expand Down Expand Up @@ -986,7 +986,7 @@ object desugar {
}

/** Invent a name for an anonympus given or extension of type or template `impl`. */
def inventGivenOrExtensionName(impl: Tree)(given ctx: Context): SimpleName =
def inventGivenOrExtensionName(impl: Tree)(using ctx: Context): SimpleName =
val str = impl match
case impl: Template =>
if impl.parents.isEmpty then
Expand Down Expand Up @@ -1253,7 +1253,7 @@ object desugar {
else Apply(ref(tupleTypeRef.classSymbol.companionModule.termRef), ts)
}

private def isTopLevelDef(stat: Tree)(given Context): Boolean = stat match
private def isTopLevelDef(stat: Tree)(using Context): Boolean = stat match
case _: ValDef | _: PatDef | _: DefDef | _: Export => true
case stat: ModuleDef =>
stat.mods.isOneOf(GivenOrImplicit)
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/MainProxies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import ast.Trees._
*/
object MainProxies {

def mainProxies(stats: List[tpd.Tree])(given Context): List[untpd.Tree] = {
def mainProxies(stats: List[tpd.Tree])(using Context): List[untpd.Tree] = {
import tpd._
def mainMethods(stats: List[Tree]): List[Symbol] = stats.flatMap {
case stat: DefDef if stat.symbol.hasAnnotation(defn.MainAnnot) =>
Expand All @@ -40,7 +40,7 @@ object MainProxies {
}

import untpd._
def mainProxy(mainFun: Symbol)(given ctx: Context): List[TypeDef] = {
def mainProxy(mainFun: Symbol)(using ctx: Context): List[TypeDef] = {
val mainAnnotSpan = mainFun.getAnnotation(defn.MainAnnot).get.tree.span
def pos = mainFun.sourcePos
val argsRef = Ident(nme.args)
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -869,10 +869,10 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
* A not-null assertion for reference `x` has the form `x.$asInstanceOf$[x.type & T]`.
*/
object AssertNotNull with
def apply(tree: tpd.Tree, tpnn: Type)(given Context): tpd.Tree =
def apply(tree: tpd.Tree, tpnn: Type)(using Context): tpd.Tree =
tree.select(defn.Any_typeCast).appliedToType(AndType(tree.tpe, tpnn))

def unapply(tree: tpd.TypeApply)(given Context): Option[tpd.Tree] = tree match
def unapply(tree: tpd.TypeApply)(using Context): Option[tpd.Tree] = tree match
case TypeApply(Select(qual: RefTree, nme.asInstanceOfPM), arg :: Nil) =>
arg.tpe match
case AndType(ref, _) if qual.tpe eq ref => Some(qual)
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
Apply(tree, args)

/** An applied node that accepts only varargs as arguments */
def appliedToVarargs(args: List[Tree], tpt: Tree)(given Context): Tree =
def appliedToVarargs(args: List[Tree], tpt: Tree)(using Context): Tree =
appliedTo(repeated(args, tpt))

/** The current tree applied to given argument lists:
Expand Down Expand Up @@ -1378,7 +1378,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
/** Convert a list of trees to a vararg-compatible tree.
* Used to make arguments for methods that accept varargs.
*/
def repeated(trees: List[Tree], tpt: Tree)(given ctx: Context): Tree =
def repeated(trees: List[Tree], tpt: Tree)(using ctx: Context): Tree =
ctx.typeAssigner.arrayToRepeated(JavaSeqLiteral(trees, tpt))

/** Create a tree representing a list containing all
Expand All @@ -1390,7 +1390,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
* @param tpe the type of the elements of the resulting list.
*
*/
def mkList(trees: List[Tree], tpe: Tree)(given Context): Tree =
def mkList(trees: List[Tree], tpe: Tree)(using Context): Tree =
ref(defn.ListModule).select(nme.apply)
.appliedToTypeTree(tpe)
.appliedToVarargs(trees, tpe)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
* describe the core of a construct whereas the existing set are the modifiers
* given in the source.
*/
def withAddedFlags(flags: FlagSet, span: Span)(given ctx: Context): Modifiers =
def withAddedFlags(flags: FlagSet, span: Span)(using ctx: Context): Modifiers =
if this.flags.isAllOf(flags) then this
else if compatible(this.flags, flags) then this | flags
else
Expand Down
16 changes: 8 additions & 8 deletions compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import util.Spans.Span

object Annotations {

def annotClass(tree: Tree)(given Context) =
def annotClass(tree: Tree)(using Context) =
if (tree.symbol.isConstructor) tree.symbol.owner
else tree.tpe.typeSymbol

Expand Down Expand Up @@ -118,25 +118,25 @@ object Annotations {
apply(New(atp, args))

/** Create an annotation where the tree is computed lazily. */
def deferred(sym: Symbol)(treeFn: (given Context) => Tree)(implicit ctx: Context): Annotation =
def deferred(sym: Symbol)(treeFn: Context ?=> Tree)(implicit ctx: Context): Annotation =
new LazyAnnotation {
override def symbol(implicit ctx: Context): Symbol = sym
def complete(implicit ctx: Context) = treeFn(given ctx)
def complete(implicit ctx: Context) = treeFn(using ctx)
}

/** Create an annotation where the symbol and the tree are computed lazily. */
def deferredSymAndTree(symf: (given Context) => Symbol)(treeFn: (given Context) => Tree)(implicit ctx: Context): Annotation =
def deferredSymAndTree(symf: Context ?=> Symbol)(treeFn: Context ?=> Tree)(implicit ctx: Context): Annotation =
new LazyAnnotation {
private var mySym: Symbol = _

override def symbol(implicit ctx: Context): Symbol = {
if (mySym == null || mySym.defRunId != ctx.runId) {
mySym = symf(given ctx)
mySym = symf(using ctx)
assert(mySym != null)
}
mySym
}
def complete(implicit ctx: Context) = treeFn(given ctx)
def complete(implicit ctx: Context) = treeFn(using ctx)
}

def deferred(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation =
Expand All @@ -153,8 +153,8 @@ object Annotations {
object Child {

/** A deferred annotation to the result of a given child computation */
def later(delayedSym: (given Context) => Symbol, span: Span)(implicit ctx: Context): Annotation = {
def makeChildLater(given ctx: Context) = {
def later(delayedSym: Context ?=> Symbol, span: Span)(implicit ctx: Context): Annotation = {
def makeChildLater(using ctx: Context) = {
val sym = delayedSym
New(defn.ChildAnnot.typeRef.appliedTo(sym.owner.thisType.select(sym.name, sym)), Nil)
.withSpan(span)
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ object Contexts {
private val initialStore = store8

/** The current context */
def curCtx(given ctx: Context): Context = ctx
def curCtx(using ctx: Context): Context = ctx

/** A context is passed basically everywhere in dotc.
* This is convenient but carries the risk of captured contexts in
Expand Down Expand Up @@ -319,7 +319,7 @@ object Contexts {
/** Run `op` as if it was run in a fresh explore typer state, but possibly
* optimized to re-use the current typer state.
*/
final def test[T](op: (given Context) => T): T = typerState.test(op)(this)
final def test[T](op: Context ?=> T): T = typerState.test(op)(this)

/** Is this a context for the members of a class definition? */
def isClassDefContext: Boolean =
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Decorators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ object Decorators {

implicit class reportDeco[T](x: T) extends AnyVal {
def reporting(
op: (given WrappedResult[T]) => String,
op: WrappedResult[T] ?=> String,
printer: config.Printers.Printer = config.Printers.default): T = {
printer.println(op(given WrappedResult(x)))
printer.println(op(using WrappedResult(x)))
x
}
}
Expand Down
36 changes: 18 additions & 18 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Definitions {
* ContextFunctionN traits follow this template:
*
* trait ContextFunctionN[T0,...,T{N-1}, R] extends Object {
* def apply(given $x0: T0, ..., $x{N_1}: T{N-1}): R
* def apply(using $x0: T0, ..., $x{N_1}: T{N-1}): R
* }
*
* ErasedFunctionN traits follow this template:
Expand All @@ -104,7 +104,7 @@ class Definitions {
* ErasedContextFunctionN traits follow this template:
*
* trait ErasedContextFunctionN[T0,...,T{N-1}, R] extends Object {
* def apply (given erased $x0: T0, ..., $x{N_1}: T{N-1}): R
* def apply(using erased $x0: T0, ..., $x{N_1}: T{N-1}): R
* }
*
* ErasedFunctionN and ErasedContextFunctionN erase to Function0.
Expand Down Expand Up @@ -439,7 +439,7 @@ class Definitions {

@tu lazy val CollectionSeqType: TypeRef = ctx.requiredClassRef("scala.collection.Seq")
@tu lazy val SeqType: TypeRef = ctx.requiredClassRef("scala.collection.immutable.Seq")
def SeqClass(given Context): ClassSymbol = SeqType.symbol.asClass
def SeqClass(using Context): ClassSymbol = SeqType.symbol.asClass
@tu lazy val Seq_apply : Symbol = SeqClass.requiredMethod(nme.apply)
@tu lazy val Seq_head : Symbol = SeqClass.requiredMethod(nme.head)
@tu lazy val Seq_drop : Symbol = SeqClass.requiredMethod(nme.drop)
Expand All @@ -448,7 +448,7 @@ class Definitions {
@tu lazy val Seq_toSeq : Symbol = SeqClass.requiredMethod(nme.toSeq)

@tu lazy val ArrayType: TypeRef = ctx.requiredClassRef("scala.Array")
def ArrayClass(given Context): ClassSymbol = ArrayType.symbol.asClass
def ArrayClass(using Context): ClassSymbol = ArrayType.symbol.asClass
@tu lazy val Array_apply : Symbol = ArrayClass.requiredMethod(nme.apply)
@tu lazy val Array_update : Symbol = ArrayClass.requiredMethod(nme.update)
@tu lazy val Array_length : Symbol = ArrayClass.requiredMethod(nme.length)
Expand All @@ -458,10 +458,10 @@ class Definitions {
@tu lazy val ArrayModule: Symbol = ctx.requiredModule("scala.Array")

@tu lazy val UnitType: TypeRef = valueTypeRef("scala.Unit", java.lang.Void.TYPE, UnitEnc, nme.specializedTypeNames.Void)
def UnitClass(given Context): ClassSymbol = UnitType.symbol.asClass
def UnitModuleClass(given Context): Symbol = UnitType.symbol.asClass.linkedClass
def UnitClass(using Context): ClassSymbol = UnitType.symbol.asClass
def UnitModuleClass(using Context): Symbol = UnitType.symbol.asClass.linkedClass
@tu lazy val BooleanType: TypeRef = valueTypeRef("scala.Boolean", java.lang.Boolean.TYPE, BooleanEnc, nme.specializedTypeNames.Boolean)
def BooleanClass(given Context): ClassSymbol = BooleanType.symbol.asClass
def BooleanClass(using Context): ClassSymbol = BooleanType.symbol.asClass
@tu lazy val Boolean_! : Symbol = BooleanClass.requiredMethod(nme.UNARY_!)
@tu lazy val Boolean_&& : Symbol = BooleanClass.requiredMethod(nme.ZAND) // ### harmonize required... calls
@tu lazy val Boolean_|| : Symbol = BooleanClass.requiredMethod(nme.ZOR)
Expand All @@ -477,13 +477,13 @@ class Definitions {
}).symbol

@tu lazy val ByteType: TypeRef = valueTypeRef("scala.Byte", java.lang.Byte.TYPE, ByteEnc, nme.specializedTypeNames.Byte)
def ByteClass(given Context): ClassSymbol = ByteType.symbol.asClass
def ByteClass(using Context): ClassSymbol = ByteType.symbol.asClass
@tu lazy val ShortType: TypeRef = valueTypeRef("scala.Short", java.lang.Short.TYPE, ShortEnc, nme.specializedTypeNames.Short)
def ShortClass(given Context): ClassSymbol = ShortType.symbol.asClass
def ShortClass(using Context): ClassSymbol = ShortType.symbol.asClass
@tu lazy val CharType: TypeRef = valueTypeRef("scala.Char", java.lang.Character.TYPE, CharEnc, nme.specializedTypeNames.Char)
def CharClass(given Context): ClassSymbol = CharType.symbol.asClass
def CharClass(using Context): ClassSymbol = CharType.symbol.asClass
@tu lazy val IntType: TypeRef = valueTypeRef("scala.Int", java.lang.Integer.TYPE, IntEnc, nme.specializedTypeNames.Int)
def IntClass(given Context): ClassSymbol = IntType.symbol.asClass
def IntClass(using Context): ClassSymbol = IntType.symbol.asClass
@tu lazy val Int_- : Symbol = IntClass.requiredMethod(nme.MINUS, List(IntType))
@tu lazy val Int_+ : Symbol = IntClass.requiredMethod(nme.PLUS, List(IntType))
@tu lazy val Int_/ : Symbol = IntClass.requiredMethod(nme.DIV, List(IntType))
Expand All @@ -492,19 +492,19 @@ class Definitions {
@tu lazy val Int_>= : Symbol = IntClass.requiredMethod(nme.GE, List(IntType))
@tu lazy val Int_<= : Symbol = IntClass.requiredMethod(nme.LE, List(IntType))
@tu lazy val LongType: TypeRef = valueTypeRef("scala.Long", java.lang.Long.TYPE, LongEnc, nme.specializedTypeNames.Long)
def LongClass(given Context): ClassSymbol = LongType.symbol.asClass
def LongClass(using Context): ClassSymbol = LongType.symbol.asClass
@tu lazy val Long_+ : Symbol = LongClass.requiredMethod(nme.PLUS, List(LongType))
@tu lazy val Long_* : Symbol = LongClass.requiredMethod(nme.MUL, List(LongType))
@tu lazy val Long_/ : Symbol = LongClass.requiredMethod(nme.DIV, List(LongType))

@tu lazy val FloatType: TypeRef = valueTypeRef("scala.Float", java.lang.Float.TYPE, FloatEnc, nme.specializedTypeNames.Float)
def FloatClass(given Context): ClassSymbol = FloatType.symbol.asClass
def FloatClass(using Context): ClassSymbol = FloatType.symbol.asClass
@tu lazy val DoubleType: TypeRef = valueTypeRef("scala.Double", java.lang.Double.TYPE, DoubleEnc, nme.specializedTypeNames.Double)
def DoubleClass(given Context): ClassSymbol = DoubleType.symbol.asClass
def DoubleClass(using Context): ClassSymbol = DoubleType.symbol.asClass

@tu lazy val BoxedUnitClass: ClassSymbol = ctx.requiredClass("scala.runtime.BoxedUnit")
def BoxedUnit_UNIT(given Context): TermSymbol = BoxedUnitClass.linkedClass.requiredValue("UNIT")
def BoxedUnit_TYPE(given Context): TermSymbol = BoxedUnitClass.linkedClass.requiredValue("TYPE")
def BoxedUnit_UNIT(using Context): TermSymbol = BoxedUnitClass.linkedClass.requiredValue("UNIT")
def BoxedUnit_TYPE(using Context): TermSymbol = BoxedUnitClass.linkedClass.requiredValue("TYPE")

@tu lazy val BoxedBooleanClass: ClassSymbol = ctx.requiredClass("java.lang.Boolean")
@tu lazy val BoxedByteClass : ClassSymbol = ctx.requiredClass("java.lang.Byte")
Expand Down Expand Up @@ -574,9 +574,9 @@ class Definitions {
// in scalac modified to have Any as parent

@tu lazy val ThrowableType: TypeRef = ctx.requiredClassRef("java.lang.Throwable")
def ThrowableClass(given Context): ClassSymbol = ThrowableType.symbol.asClass
def ThrowableClass(using Context): ClassSymbol = ThrowableType.symbol.asClass
@tu lazy val SerializableType: TypeRef = JavaSerializableClass.typeRef
def SerializableClass(given Context): ClassSymbol = SerializableType.symbol.asClass
def SerializableClass(using Context): ClassSymbol = SerializableType.symbol.asClass

@tu lazy val JavaEnumClass: ClassSymbol = {
val cls = ctx.requiredClass("java.lang.Enum")
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Periods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ abstract class Periods { self: Context =>
op(ctx.fresh.setPeriod(pd))

/** Execute `op` at given phase id */
def atPhase[T](pid: PhaseId)(op: (given Context) => T): T =
op(given ctx.withPhase(pid))
def atPhase[T](pid: PhaseId)(op: Context ?=> T): T =
op(using ctx.withPhase(pid))

/** The period containing the current period where denotations do not change.
* We compute this by taking as first phase the first phase less or equal to
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Phases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ trait Phases {
}

/** Execute `op` at given phase */
def atPhase[T](phase: Phase)(op: (given Context) => T): T =
def atPhase[T](phase: Phase)(op: Context ?=> T): T =
atPhase(phase.id)(op)

def atNextPhase[T](op: (given Context) => T): T = atPhase(phase.next)(op)
def atNextPhase[T](op: Context ?=> T): T = atPhase(phase.next)(op)

def atPhaseNotLaterThan[T](limit: Phase)(op: (given Context) => T): T =
if (!limit.exists || phase <= limit) op(given this) else atPhase(limit)(op)
def atPhaseNotLaterThan[T](limit: Phase)(op: Context ?=> T): T =
if (!limit.exists || phase <= limit) op(using this) else atPhase(limit)(op)

def isAfterTyper: Boolean = base.isAfterTyper(phase)
}
Expand Down
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ object SymDenotations {
* of the opaque type definition.
* @param rhs The right hand side tree of the type definition
*/
def opaqueToBounds(info: Type, rhs: tpd.Tree)(given Context): Type =
def opaqueToBounds(info: Type, rhs: tpd.Tree)(using Context): Type =

def setAlias(tp: Type) =
def recur(self: Type): Unit = self match
Expand Down Expand Up @@ -636,7 +636,7 @@ object SymDenotations {
name.isPackageObjectName && owner.is(Package) && this.is(Module)

/** Is this symbol a toplevel definition in a package object? */
def isWrappedToplevelDef(given Context): Boolean =
def isWrappedToplevelDef(using Context): Boolean =
!isConstructor && owner.isPackageObject

/** Is this symbol an abstract type? */
Expand Down Expand Up @@ -1086,7 +1086,7 @@ object SymDenotations {
/** A class is effectively sealed if has the `final` or `sealed` modifier, or it
* is defined in Scala 3 and is neither abstract nor open.
*/
final def isEffectivelySealed(given Context): Boolean =
final def isEffectivelySealed(using Context): Boolean =
isOneOf(FinalOrSealed) || isClass && !isOneOf(EffectivelyOpenFlags)

/** The class containing this denotation which has the given effective name. */
Expand Down Expand Up @@ -1546,7 +1546,7 @@ object SymDenotations {
myBaseTypeCachePeriod = Nowhere
}

def invalidateMemberCaches(sym: Symbol)(given Context): Unit =
def invalidateMemberCaches(sym: Symbol)(using Context): Unit =
if myMemberCache != null then myMemberCache.invalidate(sym.name)
if !sym.flagsUNSAFE.is(Private) then
invalidateMemberNamesCache()
Expand Down Expand Up @@ -1753,7 +1753,7 @@ object SymDenotations {
}

/** Enter a symbol in given `scope` without potentially replacing the old copy. */
def enterNoReplace(sym: Symbol, scope: MutableScope)(given Context): Unit =
def enterNoReplace(sym: Symbol, scope: MutableScope)(using Context): Unit =
scope.enter(sym)
invalidateMemberCaches(sym)

Expand Down Expand Up @@ -2267,7 +2267,7 @@ object SymDenotations {
* - parameters and parameter accessors, since their Local status is already
* determined by whether they have a `val` or `var` or not.
*/
def canBeLocal(name: Name, flags: FlagSet)(given Context) =
def canBeLocal(name: Name, flags: FlagSet)(using Context) =
!name.isConstructorName && !flags.is(Param) && !flags.is(ParamAccessor)

// ---- Completion --------------------------------------------------------
Expand Down
Loading