Skip to content

Commit 23b19e8

Browse files
committed
Convert core classes (4)
1 parent 114e0d2 commit 23b19e8

17 files changed

+172
-172
lines changed

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
6666
val bootstrap = ctx.fresh
6767
.setPeriod(Period(comp.nextRunId, FirstPhaseId))
6868
.setScope(rootScope)
69-
rootScope.enter(ctx.definitions.RootPackage)(bootstrap)
69+
rootScope.enter(ctx.definitions.RootPackage)(using bootstrap)
7070
val start = bootstrap.fresh
7171
.setOwner(defn.RootClass)
7272
.setTyper(new Typer)

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dotty.tools.dotc.core
22

3-
import dotty.tools.dotc.core.Contexts.Context
3+
import dotty.tools.dotc.core.Contexts.{Context, ctx}
44
import dotty.tools.dotc.core.Flags.JavaDefined
55
import dotty.tools.dotc.core.StdNames.{jnme, nme}
66
import dotty.tools.dotc.core.Symbols._
@@ -52,7 +52,7 @@ object JavaNullInterop {
5252
*
5353
* But the selection can throw an NPE if the returned value is `null`.
5454
*/
55-
def nullifyMember(sym: Symbol, tp: Type, isEnumValueDef: Boolean)(implicit ctx: Context): Type = {
55+
def nullifyMember(sym: Symbol, tp: Type, isEnumValueDef: Boolean)(using Context): Type = {
5656
assert(ctx.explicitNulls)
5757
assert(sym.is(JavaDefined), "can only nullify java-defined members")
5858

@@ -70,20 +70,20 @@ object JavaNullInterop {
7070
nullifyType(tp)
7171
}
7272

73-
private def hasNotNullAnnot(sym: Symbol)(implicit ctx: Context): Boolean =
73+
private def hasNotNullAnnot(sym: Symbol)(using Context): Boolean =
7474
ctx.definitions.NotNullAnnots.exists(nna => sym.unforcedAnnotation(nna).isDefined)
7575

7676
/** If tp is a MethodType, the parameters and the inside of return type are nullified,
7777
* but the result return type is not nullable.
7878
* If tp is a type of a field, the inside of the type is nullified,
7979
* but the result type is not nullable.
8080
*/
81-
private def nullifyExceptReturnType(tp: Type)(implicit ctx: Context): Type =
82-
new JavaNullMap(true)(ctx)(tp)
81+
private def nullifyExceptReturnType(tp: Type)(using Context): Type =
82+
new JavaNullMap(true)(tp)
8383

8484
/** Nullifies a Java type by adding `| UncheckedNull` in the relevant places. */
85-
private def nullifyType(tp: Type)(implicit ctx: Context): Type =
86-
new JavaNullMap(false)(ctx)(tp)
85+
private def nullifyType(tp: Type)(using Context): Type =
86+
new JavaNullMap(false)(tp)
8787

8888
/** A type map that implements the nullification function on types. Given a Java-sourced type, this adds `| UncheckedNull`
8989
* in the right places to make the nulls explicit in Scala.
@@ -96,7 +96,7 @@ object JavaNullInterop {
9696
* This is useful for e.g. constructors, and also so that `A & B` is nullified
9797
* to `(A & B) | UncheckedNull`, instead of `(A|UncheckedNull & B|UncheckedNull) | UncheckedNull`.
9898
*/
99-
private class JavaNullMap(var outermostLevelAlreadyNullable: Boolean)(implicit ctx: Context) extends TypeMap {
99+
private class JavaNullMap(var outermostLevelAlreadyNullable: Boolean)(using Context) extends TypeMap {
100100
/** Should we nullify `tp` at the outermost level? */
101101
def needsNull(tp: Type): Boolean =
102102
!outermostLevelAlreadyNullable && (tp match {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ object MacroClassLoader {
1212
private val MacroClassLoaderKey = new Property.Key[ClassLoader]
1313

1414
/** Get the macro class loader */
15-
def fromContext(implicit ctx: Context): ClassLoader =
15+
def fromContext(using Context): ClassLoader =
1616
ctx.property(MacroClassLoaderKey).getOrElse(makeMacroClassLoader)
1717

1818
/** Context with a cached macro class loader that can be accessed with `macroClassLoader` */
1919
def init(ctx: FreshContext): ctx.type =
20-
ctx.setProperty(MacroClassLoaderKey, makeMacroClassLoader(ctx))
20+
ctx.setProperty(MacroClassLoaderKey, makeMacroClassLoader(using ctx))
2121

22-
private def makeMacroClassLoader(implicit ctx: Context): ClassLoader = trace("new macro class loader") {
22+
private def makeMacroClassLoader(using Context): ClassLoader = trace("new macro class loader") {
2323
val urls = ctx.settings.classpath.value.split(java.io.File.pathSeparatorChar).map(cp => java.nio.file.Paths.get(cp).toUri.toURL)
2424
val out = ctx.settings.outputDir.value.jpath.toUri.toURL // to find classes in case of suspended compilation
2525
new java.net.URLClassLoader(urls :+ out, getClass.getClassLoader)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Names._
66
import NameOps._
77
import StdNames._
88
import NameTags._
9-
import Contexts.Context
9+
import Contexts.{Context, ctx}
1010
import collection.mutable
1111

1212
import scala.annotation.internal.sharable
@@ -214,11 +214,11 @@ object NameKinds {
214214
}
215215

216216
/** Generate fresh unique term name of this kind with given prefix name */
217-
def fresh(prefix: TermName = EmptyTermName)(implicit ctx: Context): TermName =
217+
def fresh(prefix: TermName = EmptyTermName)(using Context): TermName =
218218
ctx.compilationUnit.freshNames.newName(prefix, this)
219219

220220
/** Generate fresh unique type name of this kind with given prefix name */
221-
def fresh(prefix: TypeName)(implicit ctx: Context): TypeName =
221+
def fresh(prefix: TypeName)(using Context): TypeName =
222222
fresh(prefix.toTermName).toTypeName
223223

224224
uniqueNameKinds(separator) = this

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ object NameOps {
150150
* This is the fully qualified name of `base` with `ExpandPrefixName` as separator,
151151
* followed by `kind` and the name.
152152
*/
153-
def expandedName(base: Symbol, kind: QualifiedNameKind = ExpandedName)(implicit ctx: Context): N =
153+
def expandedName(base: Symbol, kind: QualifiedNameKind = ExpandedName)(using Context): N =
154154
likeSpacedN { base.fullNameSeparated(ExpandPrefixName, kind, name) }
155155

156156
/** Revert the expanded name. */
@@ -160,7 +160,7 @@ object NameOps {
160160

161161
def errorName: N = likeSpacedN(name ++ nme.ERROR)
162162

163-
def freshened(implicit ctx: Context): N = likeSpacedN {
163+
def freshened(using Context): N = likeSpacedN {
164164
name.toTermName match {
165165
case ModuleClassName(original) => ModuleClassName(original.freshened)
166166
case name => UniqueName.fresh(name)
@@ -230,7 +230,7 @@ object NameOps {
230230
case nme.clone_ => nme.clone_
231231
}
232232

233-
def specializedFor(classTargs: List[Type], classTargsNames: List[Name], methodTargs: List[Type], methodTarsNames: List[Name])(implicit ctx: Context): N = {
233+
def specializedFor(classTargs: List[Type], classTargsNames: List[Name], methodTargs: List[Type], methodTarsNames: List[Name])(using Context): N = {
234234

235235
val methodTags: Seq[Name] = (methodTargs zip methodTarsNames).sortBy(_._2).map(x => defn.typeTag(x._1))
236236
val classTags: Seq[Name] = (classTargs zip classTargsNames).sortBy(_._2).map(x => defn.typeTag(x._1))
@@ -241,7 +241,7 @@ object NameOps {
241241
}
242242

243243
/** If name length exceeds allowable limit, replace part of it by hash */
244-
def compactified(implicit ctx: Context): TermName = termName(compactify(name.toString))
244+
def compactified(using Context): TermName = termName(compactify(name.toString))
245245

246246
def unmangleClassName: N = name.toTermName match {
247247
case name: SimpleName

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dotty.tools.dotc.core
22

3-
import dotty.tools.dotc.core.Contexts.Context
3+
import dotty.tools.dotc.core.Contexts.{Context, ctx}
44
import dotty.tools.dotc.core.Symbols.defn
55
import dotty.tools.dotc.core.Types._
66

@@ -9,7 +9,7 @@ object NullOpsDecorator {
99

1010
implicit class NullOps(val self: Type) {
1111
/** Is this type exactly `UncheckedNull` (no vars, aliases, refinements etc allowed)? */
12-
def isUncheckedNullType(implicit ctx: Context): Boolean = {
12+
def isUncheckedNullType(using Context): Boolean = {
1313
assert(ctx.explicitNulls)
1414
// We can't do `self == defn.UncheckedNull` because when trees are unpickled new references
1515
// to `UncheckedNull` could be created that are different from `defn.UncheckedNull`.
@@ -24,7 +24,7 @@ object NullOpsDecorator {
2424
*
2525
* @param onlyUncheckedNull whether we only remove `UncheckedNull`, the default value is false
2626
*/
27-
def stripNull(onlyUncheckedNull: Boolean = false)(implicit ctx: Context): Type = {
27+
def stripNull(onlyUncheckedNull: Boolean = false)(using Context): Type = {
2828
assert(ctx.explicitNulls)
2929

3030
def isNull(tp: Type) =
@@ -56,14 +56,14 @@ object NullOpsDecorator {
5656
}
5757

5858
/** Like `stripNull`, but removes only the `UncheckedNull`s. */
59-
def stripUncheckedNull(implicit ctx: Context): Type = self.stripNull(true)
59+
def stripUncheckedNull(using Context): Type = self.stripNull(true)
6060

6161
/** Collapses all `UncheckedNull` unions within this type, and not just the outermost ones (as `stripUncheckedNull` does).
6262
* e.g. (Array[String|UncheckedNull]|UncheckedNull).stripUncheckedNull => Array[String|UncheckedNull]
6363
* (Array[String|UncheckedNull]|UncheckedNull).stripAllUncheckedNull => Array[String]
6464
* If no `UncheckedNull` unions are found within the type, then returns the input type unchanged.
6565
*/
66-
def stripAllUncheckedNull(implicit ctx: Context): Type = {
66+
def stripAllUncheckedNull(using Context): Type = {
6767
object RemoveNulls extends TypeMap {
6868
override def apply(tp: Type): Type = mapOver(tp.stripNull(true))
6969
}
@@ -72,13 +72,13 @@ object NullOpsDecorator {
7272
}
7373

7474
/** Is self (after widening and dealiasing) a type of the form `T | Null`? */
75-
def isNullableUnion(implicit ctx: Context): Boolean = {
75+
def isNullableUnion(using Context): Boolean = {
7676
val stripped = self.stripNull()
7777
stripped ne self
7878
}
7979

8080
/** Is self (after widening and dealiasing) a type of the form `T | UncheckedNull`? */
81-
def isUncheckedNullableUnion(implicit ctx: Context): Boolean = {
81+
def isUncheckedNullableUnion(using Context): Boolean = {
8282
val stripped = self.stripNull(true)
8383
stripped ne self
8484
}

0 commit comments

Comments
 (0)