From 31f2e0d4f2d865e8bfabc74d7a375dc51e765b90 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 2 Mar 2018 08:53:09 +0100 Subject: [PATCH] Rename `unused` to `ghost` --- compiler/src/dotty/tools/dotc/Compiler.scala | 2 +- .../src/dotty/tools/dotc/ast/Desugar.scala | 2 +- .../src/dotty/tools/dotc/ast/TreeInfo.scala | 2 +- compiler/src/dotty/tools/dotc/ast/tpd.scala | 4 +- compiler/src/dotty/tools/dotc/ast/untpd.scala | 2 +- .../dotty/tools/dotc/core/Definitions.scala | 74 ++++++------- .../src/dotty/tools/dotc/core/Flags.scala | 8 +- .../src/dotty/tools/dotc/core/NameOps.scala | 28 ++--- .../src/dotty/tools/dotc/core/StdNames.scala | 4 +- .../dotty/tools/dotc/core/TypeErasure.scala | 2 +- .../src/dotty/tools/dotc/core/Types.scala | 24 ++-- .../dotty/tools/dotc/parsing/Parsers.scala | 20 ++-- .../src/dotty/tools/dotc/parsing/Tokens.scala | 6 +- .../tools/dotc/printing/RefinedPrinter.scala | 8 +- .../dotc/reporting/diagnostic/messages.scala | 4 +- .../dotty/tools/dotc/transform/Erasure.scala | 6 +- .../dotc/transform/GenericSignatures.scala | 4 +- .../tools/dotc/transform/PostTyper.scala | 12 +- .../dotc/transform/SyntheticMethods.scala | 2 +- .../tools/dotc/transform/UnusedDecls.scala | 16 +-- .../dotty/tools/dotc/typer/Applications.scala | 14 +-- .../src/dotty/tools/dotc/typer/Checking.scala | 12 +- .../src/dotty/tools/dotc/typer/Namer.scala | 6 +- .../src/dotty/tools/dotc/typer/Typer.scala | 16 +-- .../dotty/tools/dotc/FromTastyTests.scala | 12 +- docs/_includes/features.html | 2 +- docs/docs/internals/syntax.md | 2 +- .../{unused-parameters.md => ghost-terms.md} | 104 +++++++++--------- docs/sidebar.yml | 4 +- tests/generic-java-signatures/ghost.check | 2 + .../{unused.scala => ghost.scala} | 6 +- tests/generic-java-signatures/unused.check | 2 - tests/neg/{unused-1.scala => ghost-1.scala} | 6 +- tests/neg/{unused-2.scala => ghost-2.scala} | 10 +- tests/neg/{unused-3.scala => ghost-3.scala} | 10 +- tests/neg/ghost-4.scala | 17 +++ tests/neg/{unused-5.scala => ghost-5.scala} | 6 +- tests/neg/{unused-6.scala => ghost-6.scala} | 2 +- ...s-lifted.scala => ghost-args-lifted.scala} | 2 +- ...unused-assign.scala => ghost-assign.scala} | 4 +- tests/neg/ghost-case-class.scala | 1 + tests/neg/ghost-class.scala | 1 + ...used-def-rhs.scala => ghost-def-rhs.scala} | 2 +- ...used-if-else.scala => ghost-if-else.scala} | 2 +- ...ed-implicit.scala => ghost-implicit.scala} | 2 +- tests/neg/ghost-lazy-val.scala | 3 + .../{unused-match.scala => ghost-match.scala} | 2 +- tests/neg/ghost-object.scala | 1 + ...unused-return.scala => ghost-return.scala} | 2 +- tests/neg/ghost-trait.scala | 1 + .../neg/{unused-try.scala => ghost-try.scala} | 4 +- tests/neg/ghost-type.scala | 3 + ...used-val-rhs.scala => ghost-val-rhs.scala} | 2 +- ...ue-class.scala => ghost-value-class.scala} | 2 +- tests/neg/ghost-var.scala | 3 + tests/neg/unused-4.scala | 17 --- tests/neg/unused-case-class.scala | 1 - tests/neg/unused-class.scala | 1 - tests/neg/unused-lazy-val.scala | 3 - tests/neg/unused-object.scala | 1 - tests/neg/unused-trait.scala | 1 - tests/neg/unused-type.scala | 3 - tests/neg/unused-var.scala | 3 - ...s-lifted.scala => ghost-args-lifted.scala} | 2 +- ...tanceOf.scala => ghost-asInstanceOf.scala} | 2 +- ...context.scala => ghost-deep-context.scala} | 6 +- ...hod.scala => ghost-extension-method.scala} | 2 +- tests/pos/ghost-pathdep-1.scala | 19 ++++ ...-pathdep-2.scala => ghost-pathdep-2.scala} | 2 +- tests/pos/phantom-Eq.scala | 14 +-- tests/pos/phantom-Eq2/Phantom-Eq_1.scala | 14 +-- tests/pos/phantom-Evidence.scala | 6 +- tests/pos/unused-pathdep-1.scala | 19 ---- tests/run/{unused-1.check => ghost-1.check} | 0 tests/run/{unused-1.scala => ghost-1.scala} | 2 +- tests/run/{unused-10.check => ghost-10.check} | 0 tests/run/{unused-10.scala => ghost-10.scala} | 4 +- tests/run/{unused-11.check => ghost-11.check} | 0 tests/run/{unused-11.scala => ghost-11.scala} | 6 +- tests/run/{unused-12.check => ghost-12.check} | 0 tests/run/{unused-12.scala => ghost-12.scala} | 2 +- tests/run/{unused-13.check => ghost-13.check} | 0 tests/run/{unused-13.scala => ghost-13.scala} | 4 +- tests/run/{unused-14.check => ghost-14.check} | 0 tests/run/{unused-14.scala => ghost-14.scala} | 2 +- tests/run/{unused-15.check => ghost-15.check} | 0 tests/run/{unused-15.scala => ghost-15.scala} | 4 +- tests/run/{unused-16.check => ghost-16.check} | 0 tests/run/{unused-16.scala => ghost-16.scala} | 4 +- tests/run/{unused-17.check => ghost-17.check} | 0 tests/run/{unused-17.scala => ghost-17.scala} | 4 +- tests/run/{unused-18.check => ghost-18.check} | 0 tests/run/{unused-18.scala => ghost-18.scala} | 2 +- tests/run/{unused-19.check => ghost-19.check} | 0 tests/run/{unused-19.scala => ghost-19.scala} | 2 +- tests/run/{unused-2.check => ghost-2.check} | 0 tests/run/{unused-2.scala => ghost-2.scala} | 4 +- tests/run/{unused-20.check => ghost-20.check} | 0 tests/run/{unused-20.scala => ghost-20.scala} | 4 +- tests/run/{unused-21.check => ghost-21.check} | 0 tests/run/{unused-21.scala => ghost-21.scala} | 4 +- tests/run/{unused-22.check => ghost-22.check} | 0 tests/run/{unused-22.scala => ghost-22.scala} | 2 +- tests/run/{unused-23.check => ghost-23.check} | 0 tests/run/ghost-23.scala | 22 ++++ tests/run/{unused-24.check => ghost-24.check} | 0 tests/run/{unused-24.scala => ghost-24.scala} | 4 +- tests/run/{unused-25.check => ghost-25.check} | 0 tests/run/{unused-25.scala => ghost-25.scala} | 2 +- tests/run/{unused-26.check => ghost-26.check} | 0 tests/run/{unused-26.scala => ghost-26.scala} | 2 +- tests/run/{unused-27.check => ghost-27.check} | 0 tests/run/{unused-27.scala => ghost-27.scala} | 2 +- tests/run/{unused-28.check => ghost-28.check} | 0 tests/run/{unused-28.scala => ghost-28.scala} | 4 +- tests/run/{unused-3.check => ghost-3.check} | 0 tests/run/{unused-3.scala => ghost-3.scala} | 2 +- tests/run/{unused-4.check => ghost-4.check} | 0 tests/run/{unused-4.scala => ghost-4.scala} | 4 +- tests/run/{unused-5.check => ghost-5.check} | 0 tests/run/{unused-5.scala => ghost-5.scala} | 4 +- tests/run/{unused-6.check => ghost-6.check} | 0 tests/run/{unused-6.scala => ghost-6.scala} | 2 +- tests/run/{unused-7.check => ghost-7.check} | 0 tests/run/{unused-7.scala => ghost-7.scala} | 4 +- tests/run/{unused-8.check => ghost-8.check} | 0 tests/run/{unused-8.scala => ghost-8.scala} | 4 +- tests/run/{unused-9.check => ghost-9.check} | 0 tests/run/{unused-9.scala => ghost-9.scala} | 2 +- ...-frameless.check => ghost-frameless.check} | 0 ...-frameless.scala => ghost-frameless.scala} | 6 +- ...-state.check => ghost-machine-state.check} | 0 ...-state.scala => ghost-machine-state.scala} | 4 +- ...ed-poly-ref.check => ghost-poly-ref.check} | 0 ...ed-poly-ref.scala => ghost-poly-ref.scala} | 4 +- ...prefix.check => ghost-select-prefix.check} | 0 ...prefix.scala => ghost-select-prefix.scala} | 10 +- ...ue-class.check => ghost-value-class.check} | 0 ...ue-class.scala => ghost-value-class.scala} | 2 +- tests/run/phantom-OnHList.scala | 6 +- tests/run/t7711-script-args.script | 2 +- tests/run/unused-23.scala | 22 ---- 142 files changed, 390 insertions(+), 390 deletions(-) rename docs/docs/reference/{unused-parameters.md => ghost-terms.md} (53%) create mode 100644 tests/generic-java-signatures/ghost.check rename tests/generic-java-signatures/{unused.scala => ghost.scala} (65%) delete mode 100644 tests/generic-java-signatures/unused.check rename tests/neg/{unused-1.scala => ghost-1.scala} (78%) rename tests/neg/{unused-2.scala => ghost-2.scala} (75%) rename tests/neg/{unused-3.scala => ghost-3.scala} (77%) create mode 100644 tests/neg/ghost-4.scala rename tests/neg/{unused-5.scala => ghost-5.scala} (62%) rename tests/neg/{unused-6.scala => ghost-6.scala} (83%) rename tests/neg/{unused-args-lifted.scala => ghost-args-lifted.scala} (87%) rename tests/neg/{unused-assign.scala => ghost-assign.scala} (62%) create mode 100644 tests/neg/ghost-case-class.scala create mode 100644 tests/neg/ghost-class.scala rename tests/neg/{unused-def-rhs.scala => ghost-def-rhs.scala} (66%) rename tests/neg/{unused-if-else.scala => ghost-if-else.scala} (84%) rename tests/neg/{unused-implicit.scala => ghost-implicit.scala} (58%) create mode 100644 tests/neg/ghost-lazy-val.scala rename tests/neg/{unused-match.scala => ghost-match.scala} (88%) create mode 100644 tests/neg/ghost-object.scala rename tests/neg/{unused-return.scala => ghost-return.scala} (81%) create mode 100644 tests/neg/ghost-trait.scala rename tests/neg/{unused-try.scala => ghost-try.scala} (69%) create mode 100644 tests/neg/ghost-type.scala rename tests/neg/{unused-val-rhs.scala => ghost-val-rhs.scala} (67%) rename tests/neg/{unused-value-class.scala => ghost-value-class.scala} (51%) create mode 100644 tests/neg/ghost-var.scala delete mode 100644 tests/neg/unused-4.scala delete mode 100644 tests/neg/unused-case-class.scala delete mode 100644 tests/neg/unused-class.scala delete mode 100644 tests/neg/unused-lazy-val.scala delete mode 100644 tests/neg/unused-object.scala delete mode 100644 tests/neg/unused-trait.scala delete mode 100644 tests/neg/unused-type.scala delete mode 100644 tests/neg/unused-var.scala rename tests/pos/{unused-args-lifted.scala => ghost-args-lifted.scala} (81%) rename tests/pos/{unused-asInstanceOf.scala => ghost-asInstanceOf.scala} (80%) rename tests/pos/{unused-deep-context.scala => ghost-deep-context.scala} (52%) rename tests/pos/{unused-extension-method.scala => ghost-extension-method.scala} (58%) create mode 100644 tests/pos/ghost-pathdep-1.scala rename tests/pos/{unused-pathdep-2.scala => ghost-pathdep-2.scala} (85%) delete mode 100644 tests/pos/unused-pathdep-1.scala rename tests/run/{unused-1.check => ghost-1.check} (100%) rename tests/run/{unused-1.scala => ghost-1.scala} (79%) rename tests/run/{unused-10.check => ghost-10.check} (100%) rename tests/run/{unused-10.scala => ghost-10.scala} (77%) rename tests/run/{unused-11.check => ghost-11.check} (100%) rename tests/run/{unused-11.scala => ghost-11.scala} (75%) rename tests/run/{unused-12.check => ghost-12.check} (100%) rename tests/run/{unused-12.scala => ghost-12.scala} (81%) rename tests/run/{unused-13.check => ghost-13.check} (100%) rename tests/run/{unused-13.scala => ghost-13.scala} (72%) rename tests/run/{unused-14.check => ghost-14.check} (100%) rename tests/run/{unused-14.scala => ghost-14.scala} (85%) rename tests/run/{unused-15.check => ghost-15.check} (100%) rename tests/run/{unused-15.scala => ghost-15.scala} (67%) rename tests/run/{unused-16.check => ghost-16.check} (100%) rename tests/run/{unused-16.scala => ghost-16.scala} (72%) rename tests/run/{unused-17.check => ghost-17.check} (100%) rename tests/run/{unused-17.scala => ghost-17.scala} (59%) rename tests/run/{unused-18.check => ghost-18.check} (100%) rename tests/run/{unused-18.scala => ghost-18.scala} (86%) rename tests/run/{unused-19.check => ghost-19.check} (100%) rename tests/run/{unused-19.scala => ghost-19.scala} (77%) rename tests/run/{unused-2.check => ghost-2.check} (100%) rename tests/run/{unused-2.scala => ghost-2.scala} (70%) rename tests/run/{unused-20.check => ghost-20.check} (100%) rename tests/run/{unused-20.scala => ghost-20.scala} (61%) rename tests/run/{unused-21.check => ghost-21.check} (100%) rename tests/run/{unused-21.scala => ghost-21.scala} (73%) rename tests/run/{unused-22.check => ghost-22.check} (100%) rename tests/run/{unused-22.scala => ghost-22.scala} (79%) rename tests/run/{unused-23.check => ghost-23.check} (100%) create mode 100644 tests/run/ghost-23.scala rename tests/run/{unused-24.check => ghost-24.check} (100%) rename tests/run/{unused-24.scala => ghost-24.scala} (71%) rename tests/run/{unused-25.check => ghost-25.check} (100%) rename tests/run/{unused-25.scala => ghost-25.scala} (75%) rename tests/run/{unused-26.check => ghost-26.check} (100%) rename tests/run/{unused-26.scala => ghost-26.scala} (56%) rename tests/run/{unused-27.check => ghost-27.check} (100%) rename tests/run/{unused-27.scala => ghost-27.scala} (83%) rename tests/run/{unused-28.check => ghost-28.check} (100%) rename tests/run/{unused-28.scala => ghost-28.scala} (77%) rename tests/run/{unused-3.check => ghost-3.check} (100%) rename tests/run/{unused-3.scala => ghost-3.scala} (80%) rename tests/run/{unused-4.check => ghost-4.check} (100%) rename tests/run/{unused-4.scala => ghost-4.scala} (74%) rename tests/run/{unused-5.check => ghost-5.check} (100%) rename tests/run/{unused-5.scala => ghost-5.scala} (67%) rename tests/run/{unused-6.check => ghost-6.check} (100%) rename tests/run/{unused-6.scala => ghost-6.scala} (84%) rename tests/run/{unused-7.check => ghost-7.check} (100%) rename tests/run/{unused-7.scala => ghost-7.scala} (72%) rename tests/run/{unused-8.check => ghost-8.check} (100%) rename tests/run/{unused-8.scala => ghost-8.scala} (72%) rename tests/run/{unused-9.check => ghost-9.check} (100%) rename tests/run/{unused-9.scala => ghost-9.scala} (80%) rename tests/run/{unused-frameless.check => ghost-frameless.check} (100%) rename tests/run/{unused-frameless.scala => ghost-frameless.scala} (95%) rename tests/run/{unused-machine-state.check => ghost-machine-state.check} (100%) rename tests/run/{unused-machine-state.scala => ghost-machine-state.scala} (89%) rename tests/run/{unused-poly-ref.check => ghost-poly-ref.check} (100%) rename tests/run/{unused-poly-ref.scala => ghost-poly-ref.scala} (58%) rename tests/run/{unused-select-prefix.check => ghost-select-prefix.check} (100%) rename tests/run/{unused-select-prefix.scala => ghost-select-prefix.scala} (67%) rename tests/run/{unused-value-class.check => ghost-value-class.check} (100%) rename tests/run/{unused-value-class.scala => ghost-value-class.scala} (78%) delete mode 100644 tests/run/unused-23.scala diff --git a/compiler/src/dotty/tools/dotc/Compiler.scala b/compiler/src/dotty/tools/dotc/Compiler.scala index 5ff69a5e1314..73fa76f9236d 100644 --- a/compiler/src/dotty/tools/dotc/Compiler.scala +++ b/compiler/src/dotty/tools/dotc/Compiler.scala @@ -80,7 +80,7 @@ class Compiler { new ShortcutImplicits, // Allow implicit functions without creating closures new CrossCastAnd, // Normalize selections involving intersection types. new Splitter) :: // Expand selections involving union types into conditionals - List(new UnusedDecls, // Removes all unused defs and vals decls (except for parameters) + List(new GhostDecls, // Removes all ghost defs and vals decls (except for parameters) new VCInlineMethods, // Inlines calls to value class methods new SeqLiterals, // Express vararg arguments as arrays new InterceptedMethods, // Special handling of `==`, `|=`, `getClass` methods diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 7a00a3b1ea78..b14a954876f6 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -262,7 +262,7 @@ object desugar { private def toDefParam(tparam: TypeDef): TypeDef = tparam.withMods(tparam.rawMods & EmptyFlags | Param) private def toDefParam(vparam: ValDef): ValDef = - vparam.withMods(vparam.rawMods & (Implicit | Unused) | Param) + vparam.withMods(vparam.rawMods & (Implicit | Ghost) | Param) /** The expansion of a class definition. See inline comments for what is involved */ def classDef(cdef: TypeDef)(implicit ctx: Context): Tree = { diff --git a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala index 3b0d966751e4..6b25ed7da9b1 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -396,7 +396,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => * flags set. */ private def refPurity(tree: Tree)(implicit ctx: Context): PurityLevel = - if (!tree.tpe.widen.isParameterless || tree.symbol.is(Unused)) SimplyPure + if (!tree.tpe.widen.isParameterless || tree.symbol.is(Ghost)) SimplyPure else if (!tree.symbol.isStable) Impure else if (tree.symbol.is(Lazy)) Idempotent // TODO add Module flag, sinxce Module vals or not Lazy from the start. else SimplyPure diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index 53609219ba01..a69dbd02b158 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -202,8 +202,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { case tp: MethodType => def valueParam(name: TermName, info: Type): TermSymbol = { val maybeImplicit = if (tp.isImplicitMethod) Implicit else EmptyFlags - val maybeUnused = if (tp.isUnusedMethod) Unused else EmptyFlags - ctx.newSymbol(sym, name, TermParam | maybeImplicit | maybeUnused, info, coord = sym.coord) + val maybeGhost = if (tp.isGhostMethod) Ghost else EmptyFlags + ctx.newSymbol(sym, name, TermParam | maybeImplicit | maybeGhost, info, coord = sym.coord) } val params = (tp.paramNames, tp.paramInfos).zipped.map(valueParam) val (paramss, rtp) = valueParamss(tp.instantiate(params map (_.termRef))) diff --git a/compiler/src/dotty/tools/dotc/ast/untpd.scala b/compiler/src/dotty/tools/dotc/ast/untpd.scala index f3a0b89cde52..57075f599de2 100644 --- a/compiler/src/dotty/tools/dotc/ast/untpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/untpd.scala @@ -118,7 +118,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { case class Implicit() extends Mod(Flags.ImplicitCommon) - case class Unused() extends Mod(Flags.Unused) + case class Ghost() extends Mod(Flags.Ghost) case class Final() extends Mod(Flags.Final) diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index f083075607e1..6cbb089401f6 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -88,7 +88,7 @@ class Definitions { newClassSymbol(ScalaPackageClass, name, EmptyFlags, completer).entered } - /** The trait FunctionN, ImplicitFunctionN, UnusedFunctionN or UnusedImplicitFunction, for some N + /** The trait FunctionN, ImplicitFunctionN, GhostFunctionN or GhostImplicitFunction, for some N * @param name The name of the trait to be created * * FunctionN traits follow this template: @@ -107,19 +107,19 @@ class Definitions { * def apply(implicit $x0: T0, ..., $x{N_1}: T{N-1}): R * } * - * UnusedFunctionN traits follow this template: + * GhostFunctionN traits follow this template: * - * trait UnusedFunctionN[T0,...,T{N-1}, R] extends Object { - * def apply(unused $x0: T0, ..., $x{N_1}: T{N-1}): R + * trait GhostFunctionN[T0,...,T{N-1}, R] extends Object { + * def apply(ghost $x0: T0, ..., $x{N_1}: T{N-1}): R * } * - * UnusedImplicitFunctionN traits follow this template: + * GhostImplicitFunctionN traits follow this template: * - * trait UnusedImplicitFunctionN[T0,...,T{N-1}, R] extends Object with UnusedFunctionN[T0,...,T{N-1}, R] { - * def apply(unused implicit $x0: T0, ..., $x{N_1}: T{N-1}): R + * trait GhostImplicitFunctionN[T0,...,T{N-1}, R] extends Object with GhostFunctionN[T0,...,T{N-1}, R] { + * def apply(ghost implicit $x0: T0, ..., $x{N_1}: T{N-1}): R * } * - * UnusedFunctionN and UnusedImplicitFunctionN erase to Function0. + * GhostFunctionN and GhostImplicitFunctionN erase to Function0. */ def newFunctionNTrait(name: TypeName): ClassSymbol = { val completer = new LazyType { @@ -132,10 +132,10 @@ class Definitions { enterTypeParam(cls, paramNamePrefix ++ "T" ++ (i + 1).toString, Contravariant, decls).typeRef } val resParamRef = enterTypeParam(cls, paramNamePrefix ++ "R", Covariant, decls).typeRef - val methodType = MethodType.maker(isJava = false, name.isImplicitFunction, name.isUnusedFunction) + val methodType = MethodType.maker(isJava = false, name.isImplicitFunction, name.isGhostFunction) val parentTraits = if (!name.isImplicitFunction) Nil - else FunctionType(arity, isUnused = name.isUnusedFunction).appliedTo(argParamRefs ::: resParamRef :: Nil) :: Nil + else FunctionType(arity, isGhost = name.isGhostFunction).appliedTo(argParamRefs ::: resParamRef :: Nil) :: Nil decls.enter(newMethod(cls, nme.apply, methodType(argParamRefs, resParamRef), Deferred)) denot.info = ClassInfo(ScalaPackageClass.thisType, cls, ObjectType :: parentTraits, decls) @@ -756,14 +756,14 @@ class Definitions { sym.owner.linkedClass.typeRef object FunctionOf { - def apply(args: List[Type], resultType: Type, isImplicit: Boolean = false, isUnused: Boolean = false)(implicit ctx: Context) = - FunctionType(args.length, isImplicit, isUnused).appliedTo(args ::: resultType :: Nil) + def apply(args: List[Type], resultType: Type, isImplicit: Boolean = false, isGhost: Boolean = false)(implicit ctx: Context) = + FunctionType(args.length, isImplicit, isGhost).appliedTo(args ::: resultType :: Nil) def unapply(ft: Type)(implicit ctx: Context) = { val tsym = ft.typeSymbol if (isFunctionClass(tsym)) { val targs = ft.dealias.argInfos if (targs.isEmpty) None - else Some(targs.init, targs.last, tsym.name.isImplicitFunction, tsym.name.isUnusedFunction) + else Some(targs.init, targs.last, tsym.name.isImplicitFunction, tsym.name.isGhostFunction) } else None } @@ -827,18 +827,18 @@ class Definitions { lazy val TupleType = mkArityArray("scala.Tuple", MaxTupleArity, 2) - def FunctionClass(n: Int, isImplicit: Boolean = false, isUnused: Boolean = false)(implicit ctx: Context) = { - if (isImplicit && isUnused) { + def FunctionClass(n: Int, isImplicit: Boolean = false, isGhost: Boolean = false)(implicit ctx: Context) = { + if (isImplicit && isGhost) { require(n > 0) - ctx.requiredClass("scala.UnusedImplicitFunction" + n.toString) + ctx.requiredClass("scala.GhostImplicitFunction" + n.toString) } else if (isImplicit) { require(n > 0) ctx.requiredClass("scala.ImplicitFunction" + n.toString) } - else if (isUnused) { + else if (isGhost) { require(n > 0) - ctx.requiredClass("scala.UnusedFunction" + n.toString) + ctx.requiredClass("scala.GhostFunction" + n.toString) } else if (n <= MaxImplementedFunctionArity) FunctionClassPerRun()(ctx)(n) else ctx.requiredClass("scala.Function" + n.toString) @@ -847,9 +847,9 @@ class Definitions { lazy val Function0_applyR = ImplementedFunctionType(0).symbol.requiredMethodRef(nme.apply) def Function0_apply(implicit ctx: Context) = Function0_applyR.symbol - def FunctionType(n: Int, isImplicit: Boolean = false, isUnused: Boolean = false)(implicit ctx: Context): TypeRef = - if (n <= MaxImplementedFunctionArity && (!isImplicit || ctx.erasedTypes) && !isUnused) ImplementedFunctionType(n) - else FunctionClass(n, isImplicit, isUnused).typeRef + def FunctionType(n: Int, isImplicit: Boolean = false, isGhost: Boolean = false)(implicit ctx: Context): TypeRef = + if (n <= MaxImplementedFunctionArity && (!isImplicit || ctx.erasedTypes) && !isGhost) ImplementedFunctionType(n) + else FunctionClass(n, isImplicit, isGhost).typeRef private lazy val TupleTypes: Set[TypeRef] = TupleType.toSet @@ -874,22 +874,22 @@ class Definitions { /** Is a function class. * - FunctionN for N >= 0 * - ImplicitFunctionN for N > 0 - * - UnusedFunctionN for N > 0 - * - UnusedImplicitFunctionN for N > 0 + * - GhostFunctionN for N > 0 + * - GhostImplicitFunctionN for N > 0 */ def isFunctionClass(cls: Symbol) = scalaClassName(cls).isFunction /** Is an implicit function class. * - ImplicitFunctionN for N > 0 - * - UnusedImplicitFunctionN for N > 0 + * - GhostImplicitFunctionN for N > 0 */ def isImplicitFunctionClass(cls: Symbol) = scalaClassName(cls).isImplicitFunction - /** Is an unused function class. - * - UnusedFunctionN for N > 0 - * - UnusedImplicitFunctionN for N > 0 + /** Is an ghost function class. + * - GhostFunctionN for N > 0 + * - GhostImplicitFunctionN for N > 0 */ - def isUnusedFunctionClass(cls: Symbol) = scalaClassName(cls).isUnusedFunction + def isGhostFunctionClass(cls: Symbol) = scalaClassName(cls).isGhostFunction /** Is a class that will be erased to FunctionXXL * - FunctionN for N >= 22 @@ -915,13 +915,13 @@ class Definitions { * - FunctionN for 22 > N >= 0 remains as FunctionN * - ImplicitFunctionN for N > 22 becomes FunctionXXL * - ImplicitFunctionN for 22 > N >= 0 becomes FunctionN - * - UnusedFunctionN becomes Function0 - * - ImplicitUnusedFunctionN becomes Function0 + * - GhostFunctionN becomes Function0 + * - ImplicitGhostFunctionN becomes Function0 * - anything else becomes a NoSymbol */ def erasedFunctionClass(cls: Symbol): Symbol = { val arity = scalaClassName(cls).functionArity - if (cls.name.isUnusedFunction) FunctionClass(0) + if (cls.name.isGhostFunction) FunctionClass(0) else if (arity > 22) FunctionXXLClass else if (arity >= 0) FunctionClass(arity) else NoSymbol @@ -932,13 +932,13 @@ class Definitions { * - FunctionN for 22 > N >= 0 remains as FunctionN * - ImplicitFunctionN for N > 22 becomes FunctionXXL * - ImplicitFunctionN for 22 > N >= 0 becomes FunctionN - * - UnusedFunctionN becomes Function0 - * - ImplicitUnusedFunctionN becomes Function0 + * - GhostFunctionN becomes Function0 + * - ImplicitGhostFunctionN becomes Function0 * - anything else becomes a NoType */ def erasedFunctionType(cls: Symbol): Type = { val arity = scalaClassName(cls).functionArity - if (cls.name.isUnusedFunction) FunctionType(0) + if (cls.name.isGhostFunction) FunctionType(0) else if (arity > 22) FunctionXXLType else if (arity >= 0) FunctionType(arity) else NoType @@ -1008,7 +1008,7 @@ class Definitions { def isNonDepFunctionType(tp: Type)(implicit ctx: Context) = { val arity = functionArity(tp) val sym = tp.dealias.typeSymbol - arity >= 0 && isFunctionClass(sym) && tp.isRef(FunctionType(arity, sym.name.isImplicitFunction, sym.name.isUnusedFunction).typeSymbol) + arity >= 0 && isFunctionClass(sym) && tp.isRef(FunctionType(arity, sym.name.isImplicitFunction, sym.name.isGhostFunction).typeSymbol) } /** Is `tp` a representation of a (possibly depenent) function type or an alias of such? */ @@ -1074,8 +1074,8 @@ class Definitions { def isImplicitFunctionType(tp: Type)(implicit ctx: Context): Boolean = asImplicitFunctionType(tp).exists - def isUnusedFunctionType(tp: Type)(implicit ctx: Context) = - isFunctionType(tp) && tp.dealias.typeSymbol.name.isUnusedFunction + def isGhostFunctionType(tp: Type)(implicit ctx: Context) = + isFunctionType(tp) && tp.dealias.typeSymbol.name.isGhostFunction // ----- primitive value class machinery ------------------------------------------ diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index fd02bdac4eb4..9a7fa0b5541c 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -367,8 +367,8 @@ object Flags { /** Symbol is a Java enum */ final val Enum = commonFlag(40, "") - /** Labeled with `unused` modifier (unused value) */ - final val Unused = termFlag(42, "unused") + /** Labeled with `ghost` modifier (ghost value) */ + final val Ghost = termFlag(42, "ghost") // Flags following this one are not pickled @@ -441,7 +441,7 @@ object Flags { /** Flags representing source modifiers */ final val SourceModifierFlags = commonFlags(Private, Protected, Abstract, Final, Inline, - Sealed, Case, Implicit, Override, AbsOverride, Lazy, JavaStatic, Unused) + Sealed, Case, Implicit, Override, AbsOverride, Lazy, JavaStatic, Ghost) /** Flags representing modifiers that can appear in trees */ final val ModifierFlags = @@ -515,7 +515,7 @@ object Flags { /** Flags that can apply to a module val */ final val RetainedModuleValFlags: FlagSet = RetainedModuleValAndClassFlags | Override | Final | Method | Implicit | Lazy | - Accessor | AbsOverride | Stable | Captured | Synchronized | Inline | Unused + Accessor | AbsOverride | Stable | Captured | Synchronized | Inline | Ghost /** Flags that can apply to a module class */ final val RetainedModuleClassFlags: FlagSet = RetainedModuleValAndClassFlags | ImplClass | Enum diff --git a/compiler/src/dotty/tools/dotc/core/NameOps.scala b/compiler/src/dotty/tools/dotc/core/NameOps.scala index def42bca9c88..df2f2a0c43e8 100644 --- a/compiler/src/dotty/tools/dotc/core/NameOps.scala +++ b/compiler/src/dotty/tools/dotc/core/NameOps.scala @@ -176,51 +176,51 @@ object NameOps { functionArityFor(str.Function) max { val n = functionArityFor(str.ImplicitFunction) max - functionArityFor(str.UnusedFunction) max - functionArityFor(str.UnusedImplicitFunction) + functionArityFor(str.GhostFunction) max + functionArityFor(str.GhostImplicitFunction) if (n == 0) -1 else n } /** Is a function name * - FunctionN for N >= 0 * - ImplicitFunctionN for N >= 1 - * - UnusedFunctionN for N >= 1 - * - UnusedImplicitFunctionN for N >= 1 + * - GhostFunctionN for N >= 1 + * - GhostImplicitFunctionN for N >= 1 * - false otherwise */ def isFunction: Boolean = functionArity >= 0 /** Is a implicit function name * - ImplicitFunctionN for N >= 1 - * - UnusedImplicitFunctionN for N >= 1 + * - GhostImplicitFunctionN for N >= 1 * - false otherwise */ def isImplicitFunction: Boolean = { functionArityFor(str.ImplicitFunction) >= 1 || - functionArityFor(str.UnusedImplicitFunction) >= 1 + functionArityFor(str.GhostImplicitFunction) >= 1 } /** Is a implicit function name - * - UnusedFunctionN for N >= 1 - * - UnusedImplicitFunctionN for N >= 1 + * - GhostFunctionN for N >= 1 + * - GhostImplicitFunctionN for N >= 1 * - false otherwise */ - def isUnusedFunction: Boolean = { - functionArityFor(str.UnusedFunction) >= 1 || - functionArityFor(str.UnusedImplicitFunction) >= 1 + def isGhostFunction: Boolean = { + functionArityFor(str.GhostFunction) >= 1 || + functionArityFor(str.GhostImplicitFunction) >= 1 } /** Is a synthetic function name * - FunctionN for N > 22 * - ImplicitFunctionN for N >= 1 - * - UnusedFunctionN for N >= 1 - * - UnusedImplicitFunctionN for N >= 1 + * - GhostFunctionN for N >= 1 + * - GhostImplicitFunctionN for N >= 1 * - false otherwise */ def isSyntheticFunction: Boolean = { functionArityFor(str.Function) > MaxImplementedFunctionArity || functionArityFor(str.ImplicitFunction) >= 1 || - isUnusedFunction + isGhostFunction } /** Parsed function arity for function with some specific prefix */ diff --git a/compiler/src/dotty/tools/dotc/core/StdNames.scala b/compiler/src/dotty/tools/dotc/core/StdNames.scala index c0c90b45b487..6a4f5d22a15e 100644 --- a/compiler/src/dotty/tools/dotc/core/StdNames.scala +++ b/compiler/src/dotty/tools/dotc/core/StdNames.scala @@ -36,9 +36,9 @@ object StdNames { final val MODULE_INSTANCE_FIELD = "MODULE$" final val Function = "Function" - final val UnusedFunction = "UnusedFunction" + final val GhostFunction = "GhostFunction" final val ImplicitFunction = "ImplicitFunction" - final val UnusedImplicitFunction = "UnusedImplicitFunction" + final val GhostImplicitFunction = "GhostImplicitFunction" final val AbstractFunction = "AbstractFunction" final val Tuple = "Tuple" final val Product = "Product" diff --git a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala index b0971f601fa1..75a2db3186f7 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala @@ -399,7 +399,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean case tp: MethodType => def paramErasure(tpToErase: Type) = erasureFn(tp.isJavaMethod, semiEraseVCs, isConstructor, wildcardOK)(tpToErase) - val (names, formals0) = if (tp.isUnusedMethod) (Nil, Nil) else (tp.paramNames, tp.paramInfos) + val (names, formals0) = if (tp.isGhostMethod) (Nil, Nil) else (tp.paramNames, tp.paramInfos) val formals = formals0.mapConserve(paramErasure) eraseResult(tp.resultType) match { case rt: MethodType => diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 5526e288fada..5260c920c737 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -267,7 +267,7 @@ object Types { def isImplicitMethod: Boolean = false /** Is this a MethodType for which the parameters will not be used */ - def isUnusedMethod: Boolean = false + def isGhostMethod: Boolean = false // ----- Higher-order combinators ----------------------------------- @@ -1317,10 +1317,10 @@ object Types { case mt: MethodType if !mt.isParamDependent => val formals1 = if (dropLast == 0) mt.paramInfos else mt.paramInfos dropRight dropLast val isImplicit = mt.isImplicitMethod && !ctx.erasedTypes - val isUnused = mt.isUnusedMethod && !ctx.erasedTypes + val isGhost = mt.isGhostMethod && !ctx.erasedTypes val funType = defn.FunctionOf( formals1 mapConserve (_.underlyingIfRepeated(mt.isJavaMethod)), - mt.nonDependentResultApprox, isImplicit, isUnused) + mt.nonDependentResultApprox, isImplicit, isGhost) if (mt.isResultDependent) RefinedType(funType, nme.apply, mt) else funType } @@ -2839,15 +2839,15 @@ object Types { def companion: MethodTypeCompanion final override def isJavaMethod: Boolean = companion eq JavaMethodType - final override def isImplicitMethod: Boolean = companion.eq(ImplicitMethodType) || companion.eq(UnusedImplicitMethodType) - final override def isUnusedMethod: Boolean = companion.eq(UnusedMethodType) || companion.eq(UnusedImplicitMethodType) + final override def isImplicitMethod: Boolean = companion.eq(ImplicitMethodType) || companion.eq(GhostImplicitMethodType) + final override def isGhostMethod: Boolean = companion.eq(GhostMethodType) || companion.eq(GhostImplicitMethodType) val paramInfos = paramInfosExp(this) val resType = resultTypeExp(this) assert(resType.exists) def computeSignature(implicit ctx: Context): Signature = { - val params = if (isUnusedMethod) Nil else paramInfos + val params = if (isGhostMethod) Nil else paramInfos resultSignature.prepend(params, isJavaMethod) } @@ -2937,22 +2937,22 @@ object Types { } object MethodType extends MethodTypeCompanion { - def maker(isJava: Boolean = false, isImplicit: Boolean = false, isUnused: Boolean = false): MethodTypeCompanion = { + def maker(isJava: Boolean = false, isImplicit: Boolean = false, isGhost: Boolean = false): MethodTypeCompanion = { if (isJava) { assert(!isImplicit) - assert(!isUnused) + assert(!isGhost) JavaMethodType } - else if (isImplicit && isUnused) UnusedImplicitMethodType + else if (isImplicit && isGhost) GhostImplicitMethodType else if (isImplicit) ImplicitMethodType - else if (isUnused) UnusedMethodType + else if (isGhost) GhostMethodType else MethodType } } object JavaMethodType extends MethodTypeCompanion object ImplicitMethodType extends MethodTypeCompanion - object UnusedMethodType extends MethodTypeCompanion - object UnusedImplicitMethodType extends MethodTypeCompanion + object GhostMethodType extends MethodTypeCompanion + object GhostImplicitMethodType extends MethodTypeCompanion /** A ternary extractor for MethodType */ object MethodTpe { diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 97356c7bc18d..cfad7550297b 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -732,7 +732,7 @@ object Parsers { def functionRest(params: List[Tree]): Tree = atPos(start, accept(ARROW)) { val t = typ() - if (imods.is(Implicit) || imods.is(Unused)) new NonEmptyFunction(params, t, imods) + if (imods.is(Implicit) || imods.is(Ghost)) new NonEmptyFunction(params, t, imods) else Function(params, t) } def funArgTypesRest(first: Tree, following: () => Tree) = { @@ -1068,7 +1068,7 @@ object Parsers { def expr(location: Location.Value): Tree = { val start = in.offset - if (in.token == IMPLICIT || in.token == UNUSED) { + if (in.token == IMPLICIT || in.token == GHOST) { val imods = modifiers(funArgMods) implicitClosure(start, location, imods) } else { @@ -1642,7 +1642,7 @@ object Parsers { case ABSTRACT => Mod.Abstract() case FINAL => Mod.Final() case IMPLICIT => Mod.Implicit() - case UNUSED => Mod.Unused() + case GHOST => Mod.Ghost() case INLINE => Mod.Inline() case LAZY => Mod.Lazy() case OVERRIDE => Mod.Override() @@ -1731,9 +1731,9 @@ object Parsers { normalize(loop(start)) } - /** FunArgMods ::= { `implicit` | `unused` } + /** FunArgMods ::= { `implicit` | `ghost` } */ - def funArgMods = BitSet(IMPLICIT, UNUSED) + def funArgMods = BitSet(IMPLICIT, GHOST) /** Wrap annotation or constructor in New(...). */ def wrapNew(tpt: Tree) = Select(New(tpt), nme.CONSTRUCTOR) @@ -1822,11 +1822,11 @@ object Parsers { if (in.token == LBRACKET) typeParamClause(ownerKind) else Nil /** ClsParamClauses ::= {ClsParamClause} [[nl] `(' [FunArgMods] ClsParams `)'] - * ClsParamClause ::= [nl] `(' [`unused'] [ClsParams] ')' + * ClsParamClause ::= [nl] `(' [`ghost'] [ClsParams] ')' * ClsParams ::= ClsParam {`' ClsParam} * ClsParam ::= {Annotation} [{Modifier} (`val' | `var') | `inline'] Param * DefParamClauses ::= {DefParamClause} [[nl] `(' [FunArgMods] DefParams `)'] - * DefParamClause ::= [nl] `(' [`unused'] [DefParams] ')' + * DefParamClause ::= [nl] `(' [`ghost'] [DefParams] ')' * DefParams ::= DefParam {`,' DefParam} * DefParam ::= {Annotation} [`inline'] Param * Param ::= id `:' ParamType [`=' Expr] @@ -1884,8 +1884,8 @@ object Parsers { implicitOffset = in.offset imods = addMod(imods, atPos(accept(IMPLICIT)) { Mod.Implicit() }) funArgMods() - } else if (in.token == UNUSED) { - imods = addMod(imods, atPos(accept(UNUSED)) { Mod.Unused() }) + } else if (in.token == GHOST) { + imods = addMod(imods, atPos(accept(GHOST)) { Mod.Ghost() }) funArgMods() } } @@ -2466,7 +2466,7 @@ object Parsers { else if (isExprIntro) stats += expr(Location.InBlock) else if (isDefIntro(localModifierTokens)) - if (in.token == IMPLICIT || in.token == UNUSED) { + if (in.token == IMPLICIT || in.token == GHOST) { val start = in.offset var imods = modifiers(funArgMods) if (isBindingIntro) stats += implicitClosure(start, Location.InBlock, imods) diff --git a/compiler/src/dotty/tools/dotc/parsing/Tokens.scala b/compiler/src/dotty/tools/dotc/parsing/Tokens.scala index 673c2d29cca2..ac8733151c13 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Tokens.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Tokens.scala @@ -177,7 +177,7 @@ object Tokens extends TokensCommon { final val FORSOME = 61; enter(FORSOME, "forSome") // TODO: deprecate final val INLINE = 62; enter(INLINE, "inline") final val ENUM = 63; enter(ENUM, "enum") - final val UNUSED = 64; enter(UNUSED, "unused") + final val GHOST = 64; enter(GHOST, "ghost") /** special symbols */ final val NEWLINE = 78; enter(NEWLINE, "end of statement", "new line") @@ -198,7 +198,7 @@ object Tokens extends TokensCommon { /** XML mode */ final val XMLSTART = 96; enter(XMLSTART, "$XMLSTART$<") // TODO: deprecate - final val alphaKeywords = tokenRange(IF, UNUSED) + final val alphaKeywords = tokenRange(IF, GHOST) final val symbolicKeywords = tokenRange(USCORE, VIEWBOUND) final val symbolicTokens = tokenRange(COMMA, VIEWBOUND) final val keywords = alphaKeywords | symbolicKeywords @@ -226,7 +226,7 @@ object Tokens extends TokensCommon { final val defIntroTokens = templateIntroTokens | dclIntroTokens final val localModifierTokens = BitSet( - ABSTRACT, FINAL, SEALED, IMPLICIT, INLINE, LAZY, UNUSED) + ABSTRACT, FINAL, SEALED, IMPLICIT, INLINE, LAZY, GHOST) final val accessModifierTokens = BitSet( PRIVATE, PROTECTED) diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index e3bb7ce3ce2b..96f5b446a90e 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -132,14 +132,14 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { def toTextTuple(args: List[Type]): Text = "(" ~ Text(args.map(argText), ", ") ~ ")" - def toTextFunction(args: List[Type], isImplicit: Boolean, isUnused: Boolean): Text = + def toTextFunction(args: List[Type], isImplicit: Boolean, isGhost: Boolean): Text = changePrec(GlobalPrec) { val argStr: Text = if (args.length == 2 && !defn.isTupleType(args.head)) atPrec(InfixPrec) { argText(args.head) } else toTextTuple(args.init) - (keywordText("unused ") provided isUnused) ~ (keywordText("implicit ") provided isImplicit) ~ argStr ~ " => " ~ argText(args.last) + (keywordText("ghost ") provided isGhost) ~ (keywordText("implicit ") provided isImplicit) ~ argStr ~ " => " ~ argText(args.last) } def toTextDependentFunction(appType: MethodType): Text = { @@ -174,7 +174,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { case AppliedType(tycon, args) => val cls = tycon.typeSymbol if (tycon.isRepeatedParam) return toTextLocal(args.head) ~ "*" - if (defn.isFunctionClass(cls)) return toTextFunction(args, cls.name.isImplicitFunction, cls.name.isUnusedFunction) + if (defn.isFunctionClass(cls)) return toTextFunction(args, cls.name.isImplicitFunction, cls.name.isGhostFunction) if (defn.isTupleClass(cls)) return toTextTuple(args) if (isInfixType(tp)) return toTextInfixType(tycon, args) case EtaExpansion(tycon) => @@ -745,7 +745,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { else if (sym.isClass && flags.is(Case)) "case class" else if (flags is Module) "object" else if (sym.isTerm && !flags.is(Param) && flags.is(Implicit)) "implicit val" - else if (sym.isTerm && !flags.is(Param) && flags.is(Unused)) "unused val" + else if (sym.isTerm && !flags.is(Param) && flags.is(Ghost)) "ghost val" else super.keyString(sym) } diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 2ccfaec3b0f0..00f5f76874d3 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -1713,10 +1713,10 @@ object messages { } } - case class FunctionTypeNeedsNonEmptyParameterList(isImplicit: Boolean = true, isUnused: Boolean = true)(implicit ctx: Context) + case class FunctionTypeNeedsNonEmptyParameterList(isImplicit: Boolean = true, isGhost: Boolean = true)(implicit ctx: Context) extends Message(FunctionTypeNeedsNonEmptyParameterListID) { val kind = "Syntax" - val mods = ((isImplicit, "implicit") :: (isUnused, "unused") :: Nil).filter(_._1).mkString(" ") + val mods = ((isImplicit, "implicit") :: (isGhost, "ghost") :: Nil).filter(_._1).mkString(" ") val msg = mods + " function type needs non-empty parameter list" val explanation = { val code1 = s"type Transactional[T] = $mods Transaction => T" diff --git a/compiler/src/dotty/tools/dotc/transform/Erasure.scala b/compiler/src/dotty/tools/dotc/transform/Erasure.scala index 0690b6cdfe68..bd6d0c389585 100644 --- a/compiler/src/dotty/tools/dotc/transform/Erasure.scala +++ b/compiler/src/dotty/tools/dotc/transform/Erasure.scala @@ -452,7 +452,7 @@ object Erasure { } private def protoArgs(pt: Type, methTp: Type): List[untpd.Tree] = (pt, methTp) match { - case (pt: FunProto, methTp: MethodType) if methTp.isUnusedMethod => + case (pt: FunProto, methTp: MethodType) if methTp.isGhostMethod => protoArgs(pt.resType, methTp.resType) case (pt: FunProto, methTp: MethodType) => pt.args ++ protoArgs(pt.resType, methTp.resType) @@ -489,7 +489,7 @@ object Erasure { fun1.tpe.widen match { case mt: MethodType => val outers = outer.args(fun.asInstanceOf[tpd.Tree]) // can't use fun1 here because its type is already erased - val ownArgs = if (mt.paramNames.nonEmpty && !mt.isUnusedMethod) args else Nil + val ownArgs = if (mt.paramNames.nonEmpty && !mt.isGhostMethod) args else Nil var args0 = outers ::: ownArgs ::: protoArgs(pt, tree.typeOpt) if (args0.length > MaxImplementedFunctionArity && mt.paramInfos.length == 1) { @@ -559,7 +559,7 @@ object Erasure { vparamss1 = (tpd.ValDef(bunchedParam) :: Nil) :: Nil rhs1 = untpd.Block(paramDefs, rhs1) } - vparamss1 = vparamss1.mapConserve(_.filterConserve(!_.symbol.is(Flags.Unused))) + vparamss1 = vparamss1.mapConserve(_.filterConserve(!_.symbol.is(Flags.Ghost))) val ddef1 = untpd.cpy.DefDef(ddef)( tparams = Nil, vparamss = vparamss1, diff --git a/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala b/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala index 1b4993aba789..0e76cf7ab8fd 100644 --- a/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala +++ b/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala @@ -237,9 +237,9 @@ object GenericSignatures { methodResultSig(restpe) case mtpe: MethodType => - // unused method parameters do not make it to the bytecode. + // ghost method parameters do not make it to the bytecode. def effectiveParamInfoss(t: Type)(implicit ctx: Context): List[List[Type]] = t match { - case t: MethodType if t.isUnusedMethod => effectiveParamInfoss(t.resType) + case t: MethodType if t.isGhostMethod => effectiveParamInfoss(t.resType) case t: MethodType => t.paramInfos :: effectiveParamInfoss(t.resType) case _ => Nil } diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala index d4e194fc3469..6ea39a10a9d9 100644 --- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala @@ -178,14 +178,14 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase override def transform(tree: Tree)(implicit ctx: Context): Tree = try tree match { case tree: Ident if !tree.isType => - checkNotUnused(tree) + checkNotGhost(tree) handleMeta(tree.symbol) tree.tpe match { case tpe: ThisType => This(tpe.cls).withPos(tree.pos) case _ => tree } case tree @ Select(qual, name) => - checkNotUnused(tree) + checkNotGhost(tree) handleMeta(tree.symbol) if (name.isTypeName) { Checking.checkRealizable(qual.tpe, qual.pos.focus) @@ -311,11 +311,11 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase throw ex } - private def checkNotUnused(tree: RefTree)(implicit ctx: Context): Unit = { - if (tree.symbol.is(Unused) && !ctx.mode.is(Mode.Type)) { + private def checkNotGhost(tree: RefTree)(implicit ctx: Context): Unit = { + if (tree.symbol.is(Ghost) && !ctx.mode.is(Mode.Type)) { val msg = - if (tree.symbol.is(CaseAccessor)) "First parameter list of case class may not contain `unused` parameters" - else i"${tree.symbol} is declared as unused, but is in fact used" + if (tree.symbol.is(CaseAccessor)) "First parameter list of case class may not contain `ghost` parameters" + else i"${tree.symbol} is declared as ghost, but is in fact used" ctx.error(msg, tree.pos) } } diff --git a/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala b/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala index 9832b6ef63f5..ce03bb51b1bb 100644 --- a/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala +++ b/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala @@ -59,7 +59,7 @@ class SyntheticMethods(thisPhase: DenotTransformer) { def syntheticMethods(clazz: ClassSymbol)(implicit ctx: Context): List[Tree] = { val clazzType = clazz.appliedRef lazy val accessors = - if (isDerivedValueClass(clazz)) clazz.paramAccessors.take(1) // Tail parameters can only be `unused` + if (isDerivedValueClass(clazz)) clazz.paramAccessors.take(1) // Tail parameters can only be `ghost` else clazz.caseAccessors val symbolsToSynthesize: List[Symbol] = diff --git a/compiler/src/dotty/tools/dotc/transform/UnusedDecls.scala b/compiler/src/dotty/tools/dotc/transform/UnusedDecls.scala index 1a9eaf0019a2..06e84f0c6dd3 100644 --- a/compiler/src/dotty/tools/dotc/transform/UnusedDecls.scala +++ b/compiler/src/dotty/tools/dotc/transform/UnusedDecls.scala @@ -9,14 +9,14 @@ import dotty.tools.dotc.core.Phases.Phase import dotty.tools.dotc.core.Types._ import dotty.tools.dotc.transform.MegaPhase.MiniPhase -/** This phase removes unused declarations of val`s (except for parameters). +/** This phase removes ghost declarations of val`s (except for parameters). * - * `unused val x = ...` are removed + * `ghost val x = ...` are removed */ -class UnusedDecls extends MiniPhase with InfoTransformer { +class GhostDecls extends MiniPhase with InfoTransformer { import tpd._ - override def phaseName: String = "unusedDecls" + override def phaseName: String = "ghostDecls" override def runsAfterGroupsOf: Set[Class[_ <: Phase]] = Set( classOf[PatternMatcher] // Make sure pattern match errors are emitted @@ -24,7 +24,7 @@ class UnusedDecls extends MiniPhase with InfoTransformer { /** Check what the phase achieves, to be called at any point after it is finished. */ override def checkPostCondition(tree: Tree)(implicit ctx: Context): Unit = tree match { - case tree: ValOrDefDef if !tree.symbol.is(Param) => assert(!tree.symbol.is(Unused, butNot = Param)) + case tree: ValOrDefDef if !tree.symbol.is(Param) => assert(!tree.symbol.is(Ghost, butNot = Param)) case _ => } @@ -35,15 +35,15 @@ class UnusedDecls extends MiniPhase with InfoTransformer { override def transformValDef(tree: ValDef)(implicit ctx: Context): Tree = transformValOrDefDef(tree) private def transformValOrDefDef(tree: ValOrDefDef)(implicit ctx: Context): Tree = - if (tree.symbol.is(Unused, butNot = Param)) EmptyTree else tree + if (tree.symbol.is(Ghost, butNot = Param)) EmptyTree else tree /* Info transform */ override def transformInfo(tp: Type, sym: Symbol)(implicit ctx: Context): Type = tp match { case tp: ClassInfo => - if (tp.classSymbol.is(JavaDefined) || !tp.decls.iterator.exists(_.is(Unused))) tp - else tp.derivedClassInfo(decls = tp.decls.filteredScope(!_.is(Unused))) + if (tp.classSymbol.is(JavaDefined) || !tp.decls.iterator.exists(_.is(Ghost))) tp + else tp.derivedClassInfo(decls = tp.decls.filteredScope(!_.is(Ghost))) case _ => tp } } diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 313c91e1d953..1c8f2c371e93 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -780,8 +780,8 @@ trait Applications extends Compatibility { self: Typer with Dynamic => case _ => } app match { - case Apply(fun, args) if fun.tpe.widen.isUnusedMethod => - tpd.cpy.Apply(app)(fun = fun, args = args.map(arg => normalizeUnusedExpr(arg, "This argument is given to an unused parameter. "))) + case Apply(fun, args) if fun.tpe.widen.isGhostMethod => + tpd.cpy.Apply(app)(fun = fun, args = args.map(arg => normalizeGhostExpr(arg, "This argument is given to an ghost parameter. "))) case _ => app } } @@ -1446,7 +1446,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic => val formalsForArg: List[Type] = altFormals.map(_.head) def argTypesOfFormal(formal: Type): List[Type] = formal match { - case defn.FunctionOf(args, result, isImplicit, isUnused) => args + case defn.FunctionOf(args, result, isImplicit, isGhost) => args case defn.PartialFunctionOf(arg, result) => arg :: Nil case _ => Nil } @@ -1546,17 +1546,17 @@ trait Applications extends Compatibility { self: Typer with Dynamic => /** Transforms the tree into a its default tree. * Performed to shrink the tree that is known to be erased later. */ - protected def normalizeUnusedExpr(tree: Tree, msg: String)(implicit ctx: Context): Tree = { + protected def normalizeGhostExpr(tree: Tree, msg: String)(implicit ctx: Context): Tree = { if (!isPureExpr(tree)) ctx.warning(msg + "This expression will not be evaluated.", tree.pos) defaultValue(tree.tpe) } - /** Transforms the rhs tree into a its default tree if it is in an `unused` val/def. + /** Transforms the rhs tree into a its default tree if it is in an `ghost` val/def. * Performed to shrink the tree that is known to be erased later. */ - protected def normalizeUnusedRhs(rhs: Tree, sym: Symbol)(implicit ctx: Context) = { - if (sym.is(Unused) && rhs.tpe.exists) normalizeUnusedExpr(rhs, "Expression is on the RHS of an `unused` " + sym.showKind + ". ") + protected def normalizeGhostRhs(rhs: Tree, sym: Symbol)(implicit ctx: Context) = { + if (sym.is(Ghost) && rhs.tpe.exists) normalizeGhostExpr(rhs, "Expression is on the RHS of an `ghost` " + sym.showKind + ". ") else rhs } diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 9c095dfbea50..828da5d007da 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -384,8 +384,8 @@ object Checking { fail(CannotHaveSameNameAs(sym, cls, CannotHaveSameNameAs.CannotBeOverridden)) sym.setFlag(Private) // break the overriding relationship by making sym Private } - if (sym.is(Unused)) - checkApplicable(Unused, !sym.is(MutableOrLazy)) + if (sym.is(Ghost)) + checkApplicable(Ghost, !sym.is(MutableOrLazy)) } /** Check the type signature of the symbol `M` defined by `tree` does not refer @@ -503,11 +503,11 @@ object Checking { case param :: params => if (param.is(Mutable)) ctx.error(ValueClassParameterMayNotBeAVar(clazz, param), param.pos) - if (param.is(Unused)) - ctx.error("value class first parameter cannot be `unused`", param.pos) + if (param.is(Ghost)) + ctx.error("value class first parameter cannot be `ghost`", param.pos) else { - for (p <- params if !p.is(Unused)) - ctx.error("value class can only have one non `unused` parameter", p.pos) + for (p <- params if !p.is(Ghost)) + ctx.error("value class can only have one non `ghost` parameter", p.pos) } case Nil => ctx.error(ValueClassNeedsOneValParam(clazz), clazz.pos) diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 06c26cc962db..41f6230889eb 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -134,10 +134,10 @@ trait NamerContextOps { this: Context => def methodType(typeParams: List[Symbol], valueParamss: List[List[Symbol]], resultType: Type, isJava: Boolean = false)(implicit ctx: Context): Type = { val monotpe = (valueParamss :\ resultType) { (params, resultType) => - val (isImplicit, isUnused) = + val (isImplicit, isGhost) = if (params.isEmpty) (false, false) - else (params.head is Implicit, params.head is Unused) - val make = MethodType.maker(isJava, isImplicit, isUnused) + else (params.head is Implicit, params.head is Ghost) + val make = MethodType.maker(isJava, isImplicit, isGhost) if (isJava) for (param <- params) if (param.info.isDirectRef(defn.ObjectClass)) param.info = defn.AnyType diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index cda643fee469..9387a89311e7 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -759,16 +759,16 @@ class Typer extends Namer def typedFunctionType(tree: untpd.Function, pt: Type)(implicit ctx: Context) = { val untpd.Function(args, body) = tree - val (isImplicit, isUnused) = tree match { + val (isImplicit, isGhost) = tree match { case tree: untpd.NonEmptyFunction => - if (args.nonEmpty) (tree.mods.is(Implicit), tree.mods.is(Unused)) + if (args.nonEmpty) (tree.mods.is(Implicit), tree.mods.is(Ghost)) else { ctx.error(FunctionTypeNeedsNonEmptyParameterList(), tree.pos) (false, false) } case _ => (false, false) } - val funCls = defn.FunctionClass(args.length, isImplicit, isUnused) + val funCls = defn.FunctionClass(args.length, isImplicit, isGhost) /** Typechecks dependent function type with given parameters `params` */ def typedDependent(params: List[ValDef])(implicit ctx: Context): Tree = { @@ -1344,7 +1344,7 @@ class Typer extends Namer val tpt1 = checkSimpleKinded(typedType(tpt)) val rhs1 = vdef.rhs match { case rhs @ Ident(nme.WILDCARD) => rhs withType tpt1.tpe - case rhs => normalizeUnusedRhs(typedExpr(rhs, tpt1.tpe), sym) + case rhs => normalizeGhostRhs(typedExpr(rhs, tpt1.tpe), sym) } val vdef1 = assignType(cpy.ValDef(vdef)(name, tpt1, rhs1), sym) if (sym.is(Inline, butNot = DeferredOrTermParamOrAccessor)) @@ -1402,7 +1402,7 @@ class Typer extends Namer (tparams1, sym.owner.typeParams).zipped.foreach ((tdef, tparam) => rhsCtx.gadt.setBounds(tdef.symbol, TypeAlias(tparam.typeRef))) } - val rhs1 = normalizeUnusedRhs(typedExpr(ddef.rhs, tpt1.tpe)(rhsCtx), sym) + val rhs1 = normalizeGhostRhs(typedExpr(ddef.rhs, tpt1.tpe)(rhsCtx), sym) // Overwrite inline body to make sure it is not evaluated twice if (sym.isInlineMethod) Inliner.registerInlineInfo(sym, _ => rhs1) @@ -2139,8 +2139,8 @@ class Typer extends Namer arg :: implicitArgs(formals1) } } - def eraseUnusedArgs(args: List[Tree]): List[Tree] = { - if (!wtp.isUnusedMethod) args + def eraseGhostArgs(args: List[Tree]): List[Tree] = { + if (!wtp.isGhostMethod) args else args.map { arg => arg.tpe match { case tpe if tpe.isStable => arg @@ -2149,7 +2149,7 @@ class Typer extends Namer } } } - val args = eraseUnusedArgs(implicitArgs(wtp.paramInfos)) + val args = eraseGhostArgs(implicitArgs(wtp.paramInfos)) def propagatedFailure(args: List[Tree]): Type = args match { diff --git a/compiler/test/dotty/tools/dotc/FromTastyTests.scala b/compiler/test/dotty/tools/dotc/FromTastyTests.scala index 40d89815c17e..95ee779266d2 100644 --- a/compiler/test/dotty/tools/dotc/FromTastyTests.scala +++ b/compiler/test/dotty/tools/dotc/FromTastyTests.scala @@ -115,12 +115,12 @@ class FromTastyTests extends ParallelTesting { "phantom-poly-4.scala", // Issue with JFunction1$mcI$sp/T - "unused-15.scala", - "unused-17.scala", - "unused-20.scala", - "unused-21.scala", - "unused-23.scala", - "unused-value-class.scala", + "ghost-15.scala", + "ghost-17.scala", + "ghost-20.scala", + "ghost-21.scala", + "ghost-23.scala", + "ghost-value-class.scala", ) ) step1.checkCompile() // Compile all files to generate the class files with tasty diff --git a/docs/_includes/features.html b/docs/_includes/features.html index c24856e5c87e..34c64d59ef36 100644 --- a/docs/_includes/features.html +++ b/docs/_includes/features.html @@ -41,7 +41,7 @@

So, features?

Implemented - Unused Parameters + Ghost Terms In progress diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index 5be736e3d077..c7b61fb3751d 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -120,7 +120,7 @@ ClassQualifier ::= ‘[’ id ‘]’ Type ::= [FunArgMods] FunArgTypes ‘=>’ Type Function(ts, t) | HkTypeParamClause ‘=>’ Type TypeLambda(ps, t) | InfixType -FunArgMods ::= { `implicit` | `unused` } +FunArgMods ::= { `implicit` | `ghost` } FunArgTypes ::= InfixType | ‘(’ [ FunArgType {‘,’ FunArgType } ] ‘)’ | '(' TypedFunParam {',' TypedFunParam } ')' diff --git a/docs/docs/reference/unused-parameters.md b/docs/docs/reference/ghost-terms.md similarity index 53% rename from docs/docs/reference/unused-parameters.md rename to docs/docs/reference/ghost-terms.md index 324628758e9f..0307fa97e6ac 100644 --- a/docs/docs/reference/unused-parameters.md +++ b/docs/docs/reference/ghost-terms.md @@ -1,9 +1,9 @@ --- layout: doc-page -title: "Unused Parameters" +title: "Ghost Terms" --- -Why unused parameters? +Why ghost terms? ---------------------- The following examples shows an implementation of a simple state machine which can be in a state `On` or `Off`. The machine can change state from `Off` to `On` with `turnedOn` only if it is currently `Off`. This last constraint is @@ -33,54 +33,54 @@ m.turnedOn.turnedOn // ERROR ``` Note that in the code above the actual implicit arguments for `IsOff` are never used at runtime; they serve only to establish the right constraints at compile time. -As these parameters are never used at runtime there is not real need to have them around, but they still need to be +As these terms are never used at runtime there is not real need to have them around, but they still need to be present in some form in the generated code to be able to do separate compilation and retain binary compatiblity. -How to define unused parameter? +How to define ghost terms? ------------------------------- -Parameters of methods and functions can be declared as unused, placing `unused` at the start of the parameter list (like `implicit`). +Parameters of methods and functions can be declared as ghost, placing `ghost` at the start of the parameter list (like `implicit`). ```scala -def methodWithUnusedEv(unused ev: Ev): Int = 42 +def methodWithGhostEv(ghost ev: Ev): Int = 42 -val lambdaWithUnusedEv: unused Ev => Int = - unused (ev: Ev) => 42 +val lambdaWithGhostEv: ghost Ev => Int = + ghost (ev: Ev) => 42 ``` -`unused` parameters will not be usable for computations, though they can be used as arguments to other `unused` parameters. +`ghost` parameters will not be usable for computations, though they can be used as arguments to other `ghost` parameters. ```scala -def methodWithUnusedInt1(unused i: Int): Int = +def methodWithGhostInt1(ghost i: Int): Int = i + 42 // ERROR: can not use i -def methodWithUnusedInt2(unused i: Int): Int = - methodWithUnusedInt1(i) // OK +def methodWithGhostInt2(ghost i: Int): Int = + methodWithGhostInt1(i) // OK ``` -Not only parameters can be marked as unused, `val` and `def` can also be marked with `unused`. These will also only be usable as arguments to `unused` parameters. +Not only parameters can be marked as ghost, `val` and `def` can also be marked with `ghost`. These will also only be usable as arguments to `ghost` parameters. ```scala -unused val unusedEvidence: Ev = ... -methodWithUnusedEv(unusedEvidence) +ghost val ghostEvidence: Ev = ... +methodWithGhostEv(ghostEvidence) ``` -What happens with unused values at runtime? +What happens with ghost values at runtime? ------------------------------------------- -As `unused` are guaranteed not to be used in computations, they can and will be erased. +As `ghost` are guaranteed not to be used in computations, they can and will be erased. ```scala -// becomes def methodWithUnusedEv(): Int at runtime -def methodWithUnusedEv(unused ev: Ev): Int = ... +// becomes def methodWithGhostEv(): Int at runtime +def methodWithGhostEv(ghost ev: Ev): Int = ... def evidence1: Ev = ... -unused def unusedEvidence2: Ev = ... // does not exist at runtime -unused val unusedEvidence3: Ev = ... // does not exist at runtime +ghost def ghostEvidence2: Ev = ... // does not exist at runtime +ghost val ghostEvidence3: Ev = ... // does not exist at runtime -// evidence1 is not evaluated and no value is passed to methodWithUnusedEv -methodWithUnusedEv(evidence1) +// evidence1 is not evaluated and no value is passed to methodWithGhostEv +methodWithGhostEv(evidence1) ``` -State machine with unused evidence example +State machine with ghost evidence example ------------------------------------------ The following example is an extended implementation of a simple state machine which can be in a state `On` or `Off`. The machine can change state from `Off` to `On` with `turnedOn` only if it is currently `Off`, @@ -90,9 +90,9 @@ For example, not allowing calling `turnedOff` on in an `Off` state as we would r that will not be found. As the implicit evidences of `turnedOn` and `turnedOff` are not used in the bodies of those functions -we can mark them as `unused`. This will remove the evidence parameters at runtime, but we would still +we can mark them as `ghost`. This will remove the evidence parameters at runtime, but we would still evaluate the `isOn` and `isOff` implicits that where found as arguments. -As `isOn` and `isOff` are not used except as as `unused` arguments, we can mark them as `unused`, hence +As `isOn` and `isOff` are not used except as as `ghost` arguments, we can mark them as `ghost`, hence removing the evaluation of the `isOn` and `isOff` evidences. ```scala @@ -113,13 +113,13 @@ object IsOff { class IsOn[S <: State] object IsOn { // def isOn will not exist at runtime, the compiler will only require that this evidence exists at compile time - unused implicit val isOn: IsOn[On] = new IsOn[On] + ghost implicit val isOn: IsOn[On] = new IsOn[On] } class Machine[S <: State] private { // ev will disapear from both functions - def turnedOn(implicit unused ev: IsOff[S]): Machine[On] = new Machine[On] - def turnedOff(implicit unused ev: IsOn[S]): Machine[Off] = new Machine[Off] + def turnedOn(implicit ghost ev: IsOff[S]): Machine[On] = new Machine[On] + def turnedOff(implicit ghost ev: IsOn[S]): Machine[Off] = new Machine[Off] } object Machine { @@ -147,50 +147,50 @@ object Test { Rules ----- -1) The `unused` modifier can appear: +1) The `ghost` modifier can appear: * At the start of a parameter block of a method, function or class * In a method definition * In a `val` definition (but not `lazy val` or `var`) ```scala -unused val x = ... -unused def f = ... +ghost val x = ... +ghost def f = ... -def g(unused x: Int) = ... +def g(ghost x: Int) = ... -(unused x: Int) => ... -def h(x: unused Int => Int) = ... +(ghost x: Int) => ... +def h(x: ghost Int => Int) = ... -class K(unused x: Int) { ... } +class K(ghost x: Int) { ... } ``` -2) A reference to an `unused` definition can only be used -* Inside the expression of argument to an `unused` parameter -* Inside the body of an `unused` `val` or `def` +2) A reference to an `ghost` definition can only be used +* Inside the expression of argument to an `ghost` parameter +* Inside the body of an `ghost` `val` or `def` 3) Functions -* `(unused x1: T1, x2: T2, ..., xN: TN) => y : (unused T1, T2, ..., TN) => R` -* `(implicit unused x1: T1, x2: T2, ..., xN: TN) => y : (implicit unused T1, T2, ..., TN) => R` -* `implicit unused T1 => R <:< unused T1 => R` -* `(implicit unused T1, T2) => R <:< (unused T1, T2) => R` +* `(ghost x1: T1, x2: T2, ..., xN: TN) => y : (ghost T1, T2, ..., TN) => R` +* `(implicit ghost x1: T1, x2: T2, ..., xN: TN) => y : (implicit ghost T1, T2, ..., TN) => R` +* `implicit ghost T1 => R <:< ghost T1 => R` +* `(implicit ghost T1, T2) => R <:< (ghost T1, T2) => R` * ... -Note that there is no subtype relation between `unused T => R` and `T => R` (or `implicit unused T => R` and `implicit T => R`) +Note that there is no subtype relation between `ghost T => R` and `T => R` (or `implicit ghost T => R` and `implicit T => R`) 4) Eta expansion -if `def f(unused x: T): U` then `f: (unused T) => U`. +if `def f(ghost x: T): U` then `f: (ghost T) => U`. 5) Erasure Semantics -* All `unused` paramters are removed from the function -* All argument to `unused` paramters are not passed to the function -* All `unused` definitions are removed -* All `(unused T1, T2, ..., TN) => R` and `(implicit unused T1, T2, ..., TN) => R` become `() => R` +* All `ghost` paramters are removed from the function +* All argument to `ghost` paramters are not passed to the function +* All `ghost` definitions are removed +* All `(ghost T1, T2, ..., TN) => R` and `(implicit ghost T1, T2, ..., TN) => R` become `() => R` 6) Overloading -Method with `unused` parameters will follow the normal overloading constraints after erasure. +Method with `ghost` parameters will follow the normal overloading constraints after erasure. 7) Overriding -* Member definitions overidding each other must both be `unused` or not be `unused` -* `def foo(x: T): U` cannot be overriden by `def foo(unused x: T): U` an viceversa +* Member definitions overidding each other must both be `ghost` or not be `ghost` +* `def foo(x: T): U` cannot be overriden by `def foo(ghost x: T): U` an viceversa diff --git a/docs/sidebar.yml b/docs/sidebar.yml index df73898e6730..0b602d254505 100644 --- a/docs/sidebar.yml +++ b/docs/sidebar.yml @@ -53,8 +53,8 @@ sidebar: url: docs/reference/auto-parameter-tupling.html - title: Named Type Arguments url: docs/reference/named-typeargs.html - - title: Unused Parameters - url: docs/reference/unused-parameters.html + - title: Ghost Terms + url: docs/reference/ghost-terms.html - title: Local Optimisations url: docs/reference/optimisations.html - title: Changed Features diff --git a/tests/generic-java-signatures/ghost.check b/tests/generic-java-signatures/ghost.check new file mode 100644 index 000000000000..d504bc38052e --- /dev/null +++ b/tests/generic-java-signatures/ghost.check @@ -0,0 +1,2 @@ +public int MyGhost$.f1() +U <: java.lang.Object diff --git a/tests/generic-java-signatures/unused.scala b/tests/generic-java-signatures/ghost.scala similarity index 65% rename from tests/generic-java-signatures/unused.scala rename to tests/generic-java-signatures/ghost.scala index 4ccf930a8500..3bd7ec89ecfb 100644 --- a/tests/generic-java-signatures/unused.scala +++ b/tests/generic-java-signatures/ghost.scala @@ -1,10 +1,10 @@ -object MyUnused { - def f1[U](unused a: Int): Int = 0 +object MyGhost { + def f1[U](ghost a: Int): Int = 0 } object Test { def main(args: Array[String]): Unit = { - val f1 = MyUnused.getClass.getMethods.find(_.getName.endsWith("f1")).get + val f1 = MyGhost.getClass.getMethods.find(_.getName.endsWith("f1")).get val tParams = f1.getTypeParameters println(f1.toGenericString) tParams.foreach { tp => diff --git a/tests/generic-java-signatures/unused.check b/tests/generic-java-signatures/unused.check deleted file mode 100644 index 4cf5a4d8612c..000000000000 --- a/tests/generic-java-signatures/unused.check +++ /dev/null @@ -1,2 +0,0 @@ -public int MyUnused$.f1() -U <: java.lang.Object diff --git a/tests/neg/unused-1.scala b/tests/neg/ghost-1.scala similarity index 78% rename from tests/neg/unused-1.scala rename to tests/neg/ghost-1.scala index 49ebafb7ff16..57f4ef681d1a 100644 --- a/tests/neg/unused-1.scala +++ b/tests/neg/ghost-1.scala @@ -1,6 +1,6 @@ object Test { def foo0(a: Int): Int = a - def foo1(unused a: Int): Int = { + def foo1(ghost a: Int): Int = { foo0( a // error ) @@ -17,14 +17,14 @@ object Test { ) a // error } - unused def foo2(a: Int): Int = { + ghost def foo2(a: Int): Int = { foo0(a) // OK foo1(a) // OK foo2(a) // OK foo3(a) // OK a // OK } - unused def foo3(unused a: Int): Int = { + ghost def foo3(ghost a: Int): Int = { foo0(a) // OK foo1(a) // OK foo2(a) // OK diff --git a/tests/neg/unused-2.scala b/tests/neg/ghost-2.scala similarity index 75% rename from tests/neg/unused-2.scala rename to tests/neg/ghost-2.scala index f071f5df063c..58bc4f236aa0 100644 --- a/tests/neg/unused-2.scala +++ b/tests/neg/ghost-2.scala @@ -1,6 +1,6 @@ object Test { def foo0(a: Int): Int = a - def foo1(unused a: Int): Int = { + def foo1(ghost a: Int): Int = { foo0( u // error ) @@ -14,7 +14,7 @@ object Test { u // error u // error } - unused def foo2(a: Int): Int = { + ghost def foo2(a: Int): Int = { foo0(u) // OK foo1(u) // OK foo2(u) // OK @@ -22,7 +22,7 @@ object Test { u // warn u // OK } - unused def foo3(unused a: Int): Int = { + ghost def foo3(ghost a: Int): Int = { foo0(u) // OK foo1(u) // OK foo2(u) // OK @@ -31,7 +31,7 @@ object Test { u // OK } - unused val foo4: Int = { + ghost val foo4: Int = { foo0(u) // OK foo1(u) // OK foo2(u) // OK @@ -40,5 +40,5 @@ object Test { u // OK } - unused def u: Int = 42 + ghost def u: Int = 42 } \ No newline at end of file diff --git a/tests/neg/unused-3.scala b/tests/neg/ghost-3.scala similarity index 77% rename from tests/neg/unused-3.scala rename to tests/neg/ghost-3.scala index db22487d0ae5..cb2a1435cbc9 100644 --- a/tests/neg/unused-3.scala +++ b/tests/neg/ghost-3.scala @@ -1,6 +1,6 @@ object Test { def foo0(a: Int): Int = a - def foo1(unused a: Int): Int = { + def foo1(ghost a: Int): Int = { foo0( u() // error ) @@ -14,7 +14,7 @@ object Test { u() // error u() // error } - unused def foo2(a: Int): Int = { + ghost def foo2(a: Int): Int = { foo0(u()) // OK foo1(u()) // OK foo2(u()) // OK @@ -22,7 +22,7 @@ object Test { u() // warn u() // OK } - unused def foo3(unused a: Int): Int = { + ghost def foo3(ghost a: Int): Int = { foo0(u()) // OK foo1(u()) // OK foo2(u()) // OK @@ -31,7 +31,7 @@ object Test { u() // OK } - unused val foo4: Int = { + ghost val foo4: Int = { foo0(u()) // OK foo1(u()) // OK foo2(u()) // OK @@ -41,5 +41,5 @@ object Test { u() // OK } - unused def u(): Int = 42 + ghost def u(): Int = 42 } \ No newline at end of file diff --git a/tests/neg/ghost-4.scala b/tests/neg/ghost-4.scala new file mode 100644 index 000000000000..43d80c9b8329 --- /dev/null +++ b/tests/neg/ghost-4.scala @@ -0,0 +1,17 @@ +object Test { + + def main(args: Array[String]): Unit = { + val f: ghost Int => Int = + ghost (x: Int) => { + x // error + } + + val f2: ghost Int => Int = + ghost (x: Int) => { + foo(x) + } + + def foo (ghost i: Int) = 0 + } + +} diff --git a/tests/neg/unused-5.scala b/tests/neg/ghost-5.scala similarity index 62% rename from tests/neg/unused-5.scala rename to tests/neg/ghost-5.scala index 3209a288f9a1..3d38f7614d0d 100644 --- a/tests/neg/unused-5.scala +++ b/tests/neg/ghost-5.scala @@ -1,14 +1,14 @@ object Test { - type UU[T] = unused T => Int + type UU[T] = ghost T => Int def main(args: Array[String]): Unit = { fun { x => - x // error: Cannot use `unused` value in a context that is not `unused` + x // error: Cannot use `ghost` value in a context that is not `ghost` } fun { - (x: Int) => x // error: `Int => Int` not compatible with `unused Int => Int` + (x: Int) => x // error: `Int => Int` not compatible with `ghost Int => Int` } } diff --git a/tests/neg/unused-6.scala b/tests/neg/ghost-6.scala similarity index 83% rename from tests/neg/unused-6.scala rename to tests/neg/ghost-6.scala index eeb66055d1bf..3e0c6a3b1876 100644 --- a/tests/neg/unused-6.scala +++ b/tests/neg/ghost-6.scala @@ -1,5 +1,5 @@ object Test { - unused def foo: Foo = new Foo + ghost def foo: Foo = new Foo foo.x() // error foo.y // error foo.z // error diff --git a/tests/neg/unused-args-lifted.scala b/tests/neg/ghost-args-lifted.scala similarity index 87% rename from tests/neg/unused-args-lifted.scala rename to tests/neg/ghost-args-lifted.scala index a7ef65fbb6cb..78f382e5d87e 100644 --- a/tests/neg/unused-args-lifted.scala +++ b/tests/neg/ghost-args-lifted.scala @@ -1,6 +1,6 @@ object Test { def foo(a: Int)(b: Int, c: Int) = 42 - unused def bar(i: Int): Int = { + ghost def bar(i: Int): Int = { println(1) 42 } diff --git a/tests/neg/unused-assign.scala b/tests/neg/ghost-assign.scala similarity index 62% rename from tests/neg/unused-assign.scala rename to tests/neg/ghost-assign.scala index 6fa2cf257ef4..eee1c153a733 100644 --- a/tests/neg/unused-assign.scala +++ b/tests/neg/ghost-assign.scala @@ -1,8 +1,8 @@ object Test { var i: Int = 1 - def foo(unused a: Int): Int = { + def foo(ghost a: Int): Int = { i = a // error - unused def r = { + ghost def r = { i = a () } diff --git a/tests/neg/ghost-case-class.scala b/tests/neg/ghost-case-class.scala new file mode 100644 index 000000000000..3a3f5f9b3143 --- /dev/null +++ b/tests/neg/ghost-case-class.scala @@ -0,0 +1 @@ +case class Foo1(ghost x: Int) // error diff --git a/tests/neg/ghost-class.scala b/tests/neg/ghost-class.scala new file mode 100644 index 000000000000..2c4ed12df517 --- /dev/null +++ b/tests/neg/ghost-class.scala @@ -0,0 +1 @@ +ghost class Test // error diff --git a/tests/neg/unused-def-rhs.scala b/tests/neg/ghost-def-rhs.scala similarity index 66% rename from tests/neg/unused-def-rhs.scala rename to tests/neg/ghost-def-rhs.scala index 58a51a03d050..92bbd336d021 100644 --- a/tests/neg/unused-def-rhs.scala +++ b/tests/neg/ghost-def-rhs.scala @@ -1,5 +1,5 @@ object Test { - def f(unused i: Int) = { + def f(ghost i: Int) = { def j: Int = i // error j } diff --git a/tests/neg/unused-if-else.scala b/tests/neg/ghost-if-else.scala similarity index 84% rename from tests/neg/unused-if-else.scala rename to tests/neg/ghost-if-else.scala index f1d68ded03b6..253918853641 100644 --- a/tests/neg/unused-if-else.scala +++ b/tests/neg/ghost-if-else.scala @@ -1,6 +1,6 @@ object Test { var b = true - def foo(unused a: Boolean): Boolean = { + def foo(ghost a: Boolean): Boolean = { if (a) // error true else diff --git a/tests/neg/unused-implicit.scala b/tests/neg/ghost-implicit.scala similarity index 58% rename from tests/neg/unused-implicit.scala rename to tests/neg/ghost-implicit.scala index cfb244d2a04b..fb33943c6f3c 100644 --- a/tests/neg/unused-implicit.scala +++ b/tests/neg/ghost-implicit.scala @@ -4,5 +4,5 @@ object Test { def fun(implicit a: Double): Int = 42 - unused implicit def doubleImplicit: Double = 42.0 + ghost implicit def doubleImplicit: Double = 42.0 } diff --git a/tests/neg/ghost-lazy-val.scala b/tests/neg/ghost-lazy-val.scala new file mode 100644 index 000000000000..66fde1fabeb6 --- /dev/null +++ b/tests/neg/ghost-lazy-val.scala @@ -0,0 +1,3 @@ +object Test { + ghost lazy val i: Int = 1 // error +} diff --git a/tests/neg/unused-match.scala b/tests/neg/ghost-match.scala similarity index 88% rename from tests/neg/unused-match.scala rename to tests/neg/ghost-match.scala index 9de8ee1f2bd4..d541f1192c51 100644 --- a/tests/neg/unused-match.scala +++ b/tests/neg/ghost-match.scala @@ -1,6 +1,6 @@ object Test { var b = true - def foo(unused a: Int): Int = { + def foo(ghost a: Int): Int = { a match { // error case _ => } diff --git a/tests/neg/ghost-object.scala b/tests/neg/ghost-object.scala new file mode 100644 index 000000000000..2c36a3e84fb6 --- /dev/null +++ b/tests/neg/ghost-object.scala @@ -0,0 +1 @@ +ghost object Test // error diff --git a/tests/neg/unused-return.scala b/tests/neg/ghost-return.scala similarity index 81% rename from tests/neg/unused-return.scala rename to tests/neg/ghost-return.scala index 81eba6e0d9f7..4c3498f42ee7 100644 --- a/tests/neg/unused-return.scala +++ b/tests/neg/ghost-return.scala @@ -1,6 +1,6 @@ object Test { var b = true - def foo(unused a: Int): Int = { + def foo(ghost a: Int): Int = { if (b) return a // error else diff --git a/tests/neg/ghost-trait.scala b/tests/neg/ghost-trait.scala new file mode 100644 index 000000000000..407dd6bdf47a --- /dev/null +++ b/tests/neg/ghost-trait.scala @@ -0,0 +1 @@ +ghost trait Test // error diff --git a/tests/neg/unused-try.scala b/tests/neg/ghost-try.scala similarity index 69% rename from tests/neg/unused-try.scala rename to tests/neg/ghost-try.scala index 1d8ba2c417ca..5153343f47ea 100644 --- a/tests/neg/unused-try.scala +++ b/tests/neg/ghost-try.scala @@ -1,12 +1,12 @@ object Test { - def foo(unused a: Int): Int = { + def foo(ghost a: Int): Int = { try { a // error } catch { case _ => 42 } } - def foo2(unused a: Int): Int = { + def foo2(ghost a: Int): Int = { try { 42 } catch { diff --git a/tests/neg/ghost-type.scala b/tests/neg/ghost-type.scala new file mode 100644 index 000000000000..bfb2533ab21d --- /dev/null +++ b/tests/neg/ghost-type.scala @@ -0,0 +1,3 @@ +class Test { + ghost type T // error +} diff --git a/tests/neg/unused-val-rhs.scala b/tests/neg/ghost-val-rhs.scala similarity index 67% rename from tests/neg/unused-val-rhs.scala rename to tests/neg/ghost-val-rhs.scala index ae10b3db9b98..1c8684c12021 100644 --- a/tests/neg/unused-val-rhs.scala +++ b/tests/neg/ghost-val-rhs.scala @@ -1,5 +1,5 @@ object Test { - def f(unused i: Int) = { + def f(ghost i: Int) = { val j: Int = i // error () } diff --git a/tests/neg/unused-value-class.scala b/tests/neg/ghost-value-class.scala similarity index 51% rename from tests/neg/unused-value-class.scala rename to tests/neg/ghost-value-class.scala index 8e1d2d9f4d88..38495a05dcb7 100644 --- a/tests/neg/unused-value-class.scala +++ b/tests/neg/ghost-value-class.scala @@ -1,4 +1,4 @@ -class Foo(unused x: Int) extends AnyVal // error +class Foo(ghost x: Int) extends AnyVal // error class Bar(x: Int)(y: Int) extends AnyVal // error diff --git a/tests/neg/ghost-var.scala b/tests/neg/ghost-var.scala new file mode 100644 index 000000000000..c9d7275f5a9d --- /dev/null +++ b/tests/neg/ghost-var.scala @@ -0,0 +1,3 @@ +object Test { + ghost var i: Int = 1 // error +} diff --git a/tests/neg/unused-4.scala b/tests/neg/unused-4.scala deleted file mode 100644 index 625f404c014a..000000000000 --- a/tests/neg/unused-4.scala +++ /dev/null @@ -1,17 +0,0 @@ -object Test { - - def main(args: Array[String]): Unit = { - val f: unused Int => Int = - unused (x: Int) => { - x // error - } - - val f2: unused Int => Int = - unused (x: Int) => { - foo(x) - } - - def foo (unused i: Int) = 0 - } - -} diff --git a/tests/neg/unused-case-class.scala b/tests/neg/unused-case-class.scala deleted file mode 100644 index dc1382fb3636..000000000000 --- a/tests/neg/unused-case-class.scala +++ /dev/null @@ -1 +0,0 @@ -case class Foo1(unused x: Int) // error diff --git a/tests/neg/unused-class.scala b/tests/neg/unused-class.scala deleted file mode 100644 index 69962b14522c..000000000000 --- a/tests/neg/unused-class.scala +++ /dev/null @@ -1 +0,0 @@ -unused class Test // error diff --git a/tests/neg/unused-lazy-val.scala b/tests/neg/unused-lazy-val.scala deleted file mode 100644 index 8d7f2212b0ed..000000000000 --- a/tests/neg/unused-lazy-val.scala +++ /dev/null @@ -1,3 +0,0 @@ -object Test { - unused lazy val i: Int = 1 // error -} diff --git a/tests/neg/unused-object.scala b/tests/neg/unused-object.scala deleted file mode 100644 index 1eac930dc4e0..000000000000 --- a/tests/neg/unused-object.scala +++ /dev/null @@ -1 +0,0 @@ -unused object Test // error diff --git a/tests/neg/unused-trait.scala b/tests/neg/unused-trait.scala deleted file mode 100644 index f0f5d9026891..000000000000 --- a/tests/neg/unused-trait.scala +++ /dev/null @@ -1 +0,0 @@ -unused trait Test // error diff --git a/tests/neg/unused-type.scala b/tests/neg/unused-type.scala deleted file mode 100644 index 35a8bb034a6d..000000000000 --- a/tests/neg/unused-type.scala +++ /dev/null @@ -1,3 +0,0 @@ -class Test { - unused type T // error -} diff --git a/tests/neg/unused-var.scala b/tests/neg/unused-var.scala deleted file mode 100644 index 6162b2b84e25..000000000000 --- a/tests/neg/unused-var.scala +++ /dev/null @@ -1,3 +0,0 @@ -object Test { - unused var i: Int = 1 // error -} diff --git a/tests/pos/unused-args-lifted.scala b/tests/pos/ghost-args-lifted.scala similarity index 81% rename from tests/pos/unused-args-lifted.scala rename to tests/pos/ghost-args-lifted.scala index 1115cc9ce793..7a7184787e82 100644 --- a/tests/pos/unused-args-lifted.scala +++ b/tests/pos/ghost-args-lifted.scala @@ -1,5 +1,5 @@ object Test { - def foo(unused a: Int)(b: Int, c: Int) = 42 + def foo(ghost a: Int)(b: Int, c: Int) = 42 def bar(i: Int): Int = { println(1) 42 diff --git a/tests/pos/unused-asInstanceOf.scala b/tests/pos/ghost-asInstanceOf.scala similarity index 80% rename from tests/pos/unused-asInstanceOf.scala rename to tests/pos/ghost-asInstanceOf.scala index 1a36d65c0a0c..adb46a05f59e 100644 --- a/tests/pos/unused-asInstanceOf.scala +++ b/tests/pos/ghost-asInstanceOf.scala @@ -1,6 +1,6 @@ trait Dataset { - def select(unused c: Column): Unit = () + def select(ghost c: Column): Unit = () } class Column diff --git a/tests/pos/unused-deep-context.scala b/tests/pos/ghost-deep-context.scala similarity index 52% rename from tests/pos/unused-deep-context.scala rename to tests/pos/ghost-deep-context.scala index ff8f2b1e244c..90c2c05af7a8 100644 --- a/tests/pos/unused-deep-context.scala +++ b/tests/pos/ghost-deep-context.scala @@ -1,12 +1,12 @@ object Test { def outer1(): Int = { - def inner(unused a: Int): Int = 0 + def inner(ghost a: Int): Int = 0 inner(42) } def outer2(): Int = { - def inner(unused b: Int): Int = { - def inner2(unused a: Int): Int = 0 + def inner(ghost b: Int): Int = { + def inner2(ghost a: Int): Int = 0 inner2(b) } inner(42) diff --git a/tests/pos/unused-extension-method.scala b/tests/pos/ghost-extension-method.scala similarity index 58% rename from tests/pos/unused-extension-method.scala rename to tests/pos/ghost-extension-method.scala index b89e8bdac5ac..fc73fbb9bbf4 100644 --- a/tests/pos/unused-extension-method.scala +++ b/tests/pos/ghost-extension-method.scala @@ -1,3 +1,3 @@ class IntDeco(x: Int) extends AnyVal { - def foo(unused y: Int) = x + def foo(ghost y: Int) = x } diff --git a/tests/pos/ghost-pathdep-1.scala b/tests/pos/ghost-pathdep-1.scala new file mode 100644 index 000000000000..6dfc85bdf57b --- /dev/null +++ b/tests/pos/ghost-pathdep-1.scala @@ -0,0 +1,19 @@ +object Test { + + fun1(new Bar) + fun2(new Bar) + fun3(new Bar) + + def fun1[F >: Bar <: Foo](ghost f: F): f.X = null.asInstanceOf[f.X] + def fun2[F >: Bar <: Foo](ghost f: F)(ghost bar: f.B): f.B = null.asInstanceOf[f.B] + def fun3[F >: Bar <: Foo](ghost f: F)(ghost b: f.B): b.X = null.asInstanceOf[b.X] +} + +class Foo { + type X + type B <: Bar +} + +class Bar extends Foo { + type X = String +} diff --git a/tests/pos/unused-pathdep-2.scala b/tests/pos/ghost-pathdep-2.scala similarity index 85% rename from tests/pos/unused-pathdep-2.scala rename to tests/pos/ghost-pathdep-2.scala index adbcb5250821..86788713d2d2 100644 --- a/tests/pos/unused-pathdep-2.scala +++ b/tests/pos/ghost-pathdep-2.scala @@ -2,7 +2,7 @@ object Test { type F >: Bar <: Foo - class A(unused val f: F) { + class A(ghost val f: F) { type F1 <: f.X type F2[Z <: f.X] } diff --git a/tests/pos/phantom-Eq.scala b/tests/pos/phantom-Eq.scala index 94e2caff8786..3552ded393b8 100644 --- a/tests/pos/phantom-Eq.scala +++ b/tests/pos/phantom-Eq.scala @@ -18,15 +18,15 @@ object EqUtil { type PhantomEqEq[T] = PhantomEq[T, T] implicit class EqualsDeco[T](val x: T) extends AnyVal { - def ===[U] (y: U)(implicit unused ce: PhantomEq[T, U]) = x.equals(y) + def ===[U] (y: U)(implicit ghost ce: PhantomEq[T, U]) = x.equals(y) } - implicit unused def eqString: PhantomEqEq[String] = ??? - implicit unused def eqInt: PhantomEqEq[Int] = ??? - implicit unused def eqDouble: PhantomEqEq[Double] = ??? + implicit ghost def eqString: PhantomEqEq[String] = ??? + implicit ghost def eqInt: PhantomEqEq[Int] = ??? + implicit ghost def eqDouble: PhantomEqEq[Double] = ??? - implicit unused def eqByteNum: PhantomEq[Byte, Number] = ??? - implicit unused def eqNumByte: PhantomEq[Number, Byte] = ??? + implicit ghost def eqByteNum: PhantomEq[Byte, Number] = ??? + implicit ghost def eqNumByte: PhantomEq[Number, Byte] = ??? - implicit unused def eqSeq[T, U](implicit unused eq: PhantomEq[T, U]): PhantomEq[Seq[T], Seq[U]] = ??? + implicit ghost def eqSeq[T, U](implicit ghost eq: PhantomEq[T, U]): PhantomEq[Seq[T], Seq[U]] = ??? } diff --git a/tests/pos/phantom-Eq2/Phantom-Eq_1.scala b/tests/pos/phantom-Eq2/Phantom-Eq_1.scala index dabca2718654..de1a723a98e9 100644 --- a/tests/pos/phantom-Eq2/Phantom-Eq_1.scala +++ b/tests/pos/phantom-Eq2/Phantom-Eq_1.scala @@ -6,16 +6,16 @@ object EqUtil { type PhantomEqEq[T] = PhantomEq[T, T] implicit class EqualsDeco[T](val x: T) extends AnyVal { - def ===[U] (y: U)(implicit unused ce: PhantomEq[T, U]) = x.equals(y) + def ===[U] (y: U)(implicit ghost ce: PhantomEq[T, U]) = x.equals(y) } - implicit unused def eqString: PhantomEqEq[String] = new PhantomEq[String, String] - implicit unused def eqInt: PhantomEqEq[Int] = new PhantomEq[Int, Int] - implicit unused def eqDouble: PhantomEqEq[Double] = new PhantomEq[Double, Double] + implicit ghost def eqString: PhantomEqEq[String] = new PhantomEq[String, String] + implicit ghost def eqInt: PhantomEqEq[Int] = new PhantomEq[Int, Int] + implicit ghost def eqDouble: PhantomEqEq[Double] = new PhantomEq[Double, Double] - implicit unused def eqByteNum: PhantomEq[Byte, Number] = new PhantomEq[Byte, Number] - implicit unused def eqNumByte: PhantomEq[Number, Byte] = new PhantomEq[Number, Byte] + implicit ghost def eqByteNum: PhantomEq[Byte, Number] = new PhantomEq[Byte, Number] + implicit ghost def eqNumByte: PhantomEq[Number, Byte] = new PhantomEq[Number, Byte] - implicit unused def eqSeq[T, U](implicit unused eq: PhantomEq[T, U]): PhantomEq[Seq[T], Seq[U]] = + implicit ghost def eqSeq[T, U](implicit ghost eq: PhantomEq[T, U]): PhantomEq[Seq[T], Seq[U]] = new PhantomEq[Seq[T], Seq[U]] } diff --git a/tests/pos/phantom-Evidence.scala b/tests/pos/phantom-Evidence.scala index 7dd8cc8a481a..809409d98cf6 100644 --- a/tests/pos/phantom-Evidence.scala +++ b/tests/pos/phantom-Evidence.scala @@ -10,8 +10,8 @@ object WithNormalState { def newInstance(): Instance[Off] = new Instance[Off] } class Instance[S <: State] private { - def getOnInstance(implicit unused ev: S =::= Off): Instance[On] = new Instance[On] // phantom parameter ev is erased - def getOffInstance(implicit unused ev: S =::= On): Instance[Off] = new Instance[Off] // phantom parameter ev is erased + def getOnInstance(implicit ghost ev: S =::= Off): Instance[On] = new Instance[On] // phantom parameter ev is erased + def getOffInstance(implicit ghost ev: S =::= On): Instance[Off] = new Instance[Off] // phantom parameter ev is erased } def run() = { @@ -24,5 +24,5 @@ object WithNormalState { object Utils { type =::=[From, To] - implicit unused def tpEquals[A]: A =::= A = ??? + implicit ghost def tpEquals[A]: A =::= A = ??? } diff --git a/tests/pos/unused-pathdep-1.scala b/tests/pos/unused-pathdep-1.scala deleted file mode 100644 index b4b0d3db9802..000000000000 --- a/tests/pos/unused-pathdep-1.scala +++ /dev/null @@ -1,19 +0,0 @@ -object Test { - - fun1(new Bar) - fun2(new Bar) - fun3(new Bar) - - def fun1[F >: Bar <: Foo](unused f: F): f.X = null.asInstanceOf[f.X] - def fun2[F >: Bar <: Foo](unused f: F)(unused bar: f.B): f.B = null.asInstanceOf[f.B] - def fun3[F >: Bar <: Foo](unused f: F)(unused b: f.B): b.X = null.asInstanceOf[b.X] -} - -class Foo { - type X - type B <: Bar -} - -class Bar extends Foo { - type X = String -} diff --git a/tests/run/unused-1.check b/tests/run/ghost-1.check similarity index 100% rename from tests/run/unused-1.check rename to tests/run/ghost-1.check diff --git a/tests/run/unused-1.scala b/tests/run/ghost-1.scala similarity index 79% rename from tests/run/unused-1.scala rename to tests/run/ghost-1.scala index 9e08936459f7..3ba55257ad55 100644 --- a/tests/run/unused-1.scala +++ b/tests/run/ghost-1.scala @@ -8,7 +8,7 @@ object Test { println("foo") 42 } - def fun(unused boo: Int): Unit = { + def fun(ghost boo: Int): Unit = { println("fun") } } diff --git a/tests/run/unused-10.check b/tests/run/ghost-10.check similarity index 100% rename from tests/run/unused-10.check rename to tests/run/ghost-10.check diff --git a/tests/run/unused-10.scala b/tests/run/ghost-10.scala similarity index 77% rename from tests/run/unused-10.scala rename to tests/run/ghost-10.scala index ab2850296eda..2ec9861328b0 100644 --- a/tests/run/unused-10.scala +++ b/tests/run/ghost-10.scala @@ -4,11 +4,11 @@ object Test { fun2.pacFun4(inky) } - def pacFun4(unused clyde: Int) = { + def pacFun4(ghost clyde: Int) = { println("pacFun4") } - unused def inky: Int = { + ghost def inky: Int = { println("inky") // in erased function 42 } diff --git a/tests/run/unused-11.check b/tests/run/ghost-11.check similarity index 100% rename from tests/run/unused-11.check rename to tests/run/ghost-11.check diff --git a/tests/run/unused-11.scala b/tests/run/ghost-11.scala similarity index 75% rename from tests/run/unused-11.scala rename to tests/run/ghost-11.scala index 3248b59aa46d..e8193c4281f3 100644 --- a/tests/run/unused-11.scala +++ b/tests/run/ghost-11.scala @@ -8,17 +8,17 @@ object Test { (new Fun2().fun)({ println("z1"); boo })({ println("z2"); boo }) } - def fun(unused x1: Int)(unused x2: Int) = { + def fun(ghost x1: Int)(ghost x2: Int) = { println("fun") } - class Fun(unused y1: Int)(unused y2: Int) { + class Fun(ghost y1: Int)(ghost y2: Int) { println("Fun") } class Fun2 { println("Fun2") - def fun(unused z1: Int)(unused z2: Int) = { + def fun(ghost z1: Int)(ghost z2: Int) = { println("Fun2fun") } } diff --git a/tests/run/unused-12.check b/tests/run/ghost-12.check similarity index 100% rename from tests/run/unused-12.check rename to tests/run/ghost-12.check diff --git a/tests/run/unused-12.scala b/tests/run/ghost-12.scala similarity index 81% rename from tests/run/unused-12.scala rename to tests/run/ghost-12.scala index 8bfd5dc030af..463c4c88cf0e 100644 --- a/tests/run/unused-12.scala +++ b/tests/run/ghost-12.scala @@ -12,6 +12,6 @@ object Test { } -case class Foo(a: Int)(unused b: Int) { +case class Foo(a: Int)(ghost b: Int) { println("Foo") } diff --git a/tests/run/unused-13.check b/tests/run/ghost-13.check similarity index 100% rename from tests/run/unused-13.check rename to tests/run/ghost-13.check diff --git a/tests/run/unused-13.scala b/tests/run/ghost-13.scala similarity index 72% rename from tests/run/unused-13.scala rename to tests/run/ghost-13.scala index 638d41045962..cfa8ca278bc4 100644 --- a/tests/run/unused-13.scala +++ b/tests/run/ghost-13.scala @@ -1,14 +1,14 @@ object Test { def main(args: Array[String]): Unit = { - unused val x = { + ghost val x = { println("x") 42 } foo(x) } - def foo(unused a: Int) = { + def foo(ghost a: Int) = { println("foo") } diff --git a/tests/run/unused-14.check b/tests/run/ghost-14.check similarity index 100% rename from tests/run/unused-14.check rename to tests/run/ghost-14.check diff --git a/tests/run/unused-14.scala b/tests/run/ghost-14.scala similarity index 85% rename from tests/run/unused-14.scala rename to tests/run/ghost-14.scala index f891c155d04e..0b1fe1e65291 100644 --- a/tests/run/unused-14.scala +++ b/tests/run/ghost-14.scala @@ -7,7 +7,7 @@ object Test { } class Foo { - unused val x: Int = { + ghost val x: Int = { println("x") 42 } diff --git a/tests/run/unused-15.check b/tests/run/ghost-15.check similarity index 100% rename from tests/run/unused-15.check rename to tests/run/ghost-15.check diff --git a/tests/run/unused-15.scala b/tests/run/ghost-15.scala similarity index 67% rename from tests/run/unused-15.scala rename to tests/run/ghost-15.scala index 8b99563e8d97..4fb21600849e 100644 --- a/tests/run/unused-15.scala +++ b/tests/run/ghost-15.scala @@ -10,8 +10,8 @@ object Test { } } -class Foo extends UnusedFunction1[Int, Int] { - def apply(unused x: Int): Int = { +class Foo extends GhostFunction1[Int, Int] { + def apply(ghost x: Int): Int = { println("Foo.apply") 42 } diff --git a/tests/run/unused-16.check b/tests/run/ghost-16.check similarity index 100% rename from tests/run/unused-16.check rename to tests/run/ghost-16.check diff --git a/tests/run/unused-16.scala b/tests/run/ghost-16.scala similarity index 72% rename from tests/run/unused-16.scala rename to tests/run/ghost-16.scala index 472455cca469..74dc6fe8d186 100644 --- a/tests/run/unused-16.scala +++ b/tests/run/ghost-16.scala @@ -11,11 +11,11 @@ object Test { } class Foo { - def foo(unused x: Int): Int = 42 + def foo(ghost x: Int): Int = 42 } class Bar extends Foo { - override def foo(unused x: Int): Int = { + override def foo(ghost x: Int): Int = { println("Bar.foo") 42 } diff --git a/tests/run/unused-17.check b/tests/run/ghost-17.check similarity index 100% rename from tests/run/unused-17.check rename to tests/run/ghost-17.check diff --git a/tests/run/unused-17.scala b/tests/run/ghost-17.scala similarity index 59% rename from tests/run/unused-17.scala rename to tests/run/ghost-17.scala index cb1f340689b1..eeae59837720 100644 --- a/tests/run/unused-17.scala +++ b/tests/run/ghost-17.scala @@ -1,8 +1,8 @@ object Test { def main(args: Array[String]): Unit = { - val f: unused Int => Int = - unused (x: Int) => { println("lambda"); 42 } + val f: ghost Int => Int = + ghost (x: Int) => { println("lambda"); 42 } f(foo) } diff --git a/tests/run/unused-18.check b/tests/run/ghost-18.check similarity index 100% rename from tests/run/unused-18.check rename to tests/run/ghost-18.check diff --git a/tests/run/unused-18.scala b/tests/run/ghost-18.scala similarity index 86% rename from tests/run/unused-18.scala rename to tests/run/ghost-18.scala index d1ae64829372..1702cfcd1cee 100644 --- a/tests/run/unused-18.scala +++ b/tests/run/ghost-18.scala @@ -2,7 +2,7 @@ object Test { def main(args: Array[String]): Unit = { ( - unused (x: Int) => { + ghost (x: Int) => { println("lambda") 42 } diff --git a/tests/run/unused-19.check b/tests/run/ghost-19.check similarity index 100% rename from tests/run/unused-19.check rename to tests/run/ghost-19.check diff --git a/tests/run/unused-19.scala b/tests/run/ghost-19.scala similarity index 77% rename from tests/run/unused-19.scala rename to tests/run/ghost-19.scala index 70cf1d355c13..15896356dc4c 100644 --- a/tests/run/unused-19.scala +++ b/tests/run/ghost-19.scala @@ -2,7 +2,7 @@ object Test { def main(args: Array[String]): Unit = { { - unused (x: Int) => 42 + ghost (x: Int) => 42 } println("ok") diff --git a/tests/run/unused-2.check b/tests/run/ghost-2.check similarity index 100% rename from tests/run/unused-2.check rename to tests/run/ghost-2.check diff --git a/tests/run/unused-2.scala b/tests/run/ghost-2.scala similarity index 70% rename from tests/run/unused-2.scala rename to tests/run/ghost-2.scala index 31b4ee9862cd..9f10484b52f9 100644 --- a/tests/run/unused-2.scala +++ b/tests/run/ghost-2.scala @@ -2,7 +2,7 @@ object Test { def main(args: Array[String]): Unit = { - unused def !!! : Nothing = ??? + ghost def !!! : Nothing = ??? try { fun(!!!) @@ -12,7 +12,7 @@ object Test { } } - def fun(unused bottom: Nothing): Unit = { + def fun(ghost bottom: Nothing): Unit = { println("fun") } } diff --git a/tests/run/unused-20.check b/tests/run/ghost-20.check similarity index 100% rename from tests/run/unused-20.check rename to tests/run/ghost-20.check diff --git a/tests/run/unused-20.scala b/tests/run/ghost-20.scala similarity index 61% rename from tests/run/unused-20.scala rename to tests/run/ghost-20.scala index 3984873a5925..443055b252c9 100644 --- a/tests/run/unused-20.scala +++ b/tests/run/ghost-20.scala @@ -1,14 +1,14 @@ object Test { def main(args: Array[String]): Unit = { - fun { unused (x: Int) => + fun { ghost (x: Int) => println("lambda") "abc" } } - def fun(f: unused Int => String): String = { + def fun(f: ghost Int => String): String = { f(35) } } diff --git a/tests/run/unused-21.check b/tests/run/ghost-21.check similarity index 100% rename from tests/run/unused-21.check rename to tests/run/ghost-21.check diff --git a/tests/run/unused-21.scala b/tests/run/ghost-21.scala similarity index 73% rename from tests/run/unused-21.scala rename to tests/run/ghost-21.scala index 3c38615faf26..e9619ba2ef27 100644 --- a/tests/run/unused-21.scala +++ b/tests/run/ghost-21.scala @@ -1,9 +1,9 @@ object Test { - type UU[T] = unused T => Int + type UU[T] = ghost T => Int def main(args: Array[String]): Unit = { - fun { unused x => + fun { ghost x => println("lambda") 42 } diff --git a/tests/run/unused-22.check b/tests/run/ghost-22.check similarity index 100% rename from tests/run/unused-22.check rename to tests/run/ghost-22.check diff --git a/tests/run/unused-22.scala b/tests/run/ghost-22.scala similarity index 79% rename from tests/run/unused-22.scala rename to tests/run/ghost-22.scala index ac5739c6a12a..643803c03bb6 100644 --- a/tests/run/unused-22.scala +++ b/tests/run/ghost-22.scala @@ -10,7 +10,7 @@ object Test { println("foo") 42 } - def fun1(implicit unused boo: Int): Int = { + def fun1(implicit ghost boo: Int): Int = { println("fun1") 43 } diff --git a/tests/run/unused-23.check b/tests/run/ghost-23.check similarity index 100% rename from tests/run/unused-23.check rename to tests/run/ghost-23.check diff --git a/tests/run/ghost-23.scala b/tests/run/ghost-23.scala new file mode 100644 index 000000000000..e4bae77828c0 --- /dev/null +++ b/tests/run/ghost-23.scala @@ -0,0 +1,22 @@ +object Test { + + def main(args: Array[String]): Unit = { + fun { implicit ghost (x: Int) => + println("lambda1") + "abc" + } + + fun2 { ghost implicit (x: Int) => + println("lambda2") + "abc" + } + } + + def fun(f: implicit ghost Int => String): String = { + f(35) + } + + def fun2(f: ghost implicit Int => String): String = { + f(36) + } +} diff --git a/tests/run/unused-24.check b/tests/run/ghost-24.check similarity index 100% rename from tests/run/unused-24.check rename to tests/run/ghost-24.check diff --git a/tests/run/unused-24.scala b/tests/run/ghost-24.scala similarity index 71% rename from tests/run/unused-24.scala rename to tests/run/ghost-24.scala index 45d524d4c921..23d00c52c57a 100644 --- a/tests/run/unused-24.scala +++ b/tests/run/ghost-24.scala @@ -4,11 +4,11 @@ object Test { println(fun(new Bar)) } - def fun(unused foo: Foo): foo.X = { + def fun(ghost foo: Foo): foo.X = { null.asInstanceOf[foo.X] } - def fun2(unused foo: Foo)(unused bar: foo.B): bar.X = { + def fun2(ghost foo: Foo)(ghost bar: foo.B): bar.X = { null.asInstanceOf[bar.X] } } diff --git a/tests/run/unused-25.check b/tests/run/ghost-25.check similarity index 100% rename from tests/run/unused-25.check rename to tests/run/ghost-25.check diff --git a/tests/run/unused-25.scala b/tests/run/ghost-25.scala similarity index 75% rename from tests/run/unused-25.scala rename to tests/run/ghost-25.scala index 455dda180f62..036d640eda8a 100644 --- a/tests/run/unused-25.scala +++ b/tests/run/ghost-25.scala @@ -6,5 +6,5 @@ object Test { } class Dataset { - def select[A](unused c: Boolean): String = "abc" + def select[A](ghost c: Boolean): String = "abc" } diff --git a/tests/run/unused-26.check b/tests/run/ghost-26.check similarity index 100% rename from tests/run/unused-26.check rename to tests/run/ghost-26.check diff --git a/tests/run/unused-26.scala b/tests/run/ghost-26.scala similarity index 56% rename from tests/run/unused-26.scala rename to tests/run/ghost-26.scala index 3c0b4d5a5807..0c9d84497132 100644 --- a/tests/run/unused-26.scala +++ b/tests/run/ghost-26.scala @@ -2,5 +2,5 @@ object Test { def main(args: Array[String]): Unit = { col("abc")(true) } - def col[S](s: String)(unused ev: Boolean): Unit = println(s) + def col[S](s: String)(ghost ev: Boolean): Unit = println(s) } diff --git a/tests/run/unused-27.check b/tests/run/ghost-27.check similarity index 100% rename from tests/run/unused-27.check rename to tests/run/ghost-27.check diff --git a/tests/run/unused-27.scala b/tests/run/ghost-27.scala similarity index 83% rename from tests/run/unused-27.scala rename to tests/run/ghost-27.scala index 6fcc6d6acbba..e28b16e6c6e6 100644 --- a/tests/run/unused-27.scala +++ b/tests/run/ghost-27.scala @@ -5,7 +5,7 @@ object Test { foo })(x) } - def foo(unused a: Int): Unit = { + def foo(ghost a: Int): Unit = { println("foo") } def x: Int = { diff --git a/tests/run/unused-28.check b/tests/run/ghost-28.check similarity index 100% rename from tests/run/unused-28.check rename to tests/run/ghost-28.check diff --git a/tests/run/unused-28.scala b/tests/run/ghost-28.scala similarity index 77% rename from tests/run/unused-28.scala rename to tests/run/ghost-28.scala index bd567b4461fc..f51b4ca9ab23 100644 --- a/tests/run/unused-28.scala +++ b/tests/run/ghost-28.scala @@ -5,10 +5,10 @@ object Test { a = false (if (a) foo else bar)(x) } - def foo(unused a: Int): Unit = { + def foo(ghost a: Int): Unit = { println("foo") } - def bar(unused a: Int): Unit = { + def bar(ghost a: Int): Unit = { println("bar") } def x: Int = { diff --git a/tests/run/unused-3.check b/tests/run/ghost-3.check similarity index 100% rename from tests/run/unused-3.check rename to tests/run/ghost-3.check diff --git a/tests/run/unused-3.scala b/tests/run/ghost-3.scala similarity index 80% rename from tests/run/unused-3.scala rename to tests/run/ghost-3.scala index 57bb31237ad6..e08d48daa507 100644 --- a/tests/run/unused-3.scala +++ b/tests/run/ghost-3.scala @@ -14,7 +14,7 @@ object Test { "abc" } - def fun(unused a: Int)(unused b: String): Unit = { + def fun(ghost a: Int)(ghost b: String): Unit = { println("fun") } diff --git a/tests/run/unused-4.check b/tests/run/ghost-4.check similarity index 100% rename from tests/run/unused-4.check rename to tests/run/ghost-4.check diff --git a/tests/run/unused-4.scala b/tests/run/ghost-4.scala similarity index 74% rename from tests/run/unused-4.scala rename to tests/run/ghost-4.scala index a2267bf491e9..e57febf0fd30 100644 --- a/tests/run/unused-4.scala +++ b/tests/run/ghost-4.scala @@ -15,11 +15,11 @@ object Test { "abc" } - def fun(a: Int)(unused b: String): Unit = { + def fun(a: Int)(ghost b: String): Unit = { println("fun " + a) } - def fun2(unused a: Int)(b: String): Unit = { + def fun2(ghost a: Int)(b: String): Unit = { println("fun2 " + b) } } diff --git a/tests/run/unused-5.check b/tests/run/ghost-5.check similarity index 100% rename from tests/run/unused-5.check rename to tests/run/ghost-5.check diff --git a/tests/run/unused-5.scala b/tests/run/ghost-5.scala similarity index 67% rename from tests/run/unused-5.scala rename to tests/run/ghost-5.scala index 1f2d76cd35c7..8109e3fcd4d5 100644 --- a/tests/run/unused-5.scala +++ b/tests/run/ghost-5.scala @@ -10,11 +10,11 @@ object Test { i } - def fun(a: Int)(unused b: Int)(c: Int)(unused d: Int): Unit = { + def fun(a: Int)(ghost b: Int)(c: Int)(ghost d: Int): Unit = { println("fun " + a + " " + c) } - def fun2(unused a2: Int)(b2: Int)(unused c2: Int)(d2: Int): Unit = { + def fun2(ghost a2: Int)(b2: Int)(ghost c2: Int)(d2: Int): Unit = { println("fun2 " + b2 + " " + d2) } } diff --git a/tests/run/unused-6.check b/tests/run/ghost-6.check similarity index 100% rename from tests/run/unused-6.check rename to tests/run/ghost-6.check diff --git a/tests/run/unused-6.scala b/tests/run/ghost-6.scala similarity index 84% rename from tests/run/unused-6.scala rename to tests/run/ghost-6.scala index 514d8f551ece..d5d047cc218d 100644 --- a/tests/run/unused-6.scala +++ b/tests/run/ghost-6.scala @@ -11,6 +11,6 @@ object Test { } -class Foo(unused a: Int) { +class Foo(ghost a: Int) { println("Foo") } diff --git a/tests/run/unused-7.check b/tests/run/ghost-7.check similarity index 100% rename from tests/run/unused-7.check rename to tests/run/ghost-7.check diff --git a/tests/run/unused-7.scala b/tests/run/ghost-7.scala similarity index 72% rename from tests/run/unused-7.scala rename to tests/run/ghost-7.scala index cd4f39844d66..f6f3a0d924d6 100644 --- a/tests/run/unused-7.scala +++ b/tests/run/ghost-7.scala @@ -1,7 +1,7 @@ object Test { def main(args: Array[String]): Unit = { - def f(unused i: Int) = { + def f(ghost i: Int) = { new Foo(i)(foo) } f(5) @@ -14,6 +14,6 @@ object Test { } -class Foo(unused a: Int)(b: Int) { +class Foo(ghost a: Int)(b: Int) { println("Foo") } diff --git a/tests/run/unused-8.check b/tests/run/ghost-8.check similarity index 100% rename from tests/run/unused-8.check rename to tests/run/ghost-8.check diff --git a/tests/run/unused-8.scala b/tests/run/ghost-8.scala similarity index 72% rename from tests/run/unused-8.scala rename to tests/run/ghost-8.scala index 52774d27728c..dc0b34acea0b 100644 --- a/tests/run/unused-8.scala +++ b/tests/run/ghost-8.scala @@ -1,7 +1,7 @@ object Test { def main(args: Array[String]): Unit = { - def f(unused i: Int) = { + def f(ghost i: Int) = { new Foo(foo)(i) } f(foo) @@ -14,6 +14,6 @@ object Test { } -class Foo(a: Int)(unused b: Int) { +class Foo(a: Int)(ghost b: Int) { println("Foo") } diff --git a/tests/run/unused-9.check b/tests/run/ghost-9.check similarity index 100% rename from tests/run/unused-9.check rename to tests/run/ghost-9.check diff --git a/tests/run/unused-9.scala b/tests/run/ghost-9.scala similarity index 80% rename from tests/run/unused-9.scala rename to tests/run/ghost-9.scala index 46202ee66287..d2d203f8ec3a 100644 --- a/tests/run/unused-9.scala +++ b/tests/run/ghost-9.scala @@ -9,7 +9,7 @@ object Test { 42 } - def fun[T](unused x: T): Unit = { + def fun[T](ghost x: T): Unit = { println("fun") } } diff --git a/tests/run/unused-frameless.check b/tests/run/ghost-frameless.check similarity index 100% rename from tests/run/unused-frameless.check rename to tests/run/ghost-frameless.check diff --git a/tests/run/unused-frameless.scala b/tests/run/ghost-frameless.scala similarity index 95% rename from tests/run/unused-frameless.scala rename to tests/run/ghost-frameless.scala index 31aebaa786a4..9134284d82de 100644 --- a/tests/run/unused-frameless.scala +++ b/tests/run/ghost-frameless.scala @@ -26,7 +26,7 @@ trait Dataset[T] { // Use c.label to do an untyped select on actual Spark Dataset, and // cast the result to TypedDataset[A] - def col[S <: String, A](s: S)(implicit unused ev: Exists[T, s.type, A]) = + def col[S <: String, A](s: S)(implicit ghost ev: Exists[T, s.type, A]) = new Column[T, A](s) // ev is only here to check than this is safe, it's never used at runtime! def collect(): Vector[T] @@ -111,8 +111,8 @@ object Test { val ds: Dataset[X4[Int, String, Double, Boolean]] = Dataset.create(source) - val unusedD = ds.col("d") - val outSpark1: Vector[Boolean] = ds.select(unusedD).collect() + val ghostD = ds.col("d") + val outSpark1: Vector[Boolean] = ds.select(ghostD).collect() assert(outSpark1 == outColl) println("end") diff --git a/tests/run/unused-machine-state.check b/tests/run/ghost-machine-state.check similarity index 100% rename from tests/run/unused-machine-state.check rename to tests/run/ghost-machine-state.check diff --git a/tests/run/unused-machine-state.scala b/tests/run/ghost-machine-state.scala similarity index 89% rename from tests/run/unused-machine-state.scala rename to tests/run/ghost-machine-state.scala index eba84ddeab38..749c35c7eeda 100644 --- a/tests/run/unused-machine-state.scala +++ b/tests/run/ghost-machine-state.scala @@ -23,11 +23,11 @@ object IsOn { } class Machine[S <: State] private { - def turnedOn(implicit unused s: IsOff[S]): Machine[On] = { + def turnedOn(implicit ghost s: IsOff[S]): Machine[On] = { println("turnedOn") new Machine[On] } - def turnedOff(implicit unused s: IsOn[S]): Machine[Off] = { + def turnedOff(implicit ghost s: IsOn[S]): Machine[Off] = { println("turnedOff") new Machine[Off] } diff --git a/tests/run/unused-poly-ref.check b/tests/run/ghost-poly-ref.check similarity index 100% rename from tests/run/unused-poly-ref.check rename to tests/run/ghost-poly-ref.check diff --git a/tests/run/unused-poly-ref.scala b/tests/run/ghost-poly-ref.scala similarity index 58% rename from tests/run/unused-poly-ref.scala rename to tests/run/ghost-poly-ref.scala index 3598d5c9bca0..ec3302227d56 100644 --- a/tests/run/unused-poly-ref.scala +++ b/tests/run/ghost-poly-ref.scala @@ -4,9 +4,9 @@ object Test { fun(foo(bar(5))(bar(6))) } - def fun(unused a: Int): Unit = println("fun") + def fun(ghost a: Int): Unit = println("fun") - def foo[P](unused x: Int)(unused y: Int): Int = 0 + def foo[P](ghost x: Int)(ghost y: Int): Int = 0 def bar(x: Int) = { println(x) diff --git a/tests/run/unused-select-prefix.check b/tests/run/ghost-select-prefix.check similarity index 100% rename from tests/run/unused-select-prefix.check rename to tests/run/ghost-select-prefix.check diff --git a/tests/run/unused-select-prefix.scala b/tests/run/ghost-select-prefix.scala similarity index 67% rename from tests/run/unused-select-prefix.scala rename to tests/run/ghost-select-prefix.scala index 2729383f6b12..0ab06f6d1cb1 100644 --- a/tests/run/unused-select-prefix.scala +++ b/tests/run/ghost-select-prefix.scala @@ -25,11 +25,11 @@ object Test { () } - def bar(unused i: Int): Unit = () + def bar(ghost i: Int): Unit = () - unused def foo0: Int = 0 - unused def foo1(): Int = 1 - unused def foo2[T]: Int = 2 - unused def foo3[T](): Int = 3 + ghost def foo0: Int = 0 + ghost def foo1(): Int = 1 + ghost def foo2[T]: Int = 2 + ghost def foo3[T](): Int = 3 } diff --git a/tests/run/unused-value-class.check b/tests/run/ghost-value-class.check similarity index 100% rename from tests/run/unused-value-class.check rename to tests/run/ghost-value-class.check diff --git a/tests/run/unused-value-class.scala b/tests/run/ghost-value-class.scala similarity index 78% rename from tests/run/unused-value-class.scala rename to tests/run/ghost-value-class.scala index 0bd3377194d0..6acb8063c6a2 100644 --- a/tests/run/unused-value-class.scala +++ b/tests/run/ghost-value-class.scala @@ -11,6 +11,6 @@ object Test { } } -class Bar(x: Int)(unused y: Int) extends AnyVal { +class Bar(x: Int)(ghost y: Int) extends AnyVal { def foo() = x } diff --git a/tests/run/phantom-OnHList.scala b/tests/run/phantom-OnHList.scala index 71ddee870dff..59b29dff2a8d 100644 --- a/tests/run/phantom-OnHList.scala +++ b/tests/run/phantom-OnHList.scala @@ -77,7 +77,7 @@ trait Appender[L1 <: HList, L2 <: HList] { } object Appender { - implicit def lowLevelAppender[L1 <: HList, L2 <: HList, O <: HList](implicit unused p: PhantomAppender.Aux[L1, L2, O]): Appender[L1, L2] { type Out = O } = + implicit def lowLevelAppender[L1 <: HList, L2 <: HList, O <: HList](implicit ghost p: PhantomAppender.Aux[L1, L2, O]): Appender[L1, L2] { type Out = O } = new Appender[L1, L2] { type Out = O def apply(l1: L1, l2: L2): Out = HListN(Array.concat(l1.underlying, l2.underlying)).asInstanceOf[O] @@ -88,6 +88,6 @@ object Appender { object PhantomAppender { type Aux[L1 <: HList, L2 <: HList, O <: HList] - implicit unused def caseHNil[L <: HList]: Aux[HNil, L, L] = ??? - implicit unused def caseHCons[H, T <: HList, L <: HList, O <: HList](implicit unused p: Aux[T, L, O]): Aux[H :: T, L, H :: O] = ??? + implicit ghost def caseHNil[L <: HList]: Aux[HNil, L, L] = ??? + implicit ghost def caseHCons[H, T <: HList, L <: HList, O <: HList](implicit ghost p: Aux[T, L, O]): Aux[H :: T, L, H :: O] = ??? } diff --git a/tests/run/t7711-script-args.script b/tests/run/t7711-script-args.script index 19b7a7492423..0c76747a0ac4 100644 --- a/tests/run/t7711-script-args.script +++ b/tests/run/t7711-script-args.script @@ -5,7 +5,7 @@ exec ${SCALA_HOME}/bin/scala "$0" "$@" 2>&1 Console println s"Hello, scripted test!" Console println s"What ${args mkString " "} have you for me today?" -//def unused = 88 +//def ghost = 88 //newSource1.scala:8: warning: private method in <$anon: AnyRef> is never used //Console println s"Hello, $argv, are you still here?" //newSource1.scala:9: error: not found: value argv diff --git a/tests/run/unused-23.scala b/tests/run/unused-23.scala deleted file mode 100644 index e65e2f072a42..000000000000 --- a/tests/run/unused-23.scala +++ /dev/null @@ -1,22 +0,0 @@ -object Test { - - def main(args: Array[String]): Unit = { - fun { implicit unused (x: Int) => - println("lambda1") - "abc" - } - - fun2 { unused implicit (x: Int) => - println("lambda2") - "abc" - } - } - - def fun(f: implicit unused Int => String): String = { - f(35) - } - - def fun2(f: unused implicit Int => String): String = { - f(36) - } -}