bazel syntax: remove deprecated list constructors
- rename Sequence.createImmutable to StarlarkList.immutableCopyOf
- delete StarlarkList.of(StarlarkThread, ...)
and StarlarkList.copyOf(StarlarkThread, ...)
Mutability is now always an explicit parameter.
StarlarkThread is no longer relevant to StarlarkList
- deprecate Dict constructors that take a StarlarkThread,
and provide (only a few) Mutability variants.
This CL makes only the minimum change to Dict to support
the changes to StarlarkList. A follow-up CL will
eliminate the deprecated constructors. In some cases
"(Mutability) null" is required to avoid overload ambiguity.
This is a breaking change for copybara.
BEGIN_PUBLIC
bazel syntax: remove deprecated list constructors
END_PUBLIC
PiperOrigin-RevId: 281805867
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java b/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java
index 95f27fa..365b8c6 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java
@@ -36,7 +36,7 @@
public class EvalUtilsTest extends EvaluationTestCase {
private static StarlarkList<Object> makeList(StarlarkThread thread) {
- return StarlarkList.of(thread, 1, 2, 3);
+ return StarlarkList.of(thread == null ? null : thread.mutability(), 1, 2, 3);
}
private static Dict<Object, Object> makeDict(StarlarkThread thread) {
@@ -96,8 +96,8 @@
Starlark.NONE,
Tuple.of(1, 2, 3),
Tuple.of("1", "2", "3"),
- StarlarkList.of(thread, 1, 2, 3),
- StarlarkList.of(thread, "1", "2", "3"),
+ StarlarkList.of(thread.mutability(), 1, 2, 3),
+ StarlarkList.of(thread.mutability(), "1", "2", "3"),
Dict.of(thread, "key", 123),
Dict.of(thread, 123, "value"),
StructProvider.STRUCT.create(ImmutableMap.of("key", (Object) "value"), "no field %s"),
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
index 21a47036..0685ece 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
@@ -283,7 +283,7 @@
// list
Object x = eval("[1,2] + [3,4]");
assertThat((Iterable<Object>) x).containsExactly(1, 2, 3, 4).inOrder();
- assertThat(x).isEqualTo(StarlarkList.of(thread, 1, 2, 3, 4));
+ assertThat(x).isEqualTo(StarlarkList.of(thread.mutability(), 1, 2, 3, 4));
assertThat(EvalUtils.isImmutable(x)).isFalse();
// tuple
@@ -475,7 +475,7 @@
@Test
public void testListConcatenation() throws Exception {
newTest()
- .testExpression("[1, 2] + [3, 4]", StarlarkList.of(thread, 1, 2, 3, 4))
+ .testExpression("[1, 2] + [3, 4]", StarlarkList.of(thread.mutability(), 1, 2, 3, 4))
.testExpression("(1, 2) + (3, 4)", Tuple.of(1, 2, 3, 4))
.testIfExactError(
"unsupported operand type(s) for +: 'list' and 'tuple'", "[1, 2] + (3, 4)")
@@ -485,16 +485,17 @@
@Test
public void testListMultiply() throws Exception {
+ Mutability mu = thread.mutability();
newTest()
- .testExpression("[1, 2, 3] * 1", StarlarkList.of(thread, 1, 2, 3))
- .testExpression("[1, 2] * 2", StarlarkList.of(thread, 1, 2, 1, 2))
- .testExpression("[1, 2] * 3", StarlarkList.of(thread, 1, 2, 1, 2, 1, 2))
- .testExpression("[1, 2] * 4", StarlarkList.of(thread, 1, 2, 1, 2, 1, 2, 1, 2))
- .testExpression("[8] * 5", StarlarkList.of(thread, 8, 8, 8, 8, 8))
+ .testExpression("[1, 2, 3] * 1", StarlarkList.of(mu, 1, 2, 3))
+ .testExpression("[1, 2] * 2", StarlarkList.of(mu, 1, 2, 1, 2))
+ .testExpression("[1, 2] * 3", StarlarkList.of(mu, 1, 2, 1, 2, 1, 2))
+ .testExpression("[1, 2] * 4", StarlarkList.of(mu, 1, 2, 1, 2, 1, 2, 1, 2))
+ .testExpression("[8] * 5", StarlarkList.of(mu, 8, 8, 8, 8, 8))
.testExpression("[ ] * 10", StarlarkList.empty())
.testExpression("[1, 2] * 0", StarlarkList.empty())
.testExpression("[1, 2] * -4", StarlarkList.empty())
- .testExpression("2 * [1, 2]", StarlarkList.of(thread, 1, 2, 1, 2))
+ .testExpression("2 * [1, 2]", StarlarkList.of(mu, 1, 2, 1, 2))
.testExpression("10 * []", StarlarkList.empty())
.testExpression("0 * [1, 2]", StarlarkList.empty())
.testExpression("-4 * [1, 2]", StarlarkList.empty());
@@ -569,7 +570,7 @@
public void testListComprehensionOnDictionaryCompositeExpression() throws Exception {
new BuildTest()
.setUp("d = {1:'a',2:'b'}", "l = [d[x] for x in d]")
- .testLookup("l", StarlarkList.of(thread, "a", "b"));
+ .testLookup("l", StarlarkList.of(thread.mutability(), "a", "b"));
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
index 6b8bb04..0ecc3cf 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
@@ -1084,7 +1084,7 @@
" modified_list = v + ['extra_string']",
" return modified_list",
"m = func(mock)")
- .testLookup("m", StarlarkList.of(thread, "b", "c", "extra_string"));
+ .testLookup("m", StarlarkList.of(thread.mutability(), "b", "c", "extra_string"));
}
@Test
@@ -1555,7 +1555,7 @@
" return value",
"",
"f()[1] += 1") // `f()` should be called only once here
- .testLookup("counter", StarlarkList.of(thread, 1));
+ .testLookup("counter", StarlarkList.of(thread.mutability(), 1));
// Check key position.
new SkylarkTest()
@@ -1568,7 +1568,7 @@
" return 1",
"",
"value[f()] += 1") // `f()` should be called only once here
- .testLookup("counter", StarlarkList.of(thread, 1));
+ .testLookup("counter", StarlarkList.of(thread.mutability(), 1));
}
@Test
@@ -1608,8 +1608,9 @@
"",
"f(ordinary)[0] = g(ordinary)[1]",
"f(augmented)[0] += g(augmented)[1]")
- .testLookup("ordinary", StarlarkList.of(thread, "g", "f")) // This order is consistent
- .testLookup("augmented", StarlarkList.of(thread, "f", "g")); // with Python
+ .testLookup(
+ "ordinary", StarlarkList.of(thread.mutability(), "g", "f")) // This order is consistent
+ .testLookup("augmented", StarlarkList.of(thread.mutability(), "f", "g")); // with Python
}
@Test
@@ -1741,7 +1742,7 @@
public void testDictAssignmentAsLValueSideEffects() throws Exception {
new SkylarkTest()
.setUp("def func(d):", " d['b'] = 2", "d = {'a' : 1}", "func(d)")
- .testLookup("d", Dict.of(null, "a", 1, "b", 2));
+ .testLookup("d", Dict.of((Mutability) null, "a", 1, "b", 2));
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkListTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkListTest.java
index a404505..da8b41d 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkListTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkListTest.java
@@ -155,7 +155,8 @@
@Test
public void testListConcat() throws Exception {
- assertThat(eval("[1, 2] + [3, 4]")).isEqualTo(Sequence.createImmutable(Tuple.of(1, 2, 3, 4)));
+ assertThat(eval("[1, 2] + [3, 4]"))
+ .isEqualTo(StarlarkList.of(/*mutability=*/ null, 1, 2, 3, 4));
}
@Test
@@ -317,7 +318,8 @@
public void testGetSkylarkType_GivesExpectedClassesForListsAndTuples() throws Exception {
Class<?> emptyTupleClass = Tuple.empty().getClass();
Class<?> tupleClass = Tuple.of(1, "a", "b").getClass();
- Class<?> mutableListClass = StarlarkList.copyOf(thread, Tuple.of(1, 2, 3)).getClass();
+ Class<?> mutableListClass =
+ StarlarkList.copyOf(thread.mutability(), Tuple.of(1, 2, 3)).getClass();
assertThat(EvalUtils.getSkylarkType(mutableListClass)).isEqualTo(StarlarkList.class);
assertThat(EvalUtils.getSkylarkType(emptyTupleClass)).isEqualTo(Tuple.class);
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/StarlarkFileTest.java b/src/test/java/com/google/devtools/build/lib/syntax/StarlarkFileTest.java
index 0d1fafe..20267d9 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/StarlarkFileTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/StarlarkFileTest.java
@@ -58,7 +58,7 @@
// input1.BUILD contains:
// x = [1,2,'foo',4] + [1,2, "%s%d" % ('foo', 1)]
assertThat(thread.moduleLookup("x"))
- .isEqualTo(Sequence.createImmutable(Tuple.of(1, 2, "foo", 4, 1, 2, "foo1")));
+ .isEqualTo(StarlarkList.of(/*mutability=*/ null, 1, 2, "foo", 4, 1, 2, "foo1"));
}
@Test