Skip to content

Commit

Permalink
Remove --incompatible_disallow_slash_operator
Browse files Browse the repository at this point in the history
#5823

RELNOTES: Flag --incompatible_disallow_slash_operator is removed.
PiperOrigin-RevId: 228895539
  • Loading branch information
laurentlb authored and Copybara-Service committed Jan 11, 2019
1 parent 21e21bc commit 387cb02
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 60 deletions.
16 changes: 0 additions & 16 deletions site/docs/skylark/backward-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,22 +189,6 @@ for i in range(len(my_string)):
* Tracking issue: [#5830](https://github.com/bazelbuild/bazel/issues/5830)


### Integer division operator is `//`

Integer division operator is now `//` instead of `/`. This aligns with
Python 3 and it highlights the fact it is a floor division.

```python
x = 7 / 2 # deprecated

x = 7 // 2 # x is 3
```

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


### Package name is a function

The current package name should be retrieved by calling `package_name()` in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,18 +336,6 @@ public class SkylarkSemanticsOptions extends OptionsBase implements Serializable
)
public boolean incompatibleGenerateJavaCommonSourceJar;

@Option(
name = "incompatible_disallow_slash_operator",
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, the `/` operator is disabled. Use `//` for integer division.")
public boolean incompatibleDisallowSlashOperator;

/** Controls legacy arguments to ctx.actions.Args#add. */
@Option(
name = "incompatible_disallow_old_style_args_add",
Expand Down Expand Up @@ -538,7 +526,6 @@ public SkylarkSemantics toSkylarkSemantics() {
.incompatibleDisallowLoadLabelsToCrossPackageBoundaries(
incompatibleDisallowLoadLabelsToCrossPackageBoundaries)
.incompatibleDisallowOldStyleArgsAdd(incompatibleDisallowOldStyleArgsAdd)
.incompatibleDisallowSlashOperator(incompatibleDisallowSlashOperator)
.incompatibleExpandDirectories(incompatibleExpandDirectories)
.incompatibleGenerateJavaCommonSourceJar(incompatibleGenerateJavaCommonSourceJar)
.incompatibleNewActionsApi(incompatibleNewActionsApi)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,10 @@ private static Object evaluate(
return mult(lhs, rhs, env, location);

case DIVIDE:
if (env.getSemantics().incompatibleDisallowSlashOperator()) {
throw new EvalException(
location,
"The `/` operator has been removed. Please use the `//` operator for integer "
+ "division. You can temporarily enable the `/` operator by passing "
+ "the flag --incompatible_disallow_slash_operator=false");
}
return divide(lhs, rhs, location);
throw new EvalException(
location,
"The `/` operator is not allowed. Please use the `//` operator for integer "
+ "division.");

case FLOOR_DIVIDE:
return divide(lhs, rhs, location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ public boolean flagValue(FlagIdentifier flagIdentifier) {

public abstract boolean incompatibleDisallowOldStyleArgsAdd();

public abstract boolean incompatibleDisallowSlashOperator();

public abstract boolean incompatibleExpandDirectories();

public abstract boolean incompatibleGenerateJavaCommonSourceJar();
Expand Down Expand Up @@ -222,7 +220,6 @@ public static Builder builderWithDefaults() {
.incompatibleDisallowLegacyJavaInfo(false)
.incompatibleDisallowLoadLabelsToCrossPackageBoundaries(false)
.incompatibleDisallowOldStyleArgsAdd(false)
.incompatibleDisallowSlashOperator(true)
.incompatibleExpandDirectories(false)
.incompatibleGenerateJavaCommonSourceJar(false)
.incompatibleNewActionsApi(false)
Expand Down Expand Up @@ -287,8 +284,6 @@ public abstract static class Builder {

public abstract Builder incompatibleDisallowOldStyleArgsAdd(boolean value);

public abstract Builder incompatibleDisallowSlashOperator(boolean value);

public abstract Builder incompatibleExpandDirectories(boolean value);

public abstract Builder incompatibleGenerateJavaCommonSourceJar(boolean value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ private static SkylarkSemanticsOptions buildRandomOptions(Random rand) throws Ex
"--incompatible_disallow_legacy_java_provider=" + rand.nextBoolean(),
"--incompatible_disallow_load_labels_to_cross_package_boundaries=" + rand.nextBoolean(),
"--incompatible_disallow_old_style_args_add=" + rand.nextBoolean(),
"--incompatible_disallow_slash_operator=" + rand.nextBoolean(),
"--incompatible_expand_directories=" + rand.nextBoolean(),
"--incompatible_generate_javacommon_source_jar=" + rand.nextBoolean(),
"--incompatible_new_actions_api=" + rand.nextBoolean(),
Expand Down Expand Up @@ -191,7 +190,6 @@ private static SkylarkSemantics buildRandomSemantics(Random rand) {
.incompatibleDisallowLegacyJavaProvider(rand.nextBoolean())
.incompatibleDisallowLoadLabelsToCrossPackageBoundaries(rand.nextBoolean())
.incompatibleDisallowOldStyleArgsAdd(rand.nextBoolean())
.incompatibleDisallowSlashOperator(rand.nextBoolean())
.incompatibleExpandDirectories(rand.nextBoolean())
.incompatibleGenerateJavaCommonSourceJar(rand.nextBoolean())
.incompatibleNewActionsApi(rand.nextBoolean())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,22 +196,7 @@ public void testMult() throws Exception {

@Test
public void testSlashOperatorIsForbidden() throws Exception {
newTest("--incompatible_disallow_slash_operator=true")
.testIfErrorContains("The `/` operator has been removed.", "5 / 2");
}

@Test
public void testDivision() throws Exception {
newTest("--incompatible_disallow_slash_operator=false")
.testStatement("6 / 2", 3)
.testStatement("6 / 4", 1)
.testStatement("3 / 6", 0)
.testStatement("7 / -2", -4)
.testStatement("-7 / 2", -4)
.testStatement("-7 / -2", 3)
.testStatement("2147483647 / 2", 1073741823)
.testIfErrorContains("unsupported operand type(s) for //: 'string' and 'int'", "'str' / 2")
.testIfExactError("integer division by zero", "5 / 0");
newTest().testIfErrorContains("The `/` operator is not allowed.", "5 / 2");
}

@Test
Expand Down

0 comments on commit 387cb02

Please sign in to comment.