# swiftlang/swift architecture

> Architecture diagram of the GitHub repository swiftlang/swift, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/swiftlang/swift
- Repository: https://github.com/swiftlang/swift

## Overview

Swift is a programming language implementation: developers write Swift programs, which the compiler analyzes and optimizes; the standard library and platform runtimes provide the facilities those programs use. The tree and excerpts support compiler AST, storage type-checking, diagnostics, SIL optimization, standard-library string storage, and runtime/overlay subsystems. Several major capabilities are documented or visible in the tree but their implementation and wiring were not sampled, so those branches are shown without speculative call relationships.

Main entry points: [`lib/SILOptimizer/PassManager/PassPipeline.cpp`](https://github.com/swiftlang/swift/blob/main/lib/SILOptimizer/PassManager/PassPipeline.cpp) (Pass pipeline), [`SwiftCompilerSources/Sources/AST`](https://github.com/swiftlang/swift/tree/main/SwiftCompilerSources/Sources/AST) (AST and types), [`lib/Sema/TypeCheckStorage.cpp`](https://github.com/swiftlang/swift/blob/main/lib/Sema/TypeCheckStorage.cpp) (Storage type-checking), [`SwiftCompilerSources/Sources/Optimizer`](https://github.com/swiftlang/swift/tree/main/SwiftCompilerSources/Sources/Optimizer) (Optimizer passes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_compiler["Compiler"]
  node_ast["AST and types"]
  node_storage_check["Storage type-checking"]
  node_diagnostics["Diagnostics"]
  node_sil["SIL representation"]
  node_silgen["SIL generation<br/>[StorageRefResult.h]"]
end

subgraph group_optimizer["SIL Optimizer"]
  node_pipeline["Pass pipeline<br/>[PassPipeline.cpp]"]
  node_access_analysis["Access analysis"]
  node_phi_opt["Phi storage optimization"]
  node_optimizer_modules["Optimizer passes"]
end

subgraph group_library["Library and Runtime"]
  node_stdlib_string["String storage"]
  node_core_runtime["Core runtime"]
  node_supplemental["Supplemental libraries"]
end

subgraph group_interop["Platform Interop"]
  node_overlays["Platform overlays"]
  node_com["COM support"]
end

node_developer(("Swift developer"))
node_program["Swift program"]
node_c_objc(("C and Objective-C"))

node_developer -->|"writes"| node_program
node_program -->|"analyzed as"| node_ast
node_ast -->|"type-checked by"| node_storage_check
node_storage_check -->|"reports issues"| node_diagnostics
node_silgen -->|"builds"| node_sil
node_pipeline -->|"schedules passes"| node_optimizer_modules
node_pipeline -->|"adds optimization"| node_phi_opt
node_access_analysis -->|"provides analysis"| node_optimizer_modules
node_program -->|"uses library"| node_stdlib_string
node_program -->|"uses runtime"| node_core_runtime
node_program -.->|"may use"| node_supplemental
node_program -.->|"may use"| node_overlays
node_program -.->|"may use"| node_com
node_c_objc -.->|"interoperates through"| node_overlays

click node_ast "https://github.com/swiftlang/swift/tree/main/SwiftCompilerSources/Sources/AST"
click node_storage_check "https://github.com/swiftlang/swift/blob/main/lib/Sema/TypeCheckStorage.cpp"
click node_diagnostics "https://github.com/swiftlang/swift/blob/main/lib/AST/DiagnosticEngine.cpp"
click node_sil "https://github.com/swiftlang/swift/tree/main/SwiftCompilerSources/Sources/SIL"
click node_silgen "https://github.com/swiftlang/swift/blob/main/lib/SILGen/StorageRefResult.h"
click node_pipeline "https://github.com/swiftlang/swift/blob/main/lib/SILOptimizer/PassManager/PassPipeline.cpp"
click node_access_analysis "https://github.com/swiftlang/swift/blob/main/lib/SILOptimizer/Analysis/AccessStorageAnalysis.cpp"
click node_phi_opt "https://github.com/swiftlang/swift/blob/main/lib/SILOptimizer/Mandatory/PhiStorageOptimizer.cpp"
click node_optimizer_modules "https://github.com/swiftlang/swift/tree/main/SwiftCompilerSources/Sources/Optimizer"
click node_stdlib_string "https://github.com/swiftlang/swift/blob/main/stdlib/public/core/StringStorage.swift"
click node_core_runtime "https://github.com/swiftlang/swift/tree/main/Runtimes/Core"
click node_supplemental "https://github.com/swiftlang/swift/tree/main/Runtimes/Supplemental"
click node_overlays "https://github.com/swiftlang/swift/tree/main/Runtimes/Overlay"
click node_com "https://github.com/swiftlang/swift/tree/main/Runtimes/Supplemental/COM/Sources/COM"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_ast,node_storage_check,node_diagnostics,node_sil,node_silgen toneBlue
class node_pipeline,node_access_analysis,node_phi_opt,node_optimizer_modules toneAmber
class node_stdlib_string,node_core_runtime,node_supplemental toneMint
class node_overlays,node_com toneRose
class node_developer,node_program,node_c_objc toneIndigo
```

## Components

### Compiler

- [AST and types](https://github.com/swiftlang/swift/tree/main/SwiftCompilerSources/Sources/AST): `SwiftCompilerSources/Sources/AST`
- [Storage type-checking](https://github.com/swiftlang/swift/blob/main/lib/Sema/TypeCheckStorage.cpp): `lib/Sema/TypeCheckStorage.cpp`
- [Diagnostics](https://github.com/swiftlang/swift/blob/main/lib/AST/DiagnosticEngine.cpp): `lib/AST/DiagnosticEngine.cpp`
- [SIL representation](https://github.com/swiftlang/swift/tree/main/SwiftCompilerSources/Sources/SIL): `SwiftCompilerSources/Sources/SIL`
- [SIL generation](https://github.com/swiftlang/swift/blob/main/lib/SILGen/StorageRefResult.h): `lib/SILGen/StorageRefResult.h`

### SIL Optimizer

- [Pass pipeline](https://github.com/swiftlang/swift/blob/main/lib/SILOptimizer/PassManager/PassPipeline.cpp): `lib/SILOptimizer/PassManager/PassPipeline.cpp`
- [Access analysis](https://github.com/swiftlang/swift/blob/main/lib/SILOptimizer/Analysis/AccessStorageAnalysis.cpp): `lib/SILOptimizer/Analysis/AccessStorageAnalysis.cpp`
- [Phi storage optimization](https://github.com/swiftlang/swift/blob/main/lib/SILOptimizer/Mandatory/PhiStorageOptimizer.cpp): `lib/SILOptimizer/Mandatory/PhiStorageOptimizer.cpp`
- [Optimizer passes](https://github.com/swiftlang/swift/tree/main/SwiftCompilerSources/Sources/Optimizer): `SwiftCompilerSources/Sources/Optimizer`

### Library and Runtime

- [String storage](https://github.com/swiftlang/swift/blob/main/stdlib/public/core/StringStorage.swift): `stdlib/public/core/StringStorage.swift`
- [Core runtime](https://github.com/swiftlang/swift/tree/main/Runtimes/Core): `Runtimes/Core`
- [Supplemental libraries](https://github.com/swiftlang/swift/tree/main/Runtimes/Supplemental): `Runtimes/Supplemental`

### Platform Interop

- [Platform overlays](https://github.com/swiftlang/swift/tree/main/Runtimes/Overlay): `Runtimes/Overlay`
- [COM support](https://github.com/swiftlang/swift/tree/main/Runtimes/Supplemental/COM/Sources/COM): `Runtimes/Supplemental/COM/Sources/COM`

### Other components

- **Swift developer**
- **Swift program**
- **C and Objective-C**

## Connections

- Swift developer → Swift program: writes
- Swift program → AST and types: analyzed as
- AST and types → Storage type-checking: type-checked by
- Storage type-checking → Diagnostics: reports issues
- SIL generation → SIL representation: builds
- Pass pipeline → Optimizer passes: schedules passes
- Pass pipeline → Phi storage optimization: adds optimization
- Access analysis → Optimizer passes: provides analysis
- Swift program → String storage: uses library
- Swift program → Core runtime: uses runtime
- Swift program → Supplemental libraries: may use
- Swift program → Platform overlays: may use
- Swift program → COM support: may use
- C and Objective-C → Platform overlays: interoperates through
