Skip to content

Commit 4337431

Browse files
Merge pull request #7251 from dotty-staging/given-cleanups
Given cleanups
2 parents c5d002f + 9541ec8 commit 4337431

Some content is hidden

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

55 files changed

+304
-2380
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: ImplicitFunction1[Context, Tree])(implicit ctx: Context): Annotation =
121+
def deferred(sym: Symbol)(treeFn: (given 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: ImplicitFunction1[Context, Symbol])(treeFn: ImplicitFunction1[Context, Tree])(implicit ctx: Context): Annotation =
128+
def deferredSymAndTree(symf: (given Context) => Symbol)(treeFn: (given 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: ImplicitFunction1[Context, Symbol], span: Span)(implicit ctx: Context): Annotation = {
156+
def later(delayedSym: (given 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: ImplicitFunction1[Context, T]): T = typerState.test(op)(this)
318+
final def test[T](op: (given 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: ImplicitFunction1[WrappedResult[T], String],
175+
op: (given 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: ImplicitFunction1[Context, T]): T =
24+
def atPhase[T](pid: PhaseId)(op: (given 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: ImplicitFunction1[Context, T]): T =
34+
def atPhase[T](phase: Phase)(op: (given Context) => T): T =
3535
atPhase(phase.id)(op)
3636

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

39-
def atPhaseNotLaterThan[T](limit: Phase)(op: ImplicitFunction1[Context, T]): T =
39+
def atPhaseNotLaterThan[T](limit: Phase)(op: (given 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: ImplicitFunction1[Context, T])(implicit ctx: Context): T = {
2310+
def explaining[T](say: String => Unit)(op: (given 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: ImplicitFunction1[Context, T])(implicit ctx: Context): String = {
2317+
def explained[T](op: (given 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: ImplicitFunction1[Context, T])(implicit ctx: Context): T =
99+
def test[T](op: (given 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] => ImplicitFunction1[scala.quoted.QuoteContext, quoted.Expr[?]]]
1282+
val splice1 = splice.asInstanceOf[Seq[Any] => (given 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: ImplicitFunction1[Context, T]): T =
381+
def in[T](driver: InteractiveDriver)(fn: (given Context) => T): T =
382382
fn(given driver.currentCtx)
383383

384384
if (sourceDriver == targetDriver) symbol

compiler/src/dotty/tools/dotc/printing/Formatting.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ object Formatting {
252252
* ex"disambiguate $tpe1 and $tpe2"
253253
* ```
254254
*/
255-
def explained(op: ImplicitFunction1[Context, String])(implicit ctx: Context): String = {
255+
def explained(op: (given Context) => String)(implicit ctx: Context): String = {
256256
val seen = new Seen
257257
val msg = op(given explainCtx(seen))
258258
val addendum = explanations(seen)

0 commit comments

Comments
 (0)