diff options
author | vladmos <vladmos@google.com> | 2017-11-20 10:03:20 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2017-11-20 10:05:26 -0800 |
commit | c5e9a4790288a24b22bc72761994775c029a676e (patch) | |
tree | 7c74bbe225244829f637e504393bc5a932fb29c4 /src/main/java/com/google | |
parent | 6364017ef95353969a8297c99a07c2a52102d9cc (diff) |
Remove the deprecated set constructor from Skylark
The `set` constructor used to be deprecated, but it was still possible to use
it by providing --incompatible_disallow_set_constructor=false.
It's still allowed to have `set` in parts of the code that are not executed, this will be deprecated later.
RELNOTES[INC]: The deprecated `set` constructor is removed, along with the
migration flag --incompatible_disallow_set_constructor. It is still temporarily
allowed to refer to `set` from within unexecuted code.
PiperOrigin-RevId: 176375859
Diffstat (limited to 'src/main/java/com/google')
6 files changed, 13 insertions, 98 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/collect/nestedset/Order.java b/src/main/java/com/google/devtools/build/lib/collect/nestedset/Order.java index 05cc7a1b1a..581acad779 100644 --- a/src/main/java/com/google/devtools/build/lib/collect/nestedset/Order.java +++ b/src/main/java/com/google/devtools/build/lib/collect/nestedset/Order.java @@ -20,11 +20,9 @@ import java.util.HashMap; /** * Type of a nested set (defines order). * - * * <p>STABLE_ORDER: an unspecified traversal order. Use when the order of elements does not matter. * In Skylark it is called "default"; its older deprecated name is "stable". * - * * <p>COMPILE_ORDER: left-to-right postorder. In Skylark it is called "postorder"; its older * deprecated name is "compile". * @@ -34,7 +32,6 @@ import java.util.HashMap; * <p>This type of set would typically be used for artifacts where elements of nested sets go before * the direct members of a set, for example in the case of Javascript dependencies. * - * * <p>LINK_ORDER: a variation of left-to-right preorder that enforces topological sorting. In * Skylark it is called "topological"; its older deprecated name is "link". * @@ -87,7 +84,6 @@ import java.util.HashMap; * such cases ordering is decided by the rightmost branch because of the list reversing behind the * scenes, so the ordering in the final enumeration will be "E D". * - * * <p>NAIVE_LINK_ORDER: a left-to-right preordering. In Skylark it is called "preorder"; its older * deprecated name is "naive_link". * @@ -102,23 +98,20 @@ import java.util.HashMap; * dependencies-after-parent ordering. Note that the latter is usually more important, so please use * LINK_ORDER whenever possible. */ -// TODO(bazel-team): Remove deprecatedSkylarkName and it's associated helpers before Bazel 1.0. +// TODO(bazel-team): Remove deprecated names from the documentation above. public enum Order { - STABLE_ORDER("default", "stable"), - COMPILE_ORDER("postorder", "compile"), - LINK_ORDER("topological", "link"), - NAIVE_LINK_ORDER("preorder", "naive_link"); + STABLE_ORDER("default"), + COMPILE_ORDER("postorder"), + LINK_ORDER("topological"), + NAIVE_LINK_ORDER("preorder"); private static final ImmutableMap<String, Order> VALUES; - private static final ImmutableMap<String, Order> DEPRECATED_VALUES; private final String skylarkName; - private final String deprecatedSkylarkName; private final NestedSet<?> emptySet; - private Order(String skylarkName, String deprecatedSkylarkName) { + private Order(String skylarkName) { this.skylarkName = skylarkName; - this.deprecatedSkylarkName = deprecatedSkylarkName; this.emptySet = new NestedSet<>(this); } @@ -134,47 +127,22 @@ public enum Order { return skylarkName; } - public String getDeprecatedSkylarkName() { - return deprecatedSkylarkName; - } - /** * Parses the given string as a nested set order * * @param name unique name of the order - * @param forbidDeprecatedOrderNames if true, old style ordering names will be rejected * @return the appropriate order instance * @throws IllegalArgumentException if the name is not valid */ - public static Order parse(String name, boolean forbidDeprecatedOrderNames) { + public static Order parse(String name) { if (VALUES.containsKey(name)) { return VALUES.get(name); - } else if (DEPRECATED_VALUES.containsKey(name)) { - if (forbidDeprecatedOrderNames) { - throw new IllegalArgumentException(String.format( - "Order name '%s' is deprecated, use '%s' instead", - name, - DEPRECATED_VALUES.get(name).getSkylarkName() - )); - } - return DEPRECATED_VALUES.get(name); } else { throw new IllegalArgumentException("Invalid order: " + name); } } /** - * Parses the given string as a nested set order - * - * @param name unique name of the order - * @return the appropriate order instance - * @throws IllegalArgumentException if the name is not valid - */ - public static Order parse(String name) { - return parse(name, false); - } - - /** * Determines whether two orders are considered compatible. * * <p>An order is compatible with itself (reflexivity) and all orders are compatible with @@ -191,14 +159,11 @@ public enum Order { Order[] tmpValues = Order.values(); HashMap<String, Order> entries = Maps.newHashMapWithExpectedSize(tmpValues.length); - HashMap<String, Order> deprecatedEntries = Maps.newHashMapWithExpectedSize(tmpValues.length); for (Order current : tmpValues) { entries.put(current.getSkylarkName(), current); - deprecatedEntries.put(current.getDeprecatedSkylarkName(), current); } VALUES = ImmutableMap.copyOf(entries); - DEPRECATED_VALUES = ImmutableMap.copyOf(deprecatedEntries); } } diff --git a/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsCodec.java b/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsCodec.java index e36eca2770..52db1ce009 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsCodec.java +++ b/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsCodec.java @@ -47,7 +47,6 @@ public final class SkylarkSemanticsCodec implements ObjectCodec<SkylarkSemantics codedOut.writeBoolNoTag(semantics.incompatibleDictLiteralHasNoDuplicates()); codedOut.writeBoolNoTag(semantics.incompatibleDisallowDictPlus()); codedOut.writeBoolNoTag(semantics.incompatibleDisallowKeywordOnlyArgs()); - codedOut.writeBoolNoTag(semantics.incompatibleDisallowSetConstructor()); codedOut.writeBoolNoTag(semantics.incompatibleDisallowToplevelIfStatement()); codedOut.writeBoolNoTag(semantics.incompatibleListPlusEqualsInplace()); codedOut.writeBoolNoTag(semantics.incompatibleLoadArgumentIsLabel()); @@ -70,7 +69,6 @@ public final class SkylarkSemanticsCodec implements ObjectCodec<SkylarkSemantics builder.incompatibleDictLiteralHasNoDuplicates(codedIn.readBool()); builder.incompatibleDisallowDictPlus(codedIn.readBool()); builder.incompatibleDisallowKeywordOnlyArgs(codedIn.readBool()); - builder.incompatibleDisallowSetConstructor(codedIn.readBool()); builder.incompatibleDisallowToplevelIfStatement(codedIn.readBool()); builder.incompatibleListPlusEqualsInplace(codedIn.readBool()); builder.incompatibleLoadArgumentIsLabel(codedIn.readBool()); diff --git a/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsOptions.java b/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsOptions.java index 2a7220de1d..0f8e0c4ad2 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsOptions.java +++ b/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsOptions.java @@ -146,17 +146,6 @@ public class SkylarkSemanticsOptions extends OptionsBase implements Serializable public boolean incompatibleDisallowKeywordOnlyArgs; @Option( - name = "incompatible_disallow_set_constructor", - defaultValue = "true", - category = "incompatible changes", - documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, - effectTags = {OptionEffectTag.UNKNOWN}, - metadataTags = {OptionMetadataTag.INCOMPATIBLE_CHANGE}, - help = "If set to true, disables the deprecated `set` constructor for depsets." - ) - public boolean incompatibleDisallowSetConstructor; - - @Option( name = "incompatible_disallow_toplevel_if_statement", defaultValue = "true", category = "incompatible changes", @@ -254,7 +243,6 @@ public class SkylarkSemanticsOptions extends OptionsBase implements Serializable .incompatibleDictLiteralHasNoDuplicates(incompatibleDictLiteralHasNoDuplicates) .incompatibleDisallowDictPlus(incompatibleDisallowDictPlus) .incompatibleDisallowKeywordOnlyArgs(incompatibleDisallowKeywordOnlyArgs) - .incompatibleDisallowSetConstructor(incompatibleDisallowSetConstructor) .incompatibleDisallowToplevelIfStatement(incompatibleDisallowToplevelIfStatement) .incompatibleListPlusEqualsInplace(incompatibleListPlusEqualsInplace) .incompatibleLoadArgumentIsLabel(incompatibleLoadArgumentIsLabel) diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BazelLibrary.java b/src/main/java/com/google/devtools/build/lib/syntax/BazelLibrary.java index 20111cedd6..a60ec53337 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/BazelLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/BazelLibrary.java @@ -114,8 +114,7 @@ public class BazelLibrary { defaultValue = "None" ) }, - useLocation = true, - useEnvironment = true + useLocation = true ) private static final BuiltinFunction depset = new BuiltinFunction("depset") { @@ -124,13 +123,11 @@ public class BazelLibrary { String orderString, Object direct, Object transitive, - Location loc, - Environment env) + Location loc) throws EvalException { Order order; try { - order = Order.parse( - orderString, env.getSemantics().incompatibleDisallowSetConstructor()); + order = Order.parse(orderString); } catch (IllegalArgumentException ex) { throw new EvalException(loc, ex); } @@ -180,7 +177,6 @@ public class BazelLibrary { @SkylarkSignature( name = "set", returnType = SkylarkNestedSet.class, - documentationReturnType = SkylarkNestedSet.LegacySet.class, doc = "A temporary alias for <a href=\"#depset\">depset</a>. " + "Deprecated in favor of <code>depset</code>.", @@ -198,28 +194,13 @@ public class BazelLibrary { doc = "Same as for <a href=\"#depset\">depset</a>." ) }, - useLocation = true, - useEnvironment = true + useLocation = true ) private static final BuiltinFunction set = new BuiltinFunction("set") { - public SkylarkNestedSet invoke(Object items, String order, Location loc, Environment env) + public SkylarkNestedSet invoke(Object items, String order, Location loc) throws EvalException { - if (env.getSemantics().incompatibleDisallowSetConstructor()) { - throw new EvalException( - loc, - "The `set` constructor for depsets is deprecated and will be removed. Please use " - + "the `depset` constructor instead. You can temporarily enable the " - + "deprecated `set` constructor by passing the flag " - + "--incompatible_disallow_set_constructor=false"); - } - try { - return new SkylarkNestedSet( - Order.parse(order, /*forbidDeprecatedOrderNames=*/false), - items, loc); - } catch (IllegalArgumentException ex) { - throw new EvalException(loc, ex); - } + throw new EvalException(loc, "The function 'set' has been removed in favor of 'depset'."); } }; diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkNestedSet.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkNestedSet.java index a35161dfc9..a773dd52d3 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkNestedSet.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkNestedSet.java @@ -92,20 +92,6 @@ public final class SkylarkNestedSet implements SkylarkValue, SkylarkQueryable { @Nullable private final List<NestedSet> transitiveItems; - // Dummy class used to create a documentation for the deprecated `set` type - // TODO(bazel-team): remove before the end of 2017 - @SkylarkModule( - name = "set", - category = SkylarkModuleCategory.BUILTIN, - doc = "A deprecated alias for <a href=\"depset.html\">depset</a>. " - + "Please use <a href=\"depset.html\">depset</a> instead. " - + "If you need a hash set that supports O(1) membership testing " - + "consider using a <a href=\"dict.html\">dict</a>." - ) - static final class LegacySet { - private LegacySet() {} - } - public SkylarkNestedSet(Order order, Object item, Location loc) throws EvalException { this(order, SkylarkType.TOP, item, loc, null); } diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java index 8d1fa59f4e..105768fd3d 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java @@ -46,7 +46,6 @@ public abstract class SkylarkSemantics { public abstract boolean incompatibleDictLiteralHasNoDuplicates(); public abstract boolean incompatibleDisallowDictPlus(); public abstract boolean incompatibleDisallowKeywordOnlyArgs(); - public abstract boolean incompatibleDisallowSetConstructor(); public abstract boolean incompatibleDisallowToplevelIfStatement(); public abstract boolean incompatibleListPlusEqualsInplace(); public abstract boolean incompatibleLoadArgumentIsLabel(); @@ -68,7 +67,6 @@ public abstract class SkylarkSemantics { .incompatibleDictLiteralHasNoDuplicates(true) .incompatibleDisallowDictPlus(false) .incompatibleDisallowKeywordOnlyArgs(true) - .incompatibleDisallowSetConstructor(true) .incompatibleDisallowToplevelIfStatement(true) .incompatibleListPlusEqualsInplace(true) .incompatibleLoadArgumentIsLabel(false) @@ -90,7 +88,6 @@ public abstract class SkylarkSemantics { public abstract Builder incompatibleDictLiteralHasNoDuplicates(boolean value); public abstract Builder incompatibleDisallowDictPlus(boolean value); public abstract Builder incompatibleDisallowKeywordOnlyArgs(boolean value); - public abstract Builder incompatibleDisallowSetConstructor(boolean value); public abstract Builder incompatibleDisallowToplevelIfStatement(boolean value); public abstract Builder incompatibleListPlusEqualsInplace(boolean value); public abstract Builder incompatibleLoadArgumentIsLabel(boolean value); |