From 29892586382ef846b0ad46271c2fba9970943faf Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 30 Jan 2013 17:21:38 +0100 Subject: SI-6539 moves @compileTimeOnly away from scala-reflect The move is done to provide forward compatibility with 2.10.0. The annotation isn't replaced with one of the macro-based solutions right away (see comments for more information about those), because we lack necessary tech in 2.10.x. --- src/reflect/scala/reflect/api/Exprs.scala | 2 ++ .../scala/reflect/internal/Definitions.scala | 2 +- .../internal/annotations/compileTimeOnly.scala | 31 ++++++++++++++++++++++ .../scala/reflect/macros/compileTimeOnly.scala | 16 ----------- 4 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 src/reflect/scala/reflect/internal/annotations/compileTimeOnly.scala delete mode 100644 src/reflect/scala/reflect/macros/compileTimeOnly.scala (limited to 'src') diff --git a/src/reflect/scala/reflect/api/Exprs.scala b/src/reflect/scala/reflect/api/Exprs.scala index 562b1da8e3..2ba18a8207 100644 --- a/src/reflect/scala/reflect/api/Exprs.scala +++ b/src/reflect/scala/reflect/api/Exprs.scala @@ -90,6 +90,7 @@ trait Exprs { self: Universe => * }}} * because expr of type Expr[T] itself does not have a method foo. */ + // @compileTimeOnly("Cannot use splice outside reify") def splice: T /** @@ -106,6 +107,7 @@ trait Exprs { self: Universe => * object Impls { def foo_impl(c: Context)(x: c.Expr[X]): c.Expr[x.value.T] = ... } * }}} */ + // @compileTimeOnly("Cannot use value except for signatures of macro implementations") val value: T override def canEqual(x: Any) = x.isInstanceOf[Expr[_]] diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala index 4269b65297..3806f555ac 100644 --- a/src/reflect/scala/reflect/internal/Definitions.scala +++ b/src/reflect/scala/reflect/internal/Definitions.scala @@ -949,7 +949,7 @@ trait Definitions extends api.StandardDefinitions { lazy val BeanPropertyAttr = requiredClass[scala.beans.BeanProperty] lazy val BooleanBeanPropertyAttr = requiredClass[scala.beans.BooleanBeanProperty] lazy val CloneableAttr = requiredClass[scala.annotation.cloneable] - lazy val CompileTimeOnlyAttr = getClassIfDefined("scala.reflect.macros.compileTimeOnly") + lazy val CompileTimeOnlyAttr = getClassIfDefined("scala.reflect.internal.annotations.compileTimeOnly") lazy val DeprecatedAttr = requiredClass[scala.deprecated] lazy val DeprecatedNameAttr = requiredClass[scala.deprecatedName] lazy val DeprecatedInheritanceAttr = requiredClass[scala.deprecatedInheritance] diff --git a/src/reflect/scala/reflect/internal/annotations/compileTimeOnly.scala b/src/reflect/scala/reflect/internal/annotations/compileTimeOnly.scala new file mode 100644 index 0000000000..058ff61fbf --- /dev/null +++ b/src/reflect/scala/reflect/internal/annotations/compileTimeOnly.scala @@ -0,0 +1,31 @@ +package scala.reflect +package internal +package annotations + +import scala.annotation.meta._ + +/** + * An annotation that designates a member should not be referred to after + * type checking (which includes macro expansion); it must only be used in + * the arguments of some other macro that will eliminate it from the AST. + * + * Later on, this annotation should be removed and implemented with domain-specific macros. + * If a certain method `inner` mustn't be called outside the context of a given macro `outer`, + * then it should itself be declared as a macro. + * + * Approach #1. Expansion of `inner` checks whether its enclosures contain `outer` and + * report an error if `outer` is not detected. In principle, we could use this approach right now, + * but currently enclosures are broken, because contexts aren't exactly famous for keeping precise + * track of the stack of the trees being typechecked. + * + * Approach #2. Default implementation of `inner` is just an invocation of `c.abort`. + * `outer` is an untyped macro, which expands into a block, which contains a redefinition of `inner` + * and a call to itself. The redefined `inner` could either be a stub like `Expr.splice` or carry out + * domain-specific logic. + * + * @param message the error message to print during compilation if a reference remains + * after type checking + * @since 2.10.1 + */ +@getter @setter @beanGetter @beanSetter +final class compileTimeOnly(message: String) extends scala.annotation.StaticAnnotation diff --git a/src/reflect/scala/reflect/macros/compileTimeOnly.scala b/src/reflect/scala/reflect/macros/compileTimeOnly.scala deleted file mode 100644 index 5a3a352a53..0000000000 --- a/src/reflect/scala/reflect/macros/compileTimeOnly.scala +++ /dev/null @@ -1,16 +0,0 @@ -package scala.reflect -package macros - -import scala.annotation.meta._ - -/** - * An annotation that designates a member should not be referred to after - * type checking (which includes macro expansion); it must only be used in - * the arguments of some other macro that will eliminate it from the AST. - * - * @param message the error message to print during compilation if a reference remains - * after type checking - * @since 2.10.1 - */ -@getter @setter @beanGetter @beanSetter -final class compileTimeOnly(message: String) extends scala.annotation.StaticAnnotation -- cgit v1.2.3