Skip to content

Conversation

djbe
Copy link
Contributor

@djbe djbe commented Sep 20, 2018

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.

CHANGELOG.md Outdated
@@ -7,6 +7,9 @@
- Now accessing undefined keys in NSObject does not cause runtime crash and instead renders empty string.
[Ilya Puchka](https://github.com/ilyapuchka)
[#234](https://github.com/stencilproject/Stencil/pull/234)
- `for` tag: When iterating over a dictionary the keys will now always be sorted to ensure consistent output generation.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] should mention sorting order probably

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"... sorted (in an ascending order) ..."?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

@djbe
Copy link
Contributor Author

djbe commented Sep 20, 2018

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).

  • When compiled with Swift 4, the output was always in the same order (but unsorted)
  • When compiled with Swift 4.2, the output is random (and unsorted)
  • This PR ensures that the output is always in the same order, and to do so, it's sorted (ascending).

@djbe djbe force-pushed the feature/deterministic-for-loop branch from a3da20c to 064b2f7 Compare September 20, 2018 22:20
Copy link
Collaborator

@ilyapuchka ilyapuchka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@djbe djbe merged commit 7ed95ae into master Sep 21, 2018
@djbe djbe deleted the feature/deterministic-for-loop branch September 21, 2018 10:09
@djbe djbe added this to the 0.13.0 milestone Sep 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants