Libraries

tswift implements Swift’s runtime behavior entirely in Rust — there is no Swift compiler or standard library binary involved. Every API you call (print, Array.map, String.split, …) has a native Rust implementation inside tswift-std.


Architecture

    
flowchart BT
  src["Swift source"]
  fe["Frontend\n(lex → parse → sema → lower)"]
  rt["tswift-core\nEvaluator"]
  std["tswift-std\nStandard library"]
  fnd["Foundation\n(partial)"]
  swiftui["SwiftUI\n(partial)"]
  charts["Charts\n(render-host surface)"]
  swiftdata["SwiftData\n(subset)"]

  src --> fe --> rt
  std --> rt
  fnd --> rt
  swiftui --> rt
  charts --> rt
  swiftdata --> rt

  
Library layer sits between the runtime and Swift source

Standard Library (tswift-std)

The standard library is implemented as a native seam: the evaluator recognizes calls to known Swift standard library functions/methods and dispatches them to Rust functions instead of looking them up in the AST.

Core value types

Type Status Notes
Int, UInt (all widths) ✅ Done Overflow-trapping + wrapping ops
Float, Double ✅ Done IEEE 754, Foundation.sqrt bridged
Bool ✅ Done
String, Character 🟡 Partial UTF-8 backed; most methods implemented
Substring 🟡 Partial Slicing supported
Optional<T> ✅ Done Full binding, chaining, coalescing
Range, ClosedRange, Stride ✅ Done For-in, contains, count

Collections

Type Status Notes
Array<T> ✅ Done Full CoW, all HOF methods
Dictionary<K,V> ✅ Done CoW, keys/values/merging
Set<T> ✅ Done Set algebra operations
ContiguousArray, ArraySlice ✅ Done Slicing bridge

Protocols

Protocol Status
Equatable, Hashable, Comparable ✅ Done
Sequence, IteratorProtocol ✅ Done
Collection, BidirectionalCollection 🔴 Todo
ExpressibleBy*Literal ✅ Done
CustomStringConvertible ✅ Done
Codable / Encodable / Decodable ✅ Done
Identifiable ✅ Done

Free functions

API Status
print, debugPrint, dump ✅ Done
map, filter, reduce, flatMap, compactMap ✅ Done
assert, precondition, fatalError ✅ Done
min, max, abs, stride, zip, swap ✅ Done
Result<S,F> ✅ Done
MemoryLayout ✅ Done
Unsafe*Pointer family 🔴 Todo

See the Standard Library status page → for detailed counts.


Foundation (partial)

Foundation support is measured through generated .swiftinterface inventories. The current proof slice:

API Status
Data — core constructors and properties ✅ Done
UUID — constructors and uuidString ✅ Done
IndexPath, IndexSet ✅ Done
URL, URLComponents, URLQueryItem ✅ Done
DateFormatter, JSONDecoder, JSONEncoder ✅ Done
URLSession, URLRequest 🟡 Partial
UserDefaults 🟡 Partial (host-service backed; see below)
FileManager 🟡 Partial (host-service backed; see below)
NotificationCenter 🔴 Todo

Persistence (UserDefaults/FileManager) runs over a host-service seam (tswift.defaults.* / tswift.fs.*, tswift_core::host_services), not the real Darwin APIs directly: the CLI backs it with an in-process store / the real filesystem, wasm backs UserDefaults with localStorage (no real filesystem there and no file-based persistence yet), and an embedding that hasn’t wired the service up gets a clean, catchable “unavailable on this platform” diagnostic rather than a crash. See Foundation scope notes → for the exact member list.

See the Foundation status page →.


SwiftUI (partial)

SwiftUI runs as a render host, not a native platform renderer: body is evaluated by the tree-walking interpreter into a host-neutral UIIR, which an embedding (DOM for the web, a native host elsewhere) turns into pixels. State (@State, @Binding), stacks/lists/navigation, controls, gestures, and basic animation are implemented; full layout fidelity and a native (non-web) rendering target remain open work.

See the SwiftUI status page → for detailed counts.


Charts (render-host surface)

Charts shares SwiftUI’s host-neutral UIIR path. Chart and its 2D marks (BarMark, LineMark, PointMark, AreaMark, RuleMark, RectangleMark, and SectorMark) evaluate into chart and mark values; styling, axis, scale, legend, selection, and scrolling modifiers remain attached for a host to interpret. The web host renders deterministic SVG, while the iOS host lowers to native Charts; these are explicit fidelity tiers rather than a claim of pixel-identical parity.

See the Charts status page → for the scoped API reference.


SwiftData (subset)

SwiftData implements a stage-1 subset over a SQLite-backed host service: @Model classes (discovered structurally, no macro expansion), ModelContainer/ModelContext CRUD, a SQL-compiling #Predicate subset, and @Query/.modelContainer(for:) SwiftUI integration. Relationships, migrations, CloudKit sync, and persistent history tracking are not implemented.

See the SwiftData status page → for detailed counts.


How to add a stdlib API

If you want to contribute a missing standard library method:

  1. Find the call site in tswift-std/src/ — look for the native_call dispatch table.
  2. Add a match arm for the new method name.
  3. Implement the behaviour in Rust, returning a SwiftValue.
  4. Add a golden fixture tests/swift-fixtures/<name>.swift + <name>.expected.
  5. Run cargo test — the golden harness validates automatically.

See the AGENTS.md for commit conventions.