Source: modules/stdlib/ · 14,735 LOC

Standard Library — What's Implemented

Type registrations come from auto-generated module_stubs.c (parsed from Swift's .swiftinterface). Runtime ops are hand-written C in runtime/*.c, linked into stdlib.wasm. IR lowering handlers map Swift method calls to IR instructions at compile time.

586
Type entries registered
200+
Runtime functions in stdlib.wasm
9
Runtime modules (string · array · dict · set · math · async · actor · arc · any)
12
IR-lowering handler files (compile-time dispatch)
Full — runtime + lowering wired · Partial — declared / partial methods · Stub — registered for sema only
Type registry (586) Runtime functions IR lowering Known limitations

Type Registry

All 586 stdlib type entries are registered with the semantic analyser so name resolution + protocol conformance checks work. The list below highlights notable types per kind. Full table: modules/stdlib/type_decls/module_stubs.c.

By kind (totals)586 entries
struct
240 entries — value types (Int family, Float family, Bool, String, Array, Dictionary, Set, Range…).
protocol
111 entries — Sequence, Collection, Equatable, Hashable, Comparable, BinaryInteger, BinaryFloatingPoint, etc.
enum
33 entries — Optional, Result, Unicode, FloatingPointRoundingRule, etc.
class
11 entries — KeyPath family, NSObject, JSONEncoder/Decoder, DateFormatter, UserDefaults.
typealias
186 entries — C interop aliases (CChar, CInt, CDouble…), legacy literal-protocol aliases.
Numeric types18 structs
Int / UInt
Default platform-width signed/unsigned integer (64-bit on WASM).
Int8 / UInt8
Fixed-width 8-bit integers.
Int16 / UInt16
Fixed-width 16-bit integers.
Int32 / UInt32
Fixed-width 32-bit integers.
Int64 / UInt64
Fixed-width 64-bit integers — native WASM size.
Int128 / UInt128
Declared in registry; runtime ops fall back to 64-bit.
Float / Double
IEEE 754 single + double precision; full math runtime.
Float16 / Float80
Registered; arithmetic widens to Double internally.
Bool
Native i32; standard logical / comparison ops.
Decimal
Type registered; high-precision arithmetic limited.
Collections13 structs + 2 enums
Array
Random-access; 39 runtime ops (append, sort, filter, map, slice, contains…).
ArraySlice
View into Array — shares underlying storage.
ContiguousArray
Same impl as Array on WASM.
Dictionary
Hash-keyed; 30 runtime ops (get, set, remove, merge, keys, values, iter…).
Set
Unordered unique elements; 33 ops including union, intersection, subset, symmetric_difference.
Range / ClosedRange
Half-open + closed bounds; iterable, contains.
RangeSet
Type registered; collection-of-ranges ops not yet wired.
Slice
Generic collection slice.
Optional
enum — `.some(T)` / `.none`; pattern matching, optional chaining, ??.
Result
enum — `.success(T)` / `.failure(E)` with throw/get bridge.
String & Character8 entries
String
Unicode 17.0 grapheme-cluster aware; 56 runtime ops (concat, split, contains, prefix/suffix, case, replace, slice, interp).
Substring
String view; shares storage, converts back via `String(_:)`.
Character
Single extended grapheme cluster.
Unicode.Scalar
21-bit code point; UTF8/16/32 view enums registered.
UTF8Span
Span-based UTF8 view (Swift 6); registered, ops basic.
StaticString
Compile-time string literal.
Notable protocols15 of 111
Equatable
== / !=. Auto-synthesised for structs/enums where eligible.
Hashable
hash(into:) for Set / Dictionary key use.
Comparable
< / > / sort.
Sequence
makeIterator + for-in.
Collection
Indexed access + count.
BinaryInteger
Integer protocol hierarchy.
BinaryFloatingPoint
Float / Double surface protocol.
Numeric / AdditiveArithmetic
+ - * / generic constraints.
Codable / Encodable / Decodable
Protocols registered; encoder/decoder runtime via Foundation bridge.
Error
throws / try / catch wired through async runtime.
CaseIterable
enum allCases auto-synthesis.
CustomStringConvertible
.description for print + interpolation.
ExpressibleBy*Literal
Full literal-protocol family for type-driven literals.
Sendable
Concurrency marker; isolation enforcement basic.
Copyable / Escapable
Swift 6 ownership protocols recognised.

Runtime Functions

Functions linked into stdlib.wasm and called from compiled user code. Names follow the __<module>_<op> convention.

String — string_rt.c56 functions
__str_concat / __str_eq / __str_neq / __str_lex_precedes
Concatenation, equality, lex comparison.
__str_len / __str_grapheme_len / __str_codepoint_count
UTF-8 byte length, grapheme cluster count, scalar count.
__str_substr / __str_prefix / __str_suffix / __str_grapheme_slice
Slicing — byte-, grapheme-, and prefix/suffix-aware.
__str_split / __str_split_ex / __str_join_array
Split by separator (basic + extended) and join.
__str_contains / __str_has_prefix / __str_has_suffix
Predicate searches.
__str_lowercased / __str_uppercased / __str_unicode_lower / __str_unicode_upper
ASCII + Unicode-aware case mapping.
__str_replace_subrange / __str_remove_range / __str_insert
Mutating range edits.
__str_drop_first_sub / __str_drop_last_sub / __str_remove_first / __str_remove_last
Dropping front/back chunks.
__str_from_int / __str_from_double / __str_from_bool / __str_from_int_radix
Numeric / Bool to string conversion.
__str_interp
String interpolation glue ("\\(value)").
__str_char_at / __str_codepoint_at / __str_codepoint_len
Character + scalar indexing.
__str_sorted / __str_shuffled / __str_min / __str_max
Sequence ops via Character ordering.
__str_reserve_capacity / __str_pop_last / __str_remove_at
Storage + mutation primitives.
__str_make_iterator / __str_enumerated
Iteration support — for-in, .enumerated().
__str_random_element
Picks a random Character.
Array — array_rt.c39 functions
__array_create / __array_create_n / __array_create_repeat
Empty, capacity-hint, repeat-element constructors.
__array_append / __array_insert / __array_concat / __array_plus
Mutation + concatenation.
__array_get / __array_get_ptr / __array_get_str / __array_len
Indexed access + count.
__array_remove_at / __array_remove_first / __array_remove_last / __array_pop_last
Element removal at index / ends.
__array_clear / __array_clear_discarding_capacity
Reset all / reset + free storage.
__array_first / __array_last / __array_first_index / __array_last_index
End access + lookup index.
__array_contains / __array_elements_equal
Predicate searches + equality.
__array_lex_precedes / __array_starts_with
Lex compare + prefix check.
__array_clone / __array_capacity / __array_grow
COW clone + capacity introspection.
__array_print
Pretty-print into a string buffer.
__array_make_iterator
for-in support.
Dictionary — dict_rt.c30 functions
__dict_create / __dict_create_sized / __dict_create_unique_keys
Empty, capacity-hinted, literal constructors.
__dict_get / __dict_set / __dict_remove / __dict_contains
Subscript + membership.
__dict_index_for_key / __dict_first / __dict_random_element
Index resolution + first / random pick.
__dict_count / __dict_capacity / __dict_eq
Size + equality.
__dict_keys / __dict_keys_array / __dict_values_array
Materialise key/value views as arrays.
__dict_iter / __dict_iter_next / __dict_make_iterator
for-in over key/value pairs.
__dict_merging / __dict_get_or_create_arr / __dict_reserve
Merge with strategy + reserve / multi-value upserts.
__dict_description / __dict_clear / __dict_free
Pretty-print + reset / free.
Set — set_rt.c33 functions
__set_create / __set_create_str
Constructors (typed + string fast path).
__set_insert / __set_insert_i / __set_remove / __set_remove_first / __set_remove_all / __set_update_with
Mutation primitives.
__set_contains / __set_count / __set_capacity / __set_underestimated_count
Membership + size queries.
__set_union / __set_intersection / __set_subtracting / __set_symmetric_difference
Set algebra.
__set_is_subset / __set_is_superset / __set_is_strict_subset / __set_is_strict_superset / __set_is_disjoint
Containment predicates.
__set_filter / __set_map / __set_sorted / __set_shuffled
Higher-order ops + ordered views.
__set_min / __set_max / __set_first_index / __set_first_ptr / __set_get_ptr / __set_random_element
Element access.
__set_reserve / __set_description
Capacity + pretty-print.
Math — math_rt.c15 functions
__math_sin / __math_cos / __math_tan
Trig functions (radians).
__math_asin / __math_acos / __math_atan / __math_atan2
Inverse trig + 2-arg atan2.
__math_sinh / __math_cosh / __math_tanh
Hyperbolic trig.
__math_exp / __math_pow
Exponential + power.
__math_log / __math_log2 / __math_log10
Natural / base-2 / base-10 logarithm.
__swift_max_f64 / __swift_min_f64 / __swift_abs_f64 / __swift_abs_i64
min/max/abs intrinsics for Double + Int.
Concurrency — async_rt.c11 functions
__swift_task_create / __swift_task_run / __swift_task_free / __swift_task_result / __swift_task_await
Task lifecycle for async/await.
__swift_taskgroup_create / __swift_taskgroup_add / __swift_taskgroup_await_all / __swift_taskgroup_free
Structured concurrency via TaskGroup.
__swift_async_return / __swift_main_actor_run
Async return convention + main-actor entry.
Actor isolation — actor_rt.c5 functions
__actor_create / __actor_destroy / __actor_acquire / __actor_release / __actor_enqueue / __actor_is_isolated / __main_actor_run
Single-thread WASM model — actors serialise via a per-actor queue, no real preemption.
Reference counting — arc_runtime.c8 functions
__miniswift_alloc / __miniswift_retain / __miniswift_release / __miniswift_refcount / __miniswift_is_uniquely_referenced
Class instance ARC, COW eligibility.
__atomic_fetch_add / __atomic_fetch_sub
Atomic primitives (single-thread WASM = ordinary loads).
Existentials & Any — any_rt.c7 functions
__any_box_int / __any_box_double / __any_box_bool / __any_box_ptr
Box primitives + objects into existential.
__any_as_int / __any_as_ptr / __any_get_tag
Unbox + introspect tag.

IR Lowering

Compile-time handlers that map Swift method calls to IR. Each file in modules/stdlib/ir_lowering/ handles one type-family.

array.c

Array.append / map / filter / reduce / sorted / contains / first(where:) / lastIndex(of:) → array_rt calls.

string.c

String.split / lowercased / uppercased / hasPrefix / replacingOccurrences / interpolation → string_rt calls.

dict.c

Dictionary subscript / merge / mapValues / filter / removeAll → dict_rt calls.

set.c

Set membership, set algebra (∪ ∩ ∖ △), predicates → set_rt calls.

numeric.c

BinaryInteger / BinaryFloatingPoint method calls — distance(to:), advanced(by:), magnitude.

conv.c

Int(_:), Double(_:), String(_:radix:) — numeric & textual conversions.

seq.c

Sequence / Collection generic ops — for-in, makeIterator, indices.

init.c

Initializer dispatch (9 entries) — handles both default and memberwise inits.

global_math.c

Free-standing math — abs, max, min, swap.

calendar.c / data.c / result.c

Calendar, Data, Result method dispatch.

Known Limitations

Type registry is broad; runtime depth varies. The list below names the gaps that bite most.

Int128 / UInt128 / Float80

Registered but arithmetic ops use 64-bit fallback. Wide-int multiply / divide unimplemented.

Float16

No native WASM half precision; all ops widen to Double.

Decimal

Type slot only — high-precision decimal arithmetic isn't shipped.

Codable runtime

Encodable / Decodable conformances aren't auto-synthesised; relies on Foundation JSON bridge for primitive cases.

Mirror / runtime reflection

Mirror struct registered; introspection is shallow (no children walking).

UnsafePointer family

Pointer arithmetic basic; bound-memory rebinding + memcpy primitives not yet wired.

Sendable enforcement

Marker recognised; data-race static checking is best-effort.

String regex

Regex literals + string.matches(of:) not yet lowered.

Async sequences

AsyncSequence / AsyncStream protocols registered; iterator runtime stubs only.

Distributed actors

Distributed module not in scope.

Macros

No macro expansion plugin host — @Observable, #stringify, etc. parse but don't expand.

UTF8Span ops

Type registered for Swift 6 forward-compat; span-based methods limited.