DevPrep

All topics › Programming basics

Compilation

Junior

Essence

Compilation is translating high-level source code into machine code for the target CPU before launch (ahead-of-time). On iOS this is the only way: third-party apps may not generate code at run time (JIT), so Swift and Objective-C are compiled fully.

The swiftc pipeline

  1. Parse — text → AST (syntax tree). Syntax errors are caught here.
  2. Sema — type checking and inference, overload resolution. The most expensive stage: long expressions with literals can take seconds.
  3. SILGen → SIL — Swift Intermediate Language: this is where definite initialisation checks, ARC retain/release, exclusivity enforcement and Swift-level optimisations (devirtualisation, generic specialisation, inlining) live.
  4. IRGen → LLVM IR — a machine-independent representation; LLVM optimises and emits code for arm64 (device) or arm64/x86_64 (simulator).
  5. Linker (ld) — object files and libraries are merged into an executable; dynamic frameworks are loaded by dyld at launch.
swiftc -emit-sil main.swift       # inspect the SIL
swiftc -emit-ir main.swift        # LLVM IR
swiftc -O -wmo main.swift         # optimised, whole module

What gets asked in practice

What the interviewer looks for

Do you understand that type checking, ARC and concurrency checks are the compiler's job, not the runtime's, and how build settings (-O, -wmo, final) affect the app's performance.

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store