rokdocs
v0.1

0.4. #[lang] slot mapping table

The #[lang(slot_name)] attribute (refs-lang 6.4) registers a standard library item in a slot that the compiler can look up. This chapter collects in one place, in tabular form, every slot name, its meaning, and the item it is attached to.

The slot table is the authoritative location in the spec; the compiler, the standard library and users all refer to it to stay consistent. If slot names drift, the contract between the language and the library breaks down, so any change starts from this table.

0.4.1. Slot classification

The 48 slots fall into four groups according to their responsibility. The table below shows the role and slot count of each group at a glance, indicating which category the detailed tables in the following sections belong to.

GroupResponsibilitySlots
TypeStandard library types rok recognizes as concrete types14
TraitTraits rok uses for operator / control-flow desugaring, derive, and thread-boundary checks30
MethodMethods rok calls automatically (drop)1
FunctionStandard library functions rok calls as intrinsic calls3
Total48

0.4.2. Type slots (14)

Type slots indicate the concrete type the compiler lowers to when it encounters a literal or keyword. This group divides further into two kinds. First, there are the language default types exposed directly as lowercase identifiers. They need no separate keyword registration and are the primitives users encounter every day.

Language defaults (lowercase struct, no #[keyword] needed):

Slot nameMeaningStandard library itemRef
i32_typei32 primitiverok::core::num::i322.1
i64_typei64 primitiverok::core::num::i642.1
f32_typef32 primitiverok::core::num::f322.1
f64_typef64 primitiverok::core::num::f642.1
usize_typeusize primitiverok::core::num::usize2.1
isize_typeisize primitiverok::core::num::isize2.1
bool_typebool primitiverok::core::num::bool2.1
cchar_typec_char primitive (FFI)rok::core::str::c_char2.15
str_typestr primitive (UTF-8 view)rok::core::str::str2.15
char_typechar primitive (Unicode scalar)char (methods: rok::core::str)2.15

Second, there are the PascalCase types additionally provided by the standard library. These expose a familiar lowercase alias to users separately via #[keyword(...)]; items directly entangled with language syntax gather here, such as the auto-promoting int and float, the none sentinel, and the Range literal.

Standard library additions (PascalCase struct + #[keyword(...)]):

Slot nameMeaningStandard library itemRef
none_typeType of the none literalrok::core::marker::NoneSentinel2.13
int_typeint auto-promote typerok::core::num::Int + #[keyword("int")]2.1
float_typefloat auto-promote typerok::core::num::Float + #[keyword("float")]2.1
range_typeRange<T> (a..b)rok::core::range::Range + #[literal( expr ".." expr )]2.7

A compiler that provides the primitive types built in may leave i32_type ... str_type, none_type and char_type unattached.

0.4.3. Trait slots (30)

Trait slots indicate which trait the compiler goes to when user-written syntax is desugared into a standard library trait call. Core syntax such as for loops, indexing, slicing, formatting and await all resolves through the traits registered here, so this table is the thickest bridge between the language syntax and the library.

Slot nameMeaningStandard library traitRef
iterator_traitStepping in for x in xsrok::core::iter::Iterator2.7
into_iterator_traitStart of for x in xsrok::core::iter::IntoIterator2.7
index_traitarr[i] readrok::core::ops::Index2.3
index_set_traitarr[i] = v writerok::core::ops::IndexSet2.3
slice_traits[1:3] slicingrok::core::ops::Sliceable2.3
display_traitf"{x}" default formatrok::core::fmt::Display2.10
debug_traitf"{x:?}" debug formatrok::core::fmt::Debug2.10
future_traitStepping in await exprrok::core::future::Future2.20

Next come the operator trait slots. The dispatch target of an operator token is determined by the #[infix] / #[prefix] (refs-lang 6.7) attached to each trait method, and precedence is fixed by the table in refs-lang 3.2; the slots below are fixed locations that let the compiler find "the addition trait", "the comparison trait", etc. by name during primitive lowering and diagnostics. Compound assignment (AddAssign, etc., 2.4), broadcast (DotAdd, etc., 2.6) and floored modulo (Modulo, %%) traits need only #[infix] registration and have no slots.

Slot nameMeaningStandard library traitRef
add_traita + brok::core::ops::Add2.3
sub_traita - brok::core::ops::Sub2.3
mul_traita * brok::core::ops::Mul2.3
div_traita / brok::core::ops::Div2.3
rem_traita % brok::core::ops::Rem2.3
neg_trait-a (prefix)rok::core::ops::Neg2.3
not_trait!arok::core::ops::Not2.3
bitnot_trait~arok::core::ops::BitNot2.3
bitand_traita & brok::core::ops::BitAnd2.3
bitor_traita | brok::core::ops::BitOr2.3
bitxor_traita ^ brok::core::ops::BitXor2.3
shl_traita << brok::core::ops::Shl2.3
shr_traita >> brok::core::ops::Shr2.3
logical_and_traita && brok::core::ops::LogicalAnd2.3
logical_or_traita || brok::core::ops::LogicalOr2.3
eq_trait== / !=, literal patternsrok::core::cmp::PartialEq2.5
cmp_trait< / > / <= / >=, range patternsrok::core::cmp::PartialOrd2.5
ord_traitTotal order (#[derive(Ord)])rok::core::cmp::Ord2.5
hash_traitHash (#[derive(Hash)])rok::core::cmp::Hash2.5
clone_traitClone (#[derive(Clone)])rok::core::marker::Clone2.13
send_traitAuto marker - safe to move across threadsrok::core::marker::Send2.13
sync_traitAuto marker - safe to share across threadsrok::core::marker::Sync2.13

Note

Comparison slot names and trait names do not correspond one-to-one. eq_trait is attached to PartialEq, which defines the equality operators, and cmp_trait to PartialOrd, which defines the ordering operators. The marker traits Eq, Copy and Default have no slots: sum types get them structurally (T | none is Eq when T is; its Default is none), so the compiler finds them by their fixed paths in rok::core.

0.4.4. Function slots (3)

Function slots are for standard library functions that the compiler calls directly, like intrinsics. They mainly cover abnormal termination paths - throw, OOM, unreachable - and are used where a uniform entry point is needed outside normal flow.

Slot nameMeaningStandard library functionRef
panic_fnAbort function called on panicrok::core::panic::panic2.14
oom_fnOOM abort (runtime allocation failure calls rok_oom directly)rok::core::panic::oom2.14
unreachable_fnCalled by the compiler at unreachable pointsrok::core::panic::unreachable2.14

0.4.5. Method slots (1)

Method slots are for methods the compiler calls automatically without the user writing the call. There is only one: disposal when a using binding is released. The ? operator is expanded directly by the compiler for T | none (refs-lang 3.14.10), so it has no method slot. Cloning a value (Clone::clone) is never called automatically (2.13.2), so it is registered as the trait slot clone_trait, not a method slot.

Slot nameMeaningStandard library methodRef
drop_methodCalled when a using block releasesrok::core::marker::Drop::drop2.13

0.4.6. Slot consumers: where the compiler looks up slots

Where the previous sections listed "which slots exist", this section summarizes the reverse: "when the compiler looks up which slot". When tracing which standard library item a line of user syntax resolves to, the following table is the starting point.

Compiler actionSlot looked up
Lowering the none literalnone_type
Literal type of 42 (no expected type)i32_type
Literal type of 3.14 (no expected type)f64_type
Literal type of "hello"str_type
Desugaring for x in xsinto_iterator_trait, iterator_trait
Desugaring arr[i]index_trait
Desugaring arr[i] = vindex_set_trait
Desugaring s[1:3]slice_trait
Desugaring a default f"{x}" holedisplay_trait
Desugaring f"{x:?}"debug_trait
Desugaring await exprfuture_trait
Primitive lowering of arithmetic / bitwise / logical operatorsadd_trait ... logical_or_trait
== / !=, literal pattern matchingeq_trait
< / > / <= / >=, range pattern matchingcmp_trait
Expanding #[derive(Clone / Ord / Hash)]clone_trait, ord_trait, hash_trait
Lowering panic (including try! failure)panic_fn
On OOMoom_fn
Unreachable after match exhaustiveness check of all armsunreachable_fn
Releasing a using blockdrop_method
Automatic Send / Sync implementation, + Send checkssend_trait, sync_trait

0.4.7. Duplicate / missing detection

If two standard library items are attached to the same slot, the compiler rejects it (the duplicate detection rule of refs-lang 6.4.6). Conversely, if a required slot such as iterator_trait is missing, compilation of the features that depend on it - here, for loops - is rejected. Both are devices that force the slot contract to have a single source of truth.

The actual attached items are stated in each chapter of 200-core/. Every slot in this table has its #[lang(...)] attachment site in the chapter indicated by the "Ref" column. A slot name not in this table is a compile error per refs-lang 6.4.8 - for example, Stream has no slot (2.8.10).

0.4.8. Slot naming policy

Finally, the naming rules to follow when adding a new slot or renaming an existing one. Consistent names let the kind of a slot be guessed just by scanning the table, so the policy is not taken lightly.

Names are written in snake_case: type slots take the _type suffix, trait slots the _trait suffix, function slots the _fn suffix, and method slots the _method suffix (drop_method). A slot designating a whole trait is unified under a single _trait even if the compiler handles several methods or derives of that trait; method slots are limited to cases where the compiler automatically calls one specific method. By this criterion, Clone is registered as clone_trait, not clone_method. The suffix also determines the attachment site: a _trait slot is attached to the trait declaration itself, a _method slot to the corresponding method inside the trait, a _type slot to a type declaration, and a _fn slot to a function declaration; attaching it elsewhere is rejected by the signature check of refs-lang 6.4.7.

Edit this page on GitHub