Skip to content

Commit 3ddc262

Browse files
authored
Merge pull request #4061 from dotty-staging/rename-unused
Rename `unused` to `ghost`
2 parents 7655503 + 31f2e0d commit 3ddc262

File tree

142 files changed

+390
-390
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+390
-390
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class Compiler {
8080
new ShortcutImplicits, // Allow implicit functions without creating closures
8181
new CrossCastAnd, // Normalize selections involving intersection types.
8282
new Splitter) :: // Expand selections involving union types into conditionals
83-
List(new UnusedDecls, // Removes all unused defs and vals decls (except for parameters)
83+
List(new GhostDecls, // Removes all ghost defs and vals decls (except for parameters)
8484
new VCInlineMethods, // Inlines calls to value class methods
8585
new SeqLiterals, // Express vararg arguments as arrays
8686
new InterceptedMethods, // Special handling of `==`, `|=`, `getClass` methods

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ object desugar {
262262
private def toDefParam(tparam: TypeDef): TypeDef =
263263
tparam.withMods(tparam.rawMods & EmptyFlags | Param)
264264
private def toDefParam(vparam: ValDef): ValDef =
265-
vparam.withMods(vparam.rawMods & (Implicit | Unused) | Param)
265+
vparam.withMods(vparam.rawMods & (Implicit | Ghost) | Param)
266266

267267
/** The expansion of a class definition. See inline comments for what is involved */
268268
def classDef(cdef: TypeDef)(implicit ctx: Context): Tree = {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
396396
* flags set.
397397
*/
398398
private def refPurity(tree: Tree)(implicit ctx: Context): PurityLevel =
399-
if (!tree.tpe.widen.isParameterless || tree.symbol.is(Unused)) SimplyPure
399+
if (!tree.tpe.widen.isParameterless || tree.symbol.is(Ghost)) SimplyPure
400400
else if (!tree.symbol.isStable) Impure
401401
else if (tree.symbol.is(Lazy)) Idempotent // TODO add Module flag, sinxce Module vals or not Lazy from the start.
402402
else SimplyPure

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
202202
case tp: MethodType =>
203203
def valueParam(name: TermName, info: Type): TermSymbol = {
204204
val maybeImplicit = if (tp.isImplicitMethod) Implicit else EmptyFlags
205-
val maybeUnused = if (tp.isUnusedMethod) Unused else EmptyFlags
206-
ctx.newSymbol(sym, name, TermParam | maybeImplicit | maybeUnused, info, coord = sym.coord)
205+
val maybeGhost = if (tp.isGhostMethod) Ghost else EmptyFlags
206+
ctx.newSymbol(sym, name, TermParam | maybeImplicit | maybeGhost, info, coord = sym.coord)
207207
}
208208
val params = (tp.paramNames, tp.paramInfos).zipped.map(valueParam)
209209
val (paramss, rtp) = valueParamss(tp.instantiate(params map (_.termRef)))

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
118118

119119
case class Implicit() extends Mod(Flags.ImplicitCommon)
120120

121-
case class Unused() extends Mod(Flags.Unused)
121+
case class Ghost() extends Mod(Flags.Ghost)
122122

123123
case class Final() extends Mod(Flags.Final)
124124

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

+37-37
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class Definitions {
8888
newClassSymbol(ScalaPackageClass, name, EmptyFlags, completer).entered
8989
}
9090

91-
/** The trait FunctionN, ImplicitFunctionN, UnusedFunctionN or UnusedImplicitFunction, for some N
91+
/** The trait FunctionN, ImplicitFunctionN, GhostFunctionN or GhostImplicitFunction, for some N
9292
* @param name The name of the trait to be created
9393
*
9494
* FunctionN traits follow this template:
@@ -107,19 +107,19 @@ class Definitions {
107107
* def apply(implicit $x0: T0, ..., $x{N_1}: T{N-1}): R
108108
* }
109109
*
110-
* UnusedFunctionN traits follow this template:
110+
* GhostFunctionN traits follow this template:
111111
*
112-
* trait UnusedFunctionN[T0,...,T{N-1}, R] extends Object {
113-
* def apply(unused $x0: T0, ..., $x{N_1}: T{N-1}): R
112+
* trait GhostFunctionN[T0,...,T{N-1}, R] extends Object {
113+
* def apply(ghost $x0: T0, ..., $x{N_1}: T{N-1}): R
114114
* }
115115
*
116-
* UnusedImplicitFunctionN traits follow this template:
116+
* GhostImplicitFunctionN traits follow this template:
117117
*
118-
* trait UnusedImplicitFunctionN[T0,...,T{N-1}, R] extends Object with UnusedFunctionN[T0,...,T{N-1}, R] {
119-
* def apply(unused implicit $x0: T0, ..., $x{N_1}: T{N-1}): R
118+
* trait GhostImplicitFunctionN[T0,...,T{N-1}, R] extends Object with GhostFunctionN[T0,...,T{N-1}, R] {
119+
* def apply(ghost implicit $x0: T0, ..., $x{N_1}: T{N-1}): R
120120
* }
121121
*
122-
* UnusedFunctionN and UnusedImplicitFunctionN erase to Function0.
122+
* GhostFunctionN and GhostImplicitFunctionN erase to Function0.
123123
*/
124124
def newFunctionNTrait(name: TypeName): ClassSymbol = {
125125
val completer = new LazyType {
@@ -132,10 +132,10 @@ class Definitions {
132132
enterTypeParam(cls, paramNamePrefix ++ "T" ++ (i + 1).toString, Contravariant, decls).typeRef
133133
}
134134
val resParamRef = enterTypeParam(cls, paramNamePrefix ++ "R", Covariant, decls).typeRef
135-
val methodType = MethodType.maker(isJava = false, name.isImplicitFunction, name.isUnusedFunction)
135+
val methodType = MethodType.maker(isJava = false, name.isImplicitFunction, name.isGhostFunction)
136136
val parentTraits =
137137
if (!name.isImplicitFunction) Nil
138-
else FunctionType(arity, isUnused = name.isUnusedFunction).appliedTo(argParamRefs ::: resParamRef :: Nil) :: Nil
138+
else FunctionType(arity, isGhost = name.isGhostFunction).appliedTo(argParamRefs ::: resParamRef :: Nil) :: Nil
139139
decls.enter(newMethod(cls, nme.apply, methodType(argParamRefs, resParamRef), Deferred))
140140
denot.info =
141141
ClassInfo(ScalaPackageClass.thisType, cls, ObjectType :: parentTraits, decls)
@@ -756,14 +756,14 @@ class Definitions {
756756
sym.owner.linkedClass.typeRef
757757

758758
object FunctionOf {
759-
def apply(args: List[Type], resultType: Type, isImplicit: Boolean = false, isUnused: Boolean = false)(implicit ctx: Context) =
760-
FunctionType(args.length, isImplicit, isUnused).appliedTo(args ::: resultType :: Nil)
759+
def apply(args: List[Type], resultType: Type, isImplicit: Boolean = false, isGhost: Boolean = false)(implicit ctx: Context) =
760+
FunctionType(args.length, isImplicit, isGhost).appliedTo(args ::: resultType :: Nil)
761761
def unapply(ft: Type)(implicit ctx: Context) = {
762762
val tsym = ft.typeSymbol
763763
if (isFunctionClass(tsym)) {
764764
val targs = ft.dealias.argInfos
765765
if (targs.isEmpty) None
766-
else Some(targs.init, targs.last, tsym.name.isImplicitFunction, tsym.name.isUnusedFunction)
766+
else Some(targs.init, targs.last, tsym.name.isImplicitFunction, tsym.name.isGhostFunction)
767767
}
768768
else None
769769
}
@@ -827,18 +827,18 @@ class Definitions {
827827

828828
lazy val TupleType = mkArityArray("scala.Tuple", MaxTupleArity, 2)
829829

830-
def FunctionClass(n: Int, isImplicit: Boolean = false, isUnused: Boolean = false)(implicit ctx: Context) = {
831-
if (isImplicit && isUnused) {
830+
def FunctionClass(n: Int, isImplicit: Boolean = false, isGhost: Boolean = false)(implicit ctx: Context) = {
831+
if (isImplicit && isGhost) {
832832
require(n > 0)
833-
ctx.requiredClass("scala.UnusedImplicitFunction" + n.toString)
833+
ctx.requiredClass("scala.GhostImplicitFunction" + n.toString)
834834
}
835835
else if (isImplicit) {
836836
require(n > 0)
837837
ctx.requiredClass("scala.ImplicitFunction" + n.toString)
838838
}
839-
else if (isUnused) {
839+
else if (isGhost) {
840840
require(n > 0)
841-
ctx.requiredClass("scala.UnusedFunction" + n.toString)
841+
ctx.requiredClass("scala.GhostFunction" + n.toString)
842842
}
843843
else if (n <= MaxImplementedFunctionArity) FunctionClassPerRun()(ctx)(n)
844844
else ctx.requiredClass("scala.Function" + n.toString)
@@ -847,9 +847,9 @@ class Definitions {
847847
lazy val Function0_applyR = ImplementedFunctionType(0).symbol.requiredMethodRef(nme.apply)
848848
def Function0_apply(implicit ctx: Context) = Function0_applyR.symbol
849849

850-
def FunctionType(n: Int, isImplicit: Boolean = false, isUnused: Boolean = false)(implicit ctx: Context): TypeRef =
851-
if (n <= MaxImplementedFunctionArity && (!isImplicit || ctx.erasedTypes) && !isUnused) ImplementedFunctionType(n)
852-
else FunctionClass(n, isImplicit, isUnused).typeRef
850+
def FunctionType(n: Int, isImplicit: Boolean = false, isGhost: Boolean = false)(implicit ctx: Context): TypeRef =
851+
if (n <= MaxImplementedFunctionArity && (!isImplicit || ctx.erasedTypes) && !isGhost) ImplementedFunctionType(n)
852+
else FunctionClass(n, isImplicit, isGhost).typeRef
853853

854854
private lazy val TupleTypes: Set[TypeRef] = TupleType.toSet
855855

@@ -874,22 +874,22 @@ class Definitions {
874874
/** Is a function class.
875875
* - FunctionN for N >= 0
876876
* - ImplicitFunctionN for N > 0
877-
* - UnusedFunctionN for N > 0
878-
* - UnusedImplicitFunctionN for N > 0
877+
* - GhostFunctionN for N > 0
878+
* - GhostImplicitFunctionN for N > 0
879879
*/
880880
def isFunctionClass(cls: Symbol) = scalaClassName(cls).isFunction
881881

882882
/** Is an implicit function class.
883883
* - ImplicitFunctionN for N > 0
884-
* - UnusedImplicitFunctionN for N > 0
884+
* - GhostImplicitFunctionN for N > 0
885885
*/
886886
def isImplicitFunctionClass(cls: Symbol) = scalaClassName(cls).isImplicitFunction
887887

888-
/** Is an unused function class.
889-
* - UnusedFunctionN for N > 0
890-
* - UnusedImplicitFunctionN for N > 0
888+
/** Is an ghost function class.
889+
* - GhostFunctionN for N > 0
890+
* - GhostImplicitFunctionN for N > 0
891891
*/
892-
def isUnusedFunctionClass(cls: Symbol) = scalaClassName(cls).isUnusedFunction
892+
def isGhostFunctionClass(cls: Symbol) = scalaClassName(cls).isGhostFunction
893893

894894
/** Is a class that will be erased to FunctionXXL
895895
* - FunctionN for N >= 22
@@ -915,13 +915,13 @@ class Definitions {
915915
* - FunctionN for 22 > N >= 0 remains as FunctionN
916916
* - ImplicitFunctionN for N > 22 becomes FunctionXXL
917917
* - ImplicitFunctionN for 22 > N >= 0 becomes FunctionN
918-
* - UnusedFunctionN becomes Function0
919-
* - ImplicitUnusedFunctionN becomes Function0
918+
* - GhostFunctionN becomes Function0
919+
* - ImplicitGhostFunctionN becomes Function0
920920
* - anything else becomes a NoSymbol
921921
*/
922922
def erasedFunctionClass(cls: Symbol): Symbol = {
923923
val arity = scalaClassName(cls).functionArity
924-
if (cls.name.isUnusedFunction) FunctionClass(0)
924+
if (cls.name.isGhostFunction) FunctionClass(0)
925925
else if (arity > 22) FunctionXXLClass
926926
else if (arity >= 0) FunctionClass(arity)
927927
else NoSymbol
@@ -932,13 +932,13 @@ class Definitions {
932932
* - FunctionN for 22 > N >= 0 remains as FunctionN
933933
* - ImplicitFunctionN for N > 22 becomes FunctionXXL
934934
* - ImplicitFunctionN for 22 > N >= 0 becomes FunctionN
935-
* - UnusedFunctionN becomes Function0
936-
* - ImplicitUnusedFunctionN becomes Function0
935+
* - GhostFunctionN becomes Function0
936+
* - ImplicitGhostFunctionN becomes Function0
937937
* - anything else becomes a NoType
938938
*/
939939
def erasedFunctionType(cls: Symbol): Type = {
940940
val arity = scalaClassName(cls).functionArity
941-
if (cls.name.isUnusedFunction) FunctionType(0)
941+
if (cls.name.isGhostFunction) FunctionType(0)
942942
else if (arity > 22) FunctionXXLType
943943
else if (arity >= 0) FunctionType(arity)
944944
else NoType
@@ -1008,7 +1008,7 @@ class Definitions {
10081008
def isNonDepFunctionType(tp: Type)(implicit ctx: Context) = {
10091009
val arity = functionArity(tp)
10101010
val sym = tp.dealias.typeSymbol
1011-
arity >= 0 && isFunctionClass(sym) && tp.isRef(FunctionType(arity, sym.name.isImplicitFunction, sym.name.isUnusedFunction).typeSymbol)
1011+
arity >= 0 && isFunctionClass(sym) && tp.isRef(FunctionType(arity, sym.name.isImplicitFunction, sym.name.isGhostFunction).typeSymbol)
10121012
}
10131013

10141014
/** Is `tp` a representation of a (possibly depenent) function type or an alias of such? */
@@ -1074,8 +1074,8 @@ class Definitions {
10741074
def isImplicitFunctionType(tp: Type)(implicit ctx: Context): Boolean =
10751075
asImplicitFunctionType(tp).exists
10761076

1077-
def isUnusedFunctionType(tp: Type)(implicit ctx: Context) =
1078-
isFunctionType(tp) && tp.dealias.typeSymbol.name.isUnusedFunction
1077+
def isGhostFunctionType(tp: Type)(implicit ctx: Context) =
1078+
isFunctionType(tp) && tp.dealias.typeSymbol.name.isGhostFunction
10791079

10801080
// ----- primitive value class machinery ------------------------------------------
10811081

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ object Flags {
367367
/** Symbol is a Java enum */
368368
final val Enum = commonFlag(40, "<enum>")
369369

370-
/** Labeled with `unused` modifier (unused value) */
371-
final val Unused = termFlag(42, "unused")
370+
/** Labeled with `ghost` modifier (ghost value) */
371+
final val Ghost = termFlag(42, "ghost")
372372

373373
// Flags following this one are not pickled
374374

@@ -441,7 +441,7 @@ object Flags {
441441
/** Flags representing source modifiers */
442442
final val SourceModifierFlags =
443443
commonFlags(Private, Protected, Abstract, Final, Inline,
444-
Sealed, Case, Implicit, Override, AbsOverride, Lazy, JavaStatic, Unused)
444+
Sealed, Case, Implicit, Override, AbsOverride, Lazy, JavaStatic, Ghost)
445445

446446
/** Flags representing modifiers that can appear in trees */
447447
final val ModifierFlags =
@@ -515,7 +515,7 @@ object Flags {
515515
/** Flags that can apply to a module val */
516516
final val RetainedModuleValFlags: FlagSet = RetainedModuleValAndClassFlags |
517517
Override | Final | Method | Implicit | Lazy |
518-
Accessor | AbsOverride | Stable | Captured | Synchronized | Inline | Unused
518+
Accessor | AbsOverride | Stable | Captured | Synchronized | Inline | Ghost
519519

520520
/** Flags that can apply to a module class */
521521
final val RetainedModuleClassFlags: FlagSet = RetainedModuleValAndClassFlags | ImplClass | Enum

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

+14-14
Original file line numberDiff line numberDiff line change
@@ -176,51 +176,51 @@ object NameOps {
176176
functionArityFor(str.Function) max {
177177
val n =
178178
functionArityFor(str.ImplicitFunction) max
179-
functionArityFor(str.UnusedFunction) max
180-
functionArityFor(str.UnusedImplicitFunction)
179+
functionArityFor(str.GhostFunction) max
180+
functionArityFor(str.GhostImplicitFunction)
181181
if (n == 0) -1 else n
182182
}
183183

184184
/** Is a function name
185185
* - FunctionN for N >= 0
186186
* - ImplicitFunctionN for N >= 1
187-
* - UnusedFunctionN for N >= 1
188-
* - UnusedImplicitFunctionN for N >= 1
187+
* - GhostFunctionN for N >= 1
188+
* - GhostImplicitFunctionN for N >= 1
189189
* - false otherwise
190190
*/
191191
def isFunction: Boolean = functionArity >= 0
192192

193193
/** Is a implicit function name
194194
* - ImplicitFunctionN for N >= 1
195-
* - UnusedImplicitFunctionN for N >= 1
195+
* - GhostImplicitFunctionN for N >= 1
196196
* - false otherwise
197197
*/
198198
def isImplicitFunction: Boolean = {
199199
functionArityFor(str.ImplicitFunction) >= 1 ||
200-
functionArityFor(str.UnusedImplicitFunction) >= 1
200+
functionArityFor(str.GhostImplicitFunction) >= 1
201201
}
202202

203203
/** Is a implicit function name
204-
* - UnusedFunctionN for N >= 1
205-
* - UnusedImplicitFunctionN for N >= 1
204+
* - GhostFunctionN for N >= 1
205+
* - GhostImplicitFunctionN for N >= 1
206206
* - false otherwise
207207
*/
208-
def isUnusedFunction: Boolean = {
209-
functionArityFor(str.UnusedFunction) >= 1 ||
210-
functionArityFor(str.UnusedImplicitFunction) >= 1
208+
def isGhostFunction: Boolean = {
209+
functionArityFor(str.GhostFunction) >= 1 ||
210+
functionArityFor(str.GhostImplicitFunction) >= 1
211211
}
212212

213213
/** Is a synthetic function name
214214
* - FunctionN for N > 22
215215
* - ImplicitFunctionN for N >= 1
216-
* - UnusedFunctionN for N >= 1
217-
* - UnusedImplicitFunctionN for N >= 1
216+
* - GhostFunctionN for N >= 1
217+
* - GhostImplicitFunctionN for N >= 1
218218
* - false otherwise
219219
*/
220220
def isSyntheticFunction: Boolean = {
221221
functionArityFor(str.Function) > MaxImplementedFunctionArity ||
222222
functionArityFor(str.ImplicitFunction) >= 1 ||
223-
isUnusedFunction
223+
isGhostFunction
224224
}
225225

226226
/** Parsed function arity for function with some specific prefix */

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ object StdNames {
3636
final val MODULE_INSTANCE_FIELD = "MODULE$"
3737

3838
final val Function = "Function"
39-
final val UnusedFunction = "UnusedFunction"
39+
final val GhostFunction = "GhostFunction"
4040
final val ImplicitFunction = "ImplicitFunction"
41-
final val UnusedImplicitFunction = "UnusedImplicitFunction"
41+
final val GhostImplicitFunction = "GhostImplicitFunction"
4242
final val AbstractFunction = "AbstractFunction"
4343
final val Tuple = "Tuple"
4444
final val Product = "Product"

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
399399
case tp: MethodType =>
400400
def paramErasure(tpToErase: Type) =
401401
erasureFn(tp.isJavaMethod, semiEraseVCs, isConstructor, wildcardOK)(tpToErase)
402-
val (names, formals0) = if (tp.isUnusedMethod) (Nil, Nil) else (tp.paramNames, tp.paramInfos)
402+
val (names, formals0) = if (tp.isGhostMethod) (Nil, Nil) else (tp.paramNames, tp.paramInfos)
403403
val formals = formals0.mapConserve(paramErasure)
404404
eraseResult(tp.resultType) match {
405405
case rt: MethodType =>

0 commit comments

Comments
 (0)