bazel analysis: delete ctx.expand

This feature is undocumented, unused*, and untested.

*as far as I can tell, though it is so rare to find
actual dead code, as opposed to mere vampire code:
code that serves no earthly purpose yet continues
to drain our life force.

RELNOTES: The undocumented ctx.expand feature no longer exists.
PiperOrigin-RevId: 351148802
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleContext.java
index 53a5401..84c0070 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleContext.java
@@ -37,8 +37,6 @@
 import com.google.devtools.build.lib.analysis.ExecGroupCollection;
 import com.google.devtools.build.lib.analysis.FileProvider;
 import com.google.devtools.build.lib.analysis.FilesToRunProvider;
-import com.google.devtools.build.lib.analysis.LabelExpander;
-import com.google.devtools.build.lib.analysis.LabelExpander.NotUniqueExpansionException;
 import com.google.devtools.build.lib.analysis.LocationExpander;
 import com.google.devtools.build.lib.analysis.ResolvedToolchainContext;
 import com.google.devtools.build.lib.analysis.RuleContext;
@@ -132,9 +130,6 @@
   private StarlarkAttributesCollection attributesCollection;
   private StarlarkAttributesCollection ruleAttributesCollection;
   private StructImpl splitAttributes;
-
-  // TODO(bazel-team): we only need this because of the css_binary rule.
-  private ImmutableMap<Artifact, Label> artifactsLabelMap;
   private Outputs outputsObject;
 
   /**
@@ -177,7 +172,6 @@
         }
       }
 
-      ImmutableMap.Builder<Artifact, Label> artifactLabelMapBuilder = ImmutableMap.builder();
       for (Attribute a : attributes) {
         String attrName = a.getName();
         Type<?> type = a.getType();
@@ -186,9 +180,7 @@
         }
         ImmutableList.Builder<Artifact> artifactsBuilder = ImmutableList.builder();
         for (OutputFile outputFile : ruleContext.getRule().getOutputFileMap().get(attrName)) {
-          Artifact artifact = ruleContext.createOutputArtifact(outputFile);
-          artifactsBuilder.add(artifact);
-          artifactLabelMapBuilder.put(artifact, outputFile.getLabel());
+          artifactsBuilder.add(ruleContext.createOutputArtifact(outputFile));
         }
         StarlarkList<Artifact> artifacts = StarlarkList.immutableCopyOf(artifactsBuilder.build());
 
@@ -206,7 +198,6 @@
         }
       }
 
-      this.artifactsLabelMap = artifactLabelMapBuilder.build();
       this.outputsObject = outputs;
 
       StarlarkAttributesCollection.Builder builder = StarlarkAttributesCollection.builder(this);
@@ -220,7 +211,6 @@
       this.ruleAttributesCollection = null;
     } else { // ASPECT
       this.isForAspect = true;
-      this.artifactsLabelMap = ImmutableMap.of();
       this.outputsObject = null;
 
       ImmutableCollection<Attribute> attributes =
@@ -393,7 +383,6 @@
     attributesCollection = null;
     ruleAttributesCollection = null;
     splitAttributes = null;
-    artifactsLabelMap = null;
     outputsObject = null;
   }
 
@@ -717,24 +706,6 @@
     return StarlarkList.immutableCopyOf(options);
   }
 
-  @Override
-  public String expand(
-      @Nullable String expression,
-      Sequence<?> artifacts, // <Artifact>
-      Label labelResolver)
-      throws EvalException {
-    checkMutable("expand");
-    try {
-      Map<Label, Iterable<Artifact>> labelMap = new HashMap<>();
-      for (Artifact artifact : Sequence.cast(artifacts, Artifact.class, "artifacts")) {
-        labelMap.put(artifactsLabelMap.get(artifact), ImmutableList.of(artifact));
-      }
-      return LabelExpander.expand(expression, labelMap, labelResolver);
-    } catch (NotUniqueExpansionException e) {
-      throw Starlark.errorf("%s while expanding '%s'", e.getMessage(), expression);
-    }
-  }
-
   boolean isForAspect() {
     return isForAspect;
   }
diff --git a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/StarlarkRuleContextApi.java b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/StarlarkRuleContextApi.java
index cc9a206..48643b1 100644
--- a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/StarlarkRuleContextApi.java
+++ b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/StarlarkRuleContextApi.java
@@ -358,38 +358,6 @@
   Sequence<String> tokenize(String optionString) throws EvalException;
 
   @StarlarkMethod(
-      name = "expand",
-      doc =
-          "Expands all references to labels embedded within a string for all files using a mapping "
-              + "from definition labels (i.e. the label in the output type attribute) to files. "
-              + "Deprecated.",
-      // TODO(cparsons): Look into flipping this to true.
-      documented = false,
-      parameters = {
-        @Param(
-            name = "expression",
-            positional = true,
-            named = false,
-            doc = "The string expression to expand."),
-        @Param(
-            name = "files",
-            positional = true,
-            named = false,
-            allowedTypes = {@ParamType(type = Sequence.class, generic1 = FileApi.class)},
-            doc = "The list of files."),
-        @Param(
-            name = "label_resolver",
-            positional = true,
-            named = false,
-            doc = "The label resolver."),
-      })
-  String expand(
-      @Nullable String expression,
-      Sequence<?> artifacts, // <FileT>
-      Label labelResolver)
-      throws EvalException;
-
-  @StarlarkMethod(
       name = "new_file",
       doc =
           "DEPRECATED. Use <a href=\"actions.html#declare_file\">ctx.actions.declare_file</a>. <br>"
diff --git a/src/test/java/com/google/devtools/build/lib/starlark/StarlarkRuleContextTest.java b/src/test/java/com/google/devtools/build/lib/starlark/StarlarkRuleContextTest.java
index 5d89e0d..85cbd09 100644
--- a/src/test/java/com/google/devtools/build/lib/starlark/StarlarkRuleContextTest.java
+++ b/src/test/java/com/google/devtools/build/lib/starlark/StarlarkRuleContextTest.java
@@ -2445,7 +2445,6 @@
           "aspect_ids",
           "var",
           "tokenize('foo')",
-          "expand('foo', [], Label('//test:main'))",
           "new_file('foo.txt')",
           "new_file(file, 'foo.txt')",
           "actions.declare_file('foo.txt')",