Adding a generic topological sort for the update pipeline.

I think we should discuss. It looks like the requirement for ordering is quite pervasive, which means we have lots of code that needs to be updated to still sort correctly when we add new members, etc. I wonder if we really need to have things completely sorted in this way, or whether we can extract just the salient information and use that as a sort key.