Why Indirection Is the Price of Polymorphism, With Assembly You Can Read
Polymorphism lets you call methods through an interface without knowing the concrete type at compile time. The CPU and the ABI do not understand interfaces, traits, or virtuals. They only understand bytes, fixed register widths, and stack slots. That mismatch is the root cause of why runtime polymorphism uses indirection. In this extended version I will show concrete assembly flavored examples so you can see exactly where size knowledge matters, how vtables and fat pointers are used, and what gets passed in registers or on the stack. I will use x86-64 System V ABI conventions where practical. Exact assembly will vary by compiler and flags, but the patterns are stable. The goal is to make the invisible visible. A tiny ABI checklist before we start The ABI decides how arguments are passed and where return values land. On x86-64 System V: Integer or pointer arguments are passed in RDI, RSI, RDX, RCX, R8, R9, then the stack. Floating arguments use XMM0..XMM7. The caller align...