stencilproject / Stencil

Stencil is a simple and powerful template language for Swift.
https://stencil.fuller.li
BSD 2-Clause "Simplified" License
2.34k stars 221 forks source link

Deterministic `for` loops for dictionaries #242

Closed djbe closed 5 years ago

djbe commented 5 years ago

Note: I was a bit too quick and merged #240 into the wrong branch, and github won't allow me to fix things without a new PR 🤷‍♂️

With Swift 4.2, hashing isn't consistent between runs anymore. A consequence of this is, if we iterate over a dictionary, the output won't always be the same, which will be unexpected for a user.

With this PR we iterate over the sorted keys of a dictionary, ensuring consistent output across runs.

djbe commented 5 years ago

So, small discussion point from #240 is that the current Stencil behaviour was, until now, undefined.

So let's define it then. An important note should be that the behaviour should be consistent, no matter the swift version you compile Stencil with (4 vs 4.2).