What is SIL and how is stack vs heap decided?
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