Browse the docs

Keywords.

Silk reserves 38 keywords. A keyword cannot name a declaration, binding, parameter or field. Another 14 contextual words have a meaning only in one grammar position and are ordinary identifiers everywhere else. The lists come from the compiler's lexer and parser.

Reserved keywords#

KeywordMeaningReference page
asRenames an import (import silk.collections.list as L) or gives a C symbol name (as "c_name"). Not a cast.Lexical structure, Unsafe code and C interop
breakLeaves the innermost while or while let loop.Control flow
compileErrorcompileError("text") stops the build when a static branch selects it (SEM0177).Static control flow and reflection
constDeclares a module-level constant; also *const T pointers.Static evaluation, Unsafe code and C interop
continueStarts the next iteration of the innermost while loop.Control flow
dropdrop x ends a value's life now. Also the name of the Drop hook, fn drop.Ownership and moves
effecteffect fn declares an effect function; effect { ... } builds an Effect value.Effects and run
elseSecond branch of if, if let and static if.Control flow
enumDeclares a scalar enum, optionally with a backing type: enum(u8) Color { ... }.Enums and unions
exportexport "C" fn or export "C" static makes a definition callable from C.Unsafe code and C interop
externunsafe extern "C" fn or static declares a C definition; extern "C" struct gives C layout.Unsafe code and C interop
failfail e raises the typed failure e from an effect.Typed failures
falseThe bool value false.Values and primitive types
fnDeclares a function, a function literal or a callable type.Functions and methods, Closures and callable types
forimpl I for T, higher-ranked callable types for<'a> fn(...), and static for. There is no runtime for loop.Interfaces and impls, Lifetimes, Static control flow and reflection
ifConditional statement; if let tests a pattern; static if selects code at compile time.Control flow, Patterns and match
implAdds inherent members to a type, or makes a type conform to an interface or service.Functions and methods, Interfaces and impls, Services and providers
importImports a module or its members; pub import re-exports members.Lexical structure
interfaceDeclares an interface.Interfaces and impls
letDeclares a local binding; let mut, let static and pattern lets; if let and while let.Bindings and statements
matchPattern-matching expression; match &x, match &mut x, match move x, match place x.Patterns and match
movemove x transfers ownership; match move; fail move e.Ownership and moves
mutMutable binding or parameter, &mut borrow, mut fn callable type, *mut T pointer.Bindings and statements, Borrowing
onceonce fn callable type that may be called one time; once Effect<...>.Closures and callable types, Effects and run
paramDeclares a package parameter in the root module.Package parameters
pubMakes a declaration, field or import visible outside its module.Functions and methods, Structs, tuples and arrays
returnLeaves the function with a value; return alone returns ().Bindings and statements
roleDeclares a role that tells two entries of the same service apart.Services and providers
runRuns an Effect and yields its success value. run takes the whole following expression, pipelines included.Effects and run
serviceDeclares a service contract.Services and providers
staticstatic fn, let static, static parameters, static if, static for, and C statics.Static evaluation, Static control flow and reflection
structDeclares a struct.Structs, tuples and arrays
trueThe bool value true.Values and primitive types
tupleDeclares a named tuple type: tuple Pair(i32, i32).Structs, tuples and arrays
typeDeclares a type alias: type Id = u64.Generics
unionDeclares a nominal tagged union.Enums and unions
unsafeUnsafe blocks, unsafe calls (unsafe f()), unsafe functions and C declarations.Unsafe code and C interop
whileThe only loop statement: while cond { ... }, or while let P = e { ... } to repeat while e matches the pattern P.Control flow

Contextual words#

These words are identifiers except in the position shown. let where = 1 and fn some(test: i32) compile.

WordWhere it is specialMeaningReference page
_Pattern, letMatches anything and binds nothing. let _ = e is rejected (SEM0087); write drop e.Patterns and match
addrspaceAfter *const or *mutaddrspace(n) pointer qualifier; only 0 today.Unsafe code and C interop
alignAfter *const or *mutalign(n) states a pointer's minimum alignment.Unsafe code and C interop
atRequirement rows and call type arguments&mut Journal at Audit selects a role.Services and providers
fromwhere clauseP provides X from Y.Services and providers
inwhere clause, static forwhere S in E membership; static for f in fields { ... }.Typed failures, Services and providers, Static control flow and reflection
placeAfter matchmatch place x matches the storage of x directly.Patterns and match
provideswhere clauseRelates a provider type to the requirement it supplies.Services and providers
someAfter ->-> some<F: Bound> F declares an opaque result.Generics, Effects and run
testBefore fn, effect, static, unsafe, extern or exportMarks a test function.Functions and methods
typeofType position, before (typeof(add) is the exact type of a named function.Generics
useIn a for<...> binder listfor<use 'call> binds a lifetime fresh for each call.Lifetimes
whereAfter a signature, an impl head or a paramConstraint clause; on param, a validation predicate.Generics, Package parameters
WithoutRow position, before <Without<R, S> removes S from row R.Typed failures, Services and providers

Names that are not keywords#

  • self and Self: self is an ordinary parameter name. Self names the owner type inside an impl or interface. See Interfaces and impls.

  • Intrinsic is a namespace visible in every module without an import. See Intrinsics.

  • Primitive type names (i32, bool, string, never) are not keywords.

  • loop is not a keyword. loop { ... } is reported as PAR0006: "loop is not a Silk keyword; write an unbounded loop as while true { ... }".

  • x as i64 is not an expression. as there is PAR0002: "Silk has no as cast; convert with a function of the source type, such as usize.toI32(count), or usize.checkedToI32(count) for an Option when the value may not fit".

  • with and module are ordinary identifiers. They used to introduce property clauses (with Intrinsic.inline(), module with ...); such a clause is now PAR0011, and the compiler names the directive to write instead, such as @inline. See Intrinsics.

  • Directive names after @ (inline, cold, nonParking, features, foreign, callbacks and the rest) are not keywords either. The full list is under Directives in Intrinsics.

Keywords in import paths#

An import path segment may be spelled like a keyword: import silk.core.effect {Effect}. When the last segment is a keyword and the import has neither an alias nor a member list, the import cannot bind that name:

silk
import silk.core.effect
TEXT
src/main.silk:1:18: error[PAR0004] An import whose reserved final path segment cannot form an implicit binding

Add an alias (import silk.core.effect as effects) or a member list.

See also#

Lexical structure, Operators, Grammar summary.

View the source of this page