aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
authorGravatar Vladimir Moskva <vladmos@google.com>2017-02-17 13:01:02 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2017-02-17 14:55:56 +0000
commit2b690e383f3cd98837fc376099a08be763babbc0 (patch)
tree9c150719fcde4f36744817c6f9928de218d19e72 /src/main
parenta8d36956d53e4759d22cf201306138b63bbbcd35 (diff)
Do not sort dict keys when printing
Dict keys can in theory belong to different types, it's not allowed anymore to compare such objects by < in Skylark, so the Printer class shouldn't do it either. -- PiperOrigin-RevId: 147827109 MOS_MIGRATED_REVID=147827109
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java28
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/Printer.java20
2 files changed, 1 insertions, 47 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java b/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java
index 1580fb482d..75b9a6b91e 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java
@@ -98,34 +98,6 @@ public final class EvalUtils {
};
/**
- * Legacy Skylark comparator.
- *
- * <p>Falls back to comparing by class if objects are not comparable otherwise.
- */
- public static final Ordering<Object> SAFE_SKYLARK_COMPARATOR =
- new Ordering<Object>() {
- @Override
- @SuppressWarnings("unchecked")
- public int compare(Object o1, Object o2) {
- try {
- return SKYLARK_COMPARATOR.compare(o1, o2);
- } catch (ComparisonException e) {
- return compareByClass(o1, o2);
- }
- }
- };
-
- public static final int compareByClass(Object o1, Object o2) {
- try {
- // Different types -> let the class names decide
- return o1.getClass().getName().compareTo(o2.getClass().getName());
- } catch (NullPointerException ex) {
- throw new ComparisonException(
- "Cannot compare " + getDataTypeName(o1) + " with " + EvalUtils.getDataTypeName(o2));
- }
- }
-
- /**
* Checks that an Object is a valid key for a Skylark dict.
* @param o an Object to validate
* @throws EvalException if o is not a valid key
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Printer.java b/src/main/java/com/google/devtools/build/lib/syntax/Printer.java
index 730a8302af..c0e6f225e7 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Printer.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Printer.java
@@ -26,9 +26,6 @@ import java.util.Formatter;
import java.util.List;
import java.util.Map;
import java.util.MissingFormatWidthException;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -145,7 +142,7 @@ public final class Printer {
} else if (o instanceof Map<?, ?>) {
Map<?, ?> dict = (Map<?, ?>) o;
- printList(buffer, getSortedEntrySet(dict), "{", ", ", "}", null, quotationMark);
+ printList(buffer, dict.entrySet(), "{", ", ", "}", null, quotationMark);
} else if (o instanceof Map.Entry<?, ?>) {
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) o;
@@ -166,21 +163,6 @@ public final class Printer {
return buffer;
}
- /**
- * Returns the sorted entry set of the given map
- */
- private static <K, V> Set<Map.Entry<K, V>> getSortedEntrySet(Map<K, V> dict) {
- if (!(dict instanceof SortedMap<?, ?>)) {
- // TODO(bazel-team): Dict keys should not be sorted, because comparison of objects of
- // potentially different types is not supported anymore in Skylark.
- Map<K, V> tmp = new TreeMap<>(EvalUtils.SAFE_SKYLARK_COMPARATOR);
- tmp.putAll(dict);
- dict = tmp;
- }
-
- return dict.entrySet();
- }
-
public static Appendable write(Appendable buffer, Object o) {
return write(buffer, o, SKYLARK_QUOTATION_MARK);
}