Skip to content

Commit 1e85ec5

Browse files
Refactor abstraction over language.feature module
All the deleted code was used to distinguish between scala.language.feature and dotty.language.feature, but the latter give revomed when we introduced the scalaShadowing package trick has was dead code since then. As a side effect, this removes the need for scala2Settings and the new implementation shouldn't force anything.
1 parent 935cb58 commit 1e85ec5

File tree

10 files changed

+32
-46
lines changed

10 files changed

+32
-46
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ object desugar {
472472
New(classTypeRef, vparamss.nestedMap(refOfDef))
473473
}
474474

475-
val copiedAccessFlags = if (ctx.scala2Setting) EmptyFlags else AccessFlags
475+
val copiedAccessFlags = if (ctx.scala2Mode) EmptyFlags else AccessFlags
476476

477477
// Methods to add to a case class C[..](p1: T1, ..., pN: Tn)(moreParams)
478478
// def _1: T1 = this.p1

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

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -379,29 +379,21 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
379379
* where <prefix> is the full name of the owner followed by a "." minus
380380
* the prefix "dotty.language.".
381381
*/
382-
def featureEnabled(owner: ClassSymbol, feature: TermName): Boolean = {
383-
val hasImport =
382+
def featureEnabled(feature: TermName): Boolean = {
383+
def hasImport =
384384
ctx.importInfo != null &&
385-
ctx.importInfo.featureImported(owner, feature)(ctx.withPhase(ctx.typerPhase))
386-
def hasOption = {
387-
def toPrefix(sym: Symbol): String =
388-
if (!sym.exists || (sym eq defn.LanguageModuleClass)) ""
389-
else toPrefix(sym.owner) + sym.name + "."
390-
val featureName = toPrefix(owner) + feature
391-
ctx.base.settings.language.value exists (s => s == featureName || s == "_")
392-
}
393-
hasImport || hasOption
385+
ctx.importInfo.featureImported(feature)(ctx.withPhase(ctx.typerPhase))
386+
val hasOption =
387+
ctx.base.settings.language.value.exists(s => s == feature.toString || s == "_")
388+
hasOption || hasImport
394389
}
395390

396391
/** Is auto-tupling enabled? */
397392
def canAutoTuple: Boolean =
398-
!featureEnabled(defn.LanguageModuleClass, nme.noAutoTupling)
399-
400-
def scala2Mode: Boolean =
401-
featureEnabled(defn.LanguageModuleClass, nme.Scala2)
393+
!featureEnabled(nme.noAutoTupling)
402394

403395
def dynamicsEnabled: Boolean =
404-
featureEnabled(defn.LanguageModuleClass, nme.dynamics)
396+
featureEnabled(nme.dynamics)
405397

406398
def testScala2Mode(msg: => Message, pos: SourcePosition, replace: => Unit = ()): Boolean = {
407399
if (scala2Mode) {
@@ -411,10 +403,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
411403
scala2Mode
412404
}
413405

414-
/** Is option -language:Scala2 set?
415-
* This test is used when we are too early in the pipeline to consider imports.
416-
*/
417-
def scala2Setting = ctx.settings.language.value.contains(nme.Scala2.toString)
406+
def scala2Mode: Boolean = featureEnabled(nme.Scala2)
418407

419408
/** Refine child based on parent
420409
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ object Scanners {
242242

243243
// Scala 2 compatibility
244244

245-
val isScala2Mode: Boolean = ctx.scala2Setting
245+
val isScala2Mode: Boolean = ctx.scala2Mode
246246

247247
/** Cannot use ctx.featureEnabled because accessing the context would force too much */
248248
def testScala2Mode(msg: String, span: Span = Span(offset)): Boolean = {

compiler/src/dotty/tools/dotc/reporting/Reporter.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,18 @@ trait Reporting { this: Context =>
5858
if (this.settings.deprecation.value) reportWarning(new DeprecationWarning(msg, pos))
5959

6060
def migrationWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
61-
reportWarning(new MigrationWarning(msg, pos))
61+
deprecationWarning(msg, pos)
6262

6363
def uncheckedWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
6464
reportWarning(new UncheckedWarning(msg, pos))
6565

6666
def featureWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
6767
reportWarning(new FeatureWarning(msg, pos))
6868

69-
def featureWarning(feature: String, featureDescription: String, isScala2Feature: Boolean,
69+
def featureWarning(feature: String, featureDescription: String,
7070
featureUseSite: Symbol, required: Boolean, pos: SourcePosition): Unit = {
7171
val req = if (required) "needs to" else "should"
72-
val prefix = if (isScala2Feature) "scala." else "dotty."
73-
val fqname = prefix + "language." + feature
72+
val fqname = s"scala.language.$feature"
7473

7574
val explain = {
7675
if (reporter.isReportedFeatureUseSite(featureUseSite)) ""

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ trait Checking {
617617
def checkImplicitConversionDefOK(sym: Symbol)(implicit ctx: Context): Unit = {
618618
def check(): Unit = {
619619
checkFeature(
620-
defn.LanguageModuleClass, nme.implicitConversions,
620+
nme.implicitConversions,
621621
i"Definition of implicit conversion $sym",
622622
ctx.owner.topLevelClass,
623623
sym.sourcePos)
@@ -654,20 +654,17 @@ trait Checking {
654654
defn.isPredefClass(conv.owner) ||
655655
conv.name == nme.reflectiveSelectable && conv.maybeOwner.maybeOwner.maybeOwner == defn.ScalaPackageClass
656656
if (!conversionOK)
657-
checkFeature(defn.LanguageModuleClass, nme.implicitConversions,
657+
checkFeature(nme.implicitConversions,
658658
i"Use of implicit conversion ${conv.showLocated}", NoSymbol, posd.sourcePos)
659659
}
660660

661661
/** Issue a feature warning if feature is not enabled */
662-
def checkFeature(base: ClassSymbol,
663-
name: TermName,
662+
def checkFeature(name: TermName,
664663
description: => String,
665664
featureUseSite: Symbol,
666665
pos: SourcePosition)(implicit ctx: Context): Unit =
667-
if (!ctx.featureEnabled(base, name))
668-
ctx.featureWarning(name.toString, description,
669-
isScala2Feature = base.isContainedIn(defn.LanguageModuleClass),
670-
featureUseSite, required = false, pos)
666+
if (!ctx.featureEnabled(name))
667+
ctx.featureWarning(name.toString, description, featureUseSite, required = false, pos)
671668

672669
/** Check that `tp` is a class type and that any top-level type arguments in this type
673670
* are feasible, i.e. that their lower bound conforms to their upper bound. If a type
@@ -1048,5 +1045,5 @@ trait NoChecking extends ReChecking {
10481045
override def checkNoForwardDependencies(vparams: List[ValDef])(implicit ctx: Context): Unit = ()
10491046
override def checkMembersOK(tp: Type, pos: SourcePosition)(implicit ctx: Context): Type = tp
10501047
override def checkInInlineContext(what: String, posd: Positioned)(implicit ctx: Context): Unit = ()
1051-
override def checkFeature(base: ClassSymbol, name: TermName, description: => String, featureUseSite: Symbol, pos: SourcePosition)(implicit ctx: Context): Unit = ()
1048+
override def checkFeature(name: TermName, description: => String, featureUseSite: Symbol, pos: SourcePosition)(implicit ctx: Context): Unit = ()
10521049
}

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ trait Implicits { self: Typer =>
947947

948948
private def strictEquality(implicit ctx: Context): Boolean =
949949
ctx.mode.is(Mode.StrictEquality) ||
950-
ctx.featureEnabled(defn.LanguageModuleClass, nme.strictEquality)
950+
ctx.featureEnabled(nme.strictEquality)
951951

952952
/** An Eql[T, U] instance is assumed
953953
* - if one of T, U is an error type, or

compiler/src/dotty/tools/dotc/typer/ImportInfo.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,16 @@ class ImportInfo(symf: Context => Symbol, val selectors: List[untpd.Tree],
146146
private[this] var myUnimported: Symbol = _
147147

148148
/** Does this import clause or a preceding import clause import `owner.feature`? */
149-
def featureImported(owner: Symbol, feature: TermName)(implicit ctx: Context): Boolean = {
149+
def featureImported(feature: TermName)(implicit ctx: Context): Boolean = {
150+
val owner: Symbol = defn.LanguageModuleClass
150151
def compute = {
151152
val isImportOwner = site.widen.typeSymbol `eq` owner
152153
if (isImportOwner && originals.contains(feature)) true
153154
else if (isImportOwner && excluded.contains(feature)) false
154155
else {
155156
var c = ctx.outer
156157
while (c.importInfo eq ctx.importInfo) c = c.outer
157-
(c.importInfo != null) && c.importInfo.featureImported(owner, feature)(c)
158+
(c.importInfo != null) && c.importInfo.featureImported(feature)(c)
158159
}
159160
}
160161
if (lastOwner.ne(owner) || !lastResults.contains(feature)) {

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,8 +1692,7 @@ class Typer extends Namer
16921692
!ctx.dynamicsEnabled
16931693
if (reportDynamicInheritance) {
16941694
val isRequired = parents1.exists(_.tpe.isRef(defn.DynamicClass))
1695-
ctx.featureWarning(nme.dynamics.toString, "extension of type scala.Dynamic", isScala2Feature = true,
1696-
cls, isRequired, cdef.sourcePos)
1695+
ctx.featureWarning(nme.dynamics.toString, "extension of type scala.Dynamic", cls, isRequired, cdef.sourcePos)
16971696
}
16981697

16991698
checkNonCyclicInherited(cls.thisType, cls.classParents, cls.info.decls, cdef.posd)

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ class CompilationTests extends ParallelTesting {
3131

3232
// Positive tests ------------------------------------------------------------
3333

34-
// @Test // enable to test compileStdLib separately with detailed stats
34+
@Test // enable to test compileStdLib separately with detailed stats
3535
def compileStdLibOnly: Unit = {
3636
implicit val testGroup: TestGroup = TestGroup("compileStdLibOnly")
37-
compileList("compileStdLib", TestSources.stdLibSources, scala2Mode.and("-migration", "-Yno-inline", "-Ydetailed-stats"))
37+
compileList("compileStdLib", TestSources.stdLibSources, scala2Mode.and("-migration", "-Yno-inline"))
3838
}.checkCompile()
3939

4040
@Test def pos: Unit = {

library/src/scalaShadowing/language.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ package scalaShadowing
3030
*
3131
* - [[Scala2 `Scala2`] backwards compatibility mode for Scala2
3232
* - [[noAtoTupling `noAutoTupling`]] disable auto-tupling
33+
* - [[strictEquality `strictEquality`]] enable strick equality
3334
*
3435
* @groupname production Language Features
3536
* @groupname experimental Experimental Language Features
@@ -211,12 +212,12 @@ object language {
211212
@volatile implicit lazy val macros: macros = languageFeature.experimental.macros
212213
}
213214

214-
/** Where imported, a backwards compatibility mode for Scala2 is enabled */
215-
object Scala2
216-
217215
/** Where imported, auto-tupling is disabled */
218216
object noAutoTupling
219217

220-
/* Where imported loose equality using eqAny is disabled */
218+
/** Where imported, a backwards compatibility mode for Scala2 is enabled */
219+
object Scala2
220+
221+
/** Where imported loose equality using eqAny is disabled */
221222
object strictEquality
222223
}

0 commit comments

Comments
 (0)