scala.quoted.runtime.impl

Members list

Concise view

Type members

Classlikes

final class ExprImpl(val tree: Tree, val scope: Scope) extends Expr[Any]

An Expr backed by a tree. Only the current compiler trees are allowed.

An Expr backed by a tree. Only the current compiler trees are allowed.

These expressions are used for arguments of macros. They contain and actual tree from the program that is being expanded by the macro.

May contain references to code defined outside this Expr instance.

Attributes

Graph
Supertypes
class Expr[Any]
class Object
trait Matchable
class Any
object NoScope extends Scope

Only used for outer scope of top level splice and staging run

Only used for outer scope of top level splice and staging run

Attributes

Graph
Supertypes
trait Scope
class Object
trait Matchable
class Any
Self type
NoScope.type

Matches a quoted tree against a quoted pattern tree. A quoted pattern tree may have type and term holes in addition to normal terms.

Matches a quoted tree against a quoted pattern tree. A quoted pattern tree may have type and term holes in addition to normal terms.

Semantics:

We use '{..} for expression, '[..] for types and ⟨..⟩ for patterns nested in expressions. The semantics are defined as a list of reduction rules that are tried one by one until one matches.

Operations:

  • s =?= p checks if a scrutinee s matches the pattern p while accumulating extracted parts of the code.
  • isClosedUnder(x1, .., xn)('{e}) returns true if and only if all the references in e to names defined in the pattern are contained in the set {x1, ... xn}.
  • lift(x1, .., xn)('{e}) returns (y1, ..., yn) => [xi = $yi]'{e} where yi is an Expr of the type of xi.
  • withEnv(x1 -> y1, ..., xn -> yn)(matching) evaluates matching recording that xi is equivalent to yi.
  • matched denotes that the the match succeeded and matched('{e}) denotes that a match succeeded and extracts '{e}
  • &&& matches if both sides match. Concatenates the extracted expressions of both sides.

Note: that not all quoted terms bellow are valid expressions

/* Term hole */
 '{ e } =?= '{ hole[T] }  &&  typeOf('{e}) <:< T && isClosedUnder()('{e})  ===>   matched('{e})

 /* Higher order term hole */
 '{ e } =?= '{ hole[(T1, ..., Tn) => T](x1, ..., xn) }  &&  isClosedUnder(x1, ... xn)('{e})  ===>   matched(lift(x1, ..., xn)('{e}))

 /* Match literal */
 '{ lit } =?= '{ lit }   ===>   matched

 /* Match type ascription (a) */
 '{ e: T } =?= '{ p }   ===>   '{e} =?= '{p}

 /* Match type ascription (b) */
 '{ e } =?= '{ p: P }   ===>   '{e} =?= '{p}

 /* Match selection */
 '{ e.x } =?= '{ p.x }   ===>   '{e} =?= '{p}

 /* Match reference */
 '{ x } =?= '{ x }   ===>   matched

 /* Match application */
 '{e0(e1, ..., en)} =?= '{p0(p1, ..., p2)}   ===>   '{e0} =?= '{p0} &&& '{e1} =?= '{p1} &&& ... %% '{en} =?= '{pn}

 /* Match type application */
 '{e[T1, ..., Tn]} =?= '{p[P1, ..., Pn]}   ===>   '{e} =?= '{p} &&& '[T1] =?= '{P1} &&& ... %% '[Tn] =?= '[Pn]

 /* Match block flattening */
 '{ {e0; e1; ...; en}; em } =?= '{ {p0; p1; ...; pm}; em }   ===>   '{ e0; {e1; ...; en; em} } =?= '{ p0; {p1; ...; pm; em} }

 /* Match block */
 '{ e1; e2 } =?= '{ p1; p2 }   ===>   '{e1} =?= '{p1} &&& '{e2} =?= '{p2}

 /* Match def block */
 '{ e1; e2 } =?= '{ p1; p2 }   ===>   withEnv(symOf(e1) -> symOf(p1))('{e1} =?= '{p1} &&& '{e2} =?= '{p2})

 /* Match if */
 '{ if e0 then e1 else e2 } =?= '{ if p0 then p1 else p2 }   ===>  '{e0} =?= '{p0} &&& '{e1} =?= '{p1} &&& '{e2} =?= '{p2}

 /* Match while */
 '{ while e0 do e1 } =?= '{ while p0 do p1 }   ===>  '{e0} =?= '{p0} &&& '{e1} =?= '{p1}

 /* Match assign */
 '{ e0 = e1 } =?= '{ p0 = p1 }   ==>   '{e0} =?= '{p0} &&& '{e1} =?= '{p1}

 /* Match new */
 '{ new T } =?= '{ new T }   ===>   matched

 /* Match this */
 '{ C.this } =?= '{ C.this }   ===>   matched

 /* Match super */
 '{ e.super } =?= '{ p.super }   ===>   '{e} =?= '{p}

 /* Match varargs */
 '{ e: _* } =?= '{ p: _* }   ===>   '{e} =?= '{p}

 /* Match val */
 '{ val x: T = e1; e2 } =?= '{ val y: P = p1; p2 }   ===>   withEnv(x -> y)('[T] =?= '[P] &&& '{e1} =?= '{p1} &&& '{e2} =?= '{p2})

 /* Match def */
 '{ def x0(x1: T1, ..., xn: Tn): T0 = e1; e2 } =?= '{ def y0(y1: P1, ..., yn: Pn): P0 = p1; p2 }   ===>   withEnv(x0 -> y0, ..., xn -> yn)('[T0] =?= '[P0] &&& ... &&& '[Tn] =?= '[Pn] &&& '{e1} =?= '{p1} &&& '{e2} =?= '{p2})

 // Types

 /* Match type */
 '[T] =?= '[P] && T <:< P   ===>   matched

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
object QuotesImpl

Attributes

Companion:
class
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
class QuotesImpl extends Quotes with QuoteUnpickler with QuoteMatching

Attributes

Companion:
object
Graph
Supertypes
trait QuoteMatching
trait QuoteUnpickler
trait Quotes
class Object
trait Matchable
class Any
trait Scope

A scope uniquely identifies the context for evaluating a splice

A scope uniquely identifies the context for evaluating a splice

A nested splice gets a new scope with the enclosing scope as its outer. This also applies for recursive splices.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object NoScope.type
class ScopeException(msg: String) extends Exception

Attributes

Companion:
object
Graph
Supertypes
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any

Attributes

Companion:
class
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
class SpliceScope(val pos: SourcePosition, val outer: Scope) extends Scope

Attributes

Companion:
object
Graph
Supertypes
trait Scope
class Object
trait Matchable
class Any

Attributes

Companion:
class
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
final class TypeImpl(val typeTree: Tree, val scope: Scope) extends Type[Nothing]

Quoted type (or kind) T backed by a tree

Quoted type (or kind) T backed by a tree

Attributes

Graph
Supertypes
class Type[Nothing]
class Object
trait Matchable
class Any