Move sorting into formatter-API.
This also fixes broken sorting for mappings.