Skip to content

Commit 23ca102

Browse files
committed
Drop given A => B syntax
Replace with `delegate A => B` in tests and with `ImplicitFunctionType[A, B]` in bootstrap code. Also replace `given x: T => e` with `delegate x: T => e`, except in bootstrap code, where the latter is not legal. These measures are necessary for migration to new given scheme.
1 parent 5ce4475 commit 23ca102

File tree

23 files changed

+59
-61
lines changed

23 files changed

+59
-61
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ object Annotations {
118118
apply(New(atp, args))
119119

120120
/** Create an annotation where the tree is computed lazily. */
121-
def deferred(sym: Symbol)(treeFn: given Context => Tree)(implicit ctx: Context): Annotation =
121+
def deferred(sym: Symbol)(treeFn: ImplicitFunction1[Context, Tree])(implicit ctx: Context): Annotation =
122122
new LazyAnnotation {
123123
override def symbol(implicit ctx: Context): Symbol = sym
124124
def complete(implicit ctx: Context) = treeFn given ctx
125125
}
126126

127127
/** Create an annotation where the symbol and the tree are computed lazily. */
128-
def deferredSymAndTree(symf: given Context => Symbol)(treeFn: given Context => Tree)(implicit ctx: Context): Annotation =
128+
def deferredSymAndTree(symf: ImplicitFunction1[Context, Symbol])(treeFn: ImplicitFunction1[Context, Tree])(implicit ctx: Context): Annotation =
129129
new LazyAnnotation {
130130
private[this] var mySym: Symbol = _
131131

@@ -153,7 +153,7 @@ object Annotations {
153153
object Child {
154154

155155
/** A deferred annotation to the result of a given child computation */
156-
def later(delayedSym: given Context => Symbol, span: Span)(implicit ctx: Context): Annotation = {
156+
def later(delayedSym: ImplicitFunction1[Context, Symbol], span: Span)(implicit ctx: Context): Annotation = {
157157
def makeChildLater(implicit ctx: Context) = {
158158
val sym = delayedSym
159159
New(defn.ChildAnnot.typeRef.appliedTo(sym.owner.thisType.select(sym.name, sym)), Nil)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ object Contexts {
315315
/** Run `op` as if it was run in a fresh explore typer state, but possibly
316316
* optimized to re-use the current typer state.
317317
*/
318-
final def test[T](op: given Context => T): T = typerState.test(op)(this)
318+
final def test[T](op: ImplicitFunction1[Context, T]): T = typerState.test(op)(this)
319319

320320
/** Is this a context for the members of a class definition? */
321321
def isClassDefContext: Boolean =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ object Decorators {
172172

173173
implicit object reportDeco {
174174
def (x: T) reporting[T](
175-
op: given WrappedResult[T] => String,
175+
op: ImplicitFunction1[WrappedResult[T], String],
176176
printer: config.Printers.Printer = config.Printers.default): T = {
177177
printer.println(op given WrappedResult(x))
178178
x

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ abstract class Periods { self: Context =>
2121
op(ctx.fresh.setPeriod(pd))
2222

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

2727
/** The period containing the current period where denotations do not change.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ trait Phases {
3131
}
3232

3333
/** Execute `op` at given phase */
34-
def atPhase[T](phase: Phase)(op: given Context => T): T =
34+
def atPhase[T](phase: Phase)(op: ImplicitFunction1[Context, T]): T =
3535
atPhase(phase.id)(op)
3636

37-
def atNextPhase[T](op: given Context => T): T = atPhase(phase.next)(op)
37+
def atNextPhase[T](op: ImplicitFunction1[Context, T]): T = atPhase(phase.next)(op)
3838

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

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,14 +2307,14 @@ object TypeComparer {
23072307
val FreshApprox: ApproxState = new ApproxState(4)
23082308

23092309
/** Show trace of comparison operations when performing `op` */
2310-
def explaining[T](say: String => Unit)(op: given Context => T)(implicit ctx: Context): T = {
2310+
def explaining[T](say: String => Unit)(op: ImplicitFunction1[Context, T])(implicit ctx: Context): T = {
23112311
val nestedCtx = ctx.fresh.setTypeComparerFn(new ExplainingTypeComparer(_))
23122312
val res = try { op given nestedCtx } finally { say(nestedCtx.typeComparer.lastTrace()) }
23132313
res
23142314
}
23152315

23162316
/** Like [[explaining]], but returns the trace instead */
2317-
def explained[T](op: given Context => T)(implicit ctx: Context): String = {
2317+
def explained[T](op: ImplicitFunction1[Context, T])(implicit ctx: Context): String = {
23182318
var trace: String = null
23192319
try { explaining(trace = _)(op) } catch { case ex: Throwable => ex.printStackTrace }
23202320
trace

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class TyperState(private val previous: TyperState /* | Null */) {
9696
* typerstate. If it is unshared, run `op` in current typerState, restoring typerState
9797
* to previous state afterwards.
9898
*/
99-
def test[T](op: given Context => T)(implicit ctx: Context): T =
99+
def test[T](op: ImplicitFunction1[Context, T])(implicit ctx: Context): T =
100100
if (isShared)
101101
op given ctx.fresh.setExploreTyperState()
102102
else {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,7 @@ class TreeUnpickler(reader: TastyReader,
12791279
PickledQuotes.quotedTypeToTree(quotedType)
12801280
}
12811281
else {
1282-
val splice1 = splice.asInstanceOf[Seq[Any] => given scala.quoted.QuoteContext => quoted.Expr[?]]
1282+
val splice1 = splice.asInstanceOf[Seq[Any] => ImplicitFunction1[scala.quoted.QuoteContext, quoted.Expr[?]]]
12831283
val quotedExpr = splice1(reifiedArgs) given dotty.tools.dotc.quoted.QuoteContext()
12841284
PickledQuotes.quotedExprToTree(quotedExpr)
12851285
}

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

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

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

384384
if (sourceDriver == targetDriver) symbol

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,7 +2594,7 @@ object Parsers {
25942594
else BitSet(IMPLICIT)
25952595

25962596
val funTypeMods: BitSet =
2597-
if allowOldGiven then BitSet(GIVEN, IMPLIED, ERASED)
2597+
if allowOldGiven then BitSet(IMPLIED, ERASED)
25982598
else BitSet()
25992599

26002600
/** Wrap annotation or constructor in New(...).<init> */
@@ -3710,7 +3710,7 @@ object Parsers {
37103710
setLastStatOffset()
37113711
if (in.token == IMPORT)
37123712
stats ++= importClause(IMPORT, Import)
3713-
else if (in.token == GIVEN) {
3713+
else if (in.token == IMPLIED || in.token == GIVEN) {
37143714
val start = in.offset
37153715
val mods = modifiers(closureMods)
37163716
mods.mods match {

0 commit comments

Comments
 (0)