Skip to content

Commit cfa02e2

Browse files
committed
Convert context functions in SymbolLoaders to CFTs
1 parent 33aa9cb commit cfa02e2

File tree

6 files changed

+18
-16
lines changed

6 files changed

+18
-16
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ object NamerOps:
4646
def adjustModuleCompleter(completer: LazyType, name: Name)(using Context): LazyType =
4747
val scope = ctx.effectiveScope
4848
if name.isTermName then
49-
completer.withModuleClass(implicit ctx => findModuleBuddy(name.moduleClassName, scope))
49+
completer.withModuleClass(findModuleBuddy(name.moduleClassName, scope))
5050
else
51-
completer.withSourceModule(implicit ctx => findModuleBuddy(name.sourceModuleName, scope))
51+
completer.withSourceModule(findModuleBuddy(name.sourceModuleName, scope))
5252

5353
/** Find moduleClass/sourceModule in effective scope */
5454
private def findModuleBuddy(name: Name, scope: Scope)(using Context) = {

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,27 +2431,29 @@ object SymDenotations {
24312431
def apply(sym: Symbol): LazyType = this
24322432
def apply(module: TermSymbol, modcls: ClassSymbol): LazyType = this
24332433

2434-
private val NoSymbolFn = (_: Context) => NoSymbol
24352434
private var myDecls: Scope = EmptyScope
2436-
private var mySourceModuleFn: Context => Symbol = NoSymbolFn
2437-
private var myModuleClassFn: Context => Symbol = NoSymbolFn
2435+
private var mySourceModuleFn: Context ?=> Symbol = LazyType.NoSymbolFn
2436+
private var myModuleClassFn: Context ?=> Symbol = LazyType.NoSymbolFn
24382437

24392438
/** The type parameters computed by the completer before completion has finished */
24402439
def completerTypeParams(sym: Symbol)(using Context): List[TypeParamInfo] =
24412440
if (sym.is(Touched)) Nil // return `Nil` instead of throwing a cyclic reference
24422441
else sym.info.typeParams
24432442

24442443
def decls: Scope = myDecls
2445-
def sourceModule(using Context): Symbol = mySourceModuleFn(ctx)
2446-
def moduleClass(using Context): Symbol = myModuleClassFn(ctx)
2444+
def sourceModule(using Context): Symbol = mySourceModuleFn
2445+
def moduleClass(using Context): Symbol = myModuleClassFn
24472446

24482447
def withDecls(decls: Scope): this.type = { myDecls = decls; this }
2449-
def withSourceModule(sourceModuleFn: Context => Symbol): this.type = { mySourceModuleFn = sourceModuleFn; this }
2450-
def withModuleClass(moduleClassFn: Context => Symbol): this.type = { myModuleClassFn = moduleClassFn; this }
2448+
def withSourceModule(sourceModuleFn: Context ?=> Symbol): this.type = { mySourceModuleFn = sourceModuleFn; this }
2449+
def withModuleClass(moduleClassFn: Context ?=> Symbol): this.type = { myModuleClassFn = moduleClassFn; this }
24512450

24522451
override def toString: String = getClass.toString
24532452
}
24542453

2454+
object LazyType:
2455+
private val NoSymbolFn = (using _: Context) => NoSymbol
2456+
24552457
/** A subtrait of LazyTypes where completerTypeParams yields a List[TypeSymbol], which
24562458
* should be completed independently of the info.
24572459
*/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ object SymbolLoaders {
5757
modFlags: FlagSet = EmptyFlags, clsFlags: FlagSet = EmptyFlags, scope: Scope = EmptyScope)(using Context): Symbol = {
5858
val module = newModuleSymbol(
5959
owner, name.toTermName.decode, modFlags, clsFlags,
60-
(module, _) => completer.proxy withDecls newScope withSourceModule (_ => module),
60+
(module, _) => completer.proxy.withDecls(newScope).withSourceModule(module),
6161
assocFile = completer.sourceFileOrNull)
6262
enterNew(owner, module, completer, scope)
6363
enterNew(owner, module.moduleClass, completer, scope)
@@ -379,7 +379,7 @@ abstract class SymbolLoader extends LazyType { self =>
379379
else
380380
newModuleSymbol(
381381
rootDenot.owner, rootDenot.name.toTermName, Synthetic, Synthetic,
382-
(module, _) => NoLoader().withDecls(newScope).withSourceModule(_ => module))
382+
(module, _) => NoLoader().withDecls(newScope).withSourceModule(module))
383383
.moduleClass.denot.asClass
384384
}
385385
if (rootDenot.is(ModuleClass)) (linkedDenot, rootDenot)

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class ClassfileParser(
7676
private var Scala2UnpicklingMode = Mode.Scala2Unpickling
7777

7878
classRoot.info = NoLoader().withDecls(instanceScope)
79-
moduleRoot.info = NoLoader().withDecls(staticScope).withSourceModule(_ => staticModule)
79+
moduleRoot.info = NoLoader().withDecls(staticScope).withSourceModule(staticModule)
8080

8181
private def currentIsTopLevel(using Context) = classRoot.owner.is(Flags.PackageClass)
8282

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
524524
def completer(cls: Symbol) = {
525525
val unpickler = new ClassUnpickler(infoRef) withDecls symScope(cls)
526526
if (flags.is(ModuleClass))
527-
unpickler withSourceModule (implicit ctx =>
527+
unpickler.withSourceModule(
528528
cls.owner.info.decls.lookup(cls.name.sourceModuleName)
529529
.suchThat(_.is(Module)).symbol)
530530
else unpickler
@@ -538,7 +538,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
538538
moduleRoot setFlag flags
539539
moduleRoot.symbol
540540
} else newSymbol(owner, name.asTermName, flags,
541-
new LocalUnpickler() withModuleClass(implicit ctx =>
541+
new LocalUnpickler().withModuleClass(
542542
owner.info.decls.lookup(name.moduleClassName)
543543
.suchThat(_.is(Module)).symbol)
544544
, privateWithin, coord = start)
@@ -642,7 +642,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
642642
def rootClassUnpickler(start: Coord, cls: Symbol, module: Symbol, infoRef: Int): ClassUnpickler =
643643
(new ClassUnpickler(infoRef) with SymbolLoaders.SecondCompleter {
644644
override def startCoord(denot: SymDenotation): Coord = start
645-
}) withDecls symScope(cls) withSourceModule (_ => module)
645+
}).withDecls(symScope(cls)).withSourceModule(module)
646646

647647
/** Convert
648648
* tp { type name = sym } forSome { sym >: L <: H }

docs/docs/contributing/debugging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,4 +363,4 @@ trace.force(i"typing $tree", typr, show = true) { // ...
363363
```
364364

365365
### Reporter
366-
Defined in [Reporter.scala](https://github.com/lampepfl/dotty/blob/10526a7d0aa8910729b6036ee51942e05b71abf6/compiler/src/dotty/tools/dotc/reporting/Reporter.scala). Enables calls such as `ctx.log`, `ctx.error` etc. To enable, run dotc with `-Ylog:typer` option.
366+
Defined in [Reporter.scala](https://github.com/lampepfl/dotty/blob/10526a7d0aa8910729b6036ee51942e05b71abf6/compiler/src/dotty/tools/dotc/reporting/Reporter.scala). Enables calls such as `report.log`. To enable, run dotc with `-Ylog:typer` option.

0 commit comments

Comments
 (0)