Add drop state nodes flag and apply it to `SkyframeProgressReceiver#evaluated()` method.

Due to the fact that the vast majority of the `_STATE` nodes only have one rdeps, we decided to drop them after the evaluation of `FILE` or `DIRECTORY_LISTING` nodes. So in this change:

* A new `--experimental_drop_state_nodes` is added in `CommonCommandOptions` in order to control whether `_STATE` nodes should be dropped or not;
* Inject the flag to `SequencedSkyframeExecutor` and `SkybuildV2SkyframeExecutor`;
* `SkyframeProgressReceiver#evaluated(...)` method decides whether to drop `_STATE` nodes based on the flag value and the type of input `SkyKey`.

PiperOrigin-RevId: 495949249
Change-Id: I7b4b84f7d91e8c3a7ce44f5ccb1af62ed134ebeb
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java b/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java
index a4b79f6..ef71cc9 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java
@@ -535,6 +535,18 @@
               + " invalidating the action graph.")
   public List<Map.Entry<String, String>> repositoryEnvironment;
 
+  @Option(
+      name = "experimental_heuristically_drop_nodes",
+      defaultValue = "false",
+      documentationCategory = OptionDocumentationCategory.BUILD_TIME_OPTIMIZATION,
+      effectTags = {OptionEffectTag.LOSES_INCREMENTAL_STATE},
+      help =
+          "If true, Blaze will remove FileState and DirectoryListingState nodes after related File"
+              + " and DirectoryListing node is done to save memory. We expect that it is less"
+              + " likely that these nodes will be needed again. If so, the program will re-evaluate"
+              + " them.")
+  public boolean experimentalHeuristicallyDropNodes;
+
   /** The option converter to check that the user can only specify legal profiler tasks. */
   public static class ProfilerTaskConverter extends EnumConverter<ProfilerTask> {
     public ProfilerTaskConverter() {