Python3 doesn't keep insertion order for set(), so this sorts some places for deterministic output for compiled template.