diff options
author | 2018-02-26 04:49:52 -0800 | |
---|---|---|
committer | 2018-02-26 04:52:05 -0800 | |
commit | bc0e84bd166ba2118b277e07b2d25792fe804d93 (patch) | |
tree | 7083b1234a3007208f5aec1ec599dc142b1b0845 /src/main/java/com/google/devtools/build/lib/syntax/Type.java | |
parent | c91bd9270d1a199d8daeb7fbc41762e9547b0d7c (diff) |
Keep order of dict attributes the same as it was in the BUILD file.
This is a change from behavior introduced in unknown commit, which was added to preserve determinism even though the ordering of dicts in Python is non-deterministic. Now that we don't call into Python anymore, this is not necessary.
RELNOTES[INC]: The order of dict-valued attributes is now the order in the BUILD file (or in the Skylark dict they were created from) and not lexicographically sorted.
PiperOrigin-RevId: 187003317
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax/Type.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/Type.java | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Type.java b/src/main/java/com/google/devtools/build/lib/syntax/Type.java index 8fb5643165..7d1c2b078d 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/Type.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/Type.java @@ -26,12 +26,12 @@ import com.google.devtools.build.lib.syntax.SkylarkList.MutableList; import com.google.devtools.build.lib.util.LoggingUtil; import com.google.devtools.build.lib.util.StringCanonicalizer; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import java.util.TreeMap; import java.util.logging.Level; import javax.annotation.Nullable; @@ -512,9 +512,10 @@ public abstract class Type<T> { if (!(x instanceof Map<?, ?>)) { throw new ConversionException(this, x, what); } - // Order the keys so the return value will be independent of insertion order. - Map<KeyT, ValueT> result = new TreeMap<>(); Map<?, ?> o = (Map<?, ?>) x; + // It's possible that #convert() calls transform non-equal keys into equal ones so we can't + // just use ImmutableMap.Builder() here (that throws on collisions). + LinkedHashMap<KeyT, ValueT> result = new LinkedHashMap<>(); for (Entry<?, ?> elem : o.entrySet()) { result.put( keyType.convert(elem.getKey(), "dict key element", context), |