The Kähler–Ricci flow and optimal degenerations