Skip to content

Commit 3da2ffc

Browse files
Merge pull request #7245 from dotty-staging/drop-old-given
Drop old syntax styles for givens
2 parents dbeba79 + 4d79c90 commit 3da2ffc

File tree

171 files changed

+1982
-2139
lines changed

Some content is hidden

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

171 files changed

+1982
-2139
lines changed

compiler/src/dotty/tools/backend/jvm/GenBCode.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ class GenBCodePipeline(val int: DottyBackendInterface)(implicit val ctx: Context
161161
val same = classSymbol.effectiveName.toString == dupClassSym.effectiveName.toString
162162
ctx.atPhase(ctx.typerPhase) {
163163
if (same)
164-
the[Context].warning( // FIXME: This should really be an error, but then FromTasty tests fail
164+
summon[Context].warning( // FIXME: This should really be an error, but then FromTasty tests fail
165165
s"${cl1.show} and ${cl2.showLocated} produce classes that overwrite one another", cl1.sourcePos)
166166
else
167-
the[Context].warning(s"${cl1.show} differs only in case from ${cl2.showLocated}. " +
167+
summon[Context].warning(s"${cl1.show} differs only in case from ${cl2.showLocated}. " +
168168
"Such classes will overwrite one another on case-insensitive filesystems.", cl1.sourcePos)
169169
}
170170
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ object desugar {
893893
* If the given member `mdef` is not of this form, flag it as an error.
894894
*/
895895

896-
def makeExtensionDef(mdef: Tree, tparams: List[TypeDef], leadingParams: List[ValDef]) given (ctx: Context): Tree = {
896+
def makeExtensionDef(mdef: Tree, tparams: List[TypeDef], leadingParams: List[ValDef])(given ctx: Context): Tree = {
897897
val allowed = "allowed here, since collective parameters are given"
898898
mdef match {
899899
case mdef: DefDef =>
@@ -933,7 +933,7 @@ object desugar {
933933

934934
/** Invent a name for an anonympus given of type or template `impl`. */
935935
def inventGivenName(impl: Tree)(implicit ctx: Context): SimpleName =
936-
avoidIllegalChars(s"${inventName(impl)}_given".toTermName.asSimpleName)
936+
avoidIllegalChars(s"given_${inventName(impl)}".toTermName.asSimpleName)
937937

938938
/** The normalized name of `mdef`. This means
939939
* 1. Check that the name does not redefine a Scala core class.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import ast.Trees._
2626
*/
2727
object MainProxies {
2828

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

4242
import untpd._
43-
def mainProxy(mainFun: Symbol) given (ctx: Context): List[TypeDef] = {
43+
def mainProxy(mainFun: Symbol)(given ctx: Context): List[TypeDef] = {
4444
val mainAnnotSpan = mainFun.getAnnotation(defn.MainAnnot).get.tree.span
4545
def pos = mainFun.sourcePos
4646
val argsRef = Ident(nme.args)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import util.Spans.Span
1010

1111
object Annotations {
1212

13-
def annotClass(tree: Tree) given Context =
13+
def annotClass(tree: Tree)(given Context) =
1414
if (tree.symbol.isConstructor) tree.symbol.owner
1515
else tree.tpe.typeSymbol
1616

@@ -121,7 +121,7 @@ object Annotations {
121121
def deferred(sym: Symbol)(treeFn: ImplicitFunction1[Context, Tree])(implicit ctx: Context): Annotation =
122122
new LazyAnnotation {
123123
override def symbol(implicit ctx: Context): Symbol = sym
124-
def complete(implicit ctx: Context) = treeFn given ctx
124+
def complete(implicit ctx: Context) = treeFn(given ctx)
125125
}
126126

127127
/** Create an annotation where the symbol and the tree are computed lazily. */
@@ -131,12 +131,12 @@ object Annotations {
131131

132132
override def symbol(implicit ctx: Context): Symbol = {
133133
if (mySym == null || mySym.defRunId != ctx.runId) {
134-
mySym = symf given ctx
134+
mySym = symf(given ctx)
135135
assert(mySym != null)
136136
}
137137
mySym
138138
}
139-
def complete(implicit ctx: Context) = treeFn given ctx
139+
def complete(implicit ctx: Context) = treeFn(given ctx)
140140
}
141141

142142
def deferred(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ object Decorators {
174174
def (x: T) reporting[T](
175175
op: ImplicitFunction1[WrappedResult[T], String],
176176
printer: config.Printers.Printer = config.Printers.default): T = {
177-
printer.println(op given WrappedResult(x))
177+
printer.println(op(given WrappedResult(x)))
178178
x
179179
}
180180
}

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ class Definitions {
9898
* ErasedFunctionN traits follow this template:
9999
*
100100
* trait ErasedFunctionN[T0,...,T{N-1}, R] extends Object {
101-
* def apply erased ($x0: T0, ..., $x{N_1}: T{N-1}): R
101+
* def apply(erased $x0: T0, ..., $x{N_1}: T{N-1}): R
102102
* }
103103
*
104104
* ErasedImplicitFunctionN traits follow this template:
105105
*
106106
* trait ErasedImplicitFunctionN[T0,...,T{N-1}, R] extends Object {
107-
* def apply given erased ($x0: T0, ..., $x{N_1}: T{N-1}): R
107+
* def apply (given erased $x0: T0, ..., $x{N_1}: T{N-1}): R
108108
* }
109109
*
110110
* ErasedFunctionN and ErasedImplicitFunctionN erase to Function0.
@@ -403,7 +403,7 @@ class Definitions {
403403

404404
@tu lazy val CollectionSeqType: TypeRef = ctx.requiredClassRef("scala.collection.Seq")
405405
@tu lazy val SeqType: TypeRef = ctx.requiredClassRef("scala.collection.immutable.Seq")
406-
def SeqClass given Context: ClassSymbol = SeqType.symbol.asClass
406+
def SeqClass(given Context): ClassSymbol = SeqType.symbol.asClass
407407
@tu lazy val Seq_apply : Symbol = SeqClass.requiredMethod(nme.apply)
408408
@tu lazy val Seq_head : Symbol = SeqClass.requiredMethod(nme.head)
409409
@tu lazy val Seq_drop : Symbol = SeqClass.requiredMethod(nme.drop)
@@ -412,7 +412,7 @@ class Definitions {
412412
@tu lazy val Seq_toSeq : Symbol = SeqClass.requiredMethod(nme.toSeq)
413413

414414
@tu lazy val ArrayType: TypeRef = ctx.requiredClassRef("scala.Array")
415-
def ArrayClass given Context: ClassSymbol = ArrayType.symbol.asClass
415+
def ArrayClass(given Context): ClassSymbol = ArrayType.symbol.asClass
416416
@tu lazy val Array_apply : Symbol = ArrayClass.requiredMethod(nme.apply)
417417
@tu lazy val Array_update : Symbol = ArrayClass.requiredMethod(nme.update)
418418
@tu lazy val Array_length : Symbol = ArrayClass.requiredMethod(nme.length)
@@ -422,10 +422,10 @@ class Definitions {
422422
@tu lazy val ArrayModule: Symbol = ctx.requiredModule("scala.Array")
423423

424424
@tu lazy val UnitType: TypeRef = valueTypeRef("scala.Unit", java.lang.Void.TYPE, UnitEnc, nme.specializedTypeNames.Void)
425-
def UnitClass given Context: ClassSymbol = UnitType.symbol.asClass
426-
def UnitModuleClass given Context: Symbol = UnitType.symbol.asClass.linkedClass
425+
def UnitClass(given Context): ClassSymbol = UnitType.symbol.asClass
426+
def UnitModuleClass(given Context): Symbol = UnitType.symbol.asClass.linkedClass
427427
@tu lazy val BooleanType: TypeRef = valueTypeRef("scala.Boolean", java.lang.Boolean.TYPE, BooleanEnc, nme.specializedTypeNames.Boolean)
428-
def BooleanClass given Context: ClassSymbol = BooleanType.symbol.asClass
428+
def BooleanClass(given Context): ClassSymbol = BooleanType.symbol.asClass
429429
@tu lazy val Boolean_! : Symbol = BooleanClass.requiredMethod(nme.UNARY_!)
430430
@tu lazy val Boolean_&& : Symbol = BooleanClass.requiredMethod(nme.ZAND) // ### harmonize required... calls
431431
@tu lazy val Boolean_|| : Symbol = BooleanClass.requiredMethod(nme.ZOR)
@@ -441,13 +441,13 @@ class Definitions {
441441
}).symbol
442442

443443
@tu lazy val ByteType: TypeRef = valueTypeRef("scala.Byte", java.lang.Byte.TYPE, ByteEnc, nme.specializedTypeNames.Byte)
444-
def ByteClass given Context: ClassSymbol = ByteType.symbol.asClass
444+
def ByteClass(given Context): ClassSymbol = ByteType.symbol.asClass
445445
@tu lazy val ShortType: TypeRef = valueTypeRef("scala.Short", java.lang.Short.TYPE, ShortEnc, nme.specializedTypeNames.Short)
446-
def ShortClass given Context: ClassSymbol = ShortType.symbol.asClass
446+
def ShortClass(given Context): ClassSymbol = ShortType.symbol.asClass
447447
@tu lazy val CharType: TypeRef = valueTypeRef("scala.Char", java.lang.Character.TYPE, CharEnc, nme.specializedTypeNames.Char)
448-
def CharClass given Context: ClassSymbol = CharType.symbol.asClass
448+
def CharClass(given Context): ClassSymbol = CharType.symbol.asClass
449449
@tu lazy val IntType: TypeRef = valueTypeRef("scala.Int", java.lang.Integer.TYPE, IntEnc, nme.specializedTypeNames.Int)
450-
def IntClass given Context: ClassSymbol = IntType.symbol.asClass
450+
def IntClass(given Context): ClassSymbol = IntType.symbol.asClass
451451
@tu lazy val Int_- : Symbol = IntClass.requiredMethod(nme.MINUS, List(IntType))
452452
@tu lazy val Int_+ : Symbol = IntClass.requiredMethod(nme.PLUS, List(IntType))
453453
@tu lazy val Int_/ : Symbol = IntClass.requiredMethod(nme.DIV, List(IntType))
@@ -456,18 +456,18 @@ class Definitions {
456456
@tu lazy val Int_>= : Symbol = IntClass.requiredMethod(nme.GE, List(IntType))
457457
@tu lazy val Int_<= : Symbol = IntClass.requiredMethod(nme.LE, List(IntType))
458458
@tu lazy val LongType: TypeRef = valueTypeRef("scala.Long", java.lang.Long.TYPE, LongEnc, nme.specializedTypeNames.Long)
459-
def LongClass given Context: ClassSymbol = LongType.symbol.asClass
459+
def LongClass(given Context): ClassSymbol = LongType.symbol.asClass
460460
@tu lazy val Long_+ : Symbol = LongClass.requiredMethod(nme.PLUS, List(LongType))
461461
@tu lazy val Long_* : Symbol = LongClass.requiredMethod(nme.MUL, List(LongType))
462462
@tu lazy val Long_/ : Symbol = LongClass.requiredMethod(nme.DIV, List(LongType))
463463

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

469469
@tu lazy val BoxedUnitClass: ClassSymbol = ctx.requiredClass("scala.runtime.BoxedUnit")
470-
def BoxedUnit_UNIT given Context: TermSymbol = BoxedUnitClass.linkedClass.requiredValue("UNIT")
470+
def BoxedUnit_UNIT(given Context): TermSymbol = BoxedUnitClass.linkedClass.requiredValue("UNIT")
471471

472472
@tu lazy val BoxedBooleanClass: ClassSymbol = ctx.requiredClass("java.lang.Boolean")
473473
@tu lazy val BoxedByteClass : ClassSymbol = ctx.requiredClass("java.lang.Byte")
@@ -533,9 +533,9 @@ class Definitions {
533533
// in scalac modified to have Any as parent
534534

535535
@tu lazy val ThrowableType: TypeRef = ctx.requiredClassRef("java.lang.Throwable")
536-
def ThrowableClass given Context: ClassSymbol = ThrowableType.symbol.asClass
536+
def ThrowableClass(given Context): ClassSymbol = ThrowableType.symbol.asClass
537537
@tu lazy val SerializableType: TypeRef = JavaSerializableClass.typeRef
538-
def SerializableClass given Context: ClassSymbol = SerializableType.symbol.asClass
538+
def SerializableClass(given Context): ClassSymbol = SerializableType.symbol.asClass
539539

540540
@tu lazy val JavaEnumClass: ClassSymbol = {
541541
val cls = ctx.requiredClass("java.lang.Enum")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ abstract class Periods { self: Context =>
2222

2323
/** Execute `op` at given phase id */
2424
def atPhase[T](pid: PhaseId)(op: ImplicitFunction1[Context, T]): T =
25-
op given ctx.withPhase(pid)
25+
op(given ctx.withPhase(pid))
2626

2727
/** The period containing the current period where denotations do not change.
2828
* We compute this by taking as first phase the first phase less or equal to

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ trait Phases {
3737
def atNextPhase[T](op: ImplicitFunction1[Context, T]): T = atPhase(phase.next)(op)
3838

3939
def atPhaseNotLaterThan[T](limit: Phase)(op: ImplicitFunction1[Context, T]): T =
40-
if (!limit.exists || phase <= limit) op given this else atPhase(limit)(op)
40+
if (!limit.exists || phase <= limit) op(given this) else atPhase(limit)(op)
4141

4242
def isAfterTyper: Boolean = base.isAfterTyper(phase)
4343
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ object Signature {
167167
y match {
168168
case y: TypeName =>
169169
// `Ordering[TypeName]` doesn't work due to `Ordering` still being invariant
170-
the[Ordering[Name]].compare(x, y)
170+
summon[Ordering[Name]].compare(x, y)
171171
case y: Int =>
172172
1
173173
}
@@ -184,7 +184,7 @@ object Signature {
184184
import scala.math.Ordering.Implicits.seqOrdering
185185
val paramsOrdering = seqOrdering(paramSigOrdering).compare(x.paramsSig, y.paramsSig)
186186
if (paramsOrdering != 0) paramsOrdering
187-
else the[Ordering[Name]].compare(x.resSig, y.resSig)
187+
else summon[Ordering[Name]].compare(x.resSig, y.resSig)
188188
}
189189
}
190190
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,6 @@ object StdNames {
388388
val array_length : N = "array_length"
389389
val array_update : N = "array_update"
390390
val arraycopy: N = "arraycopy"
391-
val as: N = "as"
392391
val asTerm: N = "asTerm"
393392
val asModule: N = "asModule"
394393
val asMethod: N = "asMethod"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
195195
//}
196196
assert(!ctx.settings.YnoDeepSubtypes.value)
197197
if (Config.traceDeepSubTypeRecursions && !this.isInstanceOf[ExplainingTypeComparer])
198-
ctx.log(TypeComparer.explained(the[Context].typeComparer.isSubType(tp1, tp2, approx)))
198+
ctx.log(TypeComparer.explained(summon[Context].typeComparer.isSubType(tp1, tp2, approx)))
199199
}
200200
// Eliminate LazyRefs before checking whether we have seen a type before
201201
val normalize = new TypeMap {
@@ -2309,7 +2309,7 @@ object TypeComparer {
23092309
/** Show trace of comparison operations when performing `op` */
23102310
def explaining[T](say: String => Unit)(op: ImplicitFunction1[Context, T])(implicit ctx: Context): T = {
23112311
val nestedCtx = ctx.fresh.setTypeComparerFn(new ExplainingTypeComparer(_))
2312-
val res = try { op given nestedCtx } finally { say(nestedCtx.typeComparer.lastTrace()) }
2312+
val res = try { op(given nestedCtx) } finally { say(nestedCtx.typeComparer.lastTrace()) }
23132313
res
23142314
}
23152315

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class TyperState(private val previous: TyperState /* | Null */) {
9898
*/
9999
def test[T](op: ImplicitFunction1[Context, T])(implicit ctx: Context): T =
100100
if (isShared)
101-
op given ctx.fresh.setExploreTyperState()
101+
op(given ctx.fresh.setExploreTyperState())
102102
else {
103103
val savedConstraint = myConstraint
104104
val savedReporter = myReporter
@@ -113,7 +113,7 @@ class TyperState(private val previous: TyperState /* | Null */) {
113113
testReporter.inUse = true
114114
testReporter
115115
}
116-
try op given ctx
116+
try op(given ctx)
117117
finally {
118118
testReporter.inUse = false
119119
resetConstraintTo(savedConstraint)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Standard-Section: "ASTs" TopLevelStat*
167167
METHODtype Length result_Type NamesTypes -- A method type `(NamesTypes)result`, needed for refinements
168168
ERASEDMETHODtype Length result_Type NamesTypes -- A method type `erased (NamesTypes)result`, needed for refinements
169169
GIVENMETHODtype Length result_Type NamesTypes -- A method type `given (NamesTypes)result`, needed for refinements
170-
ERASEDGIVENMETHODtype Length result_Type NamesTypes -- A method type `given erased (NamesTypes)result`, needed for refinements
170+
ERASEDGIVENMETHODtype Length result_Type NamesTypes -- A method type `given(erased NamesTypes)result`, needed for refinements
171171
IMPLICITMETHODtype Length result_Type NamesTypes -- A method type `(implicit NamesTypes)result`, needed for refinements
172172
// TODO: remove ERASEDIMPLICITMETHODtype
173173
TYPELAMBDAtype Length result_Type NamesTypes -- A type lambda `[NamesTypes] => result`, variance encoded using VARIANT names

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ class TreeUnpickler(reader: TastyReader,
12711271
val args = until(end)(readTerm())
12721272
val splice = splices(idx)
12731273
def wrap(arg: Tree) =
1274-
if (arg.isTerm) given (qctx: scala.quoted.QuoteContext) => new TastyTreeExpr(arg, QuoteContext.scopeId)
1274+
if (arg.isTerm) (given qctx: scala.quoted.QuoteContext) => new TastyTreeExpr(arg, QuoteContext.scopeId)
12751275
else new TreeType(arg, QuoteContext.scopeId)
12761276
val reifiedArgs = args.map(wrap)
12771277
val filled = if (isType) {
@@ -1280,7 +1280,7 @@ class TreeUnpickler(reader: TastyReader,
12801280
}
12811281
else {
12821282
val splice1 = splice.asInstanceOf[Seq[Any] => ImplicitFunction1[scala.quoted.QuoteContext, quoted.Expr[?]]]
1283-
val quotedExpr = splice1(reifiedArgs) given dotty.tools.dotc.quoted.QuoteContext()
1283+
val quotedExpr = splice1(reifiedArgs)(given dotty.tools.dotc.quoted.QuoteContext())
12841284
PickledQuotes.quotedExprToTree(quotedExpr)
12851285
}
12861286
// We need to make sure a hole is created with the source file of the surrounding context, even if

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
979979
val atp = readTypeRef()
980980
val phase = ctx.phase
981981
Annotation.deferred(atp.typeSymbol)(
982-
atReadPos(start, () => readAnnotationContents(end)(the[Context].withPhase(phase))))
982+
atReadPos(start, () => readAnnotationContents(end)(summon[Context].withPhase(phase))))
983983
}
984984

985985
/* Read an abstract syntax tree */

compiler/src/dotty/tools/dotc/interactive/Interactive.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ object Interactive {
379379
def localize(symbol: Symbol, sourceDriver: InteractiveDriver, targetDriver: InteractiveDriver): Symbol = {
380380

381381
def in[T](driver: InteractiveDriver)(fn: ImplicitFunction1[Context, T]): T =
382-
fn given driver.currentCtx
382+
fn(given driver.currentCtx)
383383

384384
if (sourceDriver == targetDriver) symbol
385385
else {

0 commit comments

Comments
 (0)