Skip to content

Commit 385da10

Browse files
committed
Bring back -Yerased-terms for bootstrapping
1 parent e9c944d commit 385da10

File tree

7 files changed

+27
-19
lines changed

7 files changed

+27
-19
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ class ScalaSettings extends Settings.SettingGroup with CommonScalaSettings {
229229
val YexplicitNulls: Setting[Boolean] = BooleanSetting("-Yexplicit-nulls", "Make reference types non-nullable. Nullable types can be expressed with unions: e.g. String|Null.")
230230
val YcheckInit: Setting[Boolean] = BooleanSetting("-Ysafe-init", "Ensure safe initialization of objects")
231231
val YrequireTargetName: Setting[Boolean] = BooleanSetting("-Yrequire-targetName", "Warn if an operator is defined without a @targetName annotation")
232+
val YerasedTerms: Setting[Boolean] = BooleanSetting("-Yerased-terms", "(disabled, use -language:experimental.erasedTerms instead)")
232233

233234
/** Area-specific debug output */
234235
val YexplainLowlevel: Setting[Boolean] = BooleanSetting("-Yexplain-lowlevel", "When explaining type errors, show types at a lower level.")

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ object Parsers {
180180

181181
def isIdent = in.isIdent
182182
def isIdent(name: Name) = in.isIdent(name)
183+
def isErased = isIdent(nme.erased) && in.erasedEnabled
183184
def isSimpleLiteral =
184185
simpleLiteralTokens.contains(in.token)
185186
|| isIdent(nme.raw.MINUS) && numericLitTokens.contains(in.lookahead.token)
@@ -230,9 +231,6 @@ object Parsers {
230231
else (staged & StageKind.Quoted) != 0
231232
}
232233

233-
extension (td: TokenData = in)
234-
def isErased: Boolean = td.isIdent(nme.erased) && featureEnabled(Feature.erasedTerms)
235-
236234
/* ------------- ERROR HANDLING ------------------------------------------- */
237235

238236
/** The offset of the last time when a statement on a new line was definitely
@@ -450,19 +448,18 @@ object Parsers {
450448
* Parameters appear in reverse order.
451449
*/
452450
var placeholderParams: List[ValDef] = Nil
453-
var languageImportContext: Context = ctx
454451

455452
def checkNoEscapingPlaceholders[T](op: => T): T =
456453
val savedPlaceholderParams = placeholderParams
457-
val savedLanguageImportContext = languageImportContext
454+
val savedLanguageImportContext = in.languageImportContext
458455
placeholderParams = Nil
459456
try op
460457
finally
461458
placeholderParams match
462459
case vd :: _ => syntaxError(UnboundPlaceholderParameter(), vd.span)
463460
case _ =>
464461
placeholderParams = savedPlaceholderParams
465-
languageImportContext = savedLanguageImportContext
462+
in.languageImportContext = savedLanguageImportContext
466463

467464
def isWildcard(t: Tree): Boolean = t match {
468465
case Ident(name1) => placeholderParams.nonEmpty && name1 == placeholderParams.head.name
@@ -594,8 +591,6 @@ object Parsers {
594591
if in.currentRegion.indentWidth < nextIndentWidth then
595592
warning(i"Line is indented too far to the right, or a `{` or `:` is missing", in.next.offset)
596593

597-
def featureEnabled(name: TermName) = Feature.enabled(name)(using languageImportContext)
598-
599594
/* -------- REWRITES ----------------------------------------------------------- */
600595

601596
/** The last offset where a colon at the end of line would be required if a subsequent { ... }
@@ -1147,7 +1142,7 @@ object Parsers {
11471142
Quote(t)
11481143
}
11491144
else
1150-
if !featureEnabled(Feature.symbolLiterals) then
1145+
if !in.featureEnabled(Feature.symbolLiterals) then
11511146
report.errorOrMigrationWarning(
11521147
em"""symbol literal '${in.name} is no longer supported,
11531148
|use a string literal "${in.name}" or an application Symbol("${in.name}") instead,
@@ -1380,7 +1375,7 @@ object Parsers {
13801375
functionRest(Nil)
13811376
}
13821377
else {
1383-
if in.isErased then imods = addModifier(imods)
1378+
if isErased then imods = addModifier(imods)
13841379
val paramStart = in.offset
13851380
val ts = funArgType() match {
13861381
case Ident(name) if name != tpnme.WILDCARD && in.token == COLON =>
@@ -1578,7 +1573,7 @@ object Parsers {
15781573
typeIdent()
15791574
else
15801575
def singletonArgs(t: Tree): Tree =
1581-
if in.token == LPAREN && featureEnabled(Feature.dependent)
1576+
if in.token == LPAREN && in.featureEnabled(Feature.dependent)
15821577
then singletonArgs(AppliedTypeTree(t, inParens(commaSeparated(singleton))))
15831578
else t
15841579
singletonArgs(simpleType1())
@@ -1867,7 +1862,7 @@ object Parsers {
18671862

18681863
def expr(location: Location): Tree = {
18691864
val start = in.offset
1870-
def isSpecialClosureStart = in.lookahead.isErased
1865+
def isSpecialClosureStart = in.lookahead.isIdent(nme.erased) && in.erasedEnabled
18711866
if in.token == IMPLICIT then
18721867
closure(start, location, modifiers(BitSet(IMPLICIT)))
18731868
else if in.token == LPAREN && isSpecialClosureStart then
@@ -2099,7 +2094,7 @@ object Parsers {
20992094
Nil
21002095
else
21012096
var mods1 = mods
2102-
if in.isErased then mods1 = addModifier(mods1)
2097+
if isErased then mods1 = addModifier(mods1)
21032098
try
21042099
commaSeparated(() => binding(mods1))
21052100
finally
@@ -2697,7 +2692,7 @@ object Parsers {
26972692
case SEALED => Mod.Sealed()
26982693
case IDENTIFIER =>
26992694
name match {
2700-
case nme.erased if featureEnabled(Feature.erasedTerms) => Mod.Erased()
2695+
case nme.erased if in.erasedEnabled => Mod.Erased()
27012696
case nme.inline => Mod.Inline()
27022697
case nme.opaque => Mod.Opaque()
27032698
case nme.open => Mod.Open()
@@ -2908,7 +2903,7 @@ object Parsers {
29082903
else
29092904
if isIdent(nme.using) then
29102905
addParamMod(() => Mod.Given())
2911-
if in.isErased then
2906+
if isErased then
29122907
addParamMod(() => Mod.Erased())
29132908

29142909
def param(): ValDef = {
@@ -3039,7 +3034,7 @@ object Parsers {
30393034
def mkImport(outermost: Boolean = false): ImportConstr = (tree, selectors) =>
30403035
val imp = Import(tree, selectors)
30413036
if isLanguageImport(tree) then
3042-
languageImportContext = languageImportContext.importContext(imp, NoSymbol)
3037+
in.languageImportContext = in.languageImportContext.importContext(imp, NoSymbol)
30433038
for
30443039
case ImportSelector(id @ Ident(imported), EmptyTree, _) <- selectors
30453040
if allSourceVersionNames.contains(imported)

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import scala.annotation.{switch, tailrec}
1717
import scala.collection.mutable
1818
import scala.collection.immutable.{SortedMap, BitSet}
1919
import rewrites.Rewrites.patch
20+
import config.Feature
2021
import config.Feature.migrateTo3
2122
import config.SourceVersion._
2223
import reporting.Message
@@ -185,6 +186,11 @@ object Scanners {
185186
error(s"illegal combination of -rewrite targets: ${enabled(0).name} and ${enabled(1).name}")
186187
}
187188

189+
var languageImportContext: Context = ctx
190+
191+
def featureEnabled(name: TermName) = Feature.enabled(name)(using languageImportContext)
192+
def erasedEnabled = featureEnabled(Feature.erasedTerms) || ctx.settings.YerasedTerms.value
193+
188194
/** All doc comments kept by their end position in a `Map`.
189195
*
190196
* Note: the map is necessary since the comments are looked up after an
@@ -1008,14 +1014,17 @@ object Scanners {
10081014
}
10091015

10101016
def isSoftModifier: Boolean =
1011-
token == IDENTIFIER && softModifierNames.contains(name)
1017+
token == IDENTIFIER
1018+
&& (softModifierNames.contains(name) || name == nme.erased && erasedEnabled)
10121019

10131020
def isSoftModifierInModifierPosition: Boolean =
10141021
isSoftModifier && inModifierPosition()
10151022

10161023
def isSoftModifierInParamModifierPosition: Boolean =
10171024
isSoftModifier && lookahead.token != COLON
10181025

1026+
def isErased: Boolean = isIdent(nme.erased) && erasedEnabled
1027+
10191028
def canStartStatTokens =
10201029
if migrateTo3 then canStartStatTokens2 else canStartStatTokens3
10211030

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,5 +286,5 @@ object Tokens extends TokensCommon {
286286

287287
final val skipStopTokens = BitSet(SEMI, NEWLINE, NEWLINES, RBRACE, RPAREN, RBRACKET, OUTDENT)
288288

289-
final val softModifierNames = Set(nme.inline, nme.opaque, nme.open, nme.transparent, nme.infix, nme.erased)
289+
final val softModifierNames = Set(nme.inline, nme.opaque, nme.open, nme.transparent, nme.infix)
290290
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ trait Implicits:
889889
case Select(qual, nme.apply) if defn.isFunctionType(qual.tpe.widen) =>
890890
val qt = qual.tpe.widen
891891
val qt1 = qt.dealiasKeepAnnots
892-
def addendum = if (qt1 eq qt) "" else (i"\nwhich is an alias of: $qt1")
892+
def addendum = if (qt1 eq qt) "" else (i"\nThe required type is an alias of: $qt1")
893893
em"parameter of ${qual.tpe.widen}$addendum"
894894
case _ =>
895895
em"${ if paramName.is(EvidenceParamName) then "an implicit parameter"

library/src/scala/compiletime/package.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package scala
22
import annotation.compileTimeOnly
33

44
package object compiletime {
5+
import language.experimental.erasedTerms
56

67
/** Use this method when you have a type, do not have a value for it but want to
78
* pattern match on it. For example, given a type `Tup <: Tuple`, one can

project/Build.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,8 @@ object Build {
680680
"-sourcepath", (sourceDirectories in Compile).value.map(_.getAbsolutePath).distinct.mkString(File.pathSeparator),
681681
// support declaration of scala.compiletime.erasedValue
682682
"-Yerased-terms"
683+
// TODO: drop after bootstrap with erasure language import
684+
// scala.compile now contains the roght language import so no global setting is needed
683685
),
684686
)
685687

0 commit comments

Comments
 (0)