Skip to content

Commit 8ae2570

Browse files
tetrominocopybara-github
authored andcommitted
Enable Starlark sets by default
Now that the Starlark language spec has been approved: https://github.com/bazelbuild/starlark/blob/master/spec.md#sets Require elements of arguments to StarlarkSet methods to be hashable, matching the final version of the language spec. Take the opportunity to update our documentation to match the spec whenever reasonable (modulo minor differences in terminology and formatting). RELNOTES: Flip --experimental_enable_starlark_set and enable the Starlark set data type by default. PiperOrigin-RevId: 707659085 Change-Id: Ibcad59838f9709e980d7b69f4957b8f0fede51c6
1 parent b2ec21e commit 8ae2570

File tree

5 files changed

+273
-146
lines changed

5 files changed

+273
-146
lines changed

src/main/java/com/google/devtools/build/lib/packages/semantics/BuildLanguageOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ public final class BuildLanguageOptions extends OptionsBase {
808808

809809
@Option(
810810
name = "experimental_enable_starlark_set",
811-
defaultValue = "false",
811+
defaultValue = "true",
812812
documentationCategory = OptionDocumentationCategory.STARLARK_SEMANTICS,
813813
effectTags = {OptionEffectTag.BUILD_FILE_SEMANTICS},
814814
metadataTags = {OptionMetadataTag.EXPERIMENTAL},

src/main/java/net/starlark/java/eval/MethodLibrary.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -641,13 +641,24 @@ public StarlarkInt intForStarlark(Object x, Object baseO) throws EvalException {
641641
@StarlarkMethod(
642642
name = "set",
643643
doc =
644-
"<b>Experimental</b>. This API is experimental and may change at any time. Please do not"
645-
+ " depend on it. It may be enabled on an experimental basis by setting"
646-
+ " <code>--experimental_enable_starlark_set</code>.\n" //
647-
+ "<p>Creates a new <a href=\"../core/set.html\">set</a>, optionally initialized to"
648-
+ " contain the elements from a given iterable.",
644+
"""
645+
Creates a new <a href=\"../core/set.html\">set</a> containing the unique elements of a given
646+
iterable, preserving iteration order.
647+
648+
<p>If called with no argument, <code>set()</code> returns a new empty set.
649+
650+
<p>For example,
651+
<pre class=language-python>
652+
set() # an empty set
653+
set([3, 1, 1, 2]) # set([3, 1, 2]), a set of three elements
654+
set({"k1": "v1", "k2": "v2"}) # set(["k1", "k2"]), a set of two elements
655+
</pre>
656+
""",
649657
parameters = {
650-
@Param(name = "elements", defaultValue = "[]", doc = "A set, sequence, or dict."),
658+
@Param(
659+
name = "elements",
660+
defaultValue = "[]",
661+
doc = "A set, a sequence of hashable values, or a dict."),
651662
},
652663
useStarlarkThread = true)
653664
public StarlarkSet<Object> set(Object elements, StarlarkThread thread) throws EvalException {

src/main/java/net/starlark/java/eval/StarlarkSemantics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,5 +258,5 @@ public final String toString() {
258258
public static final String ALLOW_RECURSION = "-allow_recursion";
259259

260260
/** Whether StarlarkSet objects may be constructed by the interpreter. */
261-
public static final String EXPERIMENTAL_ENABLE_STARLARK_SET = "-experimental_enable_starlark_set";
261+
public static final String EXPERIMENTAL_ENABLE_STARLARK_SET = "+experimental_enable_starlark_set";
262262
}

0 commit comments

Comments
 (0)