Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions library/src/scala/compiletime/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import annotation.{compileTimeOnly, experimental}
* @syntax markdown
*
* @tparam T the type to match against in an inline match expression
*
* @return a value of type `T` usable only as the scrutinee of an inline match; it is never evaluated at runtime
*/
def erasedValue[T]: T = erasedValue[T]

Expand Down Expand Up @@ -139,6 +141,7 @@ inline def requireConst(inline x: Boolean | Byte | Short | Int | Long | Float |
* that value wrapped in `Some`.
*
* @tparam T the constant singleton type to attempt to convert to a value
* @return `Some` wrapping the constant value if one can be constructed from `T`, or `None` otherwise
*/
transparent inline def constValueOpt[T]: Option[T] =
// implemented in dotty.tools.dotc.typer.Inliner
Expand All @@ -148,6 +151,7 @@ transparent inline def constValueOpt[T]: Option[T] =
* of the same singleton type. For example: `assert(constValue[1] == 1)`.
*
* @tparam T the constant singleton type to convert to a value
* @return the value corresponding to the constant singleton type `T`
*/
transparent inline def constValue[T]: T =
// implemented in dotty.tools.dotc.typer.Inliner
Expand All @@ -157,6 +161,7 @@ transparent inline def constValue[T]: T =
* `(constValue[X1], ..., constValue[Xn])`.
*
* @tparam T the tuple type whose element types are constant singleton types
* @return a tuple containing the values corresponding to each constant singleton element type of `T`
*/
inline def constValueTuple[T <: Tuple]: T =
// implemented in dotty.tools.dotc.typer.Inliner
Expand Down Expand Up @@ -218,6 +223,7 @@ inline def summonAll[T <: Tuple]: T =
*
* @tparam T the result type of the by-name argument
* @param x the by-name argument to evaluate
* @return the result of evaluating the by-name argument `x`
*/
def byName[T](x: => T): T = x

Expand Down
6 changes: 6 additions & 0 deletions library/src/scala/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ object Expr {
* @tparam T the type of the final expression, which determines the block's result type
* @param statements the statements to execute before the final expression in the block
* @param expr the final expression whose value becomes the result of the block
* @return an expression of type `T` representing a block of the given `statements` followed by `expr`, equivalent to `'{ $s1; $s2; ...; $expr }`
*/
def block[T](statements: List[Expr[Any]], expr: Expr[T])(using Quotes): Expr[T] = {
import quotes.reflect.*
Expand All @@ -81,6 +82,7 @@ object Expr {
*
* @tparam T the type of the value to be lifted into an expression
* @param x the value to lift into a quoted expression
* @return an expression that, when spliced, will construct the value `x`
*/
def apply[T](x: T)(using ToExpr[T])(using Quotes): Expr[T] =
scala.Predef.summon[ToExpr[T]].apply(x)
Expand Down Expand Up @@ -294,6 +296,8 @@ object Expr {
/** Given a tuple of the form `(Expr[A1], ..., Expr[An])`, outputs a tuple `Expr[(A1, ..., An)]`.
*
* @tparam T the tuple type where each element is wrapped in `Expr`, e.g., `(Expr[A1], ..., Expr[An])`
* @param tup the tuple of expressions to combine into a single tuple expression
* @return an expression representing the tuple `(A1, ..., An)` constructed from the given element expressions
*/
def ofTuple[T <: Tuple: Tuple.IsMappedBy[Expr]: Type](tup: T)(using Quotes): Expr[Tuple.InverseMap[T, Expr]] = {
val elems: Seq[Expr[Any]] = tup.asInstanceOf[Product].productIterator.toSeq.asInstanceOf[Seq[Expr[Any]]]
Expand All @@ -305,6 +309,7 @@ object Expr {
* `None` if implicit resolution failed.
*
* @tparam T type of the implicit parameter
* @return `Some` containing the found implicit expression, or `None` if implicit resolution failed
*/
def summon[T](using Type[T])(using Quotes): Option[Expr[T]] = {
import quotes.reflect.*
Expand All @@ -321,6 +326,7 @@ object Expr {
*
* @tparam T type of the implicit parameter
* @param ignored Symbols ignored during the initial implicit search
* @param quotes the `Quotes` context used for the implicit search, named so that `ignored` can refer to its path-dependent `reflect.Symbol` type
* @return `Some` containing the found implicit expression, or `None` if implicit resolution failed
*
* @note if the found given requires additional search for other given instances,
Expand Down
2 changes: 2 additions & 0 deletions library/src/scala/quoted/ExprMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ trait ExprMap:
*
* @tparam T the type of the expression being transformed
* @param e the expression to transform
* @return the transformed expression of type `T`
*/
def transform[T](e: Expr[T])(using Type[T])(using Quotes): Expr[T]

Expand All @@ -19,6 +20,7 @@ trait ExprMap:
*
* @tparam T the type of the expression whose children are transformed
* @param e the expression whose direct sub-expressions will be transformed via `transform`
* @return an expression of type `T` with each direct sub-expression replaced by the result of applying `transform` to it
*/
def transformChildren[T](e: Expr[T])(using Type[T])(using Quotes): Expr[T] = {
import quotes.reflect.*
Expand Down
Loading
Loading