Skip to content

Commit 2b3810f

Browse files
committed
Cleanups and drop redundant code
1 parent 0e5f488 commit 2b3810f

File tree

8 files changed

+33
-57
lines changed

8 files changed

+33
-57
lines changed

‎compiler/src/dotty/tools/dotc/inlines/Inliner.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ object Inliner:
5858
case Ident(_) =>
5959
isPureRef(tree) || tree.symbol.isAllOf(InlineParam)
6060
case Select(qual, _) =>
61-
if (tree.symbol.is(Erased)) true
61+
if tree.symbol.isErased then true
6262
else isPureRef(tree) && apply(qual)
6363
case New(_) | Closure(_, _, _) =>
6464
true
6565
case TypeApply(fn, _) =>
66-
if (fn.symbol.is(Erased) || fn.symbol == defn.QuotedTypeModule_of) true else apply(fn)
66+
if fn.symbol.isErased || fn.symbol == defn.QuotedTypeModule_of then true else apply(fn)
6767
case Apply(fn, args) =>
6868
val isCaseClassApply = {
6969
val cls = tree.tpe.classSymbol

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,8 @@ object Parsers {
214214
def isIdent(name: Name) = in.isIdent(name)
215215
def isPureArrow(name: Name): Boolean = isIdent(name) && Feature.pureFunsEnabled
216216
def isPureArrow: Boolean = isPureArrow(nme.PUREARROW) || isPureArrow(nme.PURECTXARROW)
217-
def isErased = isIdent(nme.erased) && in.erasedEnabled
218-
// Are we seeing an `erased` soft keyword that will not be an identifier?
219-
def isErasedKw = isErased && in.isSoftModifierInParamModifierPosition
217+
def isErased =
218+
isIdent(nme.erased) && in.erasedEnabled && in.isSoftModifierInParamModifierPosition
220219
def isSimpleLiteral =
221220
simpleLiteralTokens.contains(in.token)
222221
|| isIdent(nme.raw.MINUS) && numericLitTokens.contains(in.lookahead.token)
@@ -1725,8 +1724,8 @@ object Parsers {
17251724
else
17261725
val paramStart = in.offset
17271726
def addErased() =
1728-
erasedArgs.addOne(isErasedKw)
1729-
if isErasedKw then in.skipToken()
1727+
erasedArgs.addOne(isErased)
1728+
if isErased then in.skipToken()
17301729
addErased()
17311730
val args =
17321731
in.currentRegion.withCommasExpected:
@@ -2622,7 +2621,7 @@ object Parsers {
26222621
*/
26232622
def binding(mods: Modifiers): Tree =
26242623
atSpan(in.offset) {
2625-
val mods1 = if isErasedKw then addModifier(mods) else mods
2624+
val mods1 = if isErased then addModifier(mods) else mods
26262625
makeParameter(bindingName(), typedOpt(), mods1)
26272626
}
26282627

@@ -2825,7 +2824,7 @@ object Parsers {
28252824
else in.currentRegion.withCommasExpected {
28262825
var isFormalParams = false
28272826
def exprOrBinding() =
2828-
if isErasedKw then isFormalParams = true
2827+
if isErased then isFormalParams = true
28292828
if isFormalParams then binding(Modifiers())
28302829
else
28312830
val t = maybeNamed(exprInParens)()
@@ -3570,7 +3569,7 @@ object Parsers {
35703569
def param(): ValDef = {
35713570
val start = in.offset
35723571
var mods = impliedMods.withAnnotations(annotations())
3573-
if isErasedKw then
3572+
if isErased then
35743573
mods = addModifier(mods)
35753574
if paramOwner.isClass then
35763575
mods = addFlag(modifiers(start = mods), ParamAccessor)

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,8 +1236,6 @@ object Scanners {
12361236
def isSoftModifierInParamModifierPosition: Boolean =
12371237
isSoftModifier && !lookahead.isColon
12381238

1239-
def isErased: Boolean = isIdent(nme.erased) && erasedEnabled
1240-
12411239
def canStartStatTokens =
12421240
if migrateTo3 then canStartStatTokens2 else canStartStatTokens3
12431241

‎compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,6 @@ class Erasure extends Phase with DenotTransformer {
105105
if oldSymbol.isRetainedInlineMethod then
106106
newFlags = newFlags &~ Flags.Inline
107107
newAnnotations = newAnnotations.filterConserve(!_.isInstanceOf[BodyAnnotation])
108-
oldSymbol match
109-
case cls: ClassSymbol if cls.is(Flags.Erased) =>
110-
newFlags = newFlags | Flags.Trait | Flags.JavaInterface
111-
newAnnotations = Nil
112-
newInfo = erasedClassInfo(cls)
113-
case _ =>
114108
// TODO: define derivedSymDenotation?
115109
if ref.is(Flags.PackageClass)
116110
|| !ref.isClass // non-package classes are always copied since their base types change
@@ -550,8 +544,11 @@ object Erasure {
550544
case _ => tree.symbol.isEffectivelyErased
551545
}
552546

553-
/** Check that Java statics and packages can only be used in selections.
554-
*/
547+
/** Check that
548+
* - erased values are not referred to from normal code
549+
* - inline method applications were inlined
550+
* - Java statics and packages can only be used in selections.
551+
*/
555552
private def checkNotErased(tree: Tree)(using Context): tree.type =
556553
if !ctx.mode.is(Mode.Type) then
557554
if isErased(tree) then
@@ -582,6 +579,9 @@ object Erasure {
582579
tree
583580
end checkNotErased
584581

582+
/** Check that initializers of erased vals and arguments to erased parameters
583+
* are pure expressions.
584+
*/
585585
def checkPureErased(tree: untpd.Tree, isArgument: Boolean, isImplicit: Boolean = false)(using Context): Unit =
586586
val tree1 = tree.asInstanceOf[tpd.Tree]
587587
inContext(preErasureCtx):
@@ -1049,22 +1049,20 @@ object Erasure {
10491049
EmptyTree
10501050

10511051
override def typedClassDef(cdef: untpd.TypeDef, cls: ClassSymbol)(using Context): Tree =
1052-
if cls.is(Flags.Erased) then erasedDef(cls)
1053-
else
1054-
val typedTree@TypeDef(name, impl @ Template(constr, _, self, _)) = super.typedClassDef(cdef, cls): @unchecked
1055-
// In the case where a trait extends a class, we need to strip any non trait class from the signature
1056-
// and accept the first one (see tests/run/mixins.scala)
1057-
val newTraits = impl.parents.tail.filterConserve: tree =>
1058-
def isTraitConstructor = tree match
1059-
case Trees.Block(_, expr) => // Specific management for trait constructors (see tests/pos/i9213.scala)
1060-
expr.symbol.isConstructor && expr.symbol.owner.is(Flags.Trait)
1061-
case _ => tree.symbol.isConstructor && tree.symbol.owner.is(Flags.Trait)
1062-
tree.symbol.is(Flags.Trait) || isTraitConstructor
1063-
1064-
val newParents =
1065-
if impl.parents.tail eq newTraits then impl.parents
1066-
else impl.parents.head :: newTraits
1067-
cpy.TypeDef(typedTree)(rhs = cpy.Template(impl)(parents = newParents))
1052+
val typedTree@TypeDef(name, impl @ Template(constr, _, self, _)) = super.typedClassDef(cdef, cls): @unchecked
1053+
// In the case where a trait extends a class, we need to strip any non trait class from the signature
1054+
// and accept the first one (see tests/run/mixins.scala)
1055+
val newTraits = impl.parents.tail.filterConserve: tree =>
1056+
def isTraitConstructor = tree match
1057+
case Trees.Block(_, expr) => // Specific management for trait constructors (see tests/pos/i9213.scala)
1058+
expr.symbol.isConstructor && expr.symbol.owner.is(Flags.Trait)
1059+
case _ => tree.symbol.isConstructor && tree.symbol.owner.is(Flags.Trait)
1060+
tree.symbol.is(Flags.Trait) || isTraitConstructor
1061+
1062+
val newParents =
1063+
if impl.parents.tail eq newTraits then impl.parents
1064+
else impl.parents.head :: newTraits
1065+
cpy.TypeDef(typedTree)(rhs = cpy.Template(impl)(parents = newParents))
10681066

10691067
override def typedAnnotated(tree: untpd.Annotated, pt: Type)(using Context): Tree =
10701068
typed(tree.arg, pt)

‎compiler/src/dotty/tools/dotc/transform/Mixin.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase =>
264264
for
265265
getter <- mixin.info.decls.toList
266266
if getter.isGetter
267-
&& !getter.isEffectivelyErased
268267
&& !wasOneOf(getter, Deferred)
269268
&& !getter.isConstExprFinalVal
270269
yield

‎compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -475,15 +475,13 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
475475
case tree: ValDef =>
476476
annotateExperimentalCompanion(tree.symbol)
477477
registerIfHasMacroAnnotations(tree)
478-
//checkErasedDef(tree)
479478
Checking.checkPolyFunctionType(tree.tpt)
480479
val tree1 = cpy.ValDef(tree)(tpt = makeOverrideTypeDeclared(tree.symbol, tree.tpt))
481480
if tree1.removeAttachment(desugar.UntupledParam).isDefined then
482481
checkStableSelection(tree.rhs)
483482
processValOrDefDef(super.transform(tree1))
484483
case tree: DefDef =>
485484
registerIfHasMacroAnnotations(tree)
486-
//checkErasedDef(tree)
487485
Checking.checkPolyFunctionType(tree.tpt)
488486
annotateContextResults(tree)
489487
val tree1 = cpy.DefDef(tree)(tpt = makeOverrideTypeDeclared(tree.symbol, tree.tpt))
@@ -624,21 +622,6 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
624622
if sym.derivesFrom(defn.MacroAnnotationClass) && !sym.isStatic then
625623
report.error("classes that extend MacroAnnotation must not be inner/local classes", sym.srcPos)
626624

627-
private def checkErasedDef(tree: ValOrDefDef)(using Context): Unit =
628-
def checkOnlyErasedParams(): Unit = tree match
629-
case tree: DefDef =>
630-
for params <- tree.paramss; param <- params if !param.symbol.isType && !param.symbol.is(Erased) do
631-
report.error("erased definition can only have erased parameters", param.srcPos)
632-
case _ =>
633-
634-
if tree.symbol.is(Erased, butNot = Macro) then
635-
checkOnlyErasedParams()
636-
val tpe = tree.rhs.tpe
637-
if tpe.derivesFrom(defn.NothingClass) then
638-
report.error("`erased` definition cannot be implemented with en expression of type Nothing", tree.srcPos)
639-
else if tpe.derivesFrom(defn.NullClass) then
640-
report.error("`erased` definition cannot be implemented with en expression of type Null", tree.srcPos)
641-
642625
private def annotateExperimentalCompanion(sym: Symbol)(using Context): Unit =
643626
if sym.is(Module) then
644627
ExperimentalAnnotation.copy(sym.companionClass).foreach(sym.addAnnotation)

‎compiler/src/dotty/tools/dotc/transform/Recheck.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ abstract class Recheck extends Phase, SymTransformer:
269269
def recheckDefDef(tree: DefDef, sym: Symbol)(using Context): Type =
270270
inContext(linkConstructorParams(sym).withOwner(sym)):
271271
val resType = recheck(tree.tpt)
272-
if tree.rhs.isEmpty || sym.isInlineMethod || sym.isEffectivelyErased
272+
if tree.rhs.isEmpty || sym.isInlineMethod
273273
then resType
274274
else recheck(tree.rhs, resType)
275275

‎compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ class SuperAccessors(thisPhase: DenotTransformer) {
155155

156156
val needAccessor =
157157
name.isTermName // Types don't need super accessors
158-
&& !sym.isEffectivelyErased // Erased and concrete inline methods are not called at runtime
159-
&& !sym.isInlineMethod // so they don't need superaccessors.
158+
&& !sym.isInlineMethod // Inline methods are not called at runtime so they don't need superaccessors.
160159
&& (clazz != currentClass || !validCurrentClass || mix.name.isEmpty && clazz.is(Trait))
161160

162161
if (needAccessor) atPhase(thisPhase.next)(superAccessorCall(sel, mix.name))

0 commit comments

Comments
 (0)