More general solution for serial number misorders.
Make sort_deps more efficient, and also only alter order when necessary. This means by default we run in serial number order, only going outside when we detect a dependency.
Maintain trace file order in original sort, so sort_deps doesn't mess it up.
We still need serial numbers: sort_deps can have multiple solutions for a single key, but these may deadlock with the ordering requirements of other keys. By sticking close to the actual order (ie. serial order), we minimize the chance of this happening.