DevPrep

All topics › Modern Swift

What is SIL and how is stack vs heap decided?

Senior PRO

The idea

SIL (Swift Intermediate Language) is a Swift-specific intermediate representation between the AST and LLVM IR. The pipeline: source → AST → SILGen (raw SIL) → mandatory passes (definite initialization, exclusivity checking, diagnostics) → canonical SIL → optimizations (-O) → LLVM IR → machine code. SIL is where Swift performs its "own" optimizations that LLVM cannot: ARC optimization (removing paired retain/release), generic specialization, devirtualization, inlining, escape analysis and stack promotion.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

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