~/talk

Lowering in C#: What's really going on in your code?

Talkat NDC Oslo 2019 · 2019-06-17..06-21· [dotnet, compilers-and-language-design]
slides:none on file

Explains how Roslyn lowers C# constructs into simpler C# and then into IL, using concrete examples: foreach becomes a pattern-based foreach that compiles to a scope + getEnumerator + try/finally + two casts (element and object), interpolated strings initially lower to string.Format (later optimized to concatenation when safe), lambdas generate helper classes and a lambda capture singleton (changed in C#5 to avoid loop-capture bugs), and yield return becomes a state machine with -2 initial state that can wrap inner enumerators, causing hidden allocations and lifetime traps. SharpLab and Roslyn source are used to inspect real output.

AI-written summary · about

  1. 0:00Start
  2. 0:56What is lowering?
  3. 9:56Why do I want to know?
  4. 14:50IEnumerable
  5. 42:15Yield states
  6. 48:25Captain planet
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.