#[non_exhaustive]pub enum Arch<K> {
Show 90 variants
Module {
name: Pick<K>,
items: Pick<K>,
},
Pass {
inner: Pick<K>,
},
Splice {
items: Pick<K>,
},
Unsupported,
Let {
pat: Pick<K>,
ty: Pick<K>,
init: Pick<K>,
else_: Pick<K>,
mutable: bool,
hoist: bool,
},
ExprStmt {
expr: Pick<K>,
},
Defer {
body: Pick<K>,
},
Static {
name: Pick<K>,
ty: Pick<K>,
init: Pick<K>,
},
GlobalDecl {
names: Pick<K>,
},
Import {
path: Pick<K>,
alias: Pick<K>,
},
Fn {
name: Pick<K>,
generics: Pick<K>,
params: Pick<K>,
ret: Pick<K>,
throws: Pick<K>,
body: Pick<K>,
where_: Pick<K>,
},
Record {
name: Pick<K>,
generics: Pick<K>,
fields: Pick<K>,
shape: RecordShape,
},
Sum {
name: Pick<K>,
generics: Pick<K>,
variants: Pick<K>,
},
Interface {
name: Pick<K>,
generics: Pick<K>,
supers: Pick<K>,
items: Pick<K>,
},
Class {
name: Pick<K>,
generics: Pick<K>,
bases: Pick<K>,
interfaces: Pick<K>,
members: Pick<K>,
mixin: bool,
},
Impl {
generics: Pick<K>,
interface: Pick<K>,
self_ty: Pick<K>,
items: Pick<K>,
},
Alias {
name: Pick<K>,
generics: Pick<K>,
ty: Pick<K>,
},
AssocType {
name: Pick<K>,
bounds: Pick<K>,
default: Pick<K>,
},
Const {
name: Pick<K>,
ty: Pick<K>,
value: Pick<K>,
},
GlobalVar {
name: Pick<K>,
ty: Pick<K>,
init: Pick<K>,
mutable: bool,
},
MixinUse {
mixins: Pick<K>,
},
FieldDecl {
name: Pick<K>,
ty: Pick<K>,
default: Pick<K>,
},
VariantDecl {
name: Pick<K>,
fields: Pick<K>,
discriminant: Pick<K>,
shape: RecordShape,
},
GenericParam {
name: Pick<K>,
bounds: Pick<K>,
ty: Pick<K>,
default: Pick<K>,
},
WherePred {
subject: Pick<K>,
bounds: Pick<K>,
},
Param {
pat: Pick<K>,
ty: Pick<K>,
default: Pick<K>,
},
Capture {
name: Pick<K>,
},
Path {
segments: Pick<K>,
global: Pick<K>,
qself: Pick<K>,
qtrait: Pick<K>,
},
Segment {
name: Pick<K>,
args: Pick<K>,
},
AssocBinding {
name: Pick<K>,
ty: Pick<K>,
},
Unary {
op: Pick<K>,
operand: Pick<K>,
},
Binary {
lhs: Pick<K>,
op: Pick<K>,
rhs: Pick<K>,
},
Postfix {
operand: Pick<K>,
op: Pick<K>,
},
Assign {
target: Pick<K>,
op: Pick<K>,
value: Pick<K>,
},
RefAssign {
target: Pick<K>,
source: Pick<K>,
},
Call {
callee: Pick<K>,
args: Pick<K>,
},
Arg {
name: Pick<K>,
value: Pick<K>,
},
Member {
base: Pick<K>,
member: Pick<K>,
args: Pick<K>,
call: Pick<K>,
},
MethodCall {
receiver: Pick<K>,
method: Pick<K>,
generics: Pick<K>,
args: Pick<K>,
},
DynMember {
base: Pick<K>,
name: Pick<K>,
args: Pick<K>,
call: Pick<K>,
},
Index {
base: Pick<K>,
index: Pick<K>,
},
VarVar {
inner: Pick<K>,
},
Append {
base: Pick<K>,
},
Tuple {
elems: Pick<K>,
},
Array {
elems: Pick<K>,
},
Map {
entries: Pick<K>,
},
MapEntry {
key: Pick<K>,
value: Pick<K>,
},
RecordLit {
path: Pick<K>,
fields: Pick<K>,
base: Pick<K>,
},
FieldInit {
name: Pick<K>,
value: Pick<K>,
},
Repeat {
elem: Pick<K>,
count: Pick<K>,
},
Cast {
expr: Pick<K>,
ty: Pick<K>,
},
Borrow {
expr: Pick<K>,
},
Deref {
inner: Pick<K>,
},
Block {
stmts: Pick<K>,
tail: Pick<K>,
label: Pick<K>,
tail_from_last: bool,
},
If {
cond: Pick<K>,
then: Pick<K>,
else_: Pick<K>,
},
Match {
scrutinee: Pick<K>,
arms: Pick<K>,
},
Arm {
pat: Pick<K>,
guard: Pick<K>,
body: Pick<K>,
},
Loop {
label: Pick<K>,
body: Pick<K>,
},
Break {
label: Pick<K>,
value: Pick<K>,
},
Continue {
label: Pick<K>,
},
Return {
value: Pick<K>,
},
Throw {
value: Pick<K>,
},
Try {
body: Pick<K>,
catches: Pick<K>,
finally: Pick<K>,
},
Catch {
types: Pick<K>,
name: Pick<K>,
body: Pick<K>,
},
Await {
inner: Pick<K>,
},
Yield {
value: Pick<K>,
},
Spawn {
inner: Pick<K>,
},
Closure {
params: Pick<K>,
ret: Pick<K>,
captures: Pick<K>,
body: Pick<K>,
implicit: Option<CaptureMode>,
},
Template(TemplateUse),
WildPat,
RestPat {
bind: Pick<K>,
},
BindPat {
name: Pick<K>,
sub: Pick<K>,
},
TuplePat {
elems: Pick<K>,
},
CtorPat {
path: Pick<K>,
elems: Pick<K>,
},
RecordPat {
path: Pick<K>,
fields: Pick<K>,
},
FieldPat {
name: Pick<K>,
pat: Pick<K>,
},
OrPat {
alts: Pick<K>,
},
RangePat {
lo: Pick<K>,
hi: Pick<K>,
},
RefPat {
inner: Pick<K>,
},
SlicePat {
elems: Pick<K>,
},
TypeTestPat {
ty: Pick<K>,
pat: Pick<K>,
},
TupleTy {
elems: Pick<K>,
},
ArrayTy {
elem: Pick<K>,
len: Pick<K>,
},
SliceTy {
elem: Pick<K>,
},
RefTy {
inner: Pick<K>,
region: Pick<K>,
},
PtrTy {
inner: Pick<K>,
},
NullableTy {
inner: Pick<K>,
},
FnTy {
params: Pick<K>,
ret: Pick<K>,
},
ObjectTy {
bounds: Pick<K>,
},
ImplTy {
bounds: Pick<K>,
},
}Expand description
A semantic archetype: what a syntax node means, and where its parts are.
A Mapping maps node kinds to archetypes. Lowering a node
lowers each field in the context the archetype gives it (an If’s cond
as an expression, a Fn’s params as parameters) and builds the HIR form.
Fields marked required that a node lacks become error nodes plus a
MissingField problem; the others are
simply left out. List fields take every match of their pick.
The modifiers each archetype reads from its direct children are listed
with it (see Modifier).
§Examples
use lower_lang::{Arch, Pick};
// `if COND BLOCK (else (if_expr | BLOCK))?` with no field labels:
let if_expr: Arch<u16> = Arch::If {
cond: Pick::NthNode(0),
then: Pick::NthNode(1),
else_: Pick::NthNode(2),
};
assert!(matches!(if_expr, Arch::If { .. }));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Module
A module: the root of a file, or a nested module. Declarations among
items become the module’s items; everything else (statements and
expressions) becomes its top-level body, in order (scripts, REPL
entries, conditional definitions).
Fields
Pass
A wrapper with one meaningful child (expr, a parenthesized group, a
statement wrapper): lowered as that child, in the same context.
Splice
Several statements, items, or class members from one node
(let a = 1, b = 2;), spliced into the enclosing list.
Unsupported
A construct the language has but does not lower yet: an error node
plus an Unsupported problem.
Let
let PAT: TY = INIT else ELSE; — binds the pattern’s names for the
following statements. Modifiers: Mut makes the binders mutable.
Fields
ExprStmt
EXPR; — an expression evaluated for its effect (never a block tail).
Defer
defer BODY — runs when the enclosing block exits.
Static
static $x = INIT; — a function-static variable (PHP, C).
Fields
GlobalDecl
global $a, $b; — locals aliasing globals, one statement per name.
Import
use a::b as c; / use a::*; — an import item. Modifiers: Glob.
Fields
Fn
A function. Modifiers: visibility, Async, Generator, Throws,
Unsafe. In a class, interface, or impl it is a method.
Fields
Record
A record (struct) or union. Modifiers: visibility, Union.
Fields
shape: RecordShapeHow the field layout is decided.
Sum
A sum (enum) with variants. Modifiers: visibility.
Fields
Interface
An interface or trait. Modifiers: visibility.
Fields
Class
A class. Modifiers: visibility, Abstract, Final.
Fields
Impl
An implementation block (impl Tr for T { ... }).
Fields
Alias
A type alias. Modifiers: visibility.
Fields
AssocType
An associated type declared by an interface.
Fields
Const
A compile-time constant. Modifiers: visibility.
Fields
GlobalVar
A global or static variable item. Modifiers: visibility, Mut.
Fields
MixinUse
A mixin use inside a class (PHP use T, U;).
FieldDecl
A field of a record, variant, or class. Modifiers: visibility; in a
class, Static makes it a static (global) member instead.
Fields
VariantDecl
A variant of a sum.
Fields
shape: RecordShapeHow the field layout is decided.
GenericParam
A generic parameter: a type parameter, a const parameter (with a type), or a region (a lifetime-role token).
Fields
WherePred
A where-clause predicate: T: A + B.
Param
A parameter. Modifiers: Ref (by reference, PHP &$x), Mut,
Rest (variadic), RestNamed, NamedOnly, PositionalOnly,
Receiver.
Fields
Capture
An explicit closure capture (PHP use ($x, &$y)). Modifiers: Ref,
Mut.
Path
A path: a::b::c, ::a, self::a, super::a, Self::a,
<T as Tr>::a. Leading tokens of segments whose kind is in the
mapping’s root table set the root.
Fields
Segment
A path segment with generic arguments (Vec::<i32>).
AssocBinding
An associated-type binding in generic arguments: Item = u8.
Unary
A prefix operator; the operator token’s kind is looked up in the prefix operator table.
Binary
A binary operator; the token’s kind is looked up in the binary
operator table. &&, ||, ??, assignment, and compound assignment
are operators too.
Fields
Postfix
A postfix operator; looked up in the postfix operator table.
Assign
TARGET = VALUE or TARGET op= VALUE; a compound operator token is
looked up in the binary operator table.
Fields
RefAssign
$a = &$b: reference assignment (PHP).
Fields
Call
A call.
Arg
A call argument: named (name: value), spread (...xs, modifier
Spread; **kw, modifier SpreadNamed), or a place (&$x, modifier
Ref). Plain expressions in an argument list need no archetype.
Member
Member access, or a method call when call finds something:
a.b, a.0, a.b(x).
Fields
MethodCall
A method call with explicit generic arguments: x.f::<T>(a).
Fields
DynMember
$o->$name / $o->$name(args): a member chosen at run time (Mox).
Fields
Index
base[index].
VarVar
$$name: the variable named at run time (Mox).
Append
$a[]: append position (Mox); only a write target.
Tuple
(a, b).
Array
[a, b].
Map
An ordered map literal: [k => v, w] (PHP arrays). Elements that are
not MapEntry nodes take the next index.
MapEntry
key => value inside a map literal.
RecordLit
Path { x: 1, ..base } or an anonymous record.
Fields
FieldInit
name: value (or the shorthand name) in a record literal.
Fields
Repeat
[elem; count].
Cast
expr as Type.
Borrow
&expr / &mut expr. Modifiers: Mut.
Deref
*expr.
Block
A block. Modifiers: Unsafe.
Fields
If
if cond then else.
Fields
Match
match scrutinee { arms }.
Arm
A match arm: pat if guard => body.
Fields
Loop
loop body — HIR’s one loop. while, do-while, C for, and
for-each are templates.
Break
break 'label value.
Continue
continue 'label.
Return
return value.
Throw
throw value.
Try
try body catch... finally....
Fields
Catch
catch (A | B $e) body: a type test (or an alternative of several)
binding name. Without types it catches everything.
Fields
Await
await e.
Yield
yield v.
Spawn
spawn e — starts a task running the callable e.
Closure
A closure. Modifiers: Async, Generator, Throws.
Fields
implicit: Option<CaptureMode>How outer variables are captured implicitly; None means only the
explicit captures are visible (PHP function () use (...)).
Template(TemplateUse)
A node lowered through a template; see
MappingBuilder::template_node.
WildPat
_ as a node.
RestPat
.. (or rest @ ..) inside a tuple, constructor, slice, or record
pattern.
BindPat
ref mut x @ sub. Modifiers: Ref, Mut.
TuplePat
(a, b, ..).
CtorPat
Some(x).
RecordPat
Point { x, y: 0, .. }.
Fields
FieldPat
name: pat (or the shorthand name) in a record pattern.
Fields
OrPat
a | b.
RangePat
lo..hi / lo..=hi. Modifiers: Inclusive.
RefPat
&p / &mut p. Modifiers: Mut.
SlicePat
[a, b, rest @ .., z].
TypeTestPat
e: Type / Type e — a type test, as in catch clauses.
TupleTy
(A, B).
ArrayTy
[T; N].
SliceTy
[T].
RefTy
&'r mut T. Modifiers: Mut.
PtrTy
*mut T / *const T. Modifiers: Mut.
NullableTy
T?.
FnTy
fn(A, B) -> R.
ObjectTy
dyn A + B.
ImplTy
impl A + B.
Implementations§
Source§impl<K> Arch<K>
impl<K> Arch<K>
Sourcepub const fn pass(n: u16) -> Self
pub const fn pass(n: u16) -> Self
Pass { inner: Nth(n) }: the common wrapper.
§Examples
use lower_lang::{Arch, Pick};
assert_eq!(Arch::<u8>::pass(1), Arch::Pass { inner: Pick::Nth(1) });Sourcepub const fn binary() -> Self
pub const fn binary() -> Self
The shape of lang-forge’s operator nodes: binary is lhs op rhs.
§Examples
use lower_lang::{Arch, Pick};
let Arch::Binary { op, .. } = Arch::<u8>::binary() else { unreachable!() };
assert_eq!(op, Pick::Nth(1));