Fix skylark aspect issues.

--
MOS_MIGRATED_REVID=109690378
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java
index bddfc81..25293cd 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java
@@ -200,15 +200,15 @@
   /**
    * Returns the STL prerequisite of the rule.
    *
-   * <p>If rule has an implicit $stl attribute returns STL version set on the
-   * command line or if not set, the value of the $stl attribute. Returns
+   * <p>If rule has an implicit $stl_default attribute returns STL version set on the
+   * command line or if not set, the value of the $stl_default attribute. Returns
    * {@code null} otherwise.
    */
   private static Label getStl(Rule rule, BuildConfiguration original) {
     Label stl = null;
-    if (rule.getRuleClassObject().hasAttr("$stl", BuildType.LABEL)) {
+    if (rule.getRuleClassObject().hasAttr("$stl_default", BuildType.LABEL)) {
       Label stlConfigLabel = original.getFragment(CppConfiguration.class).getStl();
-      Label stlRuleLabel = RawAttributeMapper.of(rule).get("$stl", BuildType.LABEL);
+      Label stlRuleLabel = RawAttributeMapper.of(rule).get("$stl_default", BuildType.LABEL);
       if (stlConfigLabel == null) {
         stl = stlRuleLabel;
       } else if (!stlConfigLabel.equals(rule.getLabel()) && stlRuleLabel != null) {
@@ -260,8 +260,9 @@
           so be careful about header files included elsewhere.</p>
           <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
           .add(attr("copts", STRING_LIST))
-          .add(attr("$stl", LABEL).value(env.getLabel(
-              Constants.TOOLS_REPOSITORY + "//tools/cpp:stl")))
+          .add(
+              attr("$stl_default", LABEL)
+                  .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/cpp:stl")))
           .add(attr(":stl", LABEL).value(STL))
           .build();
     }
@@ -451,18 +452,20 @@
             accordance with gcc convention.
           </p>
           <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
-          .add(attr("srcs", LABEL_LIST)
-              .direct_compile_time_input()
-              .allowedFileTypes(ALLOWED_SRC_FILES))
+          .add(
+              attr("srcs", LABEL_LIST)
+                  .direct_compile_time_input()
+                  .allowedFileTypes(ALLOWED_SRC_FILES))
           /*<!-- #BLAZE_RULE($cc_rule).ATTRIBUTE(deps) -->
           The list of other libraries to be linked in to the binary target.
           ${SYNOPSIS}
           <p>These are always <code>cc_library</code> rules.</p>
           <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
-          .override(attr("deps", LABEL_LIST)
-              .allowedRuleClasses(DEPS_ALLOWED_RULES)
-              .allowedFileTypes(CppFileTypes.LINKER_SCRIPT)
-              .skipAnalysisTimeFileTypeCheck())
+          .override(
+              attr("deps", LABEL_LIST)
+                  .allowedRuleClasses(DEPS_ALLOWED_RULES)
+                  .allowedFileTypes(CppFileTypes.LINKER_SCRIPT)
+                  .skipAnalysisTimeFileTypeCheck())
           /*<!-- #BLAZE_RULE($cc_rule).ATTRIBUTE(linkopts) -->
           Add these flags to the C++ linker command.
           ${SYNOPSIS}
@@ -528,16 +531,20 @@
            </p>
           <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
           .add(attr("linkstatic", BOOLEAN).value(true))
-          .override(attr("$stl", LABEL).value(new Attribute.ComputedDefault() {
-            @Override
-            public Object getDefault(AttributeMap rule) {
-              // Every cc_rule depends implicitly on STL to make
-              // sure that the correct headers are used for inclusion. The only exception is
-              // STL itself to avoid cycles in the dependency graph.
-              Label stl = env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/cpp:stl");
-              return rule.getLabel().equals(stl) ? null : stl;
-            }
-          }))
+          .override(
+              attr("$stl_default", LABEL)
+                  .value(
+                      new Attribute.ComputedDefault() {
+                        @Override
+                        public Object getDefault(AttributeMap rule) {
+                          // Every cc_rule depends implicitly on STL to make
+                          // sure that the correct headers are used for inclusion.
+                          // The only exception is STL itself,
+                          // to avoid cycles in the dependency graph.
+                          Label stl = env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/cpp:stl");
+                          return rule.getLabel().equals(stl) ? null : stl;
+                        }
+                      }))
           .build();
     }
     @Override
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
index e3a673f..252bbfd 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
@@ -14,8 +14,8 @@
 
 package com.google.devtools.build.lib.packages;
 
-import static com.google.devtools.build.lib.packages.Attribute.attr;
 import static com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition.HOST;
+import static com.google.devtools.build.lib.packages.Attribute.attr;
 import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
 import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
 
@@ -1076,6 +1076,7 @@
     this.configuredTargetFunction = configuredTargetFunction;
     this.externalBindingsFunction = externalBindingsFunction;
     this.ruleDefinitionEnvironment = ruleDefinitionEnvironment;
+    validateNoClashInPublicNames(attributes);
     this.attributes = ImmutableList.copyOf(attributes);
     this.workspaceOnly = workspaceOnly;
     this.outputsDefaultExecutable = outputsDefaultExecutable;
@@ -1090,6 +1091,23 @@
     }
   }
 
+  private void validateNoClashInPublicNames(Attribute[] attributes) {
+    Map<String, Attribute> publicToPrivateNames = new HashMap<>();
+    for (Attribute attribute : attributes) {
+      String publicName = attribute.getPublicName();
+      if (publicToPrivateNames.containsKey(publicName)) {
+        throw new IllegalStateException(
+            String.format(
+                "Rule %s: Attributes %s and %s have an identical public name: %s",
+                name,
+                attribute.getName(),
+                publicToPrivateNames.get(publicName).getName(),
+                publicName));
+      }
+      publicToPrivateNames.put(publicName, attribute);
+    }
+  }
+
   /**
    * Returns the function which determines the set of implicit outputs
    * generated by a given rule.
diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java
index 8e9d13e..6d9091f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java
@@ -196,10 +196,10 @@
         continue;
       }
       String skyname = a.getPublicName();
-      Mode mode = getMode(a.getName());
       if (a.isExecutable()) {
         // In Skylark only label (not label list) type attributes can have the Executable flag.
-        FilesToRunProvider provider = ruleContext.getExecutablePrerequisite(a.getName(), mode);
+        FilesToRunProvider provider =
+            ruleContext.getExecutablePrerequisite(a.getName(), Mode.DONT_CHECK);
         if (provider != null && provider.getExecutable() != null) {
           Artifact executable = provider.getExecutable();
           executableBuilder.put(skyname, executable);
@@ -210,17 +210,18 @@
       }
       if (a.isSingleArtifact()) {
         // In Skylark only label (not label list) type attributes can have the SingleArtifact flag.
-        Artifact artifact = ruleContext.getPrerequisiteArtifact(a.getName(), mode);
+        Artifact artifact = ruleContext.getPrerequisiteArtifact(a.getName(), Mode.DONT_CHECK);
         if (artifact != null) {
           fileBuilder.put(skyname, artifact);
         } else {
           fileBuilder.put(skyname, Runtime.NONE);
         }
       }
-      filesBuilder.put(skyname, ruleContext.getPrerequisiteArtifacts(a.getName(), mode).list());
-      List<?> allPrereq = ruleContext.getPrerequisites(a.getName(), mode);
+      filesBuilder.put(
+          skyname, ruleContext.getPrerequisiteArtifacts(a.getName(), Mode.DONT_CHECK).list());
+      List<?> allPrereq = ruleContext.getPrerequisites(a.getName(), Mode.DONT_CHECK);
       if (type == BuildType.LABEL) {
-        Object prereq = ruleContext.getPrerequisite(a.getName(), mode);
+        Object prereq = ruleContext.getPrerequisite(a.getName(), Mode.DONT_CHECK);
         if (prereq == null) {
           prereq = Runtime.NONE;
         }
@@ -269,10 +270,6 @@
     return ruleContext;
   }
 
-  private Mode getMode(String attributeName) {
-    return ruleContext.getAttributeMode(attributeName);
-  }
-
   @SkylarkCallable(name = "attr", structField = true,
       doc = "A struct to access the values of the attributes. The values are provided by "
       + "the user (if not, a default value is used).")