#[non_exhaustive]pub enum Arch<K> {
Show 98 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>,
},
UseTree {
path: Pick<K>,
alias: Pick<K>,
children: 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>,
rules: Pick<K>,
},
MixinRule {
from: Pick<K>,
method: Pick<K>,
insteadof: Pick<K>,
alias: 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 {
key: Pick<K>,
value: Pick<K>,
},
YieldFrom {
inner: Pick<K>,
},
Spawn {
inner: Pick<K>,
},
Closure {
params: Pick<K>,
ret: Pick<K>,
captures: Pick<K>,
body: Pick<K>,
implicit: Option<CaptureMode>,
},
Template(TemplateUse),
Interp {
parts: Pick<K>,
close: Pick<K>,
join: Join,
},
Attr {
name: Pick<K>,
args: Pick<K>,
},
AttrArg {
key: Pick<K>,
value: Pick<K>,
},
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>,
},
UnionTy {
members: Pick<K>,
},
IntersectionTy {
members: 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
mutable: boolWhether the binders are mutable without a Mut modifier (var,
JavaScript let) rather than only with one (let / let mut).
hoist: boolFunction-scoped hoisting (JavaScript var): the name is declared
once at the top of the enclosing function (or module body) and this
statement becomes an assignment. Any other pattern (var [a, b] = x) binds hygienic temporaries that are assigned to the hoisted
names right after it matches; a by-reference binding cannot be
hoisted this way and is reported
(CannotHoist).
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
UseTree
A use tree: use a::{b, c::{d, e as f}, g::*}; (Rust), use App\{Foo, Bar as Baz}; (PHP group use). Flattened into one HIR import per leaf,
each path the concatenation of the prefixes above it. Modifiers:
visibility (on the outermost tree, for every import it makes), Glob
(a * leaf).
The expected tree: a use-tree node holds an optional prefix path (a
path node or one name), then either nested children (use-tree nodes,
names, or paths; container nodes such as { ... } splice) or, for a
leaf, an optional alias. A child spelled self (a token in the
root table mapping to
PathRoot::SelfModule) imports the prefix itself. Leading root tokens
of the outermost prefix (::, crate, super) set the import’s root.
The walk is iterative; nesting depth is bounded only by the tree.
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 { rules }).
Fields
MixinRule
One rule of a mixin use: T::hello insteadof U, V; or
T::hello as protected greet; / hello as private;. With
insteadof types it is an exclusion; otherwise an alias, with a new
name, a visibility modifier (Public, Protected, Private), or both.
A rule with neither is reported (MissingField
action).
Fields
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, or yield k => v (PHP and Mox generators). A key without
a value yields null under that key.
YieldFrom
yield from g: delegate to an inner generator or iterable; evaluates
to its return value.
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.
Interp
An interpolated string: "Hello {$name}!", "$name", "{$a['k']}",
and heredocs, as the lexer delivers them in segments.
The expected tree: the string’s node holds its pieces in order. Text
pieces are tokens with role TokenRole::StrPart
(no quotes; escapes decoded, adjacent pieces merged); every other
selected element is an embedded expression ($name as a variable
token, {$a['k']} as an index node; braces and quotes are skip kinds
or left out by the parts pick). The parts are joined by join:
one text piece alone is a string literal, no pieces the empty string,
and a lone expression is joined with an empty string first, so the
result is always a string conversion.
With close (a heredoc), close picks the closing-marker token: the
whitespace before its identifier is removed from the start of every
line of the text pieces (PHP 7.3+), a line indented less (or starting
with an embedded expression) is reported
(InvalidLiteral), and the
newline before the marker is dropped.
Fields
Attr
An attribute (#[Route("/home", methods: GET)], @inline), attached
to the node it is a direct child of. Attribute nodes (and container
nodes holding them, such as PHP’s #[A, B] group) are invisible to
every other pick of that node. HIR attributes are data, never code
(HIR spec §11): an argument value must be a literal or a name; anything
else is reported
(AttributeArgument) and left
out.
Fields
AttrArg
key: value / key = value inside an attribute’s arguments.
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.
UnionTy
A | B | C (PHP union types). Members are lowered in source order;
hir-lang’s finish puts them in canonical form (flattened, sorted,
repeats dropped, null hoisted into Nullable, one member
collapsed). No members at all is a
MissingField problem.
IntersectionTy
A & B (PHP intersection types), normalized like
UnionTy.
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));Sourcepub const fn prefix() -> Self
pub const fn prefix() -> Self
The shape of lang-forge’s prefix nodes: op operand.
§Examples
use lower_lang::{Arch, Pick};
let Arch::Unary { operand, .. } = Arch::<u8>::prefix() else { unreachable!() };
assert_eq!(operand, Pick::Nth(1));Sourcepub const fn name(&self) -> &'static str
pub const fn name(&self) -> &'static str
The archetype’s name, as problems and docs spell it.
§Examples
use lower_lang::Arch;
assert_eq!(Arch::<u8>::binary().name(), "binary");
assert_eq!(Arch::<u8>::WildPat.name(), "wildcard pattern");Sourcepub const fn lsf_name(&self) -> &'static str
pub const fn lsf_name(&self) -> &'static str
The archetype’s LSF2 name: the value of arch = "…" in
[semantics.bind] (LSF2 §15.4), and the key
MappingBuilder::modifier_in
takes. Archetypes LSF2 has no arch value for use the snake case of
the variant (mixin_rule, use_tree, attr_arg, template).
§Examples
use lower_lang::{Arch, Pick};
let param: Arch<u8> = Arch::Param { pat: Pick::Nth(0), ty: Pick::Absent, default: Pick::Absent };
assert_eq!(param.lsf_name(), "param");
assert_eq!(Arch::<u8>::binary().lsf_name(), "binary");