Skip to content

Commit

Permalink
Remove --incompatible_range_type
Browse files Browse the repository at this point in the history
#5264

RELNOTES: Flag --incompatible_range_type is removed.
PiperOrigin-RevId: 228892885
  • Loading branch information
laurentlb authored and Copybara-Service committed Jan 11, 2019
1 parent 74c274a commit 21e21bc
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 139 deletions.
10 changes: 0 additions & 10 deletions site/docs/skylark/backward-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,6 @@ or `add_joined()` instead.
* Tracking issue: [#5822](https://github.com/bazelbuild/bazel/issues/5822)


### Python 3 range behavior.
When set, the result of `range(...)` function is a lazy `range` type instead of
a `list`. Because of this repetitions using `*` operator are no longer
supported and `range` slices are also lazy `range` instances.

* Flag: `--incompatible_range_type`
* Default: `true`
* Tracking issue: [#5264](https://github.com/bazelbuild/bazel/issues/5264)


### Disable objc provider resources

This flag disables certain deprecated resource fields on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,19 +460,6 @@ public class SkylarkSemanticsOptions extends OptionsBase implements Serializable
+ "symbols introduced by load are not implicitly re-exported.")
public boolean incompatibleNoTransitiveLoads;

@Option(
name = "incompatible_range_type",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.SKYLARK_SEMANTICS,
effectTags = {OptionEffectTag.BUILD_FILE_SEMANTICS},
metadataTags = {
OptionMetadataTag.INCOMPATIBLE_CHANGE,
OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES
},
help = "If set to true, range() will use the 'range' type instead of 'list'."
)
public boolean incompatibleRangeType;

@Option(
name = "incompatible_remove_native_maven_jar",
defaultValue = "false",
Expand Down Expand Up @@ -560,7 +547,6 @@ public SkylarkSemantics toSkylarkSemantics() {
.incompatibleNoSupportToolsInActionInputs(incompatibleNoSupportToolsInActionInputs)
.incompatibleNoTargetOutputGroup(incompatibleNoTargetOutputGroup)
.incompatibleNoTransitiveLoads(incompatibleNoTransitiveLoads)
.incompatibleRangeType(incompatibleRangeType)
.incompatibleRemoveNativeMavenJar(incompatibleRemoveNativeMavenJar)
.incompatibleRequireFeatureConfigurationForPic(requireFeatureConfigurationForPic)
.incompatibleStricArgumentOrdering(incompatibleStricArgumentOrdering)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,7 @@ public SkylarkList<Integer> invoke(
if (step == 0) {
throw new EvalException(loc, "step cannot be 0");
}
RangeList range = RangeList.of(start, stop, step);
return env.getSemantics().incompatibleRangeType() ? range : range.toMutableList(env);
return RangeList.of(start, stop, step);
}
};

Expand Down
14 changes: 0 additions & 14 deletions src/main/java/com/google/devtools/build/lib/syntax/RangeList.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,20 +221,6 @@ public void repr(SkylarkPrinter printer) {
}
}

/**
* Converts this range sequence into a materialized list.
*
* <p>Usage of this method is not recommended, since it completely defeats the purpose of lazy
* computation by eagerly computing the result.
*
* @return A materialized version of the range that can be used as a
* <pre>list</pre>
* type.
*/
MutableList<Integer> toMutableList(Environment env) {
return MutableList.copyOf(env, contents);
}

/**
* @return A half-opened range defined by its starting value (inclusive), stop value (exclusive)
* and a step from previous value to the next one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ public boolean flagValue(FlagIdentifier flagIdentifier) {

public abstract boolean incompatibleNoTransitiveLoads();

public abstract boolean incompatibleRangeType();

public abstract boolean incompatibleRemoveNativeMavenJar();

public abstract boolean incompatibleRequireFeatureConfigurationForPic();
Expand Down Expand Up @@ -233,7 +231,6 @@ public static Builder builderWithDefaults() {
.incompatibleNoSupportToolsInActionInputs(false)
.incompatibleNoTargetOutputGroup(false)
.incompatibleNoTransitiveLoads(false)
.incompatibleRangeType(true)
.incompatibleRemoveNativeMavenJar(false)
.incompatibleRequireFeatureConfigurationForPic(false)
.incompatibleStricArgumentOrdering(false)
Expand Down Expand Up @@ -308,8 +305,6 @@ public abstract static class Builder {

public abstract Builder incompatibleNoTransitiveLoads(boolean value);

public abstract Builder incompatibleRangeType(boolean value);

public abstract Builder incompatibleRemoveNativeMavenJar(boolean value);

public abstract Builder incompatibleStricArgumentOrdering(boolean value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ private static SkylarkSemanticsOptions buildRandomOptions(Random rand) throws Ex
"--incompatible_no_support_tools_in_action_inputs=" + rand.nextBoolean(),
"--incompatible_no_target_output_group=" + rand.nextBoolean(),
"--incompatible_no_transitive_loads=" + rand.nextBoolean(),
"--incompatible_range_type=" + rand.nextBoolean(),
"--incompatible_remove_native_maven_jar=" + rand.nextBoolean(),
"--incompatible_require_feature_configuration_for_pic=" + rand.nextBoolean(),
"--incompatible_strict_argument_ordering=" + rand.nextBoolean(),
Expand Down Expand Up @@ -201,7 +200,6 @@ private static SkylarkSemantics buildRandomSemantics(Random rand) {
.incompatibleNoSupportToolsInActionInputs(rand.nextBoolean())
.incompatibleNoTargetOutputGroup(rand.nextBoolean())
.incompatibleNoTransitiveLoads(rand.nextBoolean())
.incompatibleRangeType(rand.nextBoolean())
.incompatibleRemoveNativeMavenJar(rand.nextBoolean())
.incompatibleRequireFeatureConfigurationForPic(rand.nextBoolean())
.incompatibleStricArgumentOrdering(rand.nextBoolean())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,47 +469,9 @@ public void testHash() throws Exception {
"hash(None)");
}

@Test
public void testRange() throws Exception {
new BothModesTest("--incompatible_range_type=false")
.testStatement("str(range(5))", "[0, 1, 2, 3, 4]")
.testStatement("str(range(0))", "[]")
.testStatement("str(range(1))", "[0]")
.testStatement("str(range(-2))", "[]")
.testStatement("str(range(-3, 2))", "[-3, -2, -1, 0, 1]")
.testStatement("str(range(3, 2))", "[]")
.testStatement("str(range(3, 3))", "[]")
.testStatement("str(range(3, 4))", "[3]")
.testStatement("str(range(3, 5))", "[3, 4]")
.testStatement("str(range(-3, 5, 2))", "[-3, -1, 1, 3]")
.testStatement("str(range(-3, 6, 2))", "[-3, -1, 1, 3, 5]")
.testStatement("str(range(5, 0, -1))", "[5, 4, 3, 2, 1]")
.testStatement("str(range(5, 0, -10))", "[5]")
.testStatement("str(range(0, -3, -2))", "[0, -2]")
.testStatement("str(range(5)[1:])", "[1, 2, 3, 4]")
.testStatement("len(range(5)[1:])", 4)
.testStatement("str(range(5)[:2])", "[0, 1]")
.testStatement("str(range(10)[1:9:2])", "[1, 3, 5, 7]")
.testStatement("str(range(10)[1:10:2])", "[1, 3, 5, 7, 9]")
.testStatement("str(range(10)[1:11:2])", "[1, 3, 5, 7, 9]")
.testStatement("str(range(0, 10, 2)[::2])", "[0, 4, 8]")
.testStatement("str(range(0, 10, 2)[::-2])", "[8, 4, 0]")
.testIfErrorContains("step cannot be 0", "range(2, 3, 0)");
}

@Test
public void testRangeIsList() throws Exception {
// range(), and slices of ranges, may change in the future to return read-only views. But for
// now it's just a list and can therefore be ordered, mutated, and concatenated. This test
// ensures we don't break backward compatibility until we intend to, even if range() is
// optimized to return lazy list-like values.
runRangeIsListAssertions("range(3)");
runRangeIsListAssertions("range(4)[:3]");
}

@Test
public void testRangeType() throws Exception {
new BothModesTest("--incompatible_range_type=true")
new BothModesTest()
.setUp("a = range(3)")
.testStatement("len(a)", 3)
.testStatement("str(a)", "range(0, 3)")
Expand Down Expand Up @@ -558,59 +520,6 @@ public void testRangeType() throws Exception {
.testStatement("range(0, 5, 2) == [0, 2, 4]", false);
}

/**
* Helper function for testRangeIsList that expects a range or range slice expression producing
* the range value containing [0, 1, 2].
*/
private void runRangeIsListAssertions(String range3expr) throws Exception {
// Check stringifications.
new BothModesTest("--incompatible_range_type=false")
.setUp("a = " + range3expr)
.testStatement("str(a)", "[0, 1, 2]")
.testStatement("repr(a)", "[0, 1, 2]")
.testStatement("type(a)", "list");

// Check comparisons.
new BothModesTest("--incompatible_range_type=false")
.setUp("a = " + range3expr)
.setUp("b = range(0, 3, 1)")
.setUp("c = range(1, 4)")
.setUp("L = [0, 1, 2]")
.setUp("T = (0, 1, 2)")
.testStatement("a == b", true)
.testStatement("a == c", false)
.testStatement("a < b", false)
.testStatement("a < c", true)
.testStatement("a == L", true)
.testStatement("a == T", false)
.testStatement("a < L", false)
.testIfErrorContains("Cannot compare list with tuple", "a < T");

// Check mutations.
new BothModesTest("--incompatible_range_type=false")
.setUp("a = " + range3expr)
.testStatement("a.append(3); str(a)", "[0, 1, 2, 3]");
new SkylarkTest("--incompatible_range_type=false")
.testStatement(
"def f():\n"
+ " a = " + range3expr + "\n"
+ " b = a\n"
+ " a += [3]\n"
+ " return str(b)\n"
+ "f()\n",
"[0, 1, 2, 3]");

// Check concatenations.
new BothModesTest("--incompatible_range_type=false")
.setUp("a = " + range3expr)
.setUp("b = range(3, 4)")
.setUp("L = [3]")
.setUp("T = (3,)")
.testStatement("str(a + b)", "[0, 1, 2, 3]")
.testStatement("str(a + L)", "[0, 1, 2, 3]")
.testIfErrorContains("unsupported operand type(s) for +: 'list' and 'tuple", "str(a + T)");
}

@Test
public void testEnumerate() throws Exception {
new BothModesTest()
Expand Down

0 comments on commit 21e21bc

Please sign in to comment.