Separate build-specific types and types inherent to Skylark.

--
MOS_MIGRATED_REVID=103374106
diff --git a/src/main/java/com/google/devtools/build/docgen/RuleDocumentationAttribute.java b/src/main/java/com/google/devtools/build/docgen/RuleDocumentationAttribute.java
index a753e3f..3cc9150 100644
--- a/src/main/java/com/google/devtools/build/docgen/RuleDocumentationAttribute.java
+++ b/src/main/java/com/google/devtools/build/docgen/RuleDocumentationAttribute.java
@@ -18,9 +18,10 @@
 import com.google.common.collect.ImmutableSet;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
 import com.google.devtools.build.lib.packages.Attribute;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.TriState;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 
 import java.util.HashMap;
 import java.util.LinkedList;
@@ -42,17 +43,17 @@
       .put(Type.INTEGER_LIST, "List of integers")
       .put(Type.STRING, "String")
       .put(Type.STRING_LIST, "List of strings")
-      .put(Type.TRISTATE, "Integer")
-      .put(Type.LABEL, "<a href=\"build-ref.html#labels\">Label</a>")
-      .put(Type.LABEL_LIST, "List of <a href=\"build-ref.html#labels\">labels</a>")
-      .put(Type.LABEL_DICT_UNARY,
+      .put(BuildType.TRISTATE, "Integer")
+      .put(BuildType.LABEL, "<a href=\"build-ref.html#labels\">Label</a>")
+      .put(BuildType.LABEL_LIST, "List of <a href=\"build-ref.html#labels\">labels</a>")
+      .put(BuildType.LABEL_DICT_UNARY,
           "Dictionary mapping strings to <a href=\"build-ref.html#labels\">labels</a>")
-      .put(Type.LABEL_LIST_DICT,
+      .put(BuildType.LABEL_LIST_DICT,
           "Dictionary mapping strings to lists of <a href=\"build-ref.html#labels\">labels</a>")
-      .put(Type.NODEP_LABEL, "<a href=\"build-ref.html#name\">Name</a>")
-      .put(Type.NODEP_LABEL_LIST, "List of <a href=\"build-ref.html#name\">names</a>")
-      .put(Type.OUTPUT, "<a href=\"build-ref.html#filename\">Filename</a>")
-      .put(Type.OUTPUT_LIST, "List of <a href=\"build-ref.html#filename\">filenames</a>")
+      .put(BuildType.NODEP_LABEL, "<a href=\"build-ref.html#name\">Name</a>")
+      .put(BuildType.NODEP_LABEL_LIST, "List of <a href=\"build-ref.html#name\">names</a>")
+      .put(BuildType.OUTPUT, "<a href=\"build-ref.html#filename\">Filename</a>")
+      .put(BuildType.OUTPUT_LIST, "List of <a href=\"build-ref.html#filename\">filenames</a>")
       .build();
 
   private final Class<? extends RuleDefinition> definitionClass;
diff --git a/src/main/java/com/google/devtools/build/lib/actions/FilesetTraversalParamsFactory.java b/src/main/java/com/google/devtools/build/lib/actions/FilesetTraversalParamsFactory.java
index c26c603..5ad85e4 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/FilesetTraversalParamsFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/FilesetTraversalParamsFactory.java
@@ -20,7 +20,7 @@
 import com.google.devtools.build.lib.actions.FilesetTraversalParams.DirectTraversal;
 import com.google.devtools.build.lib.actions.FilesetTraversalParams.DirectTraversalRoot;
 import com.google.devtools.build.lib.actions.FilesetTraversalParams.PackageBoundaryMode;
-import com.google.devtools.build.lib.syntax.FilesetEntry.SymlinkBehavior;
+import com.google.devtools.build.lib.packages.FilesetEntry.SymlinkBehavior;
 import com.google.devtools.build.lib.syntax.Label;
 import com.google.devtools.build.lib.util.Fingerprint;
 import com.google.devtools.build.lib.vfs.Path;
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/AnalysisUtils.java b/src/main/java/com/google/devtools/build/lib/analysis/AnalysisUtils.java
index 9abcb25..13bbd54 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/AnalysisUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/AnalysisUtils.java
@@ -25,8 +25,8 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.collect.nestedset.Order;
 import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.TriState;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.syntax.Label;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
@@ -52,10 +52,11 @@
    */
   public static boolean isStampingEnabled(RuleContext ruleContext) {
     BuildConfiguration config = ruleContext.getConfiguration();
-    if (config.isHostConfiguration() || !ruleContext.attributes().has("stamp", Type.TRISTATE)) {
+    if (config.isHostConfiguration()
+        || !ruleContext.attributes().has("stamp", BuildType.TRISTATE)) {
       return false;
     }
-    TriState stamp = ruleContext.attributes().get("stamp", Type.TRISTATE);
+    TriState stamp = ruleContext.attributes().get("stamp", BuildType.TRISTATE);
     return stamp == TriState.YES || (stamp == TriState.AUTO && config.stampBinaries());
   }
 
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java b/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java
index 923f24e..ef3cc51 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java
@@ -17,15 +17,15 @@
 import static com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition.DATA;
 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.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.DISTRIBUTIONS;
-import static com.google.devtools.build.lib.packages.Type.INTEGER;
-import static com.google.devtools.build.lib.packages.Type.LABEL;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.LICENSE;
-import static com.google.devtools.build.lib.packages.Type.NODEP_LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.STRING;
-import static com.google.devtools.build.lib.packages.Type.STRING_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.DISTRIBUTIONS;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LICENSE;
+import static com.google.devtools.build.lib.packages.BuildType.NODEP_LABEL_LIST;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
+import static com.google.devtools.build.lib.syntax.Type.INTEGER;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.STRING_LIST;
 
 import com.google.common.collect.ImmutableList;
 import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
@@ -40,8 +40,8 @@
 import com.google.devtools.build.lib.packages.RuleClass.Builder;
 import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
 import com.google.devtools.build.lib.packages.TestSize;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.FileTypeSet;
 
 import java.util.List;
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
index c39ab0f..e1e2f12 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
@@ -52,6 +52,7 @@
 import com.google.devtools.build.lib.events.StoredEventHandler;
 import com.google.devtools.build.lib.packages.AspectParameters;
 import com.google.devtools.build.lib.packages.Attribute;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.NoSuchPackageException;
 import com.google.devtools.build.lib.packages.NoSuchTargetException;
 import com.google.devtools.build.lib.packages.NoSuchThingException;
@@ -60,7 +61,6 @@
 import com.google.devtools.build.lib.packages.Rule;
 import com.google.devtools.build.lib.packages.Target;
 import com.google.devtools.build.lib.packages.TargetUtils;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.pkgcache.LoadingPhaseRunner.LoadingResult;
 import com.google.devtools.build.lib.pkgcache.PackageManager;
 import com.google.devtools.build.lib.rules.test.CoverageReportActionFactory;
@@ -423,7 +423,7 @@
     RawAttributeMapper mapper = RawAttributeMapper.of(rule);
     for (Attribute attribute : rule.getAttributes()) {
       for (Label label : mapper.getConfigurabilityKeys(attribute.getName(), attribute.getType())) {
-        if (Type.Selector.isReservedLabel(label)) {
+        if (BuildType.Selector.isReservedLabel(label)) {
           continue;
         }
         try {
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/CommandHelper.java b/src/main/java/com/google/devtools/build/lib/analysis/CommandHelper.java
index f515bbb..1c301a9 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/CommandHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/CommandHelper.java
@@ -24,10 +24,10 @@
 import com.google.devtools.build.lib.actions.BaseSpawn;
 import com.google.devtools.build.lib.analysis.actions.FileWriteAction;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.syntax.Label;
 import com.google.devtools.build.lib.syntax.SkylarkCallable;
 import com.google.devtools.build.lib.syntax.SkylarkModule;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.Pair;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredAttributeMapper.java b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredAttributeMapper.java
index 7643b73..4afc9f9 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredAttributeMapper.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredAttributeMapper.java
@@ -21,10 +21,13 @@
 import com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider;
 import com.google.devtools.build.lib.packages.AbstractAttributeMapper;
 import com.google.devtools.build.lib.packages.AttributeMap;
+import com.google.devtools.build.lib.packages.BuildType;
+import com.google.devtools.build.lib.packages.BuildType.Selector;
+import com.google.devtools.build.lib.packages.BuildType.SelectorList;
 import com.google.devtools.build.lib.packages.Rule;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.syntax.EvalException;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 
 import java.util.ArrayList;
 import java.util.LinkedHashSet;
@@ -103,20 +106,20 @@
    * can't be resolved due to intrinsic contradictions in the configuration.
    */
   private <T> T getAndValidate(String attributeName, Type<T> type) throws EvalException  {
-    Type.SelectorList<T> selectorList = getSelectorList(attributeName, type);
+    SelectorList<T> selectorList = getSelectorList(attributeName, type);
     if (selectorList == null) {
       // This is a normal attribute.
       return super.get(attributeName, type);
     }
 
     List<T> resolvedList = new ArrayList<>();
-    for (Type.Selector<T> selector : selectorList.getSelectors()) {
+    for (Selector<T> selector : selectorList.getSelectors()) {
       resolvedList.add(resolveSelector(attributeName, selector));
     }
     return resolvedList.size() == 1 ? resolvedList.get(0) : type.concat(resolvedList);
   }
 
-  private <T> T resolveSelector(String attributeName, Type.Selector<T> selector)
+  private <T> T resolveSelector(String attributeName, Selector<T> selector)
       throws EvalException {
     ConfigMatchingProvider matchingCondition = null;
     Set<Label> conditionLabels = new LinkedHashSet<>();
@@ -125,7 +128,7 @@
     // Find the matching condition and record its value (checking for duplicates).
     for (Map.Entry<Label, T> entry : selector.getEntries().entrySet()) {
       Label selectorKey = entry.getKey();
-      if (Type.Selector.isReservedLabel(selectorKey)) {
+      if (BuildType.Selector.isReservedLabel(selectorKey)) {
         continue;
       }
 
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/DependencyResolver.java b/src/main/java/com/google/devtools/build/lib/analysis/DependencyResolver.java
index 05e302c..422f069 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/DependencyResolver.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/DependencyResolver.java
@@ -31,6 +31,7 @@
 import com.google.devtools.build.lib.packages.Attribute.LateBoundDefault;
 import com.google.devtools.build.lib.packages.Attribute.SplitTransition;
 import com.google.devtools.build.lib.packages.AttributeMap;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.EnvironmentGroup;
 import com.google.devtools.build.lib.packages.InputFile;
 import com.google.devtools.build.lib.packages.NoSuchThingException;
@@ -39,11 +40,11 @@
 import com.google.devtools.build.lib.packages.Rule;
 import com.google.devtools.build.lib.packages.RuleClass;
 import com.google.devtools.build.lib.packages.Target;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey;
 import com.google.devtools.build.lib.syntax.EvalException;
 import com.google.devtools.build.lib.syntax.EvalUtils;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -323,8 +324,8 @@
   private void addExplicitDeps(
       ImmutableSortedKeyListMultimap.Builder<Attribute, LabelAndConfiguration> result, Rule rule,
       String attrName, Iterable<Label> labels, BuildConfiguration configuration) {
-    if (!rule.isAttrDefined(attrName, Type.LABEL_LIST)
-        && !rule.isAttrDefined(attrName, Type.NODEP_LABEL_LIST)) {
+    if (!rule.isAttrDefined(attrName, BuildType.LABEL_LIST)
+        && !rule.isAttrDefined(attrName, BuildType.NODEP_LABEL_LIST)) {
       return;
     }
     Attribute attribute = rule.getRuleClassObject().getAttributeByName(attrName);
@@ -350,7 +351,7 @@
               return;
             }
 
-            if (attribute.getType() == Type.NODEP_LABEL) {
+            if (attribute.getType() == BuildType.NODEP_LABEL) {
               return;
             }
 
@@ -376,7 +377,7 @@
 
       if (abi != null) {
         for (Map.Entry<String, List<Label>> entry
-            : attributes.get("abi_deps", Type.LABEL_LIST_DICT).entrySet()) {
+            : attributes.get("abi_deps", BuildType.LABEL_LIST_DICT).entrySet()) {
           try {
             if (Pattern.matches(entry.getKey(), abi)) {
               for (Label label : entry.getValue()) {
@@ -404,18 +405,18 @@
         continue;
       }
 
-      if (attribute.getType() == Type.LABEL) {
+      if (attribute.getType() == BuildType.LABEL) {
         Label label = mappedAttributes.contains(attribute.getName())
-            ? attributeMap.get(attribute.getName(), Type.LABEL)
-            : Type.LABEL.cast(attribute.getDefaultValue(rule));
+            ? attributeMap.get(attribute.getName(), BuildType.LABEL)
+            : BuildType.LABEL.cast(attribute.getDefaultValue(rule));
 
         if (label != null) {
           builder.put(attribute, LabelAndConfiguration.of(label, configuration));
         }
-      } else if (attribute.getType() == Type.LABEL_LIST) {
+      } else if (attribute.getType() == BuildType.LABEL_LIST) {
         List<Label> labelList = mappedAttributes.contains(attribute.getName())
-            ? attributeMap.get(attribute.getName(), Type.LABEL_LIST)
-            : Type.LABEL_LIST.cast(attribute.getDefaultValue(rule));
+            ? attributeMap.get(attribute.getName(), BuildType.LABEL_LIST)
+            : BuildType.LABEL_LIST.cast(attribute.getDefaultValue(rule));
 
         for (Label label : labelList) {
           builder.put(attribute, LabelAndConfiguration.of(label, configuration));
@@ -468,11 +469,11 @@
           continue;
         }
         try {
-          if (attribute.getType() == Type.LABEL) {
-            Label label = Type.LABEL.cast(actualValue);
+          if (attribute.getType() == BuildType.LABEL) {
+            Label label = BuildType.LABEL.cast(actualValue);
             builder.put(attribute, LabelAndConfiguration.of(label, actualConfig));
-          } else if (attribute.getType() == Type.LABEL_LIST) {
-            for (Label label : Type.LABEL_LIST.cast(actualValue)) {
+          } else if (attribute.getType() == BuildType.LABEL_LIST) {
+            for (Label label : BuildType.LABEL_LIST.cast(actualValue)) {
               builder.put(attribute, LabelAndConfiguration.of(label, actualConfig));
             }
           } else {
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java b/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java
index 26b0f8c..50ea1df 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java
@@ -24,8 +24,8 @@
 import com.google.devtools.build.lib.actions.Artifact;
 import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
 import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.OutputFile;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.syntax.Label;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
@@ -280,7 +280,7 @@
       mapGet(locationMap, out.getLabel()).add(ruleContext.createOutputArtifact(out));
     }
 
-    if (ruleContext.getRule().isAttrDefined("srcs", Type.LABEL_LIST)) {
+    if (ruleContext.getRule().isAttrDefined("srcs", BuildType.LABEL_LIST)) {
       for (FileProvider src : ruleContext
           .getPrerequisites("srcs", Mode.TARGET, FileProvider.class)) {
         Iterables.addAll(mapGet(locationMap, src.getLabel()), src.getFilesToBuild());
@@ -289,16 +289,16 @@
 
     // Add all locations associated with dependencies and tools
     List<FilesToRunProvider> depsDataAndTools = new ArrayList<>();
-    if (ruleContext.getRule().isAttrDefined("deps", Type.LABEL_LIST)) {
+    if (ruleContext.getRule().isAttrDefined("deps", BuildType.LABEL_LIST)) {
       Iterables.addAll(depsDataAndTools,
           ruleContext.getPrerequisites("deps", Mode.DONT_CHECK, FilesToRunProvider.class));
     }
     if (allowDataAttributeEntriesInLabel
-        && ruleContext.getRule().isAttrDefined("data", Type.LABEL_LIST)) {
+        && ruleContext.getRule().isAttrDefined("data", BuildType.LABEL_LIST)) {
       Iterables.addAll(depsDataAndTools,
           ruleContext.getPrerequisites("data", Mode.DATA, FilesToRunProvider.class));
     }
-    if (ruleContext.getRule().isAttrDefined("tools", Type.LABEL_LIST)) {
+    if (ruleContext.getRule().isAttrDefined("tools", BuildType.LABEL_LIST)) {
       Iterables.addAll(depsDataAndTools,
           ruleContext.getPrerequisites("tools", Mode.HOST, FilesToRunProvider.class));
     }
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RedirectChaser.java b/src/main/java/com/google/devtools/build/lib/analysis/RedirectChaser.java
index 3400b1f..c327da4 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/RedirectChaser.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/RedirectChaser.java
@@ -17,12 +17,13 @@
 import com.google.devtools.build.lib.analysis.config.ConfigurationEnvironment;
 import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
 import com.google.devtools.build.lib.packages.AbstractAttributeMapper;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.NoSuchPackageException;
 import com.google.devtools.build.lib.packages.NoSuchTargetException;
 import com.google.devtools.build.lib.packages.Rule;
 import com.google.devtools.build.lib.packages.Target;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 
 import java.util.HashSet;
 import java.util.List;
@@ -115,7 +116,7 @@
     }
 
     List<Label> labels =
-        new StaticValuedAttributeMapper(rule).getAndValidate("srcs", Type.LABEL_LIST);
+        new StaticValuedAttributeMapper(rule).getAndValidate("srcs", BuildType.LABEL_LIST);
     if (labels.size() != 1) {
       return null;
     }
@@ -133,6 +134,6 @@
       return null;
     }
 
-    return new StaticValuedAttributeMapper(rule).getAndValidate("actual", Type.LABEL);
+    return new StaticValuedAttributeMapper(rule).getAndValidate("actual", BuildType.LABEL);
   }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleConfiguredTargetBuilder.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleConfiguredTargetBuilder.java
index 7903587..a3a67db 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/RuleConfiguredTargetBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleConfiguredTargetBuilder.java
@@ -36,7 +36,6 @@
 import com.google.devtools.build.lib.packages.License;
 import com.google.devtools.build.lib.packages.Rule;
 import com.google.devtools.build.lib.packages.TargetUtils;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.SkylarkApiProvider;
 import com.google.devtools.build.lib.rules.extra.ExtraActionMapProvider;
 import com.google.devtools.build.lib.rules.extra.ExtraActionSpec;
@@ -52,6 +51,7 @@
 import com.google.devtools.build.lib.syntax.Runtime;
 import com.google.devtools.build.lib.syntax.SkylarkList;
 import com.google.devtools.build.lib.syntax.SkylarkNestedSet;
+import com.google.devtools.build.lib.syntax.Type;
 
 import java.util.LinkedHashMap;
 import java.util.List;
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
index 74616c9..7ec5899 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
@@ -49,7 +49,9 @@
 import com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition;
 import com.google.devtools.build.lib.packages.Attribute.SplitTransition;
 import com.google.devtools.build.lib.packages.AttributeMap;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.FileTarget;
+import com.google.devtools.build.lib.packages.FilesetEntry;
 import com.google.devtools.build.lib.packages.ImplicitOutputsFunction;
 import com.google.devtools.build.lib.packages.InputFile;
 import com.google.devtools.build.lib.packages.OutputFile;
@@ -60,12 +62,11 @@
 import com.google.devtools.build.lib.packages.RuleErrorConsumer;
 import com.google.devtools.build.lib.packages.Target;
 import com.google.devtools.build.lib.packages.TargetUtils;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.fileset.FilesetProvider;
 import com.google.devtools.build.lib.shell.ShellUtils;
 import com.google.devtools.build.lib.syntax.EvalException;
-import com.google.devtools.build.lib.syntax.FilesetEntry;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.FileTypeSet;
 import com.google.devtools.build.lib.vfs.FileSystemUtils;
 import com.google.devtools.build.lib.vfs.PathFragment;
@@ -890,8 +891,8 @@
       throw new IllegalStateException(getRule().getLocation() + ": " + getRule().getRuleClass()
         + " attribute " + attributeName + " is not defined");
     }
-    if (!(attributeDefinition.getType() == Type.LABEL
-        || attributeDefinition.getType() == Type.LABEL_LIST)) {
+    if (!(attributeDefinition.getType() == BuildType.LABEL
+        || attributeDefinition.getType() == BuildType.LABEL_LIST)) {
       throw new IllegalStateException(rule.getRuleClass() + " attribute " + attributeName
         + " is not a label type attribute");
     }
@@ -932,8 +933,8 @@
       throw new IllegalStateException(getRule().getLocation() + ": " + getRule().getRuleClass()
         + " attribute " + attributeName + " is not defined");
     }
-    if (!(attributeDefinition.getType() == Type.LABEL
-        || attributeDefinition.getType() == Type.LABEL_LIST)) {
+    if (!(attributeDefinition.getType() == BuildType.LABEL
+        || attributeDefinition.getType() == BuildType.LABEL_LIST)) {
       throw new IllegalStateException(rule.getRuleClass() + " attribute " + attributeName
         + " is not a label type attribute");
     }
@@ -1066,7 +1067,7 @@
    * referring to a local target. Reports a warning otherwise.
    */
   public Label getLocalNodepLabelAttribute(String attrName) {
-    Label label = attributes().get(attrName, Type.NODEP_LABEL);
+    Label label = attributes().get(attrName, BuildType.NODEP_LABEL);
     if (label == null) {
       return null;
     }
@@ -1112,7 +1113,7 @@
    *         attribute
    */
   public final FilesToRunProvider getCompiler(boolean warnIfNotDefault) {
-    Label label = attributes().get("compiler", Type.LABEL);
+    Label label = attributes().get("compiler", BuildType.LABEL);
     if (warnIfNotDefault && !label.equals(getRule().getAttrDefaultValue("compiler"))) {
       attributeWarning("compiler", "setting the compiler is strongly discouraged");
     }
@@ -1327,7 +1328,7 @@
       final ImmutableSortedKeyListMultimap.Builder<String, ConfiguredFilesetEntry> mapBuilder =
           ImmutableSortedKeyListMultimap.builder();
       for (Attribute attr : rule.getAttributes()) {
-        if (attr.getType() != Type.FILESET_ENTRY_LIST) {
+        if (attr.getType() != BuildType.FILESET_ENTRY_LIST) {
           continue;
         }
         String attributeName = attr.getName();
@@ -1336,7 +1337,7 @@
           ctMap.put(prerequisite.getLabel(), prerequisite);
         }
         List<FilesetEntry> entries = ConfiguredAttributeMapper.of(rule, configConditions)
-            .get(attributeName, Type.FILESET_ENTRY_LIST);
+            .get(attributeName, BuildType.FILESET_ENTRY_LIST);
         for (FilesetEntry entry : entries) {
           if (entry.getFiles() == null) {
             Label label = entry.getSrcLabel();
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java b/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
index 2c44a32..23c1e17 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
@@ -28,7 +28,7 @@
 import com.google.devtools.build.lib.events.Event;
 import com.google.devtools.build.lib.events.EventHandler;
 import com.google.devtools.build.lib.events.Location;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.syntax.SkylarkCallable;
 import com.google.devtools.build.lib.syntax.SkylarkModule;
 import com.google.devtools.build.lib.vfs.Path;
@@ -809,7 +809,7 @@
      */
     private static Iterable<? extends TransitiveInfoCollection> getPrerequisites(
         RuleContext ruleContext, String attributeName, Mode mode) {
-      if (ruleContext.getRule().isAttrDefined(attributeName, Type.LABEL_LIST)) {
+      if (ruleContext.getRule().isAttrDefined(attributeName, BuildType.LABEL_LIST)) {
         return ruleContext.getPrerequisites(attributeName, mode);
       } else {
         return Collections.emptyList();
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/ConfigRuleClasses.java b/src/main/java/com/google/devtools/build/lib/analysis/config/ConfigRuleClasses.java
index 44bb5e7..2a29137 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/config/ConfigRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/config/ConfigRuleClasses.java
@@ -15,14 +15,14 @@
 package com.google.devtools.build.lib.analysis.config;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.STRING_DICT;
+import static com.google.devtools.build.lib.syntax.Type.STRING_DICT;
 
 import com.google.common.collect.ImmutableList;
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
 import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
 import com.google.devtools.build.lib.packages.RuleClass;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.syntax.Type;
 
 /**
  * Definitions for rule classes that specify or manipulate configuration settings.
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/ConfigSetting.java b/src/main/java/com/google/devtools/build/lib/analysis/config/ConfigSetting.java
index 9825d05..6c2a7ef 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/config/ConfigSetting.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/config/ConfigSetting.java
@@ -28,8 +28,8 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.collect.nestedset.Order;
 import com.google.devtools.build.lib.packages.NonconfigurableAttributeMapper;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.common.options.OptionsBase;
 import com.google.devtools.common.options.OptionsParser;
 import com.google.devtools.common.options.OptionsParsingException;
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/constraints/ConstraintSemantics.java b/src/main/java/com/google/devtools/build/lib/analysis/constraints/ConstraintSemantics.java
index 3105864..a62f7df 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/constraints/ConstraintSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/constraints/ConstraintSemantics.java
@@ -26,12 +26,13 @@
 import com.google.devtools.build.lib.analysis.constraints.EnvironmentCollection.EnvironmentWithGroup;
 import com.google.devtools.build.lib.packages.Attribute;
 import com.google.devtools.build.lib.packages.AttributeMap;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.EnvironmentGroup;
 import com.google.devtools.build.lib.packages.Rule;
 import com.google.devtools.build.lib.packages.RuleClass;
 import com.google.devtools.build.lib.packages.Target;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 
 import java.util.Collection;
 import java.util.LinkedHashSet;
@@ -255,7 +256,7 @@
      */
     private EnvironmentCollection collectEnvironments(String attrName,
         EnvironmentCollection.Builder supportedEnvironments) {
-      if (!ruleContext.getRule().isAttrDefined(attrName,  Type.LABEL_LIST)) {
+      if (!ruleContext.getRule().isAttrDefined(attrName,  BuildType.LABEL_LIST)) {
         return EnvironmentCollection.EMPTY;
       }
       EnvironmentCollection.Builder environments = new EnvironmentCollection.Builder();
@@ -376,8 +377,8 @@
     String restrictionAttr = RuleClass.DEFAULT_RESTRICTED_ENVIRONMENT_ATTR;
     String compatibilityAttr = RuleClass.DEFAULT_COMPATIBLE_ENVIRONMENT_ATTR;
 
-    if (rule.isAttrDefined(restrictionAttr, Type.LABEL_LIST)
-      || rule.isAttrDefined(compatibilityAttr, Type.LABEL_LIST)) {
+    if (rule.isAttrDefined(restrictionAttr, BuildType.LABEL_LIST)
+      || rule.isAttrDefined(compatibilityAttr, BuildType.LABEL_LIST)) {
       return new EnvironmentCollector(ruleContext, restrictionAttr, compatibilityAttr,
           new GroupDefaultsProvider());
     } else {
@@ -522,7 +523,7 @@
       Type<?> attrType = attributes.getAttributeType(attr);
 
       // TODO(bazel-team): support a user-definable API for choosing which attributes are checked
-      if ((attrType != Type.LABEL && attrType != Type.LABEL_LIST)
+      if ((attrType != BuildType.LABEL && attrType != BuildType.LABEL_LIST)
           || RuleClass.isConstraintAttribute(attr)
           || attr.equals("visibility")
           // Use the same implicit deps check that query uses. This facilitates running queries to
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/constraints/EnvironmentRule.java b/src/main/java/com/google/devtools/build/lib/analysis/constraints/EnvironmentRule.java
index 8853d50..5162439 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/constraints/EnvironmentRule.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/constraints/EnvironmentRule.java
@@ -20,8 +20,9 @@
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
 import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.RuleClass;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.FileTypeSet;
 
 /**
@@ -53,7 +54,7 @@
           Environments may only fulfill other environments in the same environment group.
         </p>
         <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
-        .add(attr(FULFILLS_ATTRIBUTE, Type.LABEL_LIST)
+        .add(attr(FULFILLS_ATTRIBUTE, BuildType.LABEL_LIST)
             .allowedRuleClasses(EnvironmentRule.RULE_NAME)
             .allowedFileTypes(FileTypeSet.NO_FILE)
             .nonconfigurable("used for defining constraint models - this shouldn't be configured"))
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/GitCloneFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/GitCloneFunction.java
index e8dc70c..19d83ed 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/GitCloneFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/GitCloneFunction.java
@@ -18,8 +18,8 @@
 import com.google.devtools.build.lib.events.Reporter;
 import com.google.devtools.build.lib.packages.AggregatingAttributeMapper;
 import com.google.devtools.build.lib.packages.Rule;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.syntax.EvalException;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.vfs.FileSystemUtils;
 import com.google.devtools.build.lib.vfs.Path;
 import com.google.devtools.build.skyframe.SkyFunction;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/HttpDownloadFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/HttpDownloadFunction.java
index e282de6..49e5a56 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/HttpDownloadFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/HttpDownloadFunction.java
@@ -18,7 +18,7 @@
 import com.google.devtools.build.lib.events.Reporter;
 import com.google.devtools.build.lib.packages.AggregatingAttributeMapper;
 import com.google.devtools.build.lib.packages.Rule;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.vfs.Path;
 import com.google.devtools.build.skyframe.SkyFunction;
 import com.google.devtools.build.skyframe.SkyFunctionException;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/LocalRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/LocalRepositoryFunction.java
index 2cf0da1..48cfbc3 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/LocalRepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/LocalRepositoryFunction.java
@@ -19,10 +19,10 @@
 import com.google.devtools.build.lib.cmdline.PackageIdentifier.RepositoryName;
 import com.google.devtools.build.lib.packages.AggregatingAttributeMapper;
 import com.google.devtools.build.lib.packages.Rule;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.skyframe.FileValue;
 import com.google.devtools.build.lib.skyframe.RepositoryValue;
 import com.google.devtools.build.lib.syntax.EvalException;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.vfs.FileSystemUtils;
 import com.google.devtools.build.lib.vfs.Path;
 import com.google.devtools.build.lib.vfs.PathFragment;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunction.java
index 497daeb..db08bd9 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunction.java
@@ -27,10 +27,10 @@
 import com.google.devtools.build.lib.packages.AggregatingAttributeMapper;
 import com.google.devtools.build.lib.packages.AttributeMap;
 import com.google.devtools.build.lib.packages.Rule;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.skyframe.FileValue;
 import com.google.devtools.build.lib.skyframe.RepositoryValue;
 import com.google.devtools.build.lib.syntax.EvalException;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.vfs.Path;
 import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
 import com.google.devtools.build.skyframe.SkyFunctionName;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenServerFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenServerFunction.java
index 4485021..2c324c1 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenServerFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenServerFunction.java
@@ -20,8 +20,8 @@
 import com.google.devtools.build.lib.packages.AggregatingAttributeMapper;
 import com.google.devtools.build.lib.packages.ExternalPackage;
 import com.google.devtools.build.lib.packages.Rule;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.skyframe.FileValue;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.vfs.PathFragment;
 import com.google.devtools.build.lib.vfs.RootedPath;
 import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryFunction.java
index ebecdba..479b3c0 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryFunction.java
@@ -25,13 +25,13 @@
 import com.google.devtools.build.lib.packages.ExternalPackage;
 import com.google.devtools.build.lib.packages.NoSuchPackageException;
 import com.google.devtools.build.lib.packages.Rule;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.skyframe.FileSymlinkException;
 import com.google.devtools.build.lib.skyframe.FileValue;
 import com.google.devtools.build.lib.skyframe.InconsistentFilesystemException;
 import com.google.devtools.build.lib.skyframe.PackageValue;
 import com.google.devtools.build.lib.skyframe.RepositoryValue;
 import com.google.devtools.build.lib.syntax.EvalException;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.vfs.FileSystemUtils;
 import com.google.devtools.build.lib.vfs.Path;
 import com.google.devtools.build.lib.vfs.PathFragment;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelBaseRuleClasses.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelBaseRuleClasses.java
index 669431b..bc6e331 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelBaseRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelBaseRuleClasses.java
@@ -15,9 +15,9 @@
 package com.google.devtools.build.lib.bazel.rules;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.LICENSE;
-import static com.google.devtools.build.lib.packages.Type.STRING_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LICENSE;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
+import static com.google.devtools.build.lib.syntax.Type.STRING_LIST;
 
 import com.google.common.collect.ImmutableSet;
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelConfigurationCollection.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelConfigurationCollection.java
index 4aec2f2..f4dd97c 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelConfigurationCollection.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelConfigurationCollection.java
@@ -36,10 +36,10 @@
 import com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition;
 import com.google.devtools.build.lib.packages.Attribute.SplitTransition;
 import com.google.devtools.build.lib.packages.Attribute.Transition;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.NoSuchThingException;
 import com.google.devtools.build.lib.packages.Rule;
 import com.google.devtools.build.lib.packages.Target;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.syntax.Label;
 
 import java.util.Collection;
@@ -273,13 +273,13 @@
     Target fromTarget = loadedPackageProvider.getLoadedTarget(from);
     if (fromTarget instanceof Rule) {
       Rule rule = (Rule) fromTarget;
-      if (rule.getRuleClassObject().hasAttr("srcs", Type.LABEL_LIST)) {
+      if (rule.getRuleClassObject().hasAttr("srcs", BuildType.LABEL_LIST)) {
         // TODO(bazel-team): refine this. This visits "srcs" reachable under *any* configuration,
         // not necessarily the configuration actually applied to the rule. We should correlate the
         // two. However, doing so requires faithfully reflecting the configuration transitions that
         // might happen as we traverse the dependency chain.
         for (List<Label> labelsForConfiguration :
-            AggregatingAttributeMapper.of(rule).visitAttribute("srcs", Type.LABEL_LIST)) {
+            AggregatingAttributeMapper.of(rule).visitAttribute("srcs", BuildType.LABEL_LIST)) {
           for (Label label : labelsForConfiguration) {
             collectTransitiveClosure(loadedPackageProvider, reachableLabels, label);
           }
@@ -287,7 +287,7 @@
       }
 
       if (rule.getRuleClass().equals("bind")) {
-        Label actual = AggregatingAttributeMapper.of(rule).get("actual", Type.LABEL);
+        Label actual = AggregatingAttributeMapper.of(rule).get("actual", BuildType.LABEL);
         if (actual != null) {
           collectTransitiveClosure(loadedPackageProvider, reachableLabels, actual);
         }
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryFunction.java
index bdf2291..d9f3a20 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryFunction.java
@@ -23,10 +23,10 @@
 import com.google.devtools.build.lib.packages.AttributeMap;
 import com.google.devtools.build.lib.packages.NonconfigurableAttributeMapper;
 import com.google.devtools.build.lib.packages.Rule;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.skyframe.FileSymlinkException;
 import com.google.devtools.build.lib.skyframe.FileValue;
 import com.google.devtools.build.lib.skyframe.InconsistentFilesystemException;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.ResourceFileLoader;
 import com.google.devtools.build.lib.vfs.FileSystemUtils;
 import com.google.devtools.build.lib.vfs.Path;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryRule.java
index 73b1091..feed3fd 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryRule.java
@@ -14,8 +14,8 @@
 package com.google.devtools.build.lib.bazel.rules.android;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.INTEGER;
-import static com.google.devtools.build.lib.packages.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.INTEGER;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
 
 import com.google.common.base.Function;
 import com.google.common.collect.ImmutableMap;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidRepositoryRules.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidRepositoryRules.java
index 9c5b4ec..b1c9ccc 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidRepositoryRules.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidRepositoryRules.java
@@ -14,7 +14,7 @@
 package com.google.devtools.build.lib.bazel.rules.android;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
 
 import com.google.common.base.Function;
 import com.google.common.collect.ImmutableList;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java
index ba92548..659ff7f 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java
@@ -19,8 +19,8 @@
 import com.google.devtools.build.lib.packages.AttributeMap;
 import com.google.devtools.build.lib.packages.NonconfigurableAttributeMapper;
 import com.google.devtools.build.lib.packages.Rule;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.skyframe.FileValue;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.ResourceFileLoader;
 import com.google.devtools.build.lib.vfs.PathFragment;
 import com.google.devtools.build.skyframe.SkyFunctionException;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryRule.java
index 95bd3c7..ca70a09 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryRule.java
@@ -14,8 +14,8 @@
 package com.google.devtools.build.lib.bazel.rules.android;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.INTEGER;
-import static com.google.devtools.build.lib.packages.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.INTEGER;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
 
 import com.google.common.base.Function;
 import com.google.common.collect.ImmutableMap;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidBinaryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidBinaryRule.java
index dfa2ab2..f4b037b 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidBinaryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidBinaryRule.java
@@ -21,9 +21,9 @@
 import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
 import com.google.devtools.build.lib.bazel.rules.cpp.BazelCppRuleClasses;
 import com.google.devtools.build.lib.bazel.rules.java.BazelJavaRuleClasses;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.RuleClass;
 import com.google.devtools.build.lib.packages.RuleClass.Builder;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.android.AndroidBinaryOnlyRule;
 import com.google.devtools.build.lib.rules.android.AndroidConfiguration;
 import com.google.devtools.build.lib.rules.android.AndroidRuleClasses;
@@ -40,11 +40,11 @@
     return builder
         .requiresConfigurationFragments(
             AndroidConfiguration.class, JavaConfiguration.class, CppConfiguration.class)
-        .add(attr("$debug_keystore", Type.LABEL)
+        .add(attr("$debug_keystore", BuildType.LABEL)
             .cfg(HOST)
             .singleArtifact()
             .value(environment.getLabel(Constants.ANDROID_DEP_PREFIX + "debug_keystore")))
-        .add(attr(":cc_toolchain_split", Type.LABEL)
+        .add(attr(":cc_toolchain_split", BuildType.LABEL)
             .cfg(AndroidRuleClasses.ANDROID_SPLIT_TRANSITION)
             .value(BazelCppRuleClasses.CC_TOOLCHAIN))
         /* <!-- #BLAZE_RULE(android_binary).IMPLICIT_OUTPUTS -->
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/common/BazelActionListenerRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/common/BazelActionListenerRule.java
index fd48c3e..f7bfd9d 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/common/BazelActionListenerRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/common/BazelActionListenerRule.java
@@ -14,8 +14,8 @@
 package com.google.devtools.build.lib.bazel.rules.common;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.STRING_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.syntax.Type.STRING_LIST;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/common/BazelExtraActionRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/common/BazelExtraActionRule.java
index 94aac28..20d647a 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/common/BazelExtraActionRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/common/BazelExtraActionRule.java
@@ -15,10 +15,10 @@
 
 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.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.STRING;
-import static com.google.devtools.build.lib.packages.Type.STRING_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.STRING_LIST;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/common/BazelFilegroupRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/common/BazelFilegroupRule.java
index 9884200..466826e 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/common/BazelFilegroupRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/common/BazelFilegroupRule.java
@@ -15,9 +15,9 @@
 
 import static com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition.DATA;
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.LICENSE;
-import static com.google.devtools.build.lib.packages.Type.STRING;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LICENSE;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/common/BazelTestSuiteRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/common/BazelTestSuiteRule.java
index 348eb30..ed4cd86 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/common/BazelTestSuiteRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/common/BazelTestSuiteRule.java
@@ -14,8 +14,8 @@
 package com.google.devtools.build.lib.bazel.rules.common;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
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 1437192..577aa49 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
@@ -15,15 +15,12 @@
 package com.google.devtools.build.lib.bazel.rules.cpp;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST_DICT;
+import static com.google.devtools.build.lib.packages.BuildType.TRISTATE;
 import static com.google.devtools.build.lib.packages.ImplicitOutputsFunction.fromFunctions;
 import static com.google.devtools.build.lib.packages.ImplicitOutputsFunction.fromTemplates;
-import static com.google.devtools.build.lib.packages.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.LABEL;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST_DICT;
-import static com.google.devtools.build.lib.packages.Type.STRING;
-import static com.google.devtools.build.lib.packages.Type.STRING_LIST;
-import static com.google.devtools.build.lib.packages.Type.TRISTATE;
 import static com.google.devtools.build.lib.rules.cpp.CppFileTypes.ALWAYS_LINK_LIBRARY;
 import static com.google.devtools.build.lib.rules.cpp.CppFileTypes.ALWAYS_LINK_PIC_LIBRARY;
 import static com.google.devtools.build.lib.rules.cpp.CppFileTypes.ARCHIVE;
@@ -37,6 +34,9 @@
 import static com.google.devtools.build.lib.rules.cpp.CppFileTypes.PIC_OBJECT_FILE;
 import static com.google.devtools.build.lib.rules.cpp.CppFileTypes.SHARED_LIBRARY;
 import static com.google.devtools.build.lib.rules.cpp.CppFileTypes.VERSIONED_SHARED_LIBRARY;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.STRING_LIST;
 
 import com.google.common.base.Predicates;
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
@@ -49,6 +49,7 @@
 import com.google.devtools.build.lib.packages.Attribute.LateBoundLabel;
 import com.google.devtools.build.lib.packages.Attribute.Transition;
 import com.google.devtools.build.lib.packages.AttributeMap;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.ImplicitOutputsFunction.SafeImplicitOutputsFunction;
 import com.google.devtools.build.lib.packages.RawAttributeMapper;
 import com.google.devtools.build.lib.packages.Rule;
@@ -56,7 +57,6 @@
 import com.google.devtools.build.lib.packages.RuleClass.Builder;
 import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
 import com.google.devtools.build.lib.packages.TriState;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.cpp.CppConfiguration;
 import com.google.devtools.build.lib.rules.cpp.CppFileTypes;
 import com.google.devtools.build.lib.rules.cpp.CppRuleClasses;
@@ -204,9 +204,9 @@
    */
   private static Label getStl(Rule rule, BuildConfiguration original) {
     Label stl = null;
-    if (rule.getRuleClassObject().hasAttr("$stl", Type.LABEL)) {
+    if (rule.getRuleClassObject().hasAttr("$stl", BuildType.LABEL)) {
       Label stlConfigLabel = original.getFragment(CppConfiguration.class).getStl();
-      Label stlRuleLabel = RawAttributeMapper.of(rule).get("$stl", Type.LABEL);
+      Label stlRuleLabel = RawAttributeMapper.of(rule).get("$stl", BuildType.LABEL);
       if (stlConfigLabel == null) {
         stl = stlRuleLabel;
       } else if (!stlConfigLabel.equals(rule.getLabel()) && stlRuleLabel != null) {
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/BazelGenRuleRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/BazelGenRuleRule.java
index 5a74411..74623d1 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/BazelGenRuleRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/BazelGenRuleRule.java
@@ -15,21 +15,21 @@
 
 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.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.LABEL;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.LICENSE;
-import static com.google.devtools.build.lib.packages.Type.OUTPUT_LIST;
-import static com.google.devtools.build.lib.packages.Type.STRING;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LICENSE;
+import static com.google.devtools.build.lib.packages.BuildType.OUTPUT_LIST;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
 import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
 import com.google.devtools.build.lib.packages.Attribute;
 import com.google.devtools.build.lib.packages.AttributeMap;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.RuleClass;
 import com.google.devtools.build.lib.packages.RuleClass.Builder;
-import com.google.devtools.build.lib.packages.Type;
 
 /**
  * Rule definition for the genrule rule.
@@ -198,7 +198,7 @@
             new Attribute.ComputedDefault("outs", "executable") {
               @Override
               public Object getDefault(AttributeMap rule) {
-                return (rule.get("outs", Type.OUTPUT_LIST).size() == 1)
+                return (rule.get("outs", BuildType.OUTPUT_LIST).size() == 1)
                     && rule.get("executable", BOOLEAN);
               }
             }))
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/GenRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/GenRule.java
index 6f0554d..23d0fad 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/GenRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/GenRule.java
@@ -37,9 +37,9 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.collect.nestedset.Order;
 import com.google.devtools.build.lib.packages.TargetUtils;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
 import java.util.List;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaBinaryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaBinaryRule.java
index 23d2a68..03ccc62 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaBinaryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaBinaryRule.java
@@ -15,7 +15,7 @@
 package com.google.devtools.build.lib.bazel.rules.java;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.BOOLEAN;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
 
 import com.google.devtools.build.lib.analysis.RuleDefinition;
 import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaImportRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaImportRule.java
index 65eb595..5caa1d2 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaImportRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaImportRule.java
@@ -16,7 +16,7 @@
 
 import static com.google.devtools.build.lib.packages.Attribute.ANY_EDGE;
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
 
 import com.google.common.collect.ImmutableSet;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaLibraryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaLibraryRule.java
index 25b6aaf..3c412f0 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaLibraryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaLibraryRule.java
@@ -16,9 +16,9 @@
 
 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.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.STRING_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
+import static com.google.devtools.build.lib.syntax.Type.STRING_LIST;
 
 import com.google.devtools.build.lib.analysis.RuleDefinition;
 import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaPluginRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaPluginRule.java
index 834f683..9f08183 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaPluginRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaPluginRule.java
@@ -15,7 +15,7 @@
 package com.google.devtools.build.lib.bazel.rules.java;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
 
 import com.google.devtools.build.lib.analysis.RuleDefinition;
 import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java
index 8a88e0d..58d79c6 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java
@@ -16,13 +16,13 @@
 
 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;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.TRISTATE;
 import static com.google.devtools.build.lib.packages.ImplicitOutputsFunction.fromFunctions;
-import static com.google.devtools.build.lib.packages.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.LABEL;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.STRING;
-import static com.google.devtools.build.lib.packages.Type.STRING_LIST;
-import static com.google.devtools.build.lib.packages.Type.TRISTATE;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.STRING_LIST;
 
 import com.google.common.collect.ImmutableSet;
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java
index 92de410..ea8908a 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java
@@ -31,7 +31,7 @@
 import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
 import com.google.devtools.build.lib.analysis.config.BuildConfiguration.StrictDepsMode;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.rules.java.DeployArchiveBuilder;
 import com.google.devtools.build.lib.rules.java.DeployArchiveBuilder.Compression;
 import com.google.devtools.build.lib.rules.java.DirectDependencyProvider;
@@ -46,6 +46,7 @@
 import com.google.devtools.build.lib.rules.java.JavaTargetAttributes;
 import com.google.devtools.build.lib.rules.java.JavaUtil;
 import com.google.devtools.build.lib.rules.java.Jvm;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.ShellEscaper;
 import com.google.devtools.build.lib.vfs.FileSystemUtils;
 import com.google.devtools.build.lib.vfs.PathFragment;
@@ -118,7 +119,7 @@
 
   @Override
   public ImmutableList<Artifact> collectResources(RuleContext ruleContext) {
-    if (!ruleContext.getRule().isAttrDefined("resources", Type.LABEL_LIST)) {
+    if (!ruleContext.getRule().isAttrDefined("resources", BuildType.LABEL_LIST)) {
       return ImmutableList.of();
     }
 
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaTestRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaTestRule.java
index 853a16b..b536bc1 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaTestRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaTestRule.java
@@ -15,9 +15,9 @@
 package com.google.devtools.build.lib.bazel.rules.java;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.LABEL;
-import static com.google.devtools.build.lib.packages.Type.STRING;
-import static com.google.devtools.build.lib.packages.Type.TRISTATE;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.TRISTATE;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelIosTestRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelIosTestRule.java
index 49f711b..8c5a6e8 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelIosTestRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelIosTestRule.java
@@ -16,9 +16,9 @@
 
 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.Type.LABEL;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.STRING_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.syntax.Type.STRING_LIST;
 
 import com.google.common.collect.ImmutableList;
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelJ2ObjcLibraryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelJ2ObjcLibraryRule.java
index 2025531..ee1f1b5 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelJ2ObjcLibraryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/objc/BazelJ2ObjcLibraryRule.java
@@ -15,7 +15,7 @@
 package com.google.devtools.build.lib.bazel.rules.objc;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
 
 import com.google.devtools.build.lib.analysis.RuleDefinition;
 import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyLibraryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyLibraryRule.java
index 42d83a0..088bb27 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyLibraryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyLibraryRule.java
@@ -15,7 +15,7 @@
 package com.google.devtools.build.lib.bazel.rules.python;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
 
 import com.google.devtools.build.lib.analysis.RuleDefinition;
 import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyRuleClasses.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyRuleClasses.java
index 019170c..8d8fbff 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyRuleClasses.java
@@ -16,10 +16,10 @@
 
 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.Type.LABEL;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.STRING;
-import static com.google.devtools.build.lib.packages.Type.TRISTATE;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.TRISTATE;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyTestRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyTestRule.java
index 14e1d8e..5690af6 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyTestRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyTestRule.java
@@ -15,8 +15,8 @@
 package com.google.devtools.build.lib.bazel.rules.python;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.TRISTATE;
+import static com.google.devtools.build.lib.packages.BuildType.TRISTATE;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/sh/BazelShLibraryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/sh/BazelShLibraryRule.java
index 6f41efa..79fda2a 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/sh/BazelShLibraryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/sh/BazelShLibraryRule.java
@@ -14,7 +14,7 @@
 package com.google.devtools.build.lib.bazel.rules.sh;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
 
 import com.google.devtools.build.lib.analysis.RuleDefinition;
 import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/sh/BazelShRuleClasses.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/sh/BazelShRuleClasses.java
index 710ce56..0075277 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/sh/BazelShRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/sh/BazelShRuleClasses.java
@@ -15,7 +15,7 @@
 package com.google.devtools.build.lib.bazel.rules.sh;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
 
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/GitRepositoryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/GitRepositoryRule.java
index 5b5756e..8108407 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/GitRepositoryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/GitRepositoryRule.java
@@ -15,8 +15,8 @@
 package com.google.devtools.build.lib.bazel.rules.workspace;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
 
 import com.google.devtools.build.lib.analysis.RuleDefinition;
 import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpArchiveRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpArchiveRule.java
index fc4cbe5..b09fa3f 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpArchiveRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpArchiveRule.java
@@ -15,7 +15,7 @@
 package com.google.devtools.build.lib.bazel.rules.workspace;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
 
 import com.google.devtools.build.lib.analysis.RuleDefinition;
 import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpFileRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpFileRule.java
index c6a5471..c882451 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpFileRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpFileRule.java
@@ -15,7 +15,7 @@
 package com.google.devtools.build.lib.bazel.rules.workspace;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
 
 import com.google.devtools.build.lib.analysis.RuleDefinition;
 import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpJarRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpJarRule.java
index abf1961..a73061a 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpJarRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/HttpJarRule.java
@@ -15,7 +15,7 @@
 package com.google.devtools.build.lib.bazel.rules.workspace;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
 
 import com.google.devtools.build.lib.analysis.RuleDefinition;
 import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/LocalRepositoryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/LocalRepositoryRule.java
index 386f407..c69ca5d 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/LocalRepositoryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/LocalRepositoryRule.java
@@ -15,7 +15,7 @@
 package com.google.devtools.build.lib.bazel.rules.workspace;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
 
 import com.google.devtools.build.lib.analysis.RuleDefinition;
 import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/MavenJarRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/MavenJarRule.java
index f8f5b91..603449d 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/MavenJarRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/MavenJarRule.java
@@ -21,7 +21,7 @@
 import com.google.devtools.build.lib.packages.RuleClass;
 import com.google.devtools.build.lib.packages.RuleClass.Builder;
 import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.syntax.Type;
 
 /**
  * Rule definition for the maven_jar rule.
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/MavenServerRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/MavenServerRule.java
index 602d705..e710f9b 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/MavenServerRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/MavenServerRule.java
@@ -21,7 +21,7 @@
 import com.google.devtools.build.lib.packages.RuleClass;
 import com.google.devtools.build.lib.packages.RuleClass.Builder;
 import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.syntax.Type;
 
 /**
  * Rule definition for the maven_jar rule.
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/NewGitRepositoryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/NewGitRepositoryRule.java
index 8db1205..fcefbff 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/NewGitRepositoryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/NewGitRepositoryRule.java
@@ -15,8 +15,8 @@
 package com.google.devtools.build.lib.bazel.rules.workspace;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
 
 import com.google.devtools.build.lib.analysis.RuleDefinition;
 import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/NewHttpArchiveRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/NewHttpArchiveRule.java
index 768b7c1..e796c70 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/NewHttpArchiveRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/NewHttpArchiveRule.java
@@ -15,7 +15,7 @@
 package com.google.devtools.build.lib.bazel.rules.workspace;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
 
 import com.google.devtools.build.lib.analysis.RuleDefinition;
 import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/NewLocalRepositoryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/NewLocalRepositoryRule.java
index 642c8f7..bbf6b58 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/NewLocalRepositoryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/NewLocalRepositoryRule.java
@@ -15,7 +15,7 @@
 package com.google.devtools.build.lib.bazel.rules.workspace;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
 
 import com.google.devtools.build.lib.analysis.RuleDefinition;
 import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java b/src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java
index 256373c..85955fc 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java
@@ -62,7 +62,6 @@
 import com.google.devtools.build.lib.packages.Rule;
 import com.google.devtools.build.lib.packages.Target;
 import com.google.devtools.build.lib.packages.TargetUtils;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.pkgcache.LoadingFailedException;
 import com.google.devtools.build.lib.pkgcache.LoadingPhaseRunner.Callback;
 import com.google.devtools.build.lib.pkgcache.LoadingPhaseRunner.LoadingResult;
@@ -72,6 +71,7 @@
 import com.google.devtools.build.lib.runtime.BlazeRuntime;
 import com.google.devtools.build.lib.runtime.CommandEnvironment;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.AbruptExitException;
 import com.google.devtools.build.lib.util.ExitCode;
 import com.google.devtools.build.lib.vfs.Path;
diff --git a/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspect.java b/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspect.java
index c2fe68c..08a4aad 100644
--- a/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspect.java
@@ -40,8 +40,8 @@
 import com.google.devtools.build.lib.ideinfo.androidstudio.AndroidStudioIdeInfo.RuleIdeInfo.Kind;
 import com.google.devtools.build.lib.packages.AspectDefinition;
 import com.google.devtools.build.lib.packages.AspectParameters;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.Rule;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.android.AndroidSdkProvider;
 import com.google.devtools.build.lib.rules.java.JavaExportsProvider;
 import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider;
@@ -100,7 +100,7 @@
     // todo(dslomov,tomlu): following current build info logic, this code enumerates dependencies
     // directly by iterating over deps attribute. The more robust way to do this might be
     // to iterate classpath as provided to build action.
-    if (ruleContext.attributes().has("deps", Type.LABEL_LIST)) {
+    if (ruleContext.attributes().has("deps", BuildType.LABEL_LIST)) {
       Iterable<AndroidStudioInfoFilesProvider> androidStudioInfoFilesProviders =
           ruleContext.getPrerequisites("deps", Mode.TARGET, AndroidStudioInfoFilesProvider.class);
       for (AndroidStudioInfoFilesProvider depProvider : androidStudioInfoFilesProviders) {
diff --git a/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java b/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java
index 373d935..c8342b6 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java
@@ -16,7 +16,9 @@
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
+import com.google.devtools.build.lib.packages.BuildType.SelectorList;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
 import javax.annotation.Nullable;
@@ -144,8 +146,8 @@
       Type<?> type = attribute.getType();
       // TODO(bazel-team): clean up the typing / visitation interface so we don't have to
       // special-case these types.
-      if (type != Type.OUTPUT && type != Type.OUTPUT_LIST
-          && type != Type.NODEP_LABEL && type != Type.NODEP_LABEL_LIST) {
+      if (type != BuildType.OUTPUT && type != BuildType.OUTPUT_LIST
+          && type != BuildType.NODEP_LABEL && type != BuildType.NODEP_LABEL_LIST) {
         visitLabels(attribute, observer);
       }
     }
@@ -184,30 +186,30 @@
   }
 
   /**
-   * Returns a {@link Type.SelectorList} for the given attribute if the attribute is configurable
+   * Returns a {@link SelectorList} for the given attribute if the attribute is configurable
    * for this rule, null otherwise.
    *
-   * @return a {@link Type.SelectorList} if the attribute takes the form
+   * @return a {@link SelectorList} if the attribute takes the form
    *     "attrName = { 'a': value1_of_type_T, 'b': value2_of_type_T }") for this rule, null
    *     if it takes the form "attrName = value_of_type_T", null if it doesn't exist
    * @throws IllegalArgumentException if the attribute is configurable but of the wrong type
    */
   @Nullable
   @SuppressWarnings("unchecked")
-  protected <T> Type.SelectorList<T> getSelectorList(String attributeName, Type<T> type) {
+  protected <T> SelectorList<T> getSelectorList(String attributeName, Type<T> type) {
     Integer index = ruleClass.getAttributeIndex(attributeName);
     if (index == null) {
       return null;
     }
     Object attrValue = attributes.getAttributeValue(index);
-    if (!(attrValue instanceof Type.SelectorList)) {
+    if (!(attrValue instanceof SelectorList)) {
       return null;
     }
-    if (((Type.SelectorList<?>) attrValue).getOriginalType() != type) {
+    if (((SelectorList<?>) attrValue).getOriginalType() != type) {
       throw new IllegalArgumentException("Attribute " + attributeName
           + " is not of type " + type + " in rule " + ruleLabel);
     }
-    return (Type.SelectorList<T>) attrValue;
+    return (SelectorList<T>) attrValue;
   }
 
   /**
diff --git a/src/main/java/com/google/devtools/build/lib/packages/AggregatingAttributeMapper.java b/src/main/java/com/google/devtools/build/lib/packages/AggregatingAttributeMapper.java
index 0031170..4030614 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/AggregatingAttributeMapper.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/AggregatingAttributeMapper.java
@@ -20,7 +20,10 @@
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.devtools.build.lib.collect.CollectionUtils;
+import com.google.devtools.build.lib.packages.BuildType.Selector;
+import com.google.devtools.build.lib.packages.BuildType.SelectorList;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -80,7 +83,7 @@
   private void visitLabels(Attribute attribute, boolean includeSelectKeys,
     AcceptsLabelAttribute observer) {
     Type<?> type = attribute.getType();
-    Type.SelectorList<?> selectorList = getSelectorList(attribute.getName(), type);
+    SelectorList<?> selectorList = getSelectorList(attribute.getName(), type);
     if (selectorList == null) {
       if (getComputedDefault(attribute.getName(), attribute.getType()) != null) {
         // Computed defaults are a special pain: we have no choice but to iterate through their
@@ -96,9 +99,9 @@
         super.visitLabels(attribute, observer);
       }
     } else {
-      for (Type.Selector<?> selector : selectorList.getSelectors()) {
+      for (Selector<?> selector : selectorList.getSelectors()) {
         for (Map.Entry<Label, ?> selectorEntry : selector.getEntries().entrySet()) {
-          if (includeSelectKeys && !Type.Selector.isReservedLabel(selectorEntry.getKey())) {
+          if (includeSelectKeys && !BuildType.Selector.isReservedLabel(selectorEntry.getKey())) {
             observer.acceptLabelAttribute(selectorEntry.getKey(), attribute);
           }
           for (Label value : extractLabels(type, selectorEntry.getValue())) {
@@ -135,7 +138,7 @@
     Type<?> attrType = attribute.getType();
     ImmutableSet.Builder<Label> duplicates = ImmutableSet.builder();
 
-    Type.SelectorList<?> selectorList = getSelectorList(attribute.getName(), attrType);
+    SelectorList<?> selectorList = getSelectorList(attribute.getName(), attrType);
     if (selectorList == null || selectorList.getSelectors().size() == 1) {
       // Three possible scenarios:
       //  1) Plain old attribute (no selects). Without selects, visitAttribute runs efficiently.
@@ -156,7 +159,7 @@
       // relax this if necessary, but doing so would incur the value iteration expense this
       // code path avoids.
       List<Label> combinedLabels = new LinkedList<>(); // Labels that appear across all selectors.
-      for (Type.Selector<?> selector : selectorList.getSelectors()) {
+      for (Selector<?> selector : selectorList.getSelectors()) {
         // Labels within a single selector. It's okay for there to be duplicates as long as
         // they're in different selector paths (since only one path can actually get chosen).
         Set<Label> selectorLabels = new LinkedHashSet<>();
@@ -182,7 +185,7 @@
    */
   public <T> Iterable<T> visitAttribute(String attributeName, Type<T> type) {
     // If this attribute value is configurable, visit all possible values.
-    Type.SelectorList<T> selectorList = getSelectorList(attributeName, type);
+    SelectorList<T> selectorList = getSelectorList(attributeName, type);
     if (selectorList != null) {
       ImmutableList.Builder<T> builder = ImmutableList.builder();
       visitConfigurableAttribute(selectorList.getSelectors(), new BoundSelectorPaths(), type,
@@ -234,7 +237,7 @@
    * @param currentValueSoFar the partial value produced so far from earlier calls to this method
    * @param valuesBuilder output container for full values this attribute can take
    */
-  private <T> void visitConfigurableAttribute(List<Type.Selector<T>> selectors,
+  private <T> void visitConfigurableAttribute(List<Selector<T>> selectors,
       BoundSelectorPaths boundSelectorPaths, Type<T> type, T currentValueSoFar,
       ImmutableList.Builder<T> valuesBuilder) {
     // TODO(bazel-team): minimize or eliminate uses of this interface. It necessarily grows
@@ -247,8 +250,8 @@
     if (selectors.isEmpty()) {
       valuesBuilder.add(Preconditions.checkNotNull(currentValueSoFar));
     } else {
-      Type.Selector<T> firstSelector = selectors.get(0);
-      List<Type.Selector<T>> remainingSelectors = selectors.subList(1, selectors.size());
+      Selector<T> firstSelector = selectors.get(0);
+      List<Selector<T>> remainingSelectors = selectors.subList(1, selectors.size());
 
       Map<Label, T> firstSelectorEntries = firstSelector.getEntries();
       Label boundKey = boundSelectorPaths.getChosenKey(firstSelectorEntries.keySet());
diff --git a/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java b/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java
index 14bade6..ad02a23 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java
@@ -139,13 +139,13 @@
       if (!predicate.apply(from, aspectAttribute)) {
         continue;
       }
-      if (aspectAttribute.getType() == Type.LABEL) {
-        Label label = Type.LABEL.cast(aspectAttribute.getDefaultValue(from));
+      if (aspectAttribute.getType() == BuildType.LABEL) {
+        Label label = BuildType.LABEL.cast(aspectAttribute.getDefaultValue(from));
         if (label != null) {
           labelBuilder.put(aspectAttribute, label);
         }
-      } else if (aspectAttribute.getType() == Type.LABEL_LIST) {
-        List<Label> labelList = Type.LABEL_LIST.cast(aspectAttribute.getDefaultValue(from));
+      } else if (aspectAttribute.getType() == BuildType.LABEL_LIST) {
+        List<Label> labelList = BuildType.LABEL_LIST.cast(aspectAttribute.getDefaultValue(from));
         labelBuilder.putAll(aspectAttribute, labelList);
       }
     }
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java
index 1f30820..350f76a 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java
@@ -24,13 +24,14 @@
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Sets;
-import com.google.devtools.build.lib.packages.Type.ConversionException;
 import com.google.devtools.build.lib.syntax.ClassObject;
 import com.google.devtools.build.lib.syntax.ClassObject.SkylarkClassObject;
 import com.google.devtools.build.lib.syntax.EvalException;
 import com.google.devtools.build.lib.syntax.Label;
 import com.google.devtools.build.lib.syntax.SkylarkCallbackFunction;
 import com.google.devtools.build.lib.syntax.SkylarkModule;
+import com.google.devtools.build.lib.syntax.Type;
+import com.google.devtools.build.lib.syntax.Type.ConversionException;
 import com.google.devtools.build.lib.util.FileType;
 import com.google.devtools.build.lib.util.FileTypeSet;
 import com.google.devtools.build.lib.util.StringUtil;
@@ -362,7 +363,7 @@
      * Makes the built attribute producing a single artifact.
      */
     public Builder<TYPE> singleArtifact() {
-      Preconditions.checkState((type == Type.LABEL) || (type == Type.LABEL_LIST),
+      Preconditions.checkState((type == BuildType.LABEL) || (type == BuildType.LABEL_LIST),
           "attribute '%s' must be a label-valued type", name);
       return setPropertyFlag(PropertyFlag.SINGLE_ARTIFACT, "single_artifact");
     }
@@ -372,7 +373,7 @@
      * This flag is introduced to handle plugins, do not use it in other cases.
      */
     public Builder<TYPE> silentRuleClassFilter() {
-      Preconditions.checkState((type == Type.LABEL) || (type == Type.LABEL_LIST),
+      Preconditions.checkState((type == BuildType.LABEL) || (type == BuildType.LABEL_LIST),
           "must be a label-valued type");
       return setPropertyFlag(PropertyFlag.SILENT_RULECLASS_FILTER, "silent_ruleclass_filter");
     }
@@ -381,7 +382,7 @@
      * Skip analysis time filetype check. Don't use it if avoidable.
      */
     public Builder<TYPE> skipAnalysisTimeFileTypeCheck() {
-      Preconditions.checkState((type == Type.LABEL) || (type == Type.LABEL_LIST),
+      Preconditions.checkState((type == BuildType.LABEL) || (type == BuildType.LABEL_LIST),
           "must be a label-valued type");
       return setPropertyFlag(PropertyFlag.SKIP_ANALYSIS_TIME_FILETYPE_CHECK,
           "skip_analysis_time_filetype_check");
@@ -556,7 +557,7 @@
      * other words, it works for 'deps' attributes, but not 'srcs' attributes.
      */
     public Builder<TYPE> allowedRuleClasses(Predicate<RuleClass> allowedRuleClasses) {
-      Preconditions.checkState((type == Type.LABEL) || (type == Type.LABEL_LIST),
+      Preconditions.checkState((type == BuildType.LABEL) || (type == BuildType.LABEL_LIST),
           "must be a label-valued type");
       propertyFlags.add(PropertyFlag.STRICT_LABEL_CHECKING);
       allowedRuleClassesForLabels = allowedRuleClasses;
@@ -586,7 +587,7 @@
      * other words, it works for 'deps' attributes, but not 'srcs' attributes.
      */
     public Builder<TYPE> allowedFileTypes(FileTypeSet allowedFileTypes) {
-      Preconditions.checkState((type == Type.LABEL) || (type == Type.LABEL_LIST),
+      Preconditions.checkState((type == BuildType.LABEL) || (type == BuildType.LABEL_LIST),
           "must be a label-valued type");
       propertyFlags.add(PropertyFlag.STRICT_LABEL_CHECKING);
       allowedFileTypesForLabels = Preconditions.checkNotNull(allowedFileTypes);
@@ -641,7 +642,7 @@
      * other words, it works for 'deps' attributes, but not 'srcs' attributes.
      */
     public Builder<TYPE> allowedRuleClassesWithWarning(Predicate<RuleClass> allowedRuleClasses) {
-      Preconditions.checkState((type == Type.LABEL) || (type == Type.LABEL_LIST),
+      Preconditions.checkState((type == BuildType.LABEL) || (type == BuildType.LABEL_LIST),
           "must be a label-valued type");
       propertyFlags.add(PropertyFlag.STRICT_LABEL_CHECKING);
       allowedRuleClassesForLabelsWarning = allowedRuleClasses;
@@ -668,7 +669,7 @@
      * error is produces during the analysis phase for every missing provider.
      */
     public Builder<TYPE> mandatoryProviders(Iterable<String> providers) {
-      Preconditions.checkState((type == Type.LABEL) || (type == Type.LABEL_LIST),
+      Preconditions.checkState((type == BuildType.LABEL) || (type == BuildType.LABEL_LIST),
           "must be a label-valued type");
       this.mandatoryProviders = ImmutableSet.copyOf(providers);
       return this;
@@ -755,14 +756,14 @@
       Preconditions.checkState(!name.isEmpty(), "name has not been set");
       // TODO(bazel-team): Set the default to be no file type, then remove this check, and also
       // remove all allowedFileTypes() calls without parameters.
-      if ((type == Type.LABEL) || (type == Type.LABEL_LIST)) {
+      if ((type == BuildType.LABEL) || (type == BuildType.LABEL_LIST)) {
         if ((name.startsWith("$") || name.startsWith(":")) && allowedFileTypesForLabels == null) {
           allowedFileTypesForLabels = FileTypeSet.ANY_FILE;
         }
         if (allowedFileTypesForLabels == null) {
           throw new IllegalStateException(name);
         }
-      } else if ((type == Type.OUTPUT) || (type == Type.OUTPUT_LIST)) {
+      } else if ((type == BuildType.OUTPUT) || (type == BuildType.OUTPUT_LIST)) {
         // TODO(bazel-team): Set the default to no file type and make explicit calls instead.
         if (allowedFileTypesForLabels == null) {
           allowedFileTypesForLabels = FileTypeSet.ANY_FILE;
@@ -1084,8 +1085,8 @@
     Preconditions.checkNotNull(configTransition);
     Preconditions.checkArgument(
         (configTransition == ConfigurationTransition.NONE && configurator == null)
-        || type == Type.LABEL || type == Type.LABEL_LIST
-        || type == Type.NODEP_LABEL || type == Type.NODEP_LABEL_LIST,
+        || type == BuildType.LABEL || type == BuildType.LABEL_LIST
+        || type == BuildType.NODEP_LABEL || type == BuildType.NODEP_LABEL_LIST,
         "Configuration transitions can only be specified for label or label list attributes");
     Preconditions.checkArgument(
         isLateBound(name) == (defaultValue instanceof LateBoundDefault),
@@ -1258,8 +1259,8 @@
    * Returns true if this attribute's value can be influenced by the build configuration.
    */
   public boolean isConfigurable() {
-    return !(type == Type.OUTPUT      // Excluded because of Rule#populateExplicitOutputFiles.
-        || type == Type.OUTPUT_LIST
+    return !(type == BuildType.OUTPUT      // Excluded because of Rule#populateExplicitOutputFiles.
+        || type == BuildType.OUTPUT_LIST
         || getPropertyFlag(PropertyFlag.NONCONFIGURABLE));
   }
 
diff --git a/src/main/java/com/google/devtools/build/lib/packages/AttributeMap.java b/src/main/java/com/google/devtools/build/lib/packages/AttributeMap.java
index c4a248d..3da7150 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/AttributeMap.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/AttributeMap.java
@@ -15,6 +15,7 @@
 
 import com.google.common.collect.ImmutableList;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 
 import javax.annotation.Nullable;
 
@@ -63,7 +64,8 @@
   /**
    * Returns the type of the given attribute, if it exists. Otherwise returns null.
    */
-  @Nullable Type<?> getAttributeType(String attrName);
+  @Nullable
+  Type<?> getAttributeType(String attrName);
 
   /**
    * Returns the attribute definition whose name is {@code attrName}, or null
diff --git a/src/main/java/com/google/devtools/build/lib/packages/BuildType.java b/src/main/java/com/google/devtools/build/lib/packages/BuildType.java
new file mode 100644
index 0000000..746e06b
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/packages/BuildType.java
@@ -0,0 +1,563 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.packages;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Maps;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
+import com.google.devtools.build.lib.packages.License.DistributionType;
+import com.google.devtools.build.lib.packages.License.LicenseParsingException;
+import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.SelectorValue;
+import com.google.devtools.build.lib.syntax.Type;
+import com.google.devtools.build.lib.syntax.Type.ConversionException;
+import com.google.devtools.build.lib.syntax.Type.DictType;
+import com.google.devtools.build.lib.syntax.Type.ListType;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import javax.annotation.Nullable;
+
+/**
+ * Collection of data types that are specific to building things, i.e. not inherent to Skylark.
+ */
+public final class BuildType {
+
+  /**
+   * The type of a label. Labels are not actually a first-class datatype in
+   * the build language, but they are so frequently used in the definitions of
+   * attributes that it's worth treating them specially (and providing support
+   * for resolution of relative-labels in the <code>convert()</code> method).
+   */
+  public static final Type<Label> LABEL = new LabelType();
+  /**
+   * The type of a dictionary of {@linkplain #LABEL labels}.
+   */
+  public static final DictType<String, Label> LABEL_DICT_UNARY = DictType.create(
+      Type.STRING, LABEL);
+  /**
+   *  The type of a list of {@linkplain #LABEL labels}.
+   */
+  public static final ListType<Label> LABEL_LIST = ListType.create(LABEL);
+  /**
+   * The type of a dictionary of {@linkplain #LABEL_LIST label lists}.
+   */
+  public static final DictType<String, List<Label>> LABEL_LIST_DICT =
+      DictType.create(Type.STRING, LABEL_LIST);
+  /**
+   * This is a label type that does not cause dependencies. It is needed because
+   * certain rules want to verify the type of a target referenced by one of their attributes, but
+   * if there was a dependency edge there, it would be a circular dependency.
+   */
+  public static final Type<Label> NODEP_LABEL = new LabelType();
+  /**
+   *  The type of a list of {@linkplain #NODEP_LABEL labels} that do not cause
+   *  dependencies.
+   */
+  public static final ListType<Label> NODEP_LABEL_LIST = ListType.create(NODEP_LABEL);
+  /**
+   * The type of a license. Like Label, licenses aren't first-class, but
+   * they're important enough to justify early syntax error detection.
+   */
+  public static final Type<License> LICENSE = new LicenseType();
+  /**
+   * The type of a single distribution.  Only used internally, as a type
+   * symbol, not a converter.
+   */
+  public static final Type<DistributionType> DISTRIBUTION = new Type<DistributionType>() {
+    @Override
+    public DistributionType cast(Object value) {
+      return (DistributionType) value;
+    }
+
+    @Override
+    public DistributionType convert(Object x, String what, Object context) {
+      throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public DistributionType getDefaultValue() {
+      return null;
+    }
+
+    @Override
+    public Collection<Object> flatten(Object value) {
+      return NOT_COMPOSITE_TYPE;
+    }
+
+    @Override
+    public String toString() {
+      return "distribution";
+    }
+  };
+  /**
+   * The type of a set of distributions. Distributions are not a first-class type,
+   * but they do warrant early syntax checking.
+   */
+  public static final Type<Set<DistributionType>> DISTRIBUTIONS = new Distributions();
+  /**
+   *  The type of an output file, treated as a {@link #LABEL}.
+   */
+  public static final Type<Label> OUTPUT = new OutputType();
+  /**
+   *  The type of a list of {@linkplain #OUTPUT outputs}.
+   */
+  public static final ListType<Label> OUTPUT_LIST = ListType.create(OUTPUT);
+  /**
+   * The type of a FilesetEntry attribute inside a Fileset.
+   */
+  public static final Type<FilesetEntry> FILESET_ENTRY = new FilesetEntryType();
+  /**
+   * The type of a list of {@linkplain #FILESET_ENTRY FilesetEntries}.
+   */
+  public static final ListType<FilesetEntry> FILESET_ENTRY_LIST = ListType.create(FILESET_ENTRY);
+  /**
+   * The type of a TriState with values: true (x>0), false (x==0), auto (x<0).
+   */
+  public static final Type<TriState> TRISTATE = new TriStateType();
+
+  private BuildType() {
+    // Do not instantiate
+  }
+
+  /**
+   * Returns whether the specified type is a label type or not.
+   */
+  public static boolean isLabelType(Type<?> type) {
+    return type == LABEL || type == LABEL_LIST || type == LABEL_DICT_UNARY
+        || type == NODEP_LABEL || type == NODEP_LABEL_LIST
+        || type == LABEL_LIST_DICT || type == FILESET_ENTRY_LIST;
+  }
+
+  /**
+   * Variation of {@link Type#convert} that supports selector expressions for configurable
+   * attributes* (i.e. "{ config1: 'value1_of_orig_type', config2: 'value2_of_orig_type; }"). If x
+   * is a selector expression, returns a {@link Selector} instance that contains key-mapped entries
+   * of the native type. Else, returns the native type directly.
+   *
+   * <p>The caller is responsible for casting the returned value appropriately.
+   */
+  public static <T> Object selectableConvert(
+      Type type, Object x, String what, @Nullable Label context)
+      throws ConversionException {
+    if (x instanceof com.google.devtools.build.lib.syntax.SelectorList) {
+      return new SelectorList<T>(
+          ((com.google.devtools.build.lib.syntax.SelectorList) x).getElements(),
+          what, context, type);
+    } else {
+      return type.convert(x, what, context);
+    }
+  }
+
+  private static class FilesetEntryType extends
+      Type<FilesetEntry> {
+    @Override
+    public FilesetEntry cast(Object value) {
+      return (FilesetEntry) value;
+    }
+
+    @Override
+    public FilesetEntry convert(Object x, String what, Object context)
+        throws ConversionException {
+      if (!(x instanceof FilesetEntry)) {
+        throw new ConversionException(this, x, what);
+      }
+      return (FilesetEntry) x;
+    }
+
+    @Override
+    public String toString() {
+      return "FilesetEntry";
+    }
+
+    @Override
+    public FilesetEntry getDefaultValue() {
+      return null;
+    }
+
+    @Override
+    public Collection<? extends Object> flatten(Object value) {
+      return cast(value).getLabels();
+    }
+  }
+
+  private static class LabelType extends Type<Label> {
+    @Override
+    public Label cast(Object value) {
+      return (Label) value;
+    }
+
+    @Override
+    public Label getDefaultValue() {
+      return null; // Labels have no default value
+    }
+
+    @Override
+    public Collection<Label> flatten(Object value) {
+      return ImmutableList.of(cast(value));
+    }
+
+    @Override
+    public String toString() {
+      return "label";
+    }
+
+    @Override
+    public Label convert(Object x, String what, Object context)
+        throws ConversionException {
+      if (x instanceof Label) {
+        return (Label) x;
+      }
+      try {
+        return ((Label) context).getRelative(STRING.convert(x, what, context));
+      } catch (LabelSyntaxException e) {
+        throw new ConversionException("invalid label '" + x + "' in "
+            + what + ": " + e.getMessage());
+      }
+    }
+  }
+
+  /**
+   * Like Label, LicenseType is a derived type, which is declared specially
+   * in order to allow syntax validation. It represents the licenses, as
+   * described in {@ref License}.
+   */
+  public static class LicenseType extends Type<License> {
+    @Override
+    public License cast(Object value) {
+      return (License) value;
+    }
+
+    @Override
+    public License convert(Object x, String what, Object context) throws ConversionException {
+      try {
+        List<String> licenseStrings = STRING_LIST.convert(x, what);
+        return License.parseLicense(licenseStrings);
+      } catch (LicenseParsingException e) {
+        throw new ConversionException(e.getMessage());
+      }
+    }
+
+    @Override
+    public License getDefaultValue() {
+      return License.NO_LICENSE;
+    }
+
+    @Override
+    public Collection<Object> flatten(Object value) {
+      return NOT_COMPOSITE_TYPE;
+    }
+
+    @Override
+    public String toString() {
+      return "license";
+    }
+  }
+
+  /**
+   * Like Label, Distributions is a derived type, which is declared specially
+   * in order to allow syntax validation. It represents the declared distributions
+   * of a target, as described in {@ref License}.
+   */
+  private static class Distributions extends
+      Type<Set<DistributionType>> {
+    @SuppressWarnings("unchecked")
+    @Override
+    public Set<DistributionType> cast(Object value) {
+      return (Set<DistributionType>) value;
+    }
+
+    @Override
+    public Set<DistributionType> convert(Object x, String what, Object context)
+        throws ConversionException {
+      try {
+        List<String> distribStrings = STRING_LIST.convert(x, what);
+        return License.parseDistributions(distribStrings);
+      } catch (LicenseParsingException e) {
+        throw new ConversionException(e.getMessage());
+      }
+    }
+
+    @Override
+    public Set<DistributionType> getDefaultValue() {
+      return Collections.emptySet();
+    }
+
+    @Override
+    public Collection<Object> flatten(Object what) {
+      return NOT_COMPOSITE_TYPE;
+    }
+
+    @Override
+    public String toString() {
+      return "distributions";
+    }
+
+    @Override
+    public Type<DistributionType> getListElementType() {
+      return DISTRIBUTION;
+    }
+  }
+
+  private static class OutputType extends Type<Label> {
+    @Override
+    public Label cast(Object value) {
+      return (Label) value;
+    }
+
+    @Override
+    public Label getDefaultValue() {
+      return null;
+    }
+
+    @Override
+    public Collection<Label> flatten(Object value) {
+      return ImmutableList.of(cast(value));
+    }
+
+    @Override
+    public String toString() {
+      return "output";
+    }
+
+    @Override
+    public Label convert(Object x, String what, Object context)
+        throws ConversionException {
+
+      String value;
+      try {
+        value = STRING.convert(x, what, context);
+      } catch (ConversionException e) {
+        throw new ConversionException(this, x, what);
+      }
+      try {
+        // Enforce value is relative to the context.
+        Label currentRule = (Label) context;
+        Label result = currentRule.getRelative(value);
+        if (!result.getPackageIdentifier().equals(currentRule.getPackageIdentifier())) {
+          throw new ConversionException("label '" + value + "' is not in the current package");
+        }
+        return result;
+      } catch (LabelSyntaxException e) {
+        throw new ConversionException(
+            "illegal output file name '" + value + "' in rule " + context + ": "
+            + e.getMessage());
+      }
+    }
+  }
+
+  /**
+   * Holds an ordered collection of {@link Selector}s. This is used to support
+   * {@code attr = rawValue + select(...) + select(...) + ..."} syntax. For consistency's
+   * sake, raw values are stored as selects with only a default condition.
+   */
+  public static final class SelectorList<T> {
+    private final Type<T> originalType;
+    private final List<Selector<T>> elements;
+
+    @VisibleForTesting
+    SelectorList(List<Object> x, String what, @Nullable Label context,
+        Type<T> originalType) throws ConversionException {
+      if (x.size() > 1 && originalType.concat(ImmutableList.<T>of()) == null) {
+        throw new ConversionException(
+            String.format("type '%s' doesn't support select concatenation", originalType));
+      }
+
+      ImmutableList.Builder<Selector<T>> builder = ImmutableList.builder();
+      for (Object elem : x) {
+        if (elem instanceof SelectorValue) {
+          builder.add(new Selector<T>(((SelectorValue) elem).getDictionary(), what,
+              context, originalType));
+        } else {
+          T directValue = originalType.convert(elem, what, context);
+          builder.add(new Selector<T>(ImmutableMap.of(Selector.DEFAULT_CONDITION_KEY, directValue),
+              what, context, originalType));
+        }
+      }
+      this.originalType = originalType;
+      this.elements = builder.build();
+    }
+
+    /**
+     * Returns a syntactically order-preserved list of all values and selectors for this attribute.
+     */
+    public List<Selector<T>> getSelectors() {
+      return elements;
+    }
+
+    /**
+     * Returns the native Type for this attribute (i.e. what this would be if it wasn't a
+     * selector list).
+     */
+    public Type<T> getOriginalType() {
+      return originalType;
+    }
+
+    /**
+     * Returns the labels of all configurability keys across all selects in this expression.
+     */
+    public Set<Label> getKeyLabels() {
+      ImmutableSet.Builder<Label> keys = ImmutableSet.builder();
+      for (Selector<T> selector : getSelectors()) {
+         for (Label label : selector.getEntries().keySet()) {
+           if (!Selector.isReservedLabel(label)) {
+             keys.add(label);
+           }
+         }
+      }
+      return keys.build();
+    }
+  }
+
+  /**
+   * Special Type that represents a selector expression for configurable attributes. Holds a
+   * mapping of {@code <Label, T>} entries, where keys are configurability patterns and values are
+   * objects of the attribute's native Type.
+   */
+  public static final class Selector<T> {
+    private final Type<T> originalType;
+    private final Map<Label, T> map;
+    private final Label defaultConditionLabel;
+    private final boolean hasDefaultCondition;
+
+    /**
+     * Value to use when none of an attribute's selection criteria match.
+     */
+    @VisibleForTesting
+    public static final String DEFAULT_CONDITION_KEY = "//conditions:default";
+
+    @VisibleForTesting
+    Selector(Object x, String what, @Nullable Label context, Type<T> originalType)
+        throws ConversionException {
+      Preconditions.checkState(x instanceof Map<?, ?>);
+
+      try {
+        defaultConditionLabel = Label.parseAbsolute(DEFAULT_CONDITION_KEY);
+      } catch (LabelSyntaxException e) {
+        throw new IllegalStateException(DEFAULT_CONDITION_KEY + " is not a valid label");
+      }
+
+      this.originalType = originalType;
+      Map<Label, T> result = Maps.newLinkedHashMap();
+      boolean foundDefaultCondition = false;
+      for (Entry<?, ?> entry : ((Map<?, ?>) x).entrySet()) {
+        Label key = LABEL.convert(entry.getKey(), what, context);
+        if (key.equals(defaultConditionLabel)) {
+          foundDefaultCondition = true;
+        }
+        result.put(key, originalType.convert(entry.getValue(), what, context));
+      }
+      map = ImmutableMap.copyOf(result);
+      hasDefaultCondition = foundDefaultCondition;
+    }
+
+    /**
+     * Returns the selector's (configurability pattern --gt; matching values) map.
+     */
+    public Map<Label, T> getEntries() {
+      return map;
+    }
+
+    /**
+     * Returns the value to use when none of the attribute's selection keys match.
+     */
+    public T getDefault() {
+      return map.get(defaultConditionLabel);
+    }
+
+    /**
+     * Returns whether or not this selector has a default condition.
+     */
+    public boolean hasDefault() {
+      return hasDefaultCondition;
+    }
+
+    /**
+     * Returns the native Type for this attribute (i.e. what this would be if it wasn't a
+     * selector expression).
+     */
+    public Type<T> getOriginalType() {
+      return originalType;
+    }
+
+    /**
+     * Returns true for labels that are "reserved selector key words" and not intended to
+     * map to actual targets.
+     */
+    public static boolean isReservedLabel(Label label) {
+      return label.toString().equals(DEFAULT_CONDITION_KEY);
+    }
+  }
+
+  /**
+   * Tristate values are needed for cases where user intent matters.
+   *
+   * <p>Tristate values are not explicitly interchangeable with booleans and are
+   * handled explicitly as TriStates. Prefer Booleans with default values where
+   * possible.  The main use case for TriState values is when a Rule's behavior
+   * must interact with a Flag value in a complicated way.</p>
+   */
+  private static class TriStateType extends Type<TriState> {
+    @Override
+    public TriState cast(Object value) {
+      return (TriState) value;
+    }
+
+    @Override
+    public TriState getDefaultValue() {
+      return TriState.AUTO;
+    }
+
+    @Override
+    public Collection<Object> flatten(Object value) {
+      return NOT_COMPOSITE_TYPE;
+    }
+
+    @Override
+    public String toString() {
+      return "tristate";
+    }
+
+    // Like BooleanType, this must handle integers as well.
+    @Override
+    public TriState convert(Object x, String what, Object context)
+        throws ConversionException {
+      if (x instanceof TriState) {
+        return (TriState) x;
+      }
+      if (x instanceof Boolean) {
+        return ((Boolean) x) ? TriState.YES : TriState.NO;
+      }
+      Integer xAsInteger = INTEGER.convert(x, what, context);
+      if (xAsInteger == -1) {
+        return TriState.AUTO;
+      } else if (xAsInteger == 1) {
+        return TriState.YES;
+      } else if (xAsInteger == 0) {
+        return TriState.NO;
+      }
+      throw new ConversionException(this, x, "TriState values is not one of [-1, 0, 1]");
+    }
+  }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/DelegatingAttributeMapper.java b/src/main/java/com/google/devtools/build/lib/packages/DelegatingAttributeMapper.java
index 3bee63b..ed477ed 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/DelegatingAttributeMapper.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/DelegatingAttributeMapper.java
@@ -16,6 +16,7 @@
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 
 import javax.annotation.Nullable;
 
diff --git a/src/main/java/com/google/devtools/build/lib/packages/EnvironmentGroup.java b/src/main/java/com/google/devtools/build/lib/packages/EnvironmentGroup.java
index ff9edae..b6de272 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/EnvironmentGroup.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/EnvironmentGroup.java
@@ -161,7 +161,7 @@
       Target env = pkgTargets.get(envName.getName());
       if (isValidEnvironment(env, envName, "", events)) {
         AttributeMap attr = NonconfigurableAttributeMapper.of((Rule) env);
-        for (Label fulfilledEnv : attr.get("fulfills", Type.LABEL_LIST)) {
+        for (Label fulfilledEnv : attr.get("fulfills", BuildType.LABEL_LIST)) {
           if (isValidEnvironment(pkgTargets.get(fulfilledEnv.getName()), fulfilledEnv,
               "in \"fulfills\" attribute of " + envName + ": ", events)) {
             directFulfillers.put(fulfilledEnv, envName);
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/FilesetEntry.java b/src/main/java/com/google/devtools/build/lib/packages/FilesetEntry.java
similarity index 95%
rename from src/main/java/com/google/devtools/build/lib/syntax/FilesetEntry.java
rename to src/main/java/com/google/devtools/build/lib/packages/FilesetEntry.java
index c876d63..1b9edb2 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/FilesetEntry.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/FilesetEntry.java
@@ -12,12 +12,16 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package com.google.devtools.build.lib.syntax;
+package com.google.devtools.build.lib.packages;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
+import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Printer;
+import com.google.devtools.build.lib.syntax.SkylarkModule;
+import com.google.devtools.build.lib.syntax.SkylarkValue;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
 import java.util.Collection;
diff --git a/src/main/java/com/google/devtools/build/lib/packages/ImplicitOutputsFunction.java b/src/main/java/com/google/devtools/build/lib/packages/ImplicitOutputsFunction.java
index eb3badd..f7f9919 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/ImplicitOutputsFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/ImplicitOutputsFunction.java
@@ -31,6 +31,7 @@
 import com.google.devtools.build.lib.syntax.Label;
 import com.google.devtools.build.lib.syntax.Runtime;
 import com.google.devtools.build.lib.syntax.SkylarkCallbackFunction;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.StringUtil;
 import com.google.devtools.build.lib.vfs.FileSystemUtils;
 import com.google.devtools.build.lib.vfs.PathFragment;
@@ -295,28 +296,28 @@
       return singleton(rule.get(attrName, Type.STRING));
     } else if (Type.STRING_LIST == attrType) {
       return Sets.newLinkedHashSet(rule.get(attrName, Type.STRING_LIST));
-    } else if (Type.LABEL == attrType) {
+    } else if (BuildType.LABEL == attrType) {
       // Labels are most often used to change the extension,
       // e.g. %.foo -> %.java, so we return the basename w/o extension.
-      Label label = rule.get(attrName, Type.LABEL);
+      Label label = rule.get(attrName, BuildType.LABEL);
       return singleton(FileSystemUtils.removeExtension(label.getName()));
-    } else if (Type.LABEL_LIST == attrType) {
+    } else if (BuildType.LABEL_LIST == attrType) {
       // Labels are most often used to change the extension,
       // e.g. %.foo -> %.java, so we return the basename w/o extension.
       return Sets.newLinkedHashSet(
-          Iterables.transform(rule.get(attrName, Type.LABEL_LIST),
+          Iterables.transform(rule.get(attrName, BuildType.LABEL_LIST),
               new Function<Label, String>() {
                 @Override
                 public String apply(Label label) {
                   return FileSystemUtils.removeExtension(label.getName());
                 }
               }));
-    } else if (Type.OUTPUT == attrType) {
-      Label out = rule.get(attrName, Type.OUTPUT);
+    } else if (BuildType.OUTPUT == attrType) {
+      Label out = rule.get(attrName, BuildType.OUTPUT);
       return singleton(out.getName());
-    } else if (Type.OUTPUT_LIST == attrType) {
+    } else if (BuildType.OUTPUT_LIST == attrType) {
       return Sets.newLinkedHashSet(
-          Iterables.transform(rule.get(attrName, Type.OUTPUT_LIST),
+          Iterables.transform(rule.get(attrName, BuildType.OUTPUT_LIST),
               new Function<Label, String>() {
                 @Override
                 public String apply(Label label) {
diff --git a/src/main/java/com/google/devtools/build/lib/packages/NonconfigurableAttributeMapper.java b/src/main/java/com/google/devtools/build/lib/packages/NonconfigurableAttributeMapper.java
index ff515f3..39282e4 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/NonconfigurableAttributeMapper.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/NonconfigurableAttributeMapper.java
@@ -41,7 +41,7 @@
   }
 
   @Override
-  public <T> T get(String attributeName, Type<T> type) {
+  public <T> T get(String attributeName, com.google.devtools.build.lib.syntax.Type<T> type) {
     Preconditions.checkState(!getAttributeDefinition(attributeName).isConfigurable(),
         "Attribute '%s' is potentially configurable - not allowed here", attributeName);
     return super.get(attributeName, type);
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Package.java b/src/main/java/com/google/devtools/build/lib/packages/Package.java
index c78b6d0..41224e0 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/Package.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/Package.java
@@ -1272,9 +1272,9 @@
       for (Rule rule : rules) {
         AttributeMap attributes = NonconfigurableAttributeMapper.of(rule);
         if (rule.getRuleClass().equals("test_suite")
-            && attributes.get("tests", Type.LABEL_LIST).isEmpty()
-            && (!attributes.has("suites", Type.LABEL_LIST)
-                || attributes.get("suites", Type.LABEL_LIST).isEmpty())) {
+            && attributes.get("tests", BuildType.LABEL_LIST).isEmpty()
+            && (!attributes.has("suites", BuildType.LABEL_LIST)
+                || attributes.get("suites", BuildType.LABEL_LIST).isEmpty())) {
           rule.setAttributeValueByName("$implicit_tests", allTests);
         }
       }
diff --git a/src/main/java/com/google/devtools/build/lib/packages/PackageDeserializer.java b/src/main/java/com/google/devtools/build/lib/packages/PackageDeserializer.java
index 867a83a..1904ecb 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/PackageDeserializer.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/PackageDeserializer.java
@@ -36,10 +36,10 @@
 import com.google.devtools.build.lib.packages.RuleClass.ParsedAttributeValue;
 import com.google.devtools.build.lib.query2.proto.proto2api.Build;
 import com.google.devtools.build.lib.query2.proto.proto2api.Build.StringDictUnaryEntry;
-import com.google.devtools.build.lib.syntax.FilesetEntry;
 import com.google.devtools.build.lib.syntax.GlobCriteria;
 import com.google.devtools.build.lib.syntax.GlobList;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.vfs.Path;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
@@ -503,7 +503,7 @@
       case STRING:
         if (!attrPb.hasStringValue()) {
           return null;
-        } else if (expectedType == Type.NODEP_LABEL) {
+        } else if (expectedType == BuildType.NODEP_LABEL) {
           return deserializeLabel(attrPb.getStringValue());
         } else {
           return attrPb.getStringValue();
@@ -514,7 +514,7 @@
         return attrPb.hasStringValue() ? deserializeLabel(attrPb.getStringValue()) : null;
 
       case STRING_LIST:
-        if (expectedType == Type.NODEP_LABEL_LIST) {
+        if (expectedType == BuildType.NODEP_LABEL_LIST) {
           return deserializeGlobs(deserializeLabels(attrPb.getStringListValueList()), attrPb);
         } else {
           return deserializeGlobs(ImmutableList.copyOf(attrPb.getStringListValueList()), attrPb);
diff --git a/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java b/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java
index c192738..55046a6 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java
@@ -31,7 +31,6 @@
 import com.google.devtools.build.lib.events.StoredEventHandler;
 import com.google.devtools.build.lib.packages.GlobCache.BadGlobException;
 import com.google.devtools.build.lib.packages.License.DistributionType;
-import com.google.devtools.build.lib.packages.Type.ConversionException;
 import com.google.devtools.build.lib.syntax.AssignmentStatement;
 import com.google.devtools.build.lib.syntax.BaseFunction;
 import com.google.devtools.build.lib.syntax.BuildFileAST;
@@ -56,6 +55,8 @@
 import com.google.devtools.build.lib.syntax.SkylarkSignatureProcessor;
 import com.google.devtools.build.lib.syntax.SkylarkSignatureProcessor.HackHackEitherList;
 import com.google.devtools.build.lib.syntax.Statement;
+import com.google.devtools.build.lib.syntax.Type;
+import com.google.devtools.build.lib.syntax.Type.ConversionException;
 import com.google.devtools.build.lib.util.Pair;
 import com.google.devtools.build.lib.vfs.Path;
 import com.google.devtools.build.lib.vfs.PathFragment;
@@ -163,7 +164,7 @@
 
   private static class DefaultVisibility extends PackageArgument<List<Label>> {
     private DefaultVisibility() {
-      super("default_visibility", Type.LABEL_LIST);
+      super("default_visibility", BuildType.LABEL_LIST);
     }
 
     @Override
@@ -211,7 +212,7 @@
 
   private static class DefaultLicenses extends PackageArgument<License> {
     private DefaultLicenses() {
-      super("licenses", Type.LICENSE);
+      super("licenses", BuildType.LICENSE);
     }
 
     @Override
@@ -223,7 +224,7 @@
 
   private static class DefaultDistribs extends PackageArgument<Set<DistributionType>> {
     private DefaultDistribs() {
-      super("distribs", Type.DISTRIBUTIONS);
+      super("distribs", BuildType.DISTRIBUTIONS);
     }
 
     @Override
@@ -239,7 +240,7 @@
    */
   private static class DefaultCompatibleWith extends PackageArgument<List<Label>> {
     private DefaultCompatibleWith() {
-      super(Package.DEFAULT_COMPATIBLE_WITH_ATTRIBUTE, Type.LABEL_LIST);
+      super(Package.DEFAULT_COMPATIBLE_WITH_ATTRIBUTE, BuildType.LABEL_LIST);
     }
 
     @Override
@@ -256,7 +257,7 @@
    */
   private static class DefaultRestrictedTo extends PackageArgument<List<Label>> {
     private DefaultRestrictedTo() {
-      super(Package.DEFAULT_RESTRICTED_TO_ATTRIBUTE, Type.LABEL_LIST);
+      super(Package.DEFAULT_RESTRICTED_TO_ATTRIBUTE, BuildType.LABEL_LIST);
     }
 
     @Override
@@ -566,7 +567,7 @@
           return new BuiltinFunction("mocksubinclude", this) {
             public Runtime.NoneType invoke(Object labelO, String pathString,
                 Location loc) throws ConversionException {
-              Label label = Type.LABEL.convert(labelO, "'mocksubinclude' argument",
+              Label label = BuildType.LABEL.convert(labelO, "'mocksubinclude' argument",
                   context.pkgBuilder.getBuildFileLabel());
               Path path = pathString.isEmpty()
                   ? null : context.pkgBuilder.getFilename().getRelative(pathString);
@@ -618,9 +619,9 @@
           return new BuiltinFunction("environment_group", this) {
             public Runtime.NoneType invoke(String name, Object environmentsO, Object defaultsO,
                 Location loc) throws EvalException, ConversionException {
-              List<Label> environments = Type.LABEL_LIST.convert(environmentsO,
+              List<Label> environments = BuildType.LABEL_LIST.convert(environmentsO,
                   "'environment_group argument'", context.pkgBuilder.getBuildFileLabel());
-              List<Label> defaults = Type.LABEL_LIST.convert(defaultsO,
+              List<Label> defaults = BuildType.LABEL_LIST.convert(defaultsO,
                   "'environment_group argument'", context.pkgBuilder.getBuildFileLabel());
 
               try {
@@ -678,12 +679,12 @@
 
     RuleVisibility visibility = EvalUtils.isNullOrNone(visibilityO)
         ? ConstantRuleVisibility.PUBLIC
-        : getVisibility(Type.LABEL_LIST.convert(
+        : getVisibility(BuildType.LABEL_LIST.convert(
               visibilityO,
               "'exports_files' operand",
               pkgBuilder.getBuildFileLabel()));
     // TODO(bazel-team): is licenses plural or singular?
-    License license = Type.LICENSE.convertOptional(licensesO, "'exports_files' operand");
+    License license = BuildType.LICENSE.convertOptional(licensesO, "'exports_files' operand");
 
     for (String file : files) {
       String errorMessage = LabelValidator.validateTargetName(file);
@@ -736,7 +737,7 @@
           return new BuiltinFunction("licenses", this) {
             public Runtime.NoneType invoke(Object licensesO, Location loc) {
               try {
-                License license = Type.LICENSE.convert(licensesO, "'licenses' operand");
+                License license = BuildType.LICENSE.convert(licensesO, "'licenses' operand");
                 context.pkgBuilder.setDefaultLicense(license);
               } catch (ConversionException e) {
                 context.eventHandler.handle(Event.error(loc, e.getMessage()));
@@ -768,7 +769,7 @@
           return new BuiltinFunction("distribs", this) {
             public Runtime.NoneType invoke(Object object, Location loc) {
               try {
-                Set<DistributionType> distribs = Type.DISTRIBUTIONS.convert(object,
+                Set<DistributionType> distribs = BuildType.DISTRIBUTIONS.convert(object,
                     "'distribs' operand");
                 context.pkgBuilder.setDefaultDistribs(distribs);
               } catch (ConversionException e) {
@@ -813,7 +814,7 @@
 
     List<String> packages = Type.STRING_LIST.convert(
         packagesO, "'package_group.packages argument'");
-    List<Label> includes = Type.LABEL_LIST.convert(includesO,
+    List<Label> includes = BuildType.LABEL_LIST.convert(includesO,
         "'package_group.includes argument'", context.pkgBuilder.getBuildFileLabel());
 
     try {
diff --git a/src/main/java/com/google/devtools/build/lib/packages/PackageSerializer.java b/src/main/java/com/google/devtools/build/lib/packages/PackageSerializer.java
index 9a336c1..3d906e4 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/PackageSerializer.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/PackageSerializer.java
@@ -13,26 +13,26 @@
 // limitations under the License.
 package com.google.devtools.build.lib.packages;
 
-import static com.google.devtools.build.lib.packages.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.DISTRIBUTIONS;
-import static com.google.devtools.build.lib.packages.Type.FILESET_ENTRY_LIST;
-import static com.google.devtools.build.lib.packages.Type.INTEGER;
-import static com.google.devtools.build.lib.packages.Type.INTEGER_LIST;
-import static com.google.devtools.build.lib.packages.Type.LABEL;
-import static com.google.devtools.build.lib.packages.Type.LABEL_DICT_UNARY;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST_DICT;
-import static com.google.devtools.build.lib.packages.Type.LICENSE;
-import static com.google.devtools.build.lib.packages.Type.NODEP_LABEL;
-import static com.google.devtools.build.lib.packages.Type.NODEP_LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.OUTPUT;
-import static com.google.devtools.build.lib.packages.Type.OUTPUT_LIST;
-import static com.google.devtools.build.lib.packages.Type.STRING;
-import static com.google.devtools.build.lib.packages.Type.STRING_DICT;
-import static com.google.devtools.build.lib.packages.Type.STRING_DICT_UNARY;
-import static com.google.devtools.build.lib.packages.Type.STRING_LIST;
-import static com.google.devtools.build.lib.packages.Type.STRING_LIST_DICT;
-import static com.google.devtools.build.lib.packages.Type.TRISTATE;
+import static com.google.devtools.build.lib.packages.BuildType.DISTRIBUTIONS;
+import static com.google.devtools.build.lib.packages.BuildType.FILESET_ENTRY_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_DICT_UNARY;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST_DICT;
+import static com.google.devtools.build.lib.packages.BuildType.LICENSE;
+import static com.google.devtools.build.lib.packages.BuildType.NODEP_LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.NODEP_LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.OUTPUT;
+import static com.google.devtools.build.lib.packages.BuildType.OUTPUT_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.TRISTATE;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
+import static com.google.devtools.build.lib.syntax.Type.INTEGER;
+import static com.google.devtools.build.lib.syntax.Type.INTEGER_LIST;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.STRING_DICT;
+import static com.google.devtools.build.lib.syntax.Type.STRING_DICT_UNARY;
+import static com.google.devtools.build.lib.syntax.Type.STRING_LIST;
+import static com.google.devtools.build.lib.syntax.Type.STRING_LIST_DICT;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
@@ -40,7 +40,6 @@
 import com.google.devtools.build.lib.packages.License.DistributionType;
 import com.google.devtools.build.lib.packages.MakeEnvironment.Binding;
 import com.google.devtools.build.lib.query2.proto.proto2api.Build;
-import com.google.devtools.build.lib.syntax.FilesetEntry;
 import com.google.devtools.build.lib.syntax.GlobCriteria;
 import com.google.devtools.build.lib.syntax.GlobList;
 import com.google.devtools.build.lib.syntax.Label;
@@ -182,7 +181,7 @@
   private Build.Attribute serializeAttribute(Attribute attr, Iterable<Object> values,
       Boolean explicitlySpecified, boolean includeGlobs) {
     // Get the attribute type.  We need to convert and add appropriately
-    com.google.devtools.build.lib.packages.Type<?> type = attr.getType();
+    com.google.devtools.build.lib.syntax.Type<?> type = attr.getType();
 
     Build.Attribute.Builder attrPb = Build.Attribute.newBuilder();
 
diff --git a/src/main/java/com/google/devtools/build/lib/packages/ProtoUtils.java b/src/main/java/com/google/devtools/build/lib/packages/ProtoUtils.java
index b566ba7..579d3a3 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/ProtoUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/ProtoUtils.java
@@ -14,26 +14,26 @@
 
 package com.google.devtools.build.lib.packages;
 
-import static com.google.devtools.build.lib.packages.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.DISTRIBUTIONS;
-import static com.google.devtools.build.lib.packages.Type.FILESET_ENTRY_LIST;
-import static com.google.devtools.build.lib.packages.Type.INTEGER;
-import static com.google.devtools.build.lib.packages.Type.INTEGER_LIST;
-import static com.google.devtools.build.lib.packages.Type.LABEL;
-import static com.google.devtools.build.lib.packages.Type.LABEL_DICT_UNARY;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST_DICT;
-import static com.google.devtools.build.lib.packages.Type.LICENSE;
-import static com.google.devtools.build.lib.packages.Type.NODEP_LABEL;
-import static com.google.devtools.build.lib.packages.Type.NODEP_LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.OUTPUT;
-import static com.google.devtools.build.lib.packages.Type.OUTPUT_LIST;
-import static com.google.devtools.build.lib.packages.Type.STRING;
-import static com.google.devtools.build.lib.packages.Type.STRING_DICT;
-import static com.google.devtools.build.lib.packages.Type.STRING_DICT_UNARY;
-import static com.google.devtools.build.lib.packages.Type.STRING_LIST;
-import static com.google.devtools.build.lib.packages.Type.STRING_LIST_DICT;
-import static com.google.devtools.build.lib.packages.Type.TRISTATE;
+import static com.google.devtools.build.lib.packages.BuildType.DISTRIBUTIONS;
+import static com.google.devtools.build.lib.packages.BuildType.FILESET_ENTRY_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_DICT_UNARY;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST_DICT;
+import static com.google.devtools.build.lib.packages.BuildType.LICENSE;
+import static com.google.devtools.build.lib.packages.BuildType.NODEP_LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.NODEP_LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.OUTPUT;
+import static com.google.devtools.build.lib.packages.BuildType.OUTPUT_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.TRISTATE;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
+import static com.google.devtools.build.lib.syntax.Type.INTEGER;
+import static com.google.devtools.build.lib.syntax.Type.INTEGER_LIST;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.STRING_DICT;
+import static com.google.devtools.build.lib.syntax.Type.STRING_DICT_UNARY;
+import static com.google.devtools.build.lib.syntax.Type.STRING_LIST;
+import static com.google.devtools.build.lib.syntax.Type.STRING_LIST_DICT;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
@@ -44,6 +44,7 @@
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Sets;
 import com.google.devtools.build.lib.query2.proto.proto2api.Build.Attribute.Discriminator;
+import com.google.devtools.build.lib.syntax.Type;
 
 import java.util.Set;
 
@@ -85,8 +86,7 @@
           .put(STRING_DICT_UNARY, Discriminator.STRING_DICT_UNARY)
           .build();
 
-  static final ImmutableSet<Type<?>> NODEP_TYPES =
-      ImmutableSet.of(NODEP_LABEL, NODEP_LABEL_LIST);
+  static final ImmutableSet<Type<?>> NODEP_TYPES = ImmutableSet.of(NODEP_LABEL, NODEP_LABEL_LIST);
 
   static final ImmutableSetMultimap<Discriminator, Type<?>> INVERSE_TYPE_MAP =
       TYPE_MAP.asMultimap().inverse();
@@ -94,7 +94,8 @@
   /**
    * Returns the appropriate Attribute.Discriminator value from an internal attribute type.
    */
-  public static Discriminator getDiscriminatorFromType(Type<?> type) {
+  public static Discriminator getDiscriminatorFromType(
+      Type<?> type) {
     Preconditions.checkArgument(TYPE_MAP.containsKey(type), type);
     return TYPE_MAP.get(type);
   }
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RawAttributeMapper.java b/src/main/java/com/google/devtools/build/lib/packages/RawAttributeMapper.java
index 141e0e4..f7a660c 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/RawAttributeMapper.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/RawAttributeMapper.java
@@ -16,7 +16,10 @@
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
+import com.google.devtools.build.lib.packages.BuildType.Selector;
+import com.google.devtools.build.lib.packages.BuildType.SelectorList;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 
 import java.util.Collection;
 import java.util.List;
@@ -66,7 +69,7 @@
     }
 
     ImmutableSet.Builder<T> mergedValues = ImmutableSet.builder();
-    for (Type.Selector<List<T>> selector : getSelectorList(attributeName, type).getSelectors()) {
+    for (Selector<List<T>> selector : getSelectorList(attributeName, type).getSelectors()) {
       for (List<T> configuredList : selector.getEntries().values()) {
         mergedValues.addAll(configuredList);
       }
@@ -79,12 +82,12 @@
    * keys. Else returns an empty list.
    */
   public <T> Iterable<Label> getConfigurabilityKeys(String attributeName, Type<T> type) {
-    Type.SelectorList<T> selectorList = getSelectorList(attributeName, type);
+    SelectorList<T> selectorList = getSelectorList(attributeName, type);
     if (selectorList == null) {
       return ImmutableList.of();
     }
     ImmutableList.Builder<Label> builder = ImmutableList.builder();
-    for (Type.Selector<T> selector : selectorList.getSelectors()) {
+    for (Selector<T> selector : selectorList.getSelectors()) {
       builder.addAll(selector.getEntries().keySet());
     }
     return builder.build();
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Rule.java b/src/main/java/com/google/devtools/build/lib/packages/Rule.java
index 4802169..3a310da 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/Rule.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/Rule.java
@@ -37,6 +37,7 @@
 import com.google.devtools.build.lib.syntax.FuncallExpression;
 import com.google.devtools.build.lib.syntax.GlobList;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.BinaryPredicate;
 
 import java.util.Collection;
@@ -76,7 +77,7 @@
     @Override
     public boolean apply(Rule rule, Attribute attribute) {
       // isHostConfiguration() is only defined for labels and label lists.
-      if (attribute.getType() != Type.LABEL && attribute.getType() != Type.LABEL_LIST) {
+      if (attribute.getType() != BuildType.LABEL && attribute.getType() != BuildType.LABEL_LIST) {
         return true;
       }
 
@@ -101,8 +102,8 @@
       new BinaryPredicate<Rule, Attribute>() {
     @Override
     public boolean apply(Rule rule, Attribute attribute) {
-      return attribute.getType() != Type.NODEP_LABEL
-          && attribute.getType() != Type.NODEP_LABEL_LIST;
+      return attribute.getType() != BuildType.NODEP_LABEL
+          && attribute.getType() != BuildType.NODEP_LABEL_LIST;
     }
   };
 
@@ -502,13 +503,13 @@
     for (Attribute attribute : ruleClass.getAttributes()) {
       String name = attribute.getName();
       Type<?> type = attribute.getType();
-      if (type == Type.OUTPUT) {
-        Label outputLabel = nonConfigurableAttributes.get(name, Type.OUTPUT);
+      if (type == BuildType.OUTPUT) {
+        Label outputLabel = nonConfigurableAttributes.get(name, BuildType.OUTPUT);
         if (outputLabel != null) {
           addLabelOutput(attribute, outputLabel, eventHandler);
         }
-      } else if (type == Type.OUTPUT_LIST) {
-        for (Label label : nonConfigurableAttributes.get(name, Type.OUTPUT_LIST)) {
+      } else if (type == BuildType.OUTPUT_LIST) {
+        for (Label label : nonConfigurableAttributes.get(name, BuildType.OUTPUT_LIST)) {
           addLabelOutput(attribute, label, eventHandler);
         }
       }
@@ -613,9 +614,9 @@
   @Override
   @SuppressWarnings("unchecked")
   public Set<DistributionType> getDistributions() {
-    if (isAttrDefined("distribs", Type.DISTRIBUTIONS)
+    if (isAttrDefined("distribs", BuildType.DISTRIBUTIONS)
         && isAttributeValueExplicitlySpecified("distribs")) {
-      return NonconfigurableAttributeMapper.of(this).get("distribs", Type.DISTRIBUTIONS);
+      return NonconfigurableAttributeMapper.of(this).get("distribs", BuildType.DISTRIBUTIONS);
     } else {
       return getPackage().getDefaultDistribs();
     }
@@ -623,9 +624,9 @@
 
   @Override
   public License getLicense() {
-    if (isAttrDefined("licenses", Type.LICENSE)
+    if (isAttrDefined("licenses", BuildType.LICENSE)
         && isAttributeValueExplicitlySpecified("licenses")) {
-      return NonconfigurableAttributeMapper.of(this).get("licenses", Type.LICENSE);
+      return NonconfigurableAttributeMapper.of(this).get("licenses", BuildType.LICENSE);
     } else {
       return getPackage().getDefaultLicense();
     }
@@ -636,9 +637,9 @@
    * null if it is not specified.
    */
   public License getToolOutputLicense(AttributeMap attributes) {
-    if (isAttrDefined("output_licenses", Type.LICENSE)
+    if (isAttrDefined("output_licenses", BuildType.LICENSE)
         && attributes.isAttributeValueExplicitlySpecified("output_licenses")) {
-      return attributes.get("output_licenses", Type.LICENSE);
+      return attributes.get("output_licenses", BuildType.LICENSE);
     } else {
       return null;
     }
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 34ff1af..2f44210 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
@@ -16,8 +16,8 @@
 
 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.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Function;
@@ -33,6 +33,7 @@
 import com.google.devtools.build.lib.events.EventHandler;
 import com.google.devtools.build.lib.events.Location;
 import com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition;
+import com.google.devtools.build.lib.packages.BuildType.SelectorList;
 import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
 import com.google.devtools.build.lib.syntax.Argument;
 import com.google.devtools.build.lib.syntax.BaseFunction;
@@ -42,6 +43,7 @@
 import com.google.devtools.build.lib.syntax.GlobList;
 import com.google.devtools.build.lib.syntax.Label;
 import com.google.devtools.build.lib.syntax.Runtime;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.StringUtil;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
@@ -1488,7 +1490,7 @@
 
     Set<Label> configLabels = new LinkedHashSet<>();
     for (Attribute attr : rule.getAttributes()) {
-      Type.SelectorList<?> selectors = attributes.getSelectorList(attr.getName(), attr.getType());
+      SelectorList<?> selectors = attributes.getSelectorList(attr.getName(), attr.getType());
       if (selectors != null) {
         configLabels.addAll(selectors.getKeyLabels());
       }
@@ -1519,7 +1521,7 @@
    */
   private static void checkForDuplicateLabels(Rule rule, EventHandler eventHandler) {
     for (Attribute attribute : rule.getAttributes()) {
-      if (attribute.getType() == Type.LABEL_LIST) {
+      if (attribute.getType() == BuildType.LABEL_LIST) {
         checkForDuplicateLabels(rule, attribute, eventHandler);
       }
     }
@@ -1640,9 +1642,9 @@
     Object converted;
     try {
       String what = "attribute '" + attrName + "' in '" + name + "' rule";
-      converted = attr.getType().selectableConvert(attrVal, what, rule.getLabel());
+      converted = BuildType.selectableConvert(attr.getType(), attrVal, what, rule.getLabel());
 
-      if ((converted instanceof Type.SelectorList<?>) && !attr.isConfigurable()) {
+      if ((converted instanceof SelectorList<?>) && !attr.isConfigurable()) {
         rule.reportError(rule.getLabel() + ": attribute \"" + attr.getName()
             + "\" is not configurable", eventHandler);
         return null;
diff --git a/src/main/java/com/google/devtools/build/lib/packages/SkylarkNativeModule.java b/src/main/java/com/google/devtools/build/lib/packages/SkylarkNativeModule.java
index ab82394..f303cb1 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/SkylarkNativeModule.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/SkylarkNativeModule.java
@@ -14,7 +14,6 @@
 
 package com.google.devtools.build.lib.packages;
 
-import com.google.devtools.build.lib.packages.Type.ConversionException;
 import com.google.devtools.build.lib.syntax.BuiltinFunction;
 import com.google.devtools.build.lib.syntax.Environment;
 import com.google.devtools.build.lib.syntax.EvalException;
@@ -26,6 +25,7 @@
 import com.google.devtools.build.lib.syntax.SkylarkSignature;
 import com.google.devtools.build.lib.syntax.SkylarkSignature.Param;
 import com.google.devtools.build.lib.syntax.SkylarkSignatureProcessor;
+import com.google.devtools.build.lib.syntax.Type.ConversionException;
 
 /**
  * A class for the Skylark native module.
diff --git a/src/main/java/com/google/devtools/build/lib/packages/TargetUtils.java b/src/main/java/com/google/devtools/build/lib/packages/TargetUtils.java
index 6dd3dac..8c1942a 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/TargetUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/TargetUtils.java
@@ -17,6 +17,7 @@
 import com.google.common.collect.ImmutableMap;
 import com.google.devtools.build.lib.events.Location;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 
 import java.util.HashMap;
 import java.util.Map;
diff --git a/src/main/java/com/google/devtools/build/lib/packages/TestSize.java b/src/main/java/com/google/devtools/build/lib/packages/TestSize.java
index 425a343..f660422 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/TestSize.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/TestSize.java
@@ -14,6 +14,7 @@
 
 package com.google.devtools.build.lib.packages;
 
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.common.options.OptionsParsingException;
 
 import java.util.Set;
diff --git a/src/main/java/com/google/devtools/build/lib/packages/TestTargetUtils.java b/src/main/java/com/google/devtools/build/lib/packages/TestTargetUtils.java
index fb5cf5d..7461e86 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/TestTargetUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/TestTargetUtils.java
@@ -22,6 +22,7 @@
 import com.google.devtools.build.lib.events.EventHandler;
 import com.google.devtools.build.lib.pkgcache.TargetProvider;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.Pair;
 
 import java.util.ArrayList;
@@ -281,7 +282,7 @@
       // Note that testsAndSuites can contain input file targets; the test_suite rule does not
       // restrict the set of targets that can appear in tests or suites.
       testsAndSuites.addAll(getPrerequisites(testSuite, "tests"));
-      if (testSuite.getRuleClassObject().hasAttr("suites", Type.LABEL_LIST)) {
+      if (testSuite.getRuleClassObject().hasAttr("suites", BuildType.LABEL_LIST)) {
         testsAndSuites.addAll(getPrerequisites(testSuite, "suites"));
       }
 
@@ -334,7 +335,7 @@
         // TODO(bazel-team): This serializes package loading in some cases. We might want to make
         // this multi-threaded.
         for (Label label :
-            NonconfigurableAttributeMapper.of(testSuite).get(attrName, Type.LABEL_LIST)) {
+            NonconfigurableAttributeMapper.of(testSuite).get(attrName, BuildType.LABEL_LIST)) {
           targets.add(targetProvider.getTarget(eventHandler, label));
         }
         return targets;
diff --git a/src/main/java/com/google/devtools/build/lib/packages/TestTimeout.java b/src/main/java/com/google/devtools/build/lib/packages/TestTimeout.java
index f605b80..ee53e94 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/TestTimeout.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/TestTimeout.java
@@ -16,6 +16,7 @@
 
 import com.google.common.base.Splitter;
 import com.google.common.collect.Maps;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.common.options.Converter;
 import com.google.devtools.common.options.OptionsParsingException;
 
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Type.java b/src/main/java/com/google/devtools/build/lib/packages/Type.java
deleted file mode 100644
index 0f95601..0000000
--- a/src/main/java/com/google/devtools/build/lib/packages/Type.java
+++ /dev/null
@@ -1,1163 +0,0 @@
-// Copyright 2014 Google Inc. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//    http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.lib.packages;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Joiner;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
-import com.google.devtools.build.lib.packages.License.DistributionType;
-import com.google.devtools.build.lib.packages.License.LicenseParsingException;
-import com.google.devtools.build.lib.syntax.EvalException;
-import com.google.devtools.build.lib.syntax.EvalUtils;
-import com.google.devtools.build.lib.syntax.FilesetEntry;
-import com.google.devtools.build.lib.syntax.GlobList;
-import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Printer;
-import com.google.devtools.build.lib.syntax.SelectorValue;
-import com.google.devtools.build.lib.syntax.SkylarkList;
-import com.google.devtools.build.lib.util.LoggingUtil;
-import com.google.devtools.build.lib.util.StringCanonicalizer;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.logging.Level;
-
-import javax.annotation.Nullable;
-
-/**
- *  <p>Root of Type symbol hierarchy for values in the build language.</p>
- *
- *  <p>Type symbols are primarily used for their <code>convert</code> method,
- *  which is a kind of cast operator enabling conversion from untyped (Object)
- *  references to values in the build language, to typed references.</p>
- *
- *  <p>For example, this code type-converts a value <code>x</code> returned by
- *  the evaluator, to a list of strings:</p>
- *
- *  <pre>
- *  Object x = expr.eval(env);
- *  List&lt;String&gt; s = Type.STRING_LIST.convert(x);
- *  </pre>
- */
-public abstract class Type<T> {
-
-  private Type() {}
-
-  /**
-   * Converts untyped Object x resulting from the evaluation of an expression in the build language,
-   * into a typed object of type T.
-   *
-   * <p>x must be *directly* convertible to this type. This therefore disqualifies "selector
-   * expressions" of the form "{ config1: 'value1_of_orig_type', config2: 'value2_of_orig_type; }"
-   * (which support configurable attributes). To handle those expressions, see
-   * {@link #selectableConvert}.
-   *
-   * @param x the build-interpreter value to convert.
-   * @param what a string description of what x is for; should be included in
-   *    any exception thrown.  Grammatically, must describe a syntactic
-   *    construct, e.g. "attribute 'srcs' of rule foo".
-   * @param context the label of the current BUILD rule; must be non-null if resolution of
-   *    package-relative label strings is required
-   * @throws ConversionException if there was a problem performing the type conversion
-   */
-  public abstract T convert(Object x, String what, @Nullable Object context)
-      throws ConversionException;
-  // TODO(bazel-team): Check external calls (e.g. in PackageFactory), verify they always want
-  // this over selectableConvert.
-
-  /**
-   * Equivalent to {@link #convert(Object, String, Object)} where the label is {@code null}.
-   * Useful for converting values to types that do not involve the type {@code LABEL}
-   * and hence do not require the label of the current package.
-   */
-  public final T convert(Object x, String what) throws ConversionException {
-    return convert(x, what, null);
-  }
-
-  /**
-   * Like {@link #convert(Object, String, Object)}, but converts skylark {@code None}
-   * to given {@code defaultValue}.
-   */
-  @Nullable public final T convertOptional(Object x,
-      String what, @Nullable Object context, T defaultValue)
-      throws ConversionException {
-    if (EvalUtils.isNullOrNone(x)) {
-      return defaultValue;
-    }
-    return convert(x, what, context);
-  }
-
-  /**
-   * Like {@link #convert(Object, String, Object)}, but converts skylark {@code None}
-   * to java {@code null}.
-   */
-  @Nullable public final T convertOptional(Object x, String what, @Nullable Object context)
-      throws ConversionException {
-    return convertOptional(x, what, context, null);
-  }
-
-  /**
-   * Like {@link #convert(Object, String)}, but converts skylark {@code NONE} to java {@code null}.
-   */
-  @Nullable public final T convertOptional(Object x, String what) throws ConversionException {
-    return convertOptional(x, what, null);
-  }
-
-  /**
-   * Variation of {@link #convert} that supports selector expressions for configurable attributes
-   * (i.e. "{ config1: 'value1_of_orig_type', config2: 'value2_of_orig_type; }"). If x is a
-   * selector expression, returns a {@link Selector} instance that contains key-mapped entries
-   * of the native type. Else, returns the native type directly.
-   *
-   * <p>The caller is responsible for casting the returned value appropriately.
-   */
-  public Object selectableConvert(Object x, String what, @Nullable Label context)
-      throws ConversionException {
-    if (x instanceof com.google.devtools.build.lib.syntax.SelectorList) {
-      return new SelectorList<T>(
-          ((com.google.devtools.build.lib.syntax.SelectorList) x).getElements(),
-          what, context, this);
-    } else {
-      return convert(x, what, context);
-    }
-  }
-
-  public abstract T cast(Object value);
-
-  @Override
-  public abstract String toString();
-
-  /**
-   * Returns the default value for this type; may return null iff no default is defined for this
-   * type.
-   */
-  public abstract T getDefaultValue();
-
-  /**
-   * Flatten the an instance of the type if the type is a composite one.
-   *
-   * <p>This is used to support reliable label visitation in
-   * {@link AbstractAttributeMapper#visitLabels}. To preserve that reliability, every
-   * type should faithfully define its own instance of this method. In other words,
-   * be careful about defining default instances in base types that get auto-inherited
-   * by their children. Keep all definitions as explicit as possible.
-   */
-  public abstract Collection<? extends Object> flatten(Object value);
-
-  /**
-   * {@link #flatten} return value for types that don't contain labels.
-   */
-  private static final Collection<Object> NOT_COMPOSITE_TYPE = ImmutableList.of();
-
-  /**
-   * Implementation of concatenation for this type (e.g. "val1 + val2"). Returns null to
-   * designate concatenation isn't supported.
-   */
-  public T concat(Iterable<T> elements) {
-    return null;
-  }
-
-  /**
-   * Converts an initialized Type object into a tag set representation.
-   * This operation is only valid for certain sub-Types which are guaranteed
-   * to be properly initialized.
-   *
-   * @param value the actual value
-   * @throws UnsupportedOperationException if the concrete type does not support
-   * tag conversion or if a convertible type has no initialized value.
-   */
-  public Set<String> toTagSet(Object value, String name) {
-    String msg = "Attribute " + name + " does not support tag conversion.";
-    throw new UnsupportedOperationException(msg);
-  }
-
-  /**
-   * The type of an integer.
-   */
-  public static final Type<Integer> INTEGER = new IntegerType();
-
-  /**
-   * The type of a string.
-   */
-  public static final Type<String> STRING = new StringType();
-
-  /**
-   * The type of a boolean.
-   */
-  public static final Type<Boolean> BOOLEAN = new BooleanType();
-
-  /**
-   * The type of a TriState with values: true (x>0), false (x==0), auto (x<0).
-   */
-  public static final Type<TriState> TRISTATE = new TriStateType();
-
-  /**
-   * The type of a label. Labels are not actually a first-class datatype in
-   * the build language, but they are so frequently used in the definitions of
-   * attributes that it's worth treating them specially (and providing support
-   * for resolution of relative-labels in the <code>convert()</code> method).
-   */
-  public static final Type<Label> LABEL = new LabelType();
-
-  /**
-   * This is a label type that does not cause dependencies. It is needed because
-   * certain rules want to verify the type of a target referenced by one of their attributes, but
-   * if there was a dependency edge there, it would be a circular dependency.
-   */
-  public static final Type<Label> NODEP_LABEL = new LabelType();
-
-  /**
-   * The type of a license. Like Label, licenses aren't first-class, but
-   * they're important enough to justify early syntax error detection.
-   */
-  public static final Type<License> LICENSE = new LicenseType();
-
-  /**
-   * The type of a single distribution.  Only used internally, as a type
-   * symbol, not a converter.
-   */
-  public static final Type<DistributionType> DISTRIBUTION = new Type<DistributionType>() {
-    @Override
-    public DistributionType cast(Object value) {
-      return (DistributionType) value;
-    }
-
-    @Override
-    public DistributionType convert(Object x, String what, Object context) {
-      throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public DistributionType getDefaultValue() {
-      return null;
-    }
-
-    @Override
-    public Collection<Object> flatten(Object value) {
-      return NOT_COMPOSITE_TYPE;
-    }
-
-    @Override
-    public String toString() {
-      return "distribution";
-    }
-  };
-
-  /**
-   * The type of a set of distributions. Distributions are not a first-class type,
-   * but they do warrant early syntax checking.
-   */
-  public static final Type<Set<DistributionType>> DISTRIBUTIONS = new Distributions();
-
-  /**
-   *  The type of an output file, treated as a {@link #LABEL}.
-   */
-  public static final Type<Label> OUTPUT = new OutputType();
-
-  /**
-   * The type of a FilesetEntry attribute inside a Fileset.
-   */
-  public static final Type<FilesetEntry> FILESET_ENTRY = new FilesetEntryType();
-
-  /**
-   *  The type of a list of not-yet-typed objects.
-   */
-  public static final ObjectListType OBJECT_LIST = new ObjectListType();
-
-  /**
-   *  The type of a list of {@linkplain #STRING strings}.
-   */
-  public static final ListType<String> STRING_LIST = ListType.create(STRING);
-
-  /**
-   *  The type of a list of {@linkplain #INTEGER strings}.
-   */
-  public static final ListType<Integer> INTEGER_LIST = ListType.create(INTEGER);
-
-  /**
-   *  The type of a dictionary of {@linkplain #STRING strings}.
-   */
-  public static final DictType<String, String> STRING_DICT = DictType.create(STRING, STRING);
-
-  /**
-   *  The type of a list of {@linkplain #OUTPUT outputs}.
-   */
-  public static final ListType<Label> OUTPUT_LIST = ListType.create(OUTPUT);
-
-  /**
-   *  The type of a list of {@linkplain #LABEL labels}.
-   */
-  public static final ListType<Label> LABEL_LIST = ListType.create(LABEL);
-
-  /**
-   *  The type of a list of {@linkplain #NODEP_LABEL labels} that do not cause
-   *  dependencies.
-   */
-  public static final ListType<Label> NODEP_LABEL_LIST = ListType.create(NODEP_LABEL);
-
-  /**
-   * The type of a dictionary of {@linkplain #STRING_LIST label lists}.
-   */
-  public static final DictType<String, List<String>> STRING_LIST_DICT =
-      DictType.create(STRING, STRING_LIST);
-
-  /**
-   * The type of a dictionary of {@linkplain #STRING strings}, where each entry
-   * maps to a single string value.
-   */
-  public static final DictType<String, String> STRING_DICT_UNARY = DictType.create(STRING, STRING);
-
-  /**
-   * The type of a dictionary of {@linkplain #LABEL_LIST label lists}.
-   */
-  public static final DictType<String, List<Label>> LABEL_LIST_DICT =
-      DictType.create(STRING, LABEL_LIST);
-
-  /**
-   * The type of a dictionary of {@linkplain #LABEL labels}.
-   */
-  public static final DictType<String, Label> LABEL_DICT_UNARY = DictType.create(STRING, LABEL);
-
-  /**
-   * The type of a list of {@linkplain #FILESET_ENTRY FilesetEntries}.
-   */
-  public static final ListType<FilesetEntry> FILESET_ENTRY_LIST = ListType.create(FILESET_ENTRY);
-
-  /**
-   *  For ListType objects, returns the type of the elements of the list; for
-   *  all other types, returns null.  (This non-obvious implementation strategy
-   *  is necessitated by the wildcard capture rules of the Java type system,
-   *  which disallow conversion from Type{List{ELEM}} to Type{List{?}}.)
-   */
-  public Type<?> getListElementType() {
-    return null;
-  }
-
-  /**
-   *  ConversionException is thrown when a type-conversion fails; it contains
-   *  an explanatory error message.
-   */
-  public static class ConversionException extends EvalException {
-    private static String message(Type<?> type, Object value, String what) {
-      StringBuilder builder = new StringBuilder();
-      builder.append("expected value of type '").append(type).append("'");
-      if (what != null) {
-        builder.append(" for ").append(what);
-      }
-      builder.append(", but got ");
-      Printer.write(builder, value);
-      builder.append(" (").append(EvalUtils.getDataTypeName(value)).append(")");
-      return builder.toString();
-    }
-
-    private ConversionException(Type<?> type, Object value, String what) {
-      super(null, message(type, value, what));
-    }
-
-    private ConversionException(String message) {
-      super(null, message);
-    }
-  }
-
-  /********************************************************************
-   *                                                                  *
-   *                            Subclasses                            *
-   *                                                                  *
-   ********************************************************************/
-
-  private static class ObjectType extends Type<Object> {
-    @Override
-    public Object cast(Object value) {
-      return value;
-    }
-
-    @Override
-    public String getDefaultValue() {
-      throw new UnsupportedOperationException(
-          "ObjectType has no default value");
-    }
-
-    @Override
-    public Collection<Object> flatten(Object value) {
-      return NOT_COMPOSITE_TYPE;
-    }
-
-    @Override
-    public String toString() {
-      return "object";
-    }
-
-    @Override
-    public Object convert(Object x, String what, Object context) {
-      return x;
-    }
-  }
-
-  private static class IntegerType extends Type<Integer> {
-    @Override
-    public Integer cast(Object value) {
-      return (Integer) value;
-    }
-
-    @Override
-    public Integer getDefaultValue() {
-      return 0;
-    }
-
-    @Override
-    public Collection<Object> flatten(Object value) {
-      return NOT_COMPOSITE_TYPE;
-    }
-
-    @Override
-    public String toString() {
-      return "int";
-    }
-
-    @Override
-    public Integer convert(Object x, String what, Object context)
-        throws ConversionException {
-      if (!(x instanceof Integer)) {
-        throw new ConversionException(this, x, what);
-      }
-      return (Integer) x;
-    }
-
-    @Override
-    public Integer concat(Iterable<Integer> elements) {
-      int ans = 0;
-      for (Integer elem : elements) {
-        ans += elem;
-      }
-      return Integer.valueOf(ans);
-    }
-  }
-
-  private static class BooleanType extends Type<Boolean> {
-    @Override
-    public Boolean cast(Object value) {
-      return (Boolean) value;
-    }
-
-    @Override
-    public Boolean getDefaultValue() {
-      return false;
-    }
-
-    @Override
-    public Collection<Object> flatten(Object value) {
-      return NOT_COMPOSITE_TYPE;
-    }
-
-    @Override
-    public String toString() {
-      return "boolean";
-    }
-
-    // Conversion to boolean must also tolerate integers of 0 and 1 only.
-    @Override
-    public Boolean convert(Object x, String what, Object context)
-        throws ConversionException {
-      if (x instanceof Boolean) {
-        return (Boolean) x;
-      }
-      Integer xAsInteger = INTEGER.convert(x, what, context);
-      if (xAsInteger == 0) {
-        return false;
-      } else if (xAsInteger == 1) {
-        return true;
-      }
-      throw new ConversionException("boolean is not one of [0, 1]");
-    }
-
-    /**
-     * Booleans attributes are converted to tags based on their names.
-     */
-    @Override
-    public Set<String> toTagSet(Object value, String name) {
-      if (value == null) {
-        String msg = "Illegal tag conversion from null on Attribute " + name  + ".";
-        throw new IllegalStateException(msg);
-      }
-      String tag = (Boolean) value ? name : "no" + name;
-      return ImmutableSet.of(tag);
-    }
-  }
-
-  /**
-   * Tristate values are needed for cases where user intent matters.
-   *
-   * <p>Tristate values are not explicitly interchangeable with booleans and are
-   * handled explicitly as TriStates. Prefer Booleans with default values where
-   * possible.  The main use case for TriState values is when a Rule's behavior
-   * must interact with a Flag value in a complicated way.</p>
-   */
-  private static class TriStateType extends Type<TriState> {
-    @Override
-    public TriState cast(Object value) {
-      return (TriState) value;
-    }
-
-    @Override
-    public TriState getDefaultValue() {
-      return TriState.AUTO;
-    }
-
-    @Override
-    public Collection<Object> flatten(Object value) {
-      return NOT_COMPOSITE_TYPE;
-    }
-
-    @Override
-    public String toString() {
-      return "tristate";
-    }
-
-    // Like BooleanType, this must handle integers as well.
-    @Override
-    public TriState convert(Object x, String what, Object context)
-        throws ConversionException {
-      if (x instanceof TriState) {
-        return (TriState) x;
-      }
-      if (x instanceof Boolean) {
-        return ((Boolean) x) ? TriState.YES : TriState.NO;
-      }
-      Integer xAsInteger = INTEGER.convert(x, what, context);
-      if (xAsInteger == -1) {
-        return TriState.AUTO;
-      } else if (xAsInteger == 1) {
-        return TriState.YES;
-      } else if (xAsInteger == 0) {
-        return TriState.NO;
-      }
-      throw new ConversionException(this, x, "TriState values is not one of [-1, 0, 1]");
-    }
-  }
-
-  private static class StringType extends Type<String> {
-    @Override
-    public String cast(Object value) {
-      return (String) value;
-    }
-
-    @Override
-    public String getDefaultValue() {
-      return "";
-    }
-
-    @Override
-    public Collection<Object> flatten(Object value) {
-      return NOT_COMPOSITE_TYPE;
-    }
-
-    @Override
-    public String toString() {
-      return "string";
-    }
-
-    @Override
-    public String convert(Object x, String what, Object context)
-        throws ConversionException {
-      if (!(x instanceof String)) {
-        throw new ConversionException(this, x, what);
-      }
-      return StringCanonicalizer.intern((String) x);
-    }
-
-    @Override
-    public String concat(Iterable<String> elements) {
-      return Joiner.on("").join(elements);
-    }
-
-    /**
-     * A String is representable as a set containing its value.
-     */
-    @Override
-    public Set<String> toTagSet(Object value, String name) {
-      if (value == null) {
-        String msg = "Illegal tag conversion from null on Attribute " + name + ".";
-        throw new IllegalStateException(msg);
-      }
-      return ImmutableSet.of((String) value);
-    }
-  }
-
-  private static class FilesetEntryType extends Type<FilesetEntry> {
-    @Override
-    public FilesetEntry cast(Object value) {
-      return (FilesetEntry) value;
-    }
-
-    @Override
-    public FilesetEntry convert(Object x, String what, Object context)
-        throws ConversionException {
-      if (!(x instanceof FilesetEntry)) {
-        throw new ConversionException(this, x, what);
-      }
-      return (FilesetEntry) x;
-    }
-
-    @Override
-    public String toString() {
-      return "FilesetEntry";
-    }
-
-    @Override
-    public FilesetEntry getDefaultValue() {
-      return null;
-    }
-
-    @Override
-    public Collection<? extends Object> flatten(Object value) {
-      return cast(value).getLabels();
-    }
-  }
-
-  private static class LabelType extends Type<Label> {
-    @Override
-    public Label cast(Object value) {
-      return (Label) value;
-    }
-
-    @Override
-    public Label getDefaultValue() {
-      return null; // Labels have no default value
-    }
-
-    @Override
-    public Collection<Label> flatten(Object value) {
-      return ImmutableList.of(cast(value));
-    }
-
-    @Override
-    public String toString() {
-      return "label";
-    }
-
-    @Override
-    public Label convert(Object x, String what, Object context)
-        throws ConversionException {
-      if (x instanceof Label) {
-        return (Label) x;
-      }
-      try {
-        return ((Label) context).getRelative(STRING.convert(x, what, context));
-      } catch (LabelSyntaxException e) {
-        throw new ConversionException("invalid label '" + x + "' in "
-            + what + ": " + e.getMessage());
-      }
-    }
-  }
-
-  /**
-   * Like Label, LicenseType is a derived type, which is declared specially
-   * in order to allow syntax validation. It represents the licenses, as
-   * described in {@ref License}.
-   */
-  public static class LicenseType extends Type<License> {
-    @Override
-    public License cast(Object value) {
-      return (License) value;
-    }
-
-    @Override
-    public License convert(Object x, String what, Object context) throws ConversionException {
-      try {
-        List<String> licenseStrings = STRING_LIST.convert(x, what);
-        return License.parseLicense(licenseStrings);
-      } catch (LicenseParsingException e) {
-        throw new ConversionException(e.getMessage());
-      }
-    }
-
-    @Override
-    public License getDefaultValue() {
-      return License.NO_LICENSE;
-    }
-
-    @Override
-    public Collection<Object> flatten(Object value) {
-      return NOT_COMPOSITE_TYPE;
-    }
-
-    @Override
-    public String toString() {
-      return "license";
-    }
-  }
-
-  /**
-   * Like Label, Distributions is a derived type, which is declared specially
-   * in order to allow syntax validation. It represents the declared distributions
-   * of a target, as described in {@ref License}.
-   */
-  private static class Distributions extends Type<Set<DistributionType>> {
-    @SuppressWarnings("unchecked")
-    @Override
-    public Set<DistributionType> cast(Object value) {
-      return (Set<DistributionType>) value;
-    }
-
-    @Override
-    public Set<DistributionType> convert(Object x, String what, Object context)
-        throws ConversionException {
-      try {
-        List<String> distribStrings = STRING_LIST.convert(x, what);
-        return License.parseDistributions(distribStrings);
-      } catch (LicenseParsingException e) {
-        throw new ConversionException(e.getMessage());
-      }
-    }
-
-    @Override
-    public Set<DistributionType> getDefaultValue() {
-      return Collections.emptySet();
-    }
-
-    @Override
-    public Collection<Object> flatten(Object what) {
-      return NOT_COMPOSITE_TYPE;
-    }
-
-    @Override
-    public String toString() {
-      return "distributions";
-    }
-
-    @Override
-    public Type<DistributionType> getListElementType() {
-      return DISTRIBUTION;
-    }
-  }
-
-  private static class OutputType extends Type<Label> {
-    @Override
-    public Label cast(Object value) {
-      return (Label) value;
-    }
-
-    @Override
-    public Label getDefaultValue() {
-      return null;
-    }
-
-    @Override
-    public Collection<Label> flatten(Object value) {
-      return ImmutableList.of(cast(value));
-    }
-
-    @Override
-    public String toString() {
-      return "output";
-    }
-
-    @Override
-    public Label convert(Object x, String what, Object context)
-        throws ConversionException {
-
-      String value;
-      try {
-        value = STRING.convert(x, what, context);
-      } catch (ConversionException e) {
-        throw new ConversionException(this, x, what);
-      }
-      try {
-        // Enforce value is relative to the context.
-        Label currentRule = (Label) context;
-        Label result = currentRule.getRelative(value);
-        if (!result.getPackageIdentifier().equals(currentRule.getPackageIdentifier())) {
-          throw new ConversionException("label '" + value + "' is not in the current package");
-        }
-        return result;
-      } catch (LabelSyntaxException e) {
-        throw new ConversionException(
-            "illegal output file name '" + value + "' in rule " + context + ": "
-            + e.getMessage());
-      }
-    }
-  }
-
-  /**
-   * A type to support dictionary attributes.
-   */
-  public static class DictType<KeyT, ValueT> extends Type<Map<KeyT, ValueT>> {
-
-    private final Type<KeyT> keyType;
-    private final Type<ValueT> valueType;
-
-    private final Map<KeyT, ValueT> empty = ImmutableMap.of();
-
-    private static <KEY, VALUE> DictType<KEY, VALUE> create(
-        Type<KEY> keyType, Type<VALUE> valueType) {
-      return new DictType<>(keyType, valueType);
-    }
-
-    private DictType(Type<KeyT> keyType, Type<ValueT> valueType) {
-      this.keyType = keyType;
-      this.valueType = valueType;
-    }
-
-    public Type<KeyT> getKeyType() {
-      return keyType;
-    }
-
-    public Type<ValueT> getValueType() {
-      return valueType;
-    }
-
-    @SuppressWarnings("unchecked")
-    @Override
-    public Map<KeyT, ValueT> cast(Object value) {
-      return (Map<KeyT, ValueT>) value;
-    }
-
-    @Override
-    public String toString() {
-      return "dict(" + keyType + ", " + valueType + ")";
-    }
-
-    @Override
-    public Map<KeyT, ValueT> convert(Object x, String what, Object context)
-        throws ConversionException {
-      if (!(x instanceof Map<?, ?>)) {
-        throw new ConversionException(String.format(
-            "Expected a map for dictionary but got a %s", x.getClass().getName())); 
-      }
-      // Order the keys so the return value will be independent of insertion order.
-      Map<KeyT, ValueT> result = new TreeMap<>();
-      Map<?, ?> o = (Map<?, ?>) x;
-      for (Entry<?, ?> elem : o.entrySet()) {
-        result.put(
-            keyType.convert(elem.getKey(), "dict key element", context),
-            valueType.convert(elem.getValue(), "dict value element", context));
-      }
-      return ImmutableMap.copyOf(result);
-    }
-
-    @Override
-    public Map<KeyT, ValueT> getDefaultValue() {
-      return empty;
-    }
-
-    @Override
-    public Collection<Object> flatten(Object value) {
-      ImmutableList.Builder<Object> result = ImmutableList.builder();
-      for (Map.Entry<KeyT, ValueT> entry : cast(value).entrySet()) {
-        result.addAll(keyType.flatten(entry.getKey()));
-        result.addAll(valueType.flatten(entry.getValue()));
-      }
-      return result.build();
-    }
-  }
-
-  /** A type for lists of a given element type */
-  public static class ListType<ElemT> extends Type<List<ElemT>> {
-
-    private final Type<ElemT> elemType;
-
-    private final List<ElemT> empty = ImmutableList.of();
-
-    private static <ELEM> ListType<ELEM> create(Type<ELEM> elemType) {
-      return new ListType<>(elemType);
-    }
-
-    private ListType(Type<ElemT> elemType) {
-      this.elemType = elemType;
-    }
-
-    @SuppressWarnings("unchecked")
-    @Override
-    public List<ElemT> cast(Object value) {
-      return (List<ElemT>) value;
-    }
-
-    @Override
-    public Type<ElemT> getListElementType() {
-      return elemType;
-    }
-
-    @Override
-    public List<ElemT> getDefaultValue() {
-      return empty;
-    }
-
-    @Override
-    public Collection<Object> flatten(Object value) {
-      ImmutableList.Builder<Object> labels = ImmutableList.builder();
-      for (ElemT entry : cast(value)) {
-        labels.addAll(elemType.flatten(entry));
-      }
-      return labels.build();
-    }
-
-    @Override
-    public String toString() {
-      return "list(" + elemType + ")";
-    }
-
-    @Override
-    public List<ElemT> convert(Object x, String what, Object context)
-        throws ConversionException {
-      if (!(x instanceof Iterable<?>)) {
-        throw new ConversionException(this, x, what);
-      }
-      int index = 0;
-      Iterable<?> iterable = (Iterable<?>) x;
-      List<ElemT> result = Lists.newArrayListWithExpectedSize(Iterables.size(iterable));
-      for (Object elem : iterable) {
-        ElemT converted = elemType.convert(elem, "element " + index + " of " + what, context);
-        if (converted != null) {
-          result.add(converted);
-        } else {
-          // shouldn't happen but it does, rarely
-          String message = "Converting a list with a null element: "
-              + "element " + index + " of " + what + " in " + context;
-          LoggingUtil.logToRemote(Level.WARNING, message,
-              new ConversionException(message));
-        }
-        ++index;
-      }
-      if (x instanceof GlobList<?>) {
-        return new GlobList<>(((GlobList<?>) x).getCriteria(), result);
-      } else {
-        return result;
-      }
-    }
-
-    @Override
-    public List<ElemT> concat(Iterable<List<ElemT>> elements) {
-      ImmutableList.Builder<ElemT> builder = ImmutableList.builder();
-      for (List<ElemT> list : elements) {
-        builder.addAll(list);
-      }
-      return builder.build();
-    }
-
-    /**
-     * A list is representable as a tag set as the contents of itself expressed
-     * as Strings. So a {@code List<String>} is effectively converted to a {@code Set<String>}.
-     */
-    @Override
-    public Set<String> toTagSet(Object items, String name) {
-      if (items == null) {
-        String msg = "Illegal tag conversion from null on Attribute" + name + ".";
-        throw new IllegalStateException(msg);
-      }
-      Set<String> tags = new LinkedHashSet<>();
-      @SuppressWarnings("unchecked")
-      List<ElemT> itemsAsListofElem = (List<ElemT>) items;
-      for (ElemT element : itemsAsListofElem) {
-        tags.add(element.toString());
-      }
-      return tags;
-    }
-  }
-
-  /** Type for lists of arbitrary objects */
-  public static class ObjectListType extends ListType<Object> {
-
-    private static final Type<Object> elemType = new ObjectType();
-
-    private ObjectListType() {
-      super(elemType);
-    }
-
-    @Override
-    @SuppressWarnings("unchecked")
-    public List<Object> convert(Object x, String what, Object context)
-        throws ConversionException {
-      if (x instanceof SkylarkList) {
-        return ((SkylarkList) x).getList();
-      } else if (x instanceof List) {
-        return (List<Object>) x;
-      } else if (x instanceof Iterable) {
-        return ImmutableList.copyOf((Iterable<?>) x);
-      } else {
-        throw new ConversionException(this, x, what);
-      }
-    }
-  }
-
-  /**
-   * The type of a general list.
-   */
-  public static final ListType<Object> LIST = new ListType<>(new ObjectType());
-
-  /**
-   * Returns whether the specified type is a label type or not.
-   */
-  public static boolean isLabelType(Type<?> type) {
-    return type == LABEL || type == LABEL_LIST || type == LABEL_DICT_UNARY
-        || type == NODEP_LABEL || type == NODEP_LABEL_LIST
-        || type == LABEL_LIST_DICT || type == FILESET_ENTRY_LIST;
-  }
-
-  /**
-   * Special Type that represents a selector expression for configurable attributes. Holds a
-   * mapping of {@code <Label, T>} entries, where keys are configurability patterns and values are
-   * objects of the attribute's native Type.
-   */
-  public static final class Selector<T> {
-    private final Type<T> originalType;
-    private final Map<Label, T> map;
-    private final Label defaultConditionLabel;
-    private final boolean hasDefaultCondition;
-
-    /**
-     * Value to use when none of an attribute's selection criteria match.
-     */
-    @VisibleForTesting
-    public static final String DEFAULT_CONDITION_KEY = "//conditions:default";
-
-    @VisibleForTesting
-    Selector(Object x, String what, @Nullable Label context, Type<T> originalType)
-        throws ConversionException {
-      Preconditions.checkState(x instanceof Map<?, ?>);
-
-      try {
-        defaultConditionLabel = Label.parseAbsolute(DEFAULT_CONDITION_KEY);
-      } catch (LabelSyntaxException e) {
-        throw new IllegalStateException(DEFAULT_CONDITION_KEY + " is not a valid label");
-      }
-
-      this.originalType = originalType;
-      Map<Label, T> result = Maps.newLinkedHashMap();
-      boolean foundDefaultCondition = false;
-      for (Entry<?, ?> entry : ((Map<?, ?>) x).entrySet()) {
-        Label key = LABEL.convert(entry.getKey(), what, context);
-        if (key.equals(defaultConditionLabel)) {
-          foundDefaultCondition = true;
-        }
-        result.put(key, originalType.convert(entry.getValue(), what, context));
-      }
-      map = ImmutableMap.copyOf(result);
-      hasDefaultCondition = foundDefaultCondition;
-    }
-
-    /**
-     * Returns the selector's (configurability pattern --gt; matching values) map.
-     */
-    public Map<Label, T> getEntries() {
-      return map;
-    }
-
-    /**
-     * Returns the value to use when none of the attribute's selection keys match.
-     */
-    public T getDefault() {
-      return map.get(defaultConditionLabel);
-    }
-
-    /**
-     * Returns whether or not this selector has a default condition.
-     */
-    public boolean hasDefault() {
-      return hasDefaultCondition;
-    }
-
-    /**
-     * Returns the native Type for this attribute (i.e. what this would be if it wasn't a
-     * selector expression).
-     */
-    public Type<T> getOriginalType() {
-      return originalType;
-    }
-
-    /**
-     * Returns true for labels that are "reserved selector key words" and not intended to
-     * map to actual targets.
-     */
-    public static boolean isReservedLabel(Label label) {
-      return label.toString().equals(DEFAULT_CONDITION_KEY);
-    }
-  }
-
-  /**
-   * Holds an ordered collection of {@link Selector}s. This is used to support
-   * {@code attr = rawValue + select(...) + select(...) + ..."} syntax. For consistency's
-   * sake, raw values are stored as selects with only a default condition.
-   */
-  public static final class SelectorList<T> {
-    private final Type<T> originalType;
-    private final List<Selector<T>> elements;
-
-    @VisibleForTesting
-    SelectorList(List<Object> x, String what, @Nullable Label context,
-        Type<T> originalType) throws ConversionException {
-      if (x.size() > 1 && originalType.concat(ImmutableList.<T>of()) == null) {
-        throw new ConversionException(
-            String.format("type '%s' doesn't support select concatenation", originalType));
-      }
-
-      ImmutableList.Builder<Selector<T>> builder = ImmutableList.builder();
-      for (Object elem : x) {
-        if (elem instanceof SelectorValue) {
-          builder.add(new Selector<T>(((SelectorValue) elem).getDictionary(), what,
-              context, originalType));
-        } else {
-          T directValue = originalType.convert(elem, what, context);
-          builder.add(new Selector<T>(ImmutableMap.of(Selector.DEFAULT_CONDITION_KEY, directValue),
-              what, context, originalType));
-        }
-      }
-      this.originalType = originalType;
-      this.elements = builder.build();
-    }
-
-    /**
-     * Returns a syntactically order-preserved list of all values and selectors for this attribute.
-     */
-    public List<Selector<T>> getSelectors() {
-      return elements;
-    }
-
-    /**
-     * Returns the native Type for this attribute (i.e. what this would be if it wasn't a
-     * selector list).
-     */
-    public Type<T> getOriginalType() {
-      return originalType;
-    }
-
-    /**
-     * Returns the labels of all configurability keys across all selects in this expression.
-     */
-    public Set<Label> getKeyLabels() {
-      ImmutableSet.Builder<Label> keys = ImmutableSet.builder();
-      for (Selector<T> selector : getSelectors()) {
-         for (Label label : selector.getEntries().keySet()) {
-           if (!Selector.isReservedLabel(label)) {
-             keys.add(label);
-           }
-         }
-      }
-      return keys.build();
-    }
-  }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/pkgcache/CompileOneDependencyTransformer.java b/src/main/java/com/google/devtools/build/lib/pkgcache/CompileOneDependencyTransformer.java
index 0d22e68..47d7215 100644
--- a/src/main/java/com/google/devtools/build/lib/pkgcache/CompileOneDependencyTransformer.java
+++ b/src/main/java/com/google/devtools/build/lib/pkgcache/CompileOneDependencyTransformer.java
@@ -18,6 +18,7 @@
 import com.google.devtools.build.lib.cmdline.TargetParsingException;
 import com.google.devtools.build.lib.events.EventHandler;
 import com.google.devtools.build.lib.packages.Attribute;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.FileTarget;
 import com.google.devtools.build.lib.packages.NoSuchThingException;
 import com.google.devtools.build.lib.packages.Package;
@@ -25,7 +26,6 @@
 import com.google.devtools.build.lib.packages.Rule;
 import com.google.devtools.build.lib.packages.RuleClass;
 import com.google.devtools.build.lib.packages.Target;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.syntax.Label;
 import com.google.devtools.build.lib.util.BinaryPredicate;
 
@@ -160,16 +160,16 @@
     for (Rule rule : orderedRuleList) {
       RawAttributeMapper attributes = RawAttributeMapper.of(rule);
       // We don't know which path to follow for configurable attributes, so skip them.
-      if (attributes.isConfigurable("deps", Type.LABEL_LIST)
-          || attributes.isConfigurable("srcs", Type.LABEL_LIST)) {
+      if (attributes.isConfigurable("deps", BuildType.LABEL_LIST)
+          || attributes.isConfigurable("srcs", BuildType.LABEL_LIST)) {
         continue;
       }
       RuleClass ruleClass = rule.getRuleClassObject();
-      if (ruleClass.hasAttr("deps", Type.LABEL_LIST) &&
-          ruleClass.hasAttr("srcs", Type.LABEL_LIST)) {
-        for (Label dep : attributes.get("deps", Type.LABEL_LIST)) {
+      if (ruleClass.hasAttr("deps", BuildType.LABEL_LIST) &&
+          ruleClass.hasAttr("srcs", BuildType.LABEL_LIST)) {
+        for (Label dep : attributes.get("deps", BuildType.LABEL_LIST)) {
           if (dep.equals(result.getLabel())) {
-            if (!attributes.get("srcs", Type.LABEL_LIST).isEmpty()) {
+            if (!attributes.get("srcs", BuildType.LABEL_LIST).isEmpty()) {
               return rule;
             }
           }
diff --git a/src/main/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunner.java b/src/main/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunner.java
index 8006899..dd9b3c8 100644
--- a/src/main/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunner.java
+++ b/src/main/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunner.java
@@ -36,8 +36,8 @@
 import com.google.devtools.build.lib.packages.TestSize;
 import com.google.devtools.build.lib.packages.TestTargetUtils;
 import com.google.devtools.build.lib.packages.TestTimeout;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.vfs.Path;
 import com.google.devtools.build.lib.vfs.PathFragment;
 import com.google.devtools.common.options.Converters.CommaSeparatedOptionListConverter;
diff --git a/src/main/java/com/google/devtools/build/lib/pkgcache/SrcTargetUtil.java b/src/main/java/com/google/devtools/build/lib/pkgcache/SrcTargetUtil.java
index f2d2cb8..06af89f 100644
--- a/src/main/java/com/google/devtools/build/lib/pkgcache/SrcTargetUtil.java
+++ b/src/main/java/com/google/devtools/build/lib/pkgcache/SrcTargetUtil.java
@@ -20,13 +20,13 @@
 import com.google.devtools.build.lib.concurrent.ThreadSafety;
 import com.google.devtools.build.lib.events.EventHandler;
 import com.google.devtools.build.lib.packages.AttributeMap;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.FileTarget;
 import com.google.devtools.build.lib.packages.NoSuchPackageException;
 import com.google.devtools.build.lib.packages.NoSuchTargetException;
 import com.google.devtools.build.lib.packages.RawAttributeMapper;
 import com.google.devtools.build.lib.packages.Rule;
 import com.google.devtools.build.lib.packages.Target;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.syntax.Label;
 
 import java.util.ArrayList;
@@ -123,10 +123,10 @@
       if (rule.isConfigurableAttribute(attrName)) {
         // We don't know which path to follow for configurable attributes. So skip them.
         continue;
-      } else if (rule.isAttrDefined(attrName, Type.LABEL_LIST)) {
-        srcLabels.addAll(attributeMap.get(attrName, Type.LABEL_LIST));
-      } else if (rule.isAttrDefined(attrName, Type.LABEL)) {
-        Label srcLabel = attributeMap.get(attrName, Type.LABEL);
+      } else if (rule.isAttrDefined(attrName, BuildType.LABEL_LIST)) {
+        srcLabels.addAll(attributeMap.get(attrName, BuildType.LABEL_LIST));
+      } else if (rule.isAttrDefined(attrName, BuildType.LABEL)) {
+        Label srcLabel = attributeMap.get(attrName, BuildType.LABEL);
         if (srcLabel != null) {
           srcLabels.add(srcLabel);
         }
diff --git a/src/main/java/com/google/devtools/build/lib/query2/BlazeTargetAccessor.java b/src/main/java/com/google/devtools/build/lib/query2/BlazeTargetAccessor.java
index abba93c..1a7517d 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/BlazeTargetAccessor.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/BlazeTargetAccessor.java
@@ -13,14 +13,15 @@
 // limitations under the License.
 package com.google.devtools.build.lib.query2;
 
-import static com.google.devtools.build.lib.packages.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.TRISTATE;
+import static com.google.devtools.build.lib.packages.BuildType.TRISTATE;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.devtools.build.lib.packages.AggregatingAttributeMapper;
 import com.google.devtools.build.lib.packages.Attribute;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.ConstantRuleVisibility;
 import com.google.devtools.build.lib.packages.NonconfigurableAttributeMapper;
 import com.google.devtools.build.lib.packages.PackageGroup;
@@ -30,13 +31,13 @@
 import com.google.devtools.build.lib.packages.RuleVisibility;
 import com.google.devtools.build.lib.packages.Target;
 import com.google.devtools.build.lib.packages.TargetUtils;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.query2.engine.QueryEnvironment.TargetAccessor;
 import com.google.devtools.build.lib.query2.engine.QueryEnvironment.TargetNotFoundException;
 import com.google.devtools.build.lib.query2.engine.QueryException;
 import com.google.devtools.build.lib.query2.engine.QueryExpression;
 import com.google.devtools.build.lib.query2.engine.QueryVisibility;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -125,7 +126,7 @@
         if (attributeType == BOOLEAN) {
           values.add(Type.BOOLEAN.cast(attrValue) ? "1" : "0");
         } else if (attributeType == TRISTATE) {
-            switch (Type.TRISTATE.cast(attrValue)) {
+            switch (BuildType.TRISTATE.cast(attrValue)) {
               case AUTO :
                 values.add("-1");
                 break;
diff --git a/src/main/java/com/google/devtools/build/lib/query2/LabelVisitor.java b/src/main/java/com/google/devtools/build/lib/query2/LabelVisitor.java
index ffc1fef..acdc7d3 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/LabelVisitor.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/LabelVisitor.java
@@ -29,6 +29,7 @@
 import com.google.devtools.build.lib.packages.AspectDefinition;
 import com.google.devtools.build.lib.packages.Attribute;
 import com.google.devtools.build.lib.packages.AttributeMap;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.InputFile;
 import com.google.devtools.build.lib.packages.NoSuchThingException;
 import com.google.devtools.build.lib.packages.OutputFile;
@@ -37,7 +38,6 @@
 import com.google.devtools.build.lib.packages.Rule;
 import com.google.devtools.build.lib.packages.RuleClass;
 import com.google.devtools.build.lib.packages.Target;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.pkgcache.PackageProvider;
 import com.google.devtools.build.lib.pkgcache.TargetEdgeObserver;
 import com.google.devtools.build.lib.syntax.Label;
@@ -368,7 +368,7 @@
       Attribute attribute = null;
       if (target instanceof Rule) {
         RuleClass ruleClass = ((Rule) target).getRuleClassObject();
-        if (!ruleClass.hasAttr("visibility", Type.NODEP_LABEL_LIST)) {
+        if (!ruleClass.hasAttr("visibility", BuildType.NODEP_LABEL_LIST)) {
           return;
         }
         attribute = ruleClass.getAttributeByName("visibility");
diff --git a/src/main/java/com/google/devtools/build/lib/query2/output/ProtoOutputFormatter.java b/src/main/java/com/google/devtools/build/lib/query2/output/ProtoOutputFormatter.java
index a013b9d..0068e67 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/output/ProtoOutputFormatter.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/output/ProtoOutputFormatter.java
@@ -149,7 +149,7 @@
             Build.Attribute.newBuilder()
                 .setName(RULE_IMPLEMENTATION_HASH_ATTR_NAME)
                 .setType(ProtoUtils.getDiscriminatorFromType(
-                    com.google.devtools.build.lib.packages.Type.STRING))
+                    com.google.devtools.build.lib.syntax.Type.STRING))
                 .setStringValue(env.getTransitiveContentHashCode()));
       }
 
diff --git a/src/main/java/com/google/devtools/build/lib/query2/output/XmlOutputFormatter.java b/src/main/java/com/google/devtools/build/lib/query2/output/XmlOutputFormatter.java
index 60e085e..efb2adf 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/output/XmlOutputFormatter.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/output/XmlOutputFormatter.java
@@ -16,7 +16,9 @@
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 import com.google.devtools.build.lib.packages.Attribute;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.EnvironmentGroup;
+import com.google.devtools.build.lib.packages.FilesetEntry;
 import com.google.devtools.build.lib.packages.InputFile;
 import com.google.devtools.build.lib.packages.License;
 import com.google.devtools.build.lib.packages.OutputFile;
@@ -26,7 +28,6 @@
 import com.google.devtools.build.lib.query2.FakeSubincludeTarget;
 import com.google.devtools.build.lib.query2.output.AspectResolver.BuildFileDependencyMode;
 import com.google.devtools.build.lib.query2.output.OutputFormatter.AbstractUnorderedFormatter;
-import com.google.devtools.build.lib.syntax.FilesetEntry;
 import com.google.devtools.build.lib.syntax.Label;
 import com.google.devtools.build.lib.util.BinaryPredicate;
 import com.google.devtools.build.lib.util.Pair;
@@ -157,12 +158,12 @@
       elem = doc.createElement("package-group");
       elem.setAttribute("name", packageGroup.getName());
       Element includes = createValueElement(doc,
-          com.google.devtools.build.lib.packages.Type.LABEL_LIST,
+          BuildType.LABEL_LIST,
           packageGroup.getIncludes());
       includes.setAttribute("name", "includes");
       elem.appendChild(includes);
       Element packages = createValueElement(doc,
-          com.google.devtools.build.lib.packages.Type.STRING_LIST,
+          com.google.devtools.build.lib.syntax.Type.STRING_LIST,
           packageGroup.getContainedPackages());
       packages.setAttribute("name", "packages");
       elem.appendChild(packages);
@@ -188,12 +189,12 @@
       elem = doc.createElement("environment-group");
       elem.setAttribute("name", envGroup.getName());
       Element environments = createValueElement(doc,
-          com.google.devtools.build.lib.packages.Type.LABEL_LIST,
+          BuildType.LABEL_LIST,
           envGroup.getEnvironments());
       environments.setAttribute("name", "environments");
       elem.appendChild(environments);
       Element defaults = createValueElement(doc,
-          com.google.devtools.build.lib.packages.Type.LABEL_LIST,
+          BuildType.LABEL_LIST,
           envGroup.getDefaults());
       defaults.setAttribute("name", "defaults");
       elem.appendChild(defaults);
@@ -276,17 +277,17 @@
    * OutputFormatter.Type.)
    */
   private static Element createValueElement(Document doc,
-      com.google.devtools.build.lib.packages.Type<?> type, Iterable<Object> values) {
+      com.google.devtools.build.lib.syntax.Type<?> type, Iterable<Object> values) {
     // "Import static" with method scope:
-    com.google.devtools.build.lib.packages.Type<?>
-        FILESET_ENTRY = com.google.devtools.build.lib.packages.Type.FILESET_ENTRY,
-        LABEL_LIST    = com.google.devtools.build.lib.packages.Type.LABEL_LIST,
-        LICENSE       = com.google.devtools.build.lib.packages.Type.LICENSE,
-        STRING_LIST   = com.google.devtools.build.lib.packages.Type.STRING_LIST;
+    com.google.devtools.build.lib.syntax.Type<?>
+        FILESET_ENTRY = BuildType.FILESET_ENTRY,
+        LABEL_LIST    = BuildType.LABEL_LIST,
+        LICENSE       = BuildType.LICENSE,
+        STRING_LIST   = com.google.devtools.build.lib.syntax.Type.STRING_LIST;
 
     final Element elem;
     final boolean hasMultipleValues = Iterables.size(values) > 1;
-    com.google.devtools.build.lib.packages.Type<?> elemType = type.getListElementType();
+    com.google.devtools.build.lib.syntax.Type<?> elemType = type.getListElementType();
     if (elemType != null) { // it's a list (includes "distribs")
       elem = doc.createElement("list");
       for (Object value : values) {
@@ -294,11 +295,11 @@
           elem.appendChild(createValueElement(doc, elemType, elemValue));
         }
       }
-    } else if (type instanceof com.google.devtools.build.lib.packages.Type.DictType) {
+    } else if (type instanceof com.google.devtools.build.lib.syntax.Type.DictType) {
       Set<Object> visitedValues = new HashSet<>();
       elem = doc.createElement("dict");
-      com.google.devtools.build.lib.packages.Type.DictType<?, ?> dictType =
-          (com.google.devtools.build.lib.packages.Type.DictType<?, ?>) type;
+      com.google.devtools.build.lib.syntax.Type.DictType<?, ?> dictType =
+          (com.google.devtools.build.lib.syntax.Type.DictType<?, ?>) type;
       for (Object value : values) {
         for (Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) {
           if (visitedValues.add(entry.getKey())) {
@@ -362,7 +363,7 @@
   }
 
   private static Element createValueElement(Document doc,
-        com.google.devtools.build.lib.packages.Type<?> type, Object value) {
+        com.google.devtools.build.lib.syntax.Type<?> type, Object value) {
     return createValueElement(doc, type, ImmutableList.of(value));
   }
 
diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java
index e6d8f3c..c01bd34 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java
@@ -21,8 +21,7 @@
 import com.google.devtools.build.lib.packages.Attribute.AllowedValueSet;
 import com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition;
 import com.google.devtools.build.lib.packages.Attribute.SkylarkLateBound;
-import com.google.devtools.build.lib.packages.Type;
-import com.google.devtools.build.lib.packages.Type.ConversionException;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.syntax.BuiltinFunction;
 import com.google.devtools.build.lib.syntax.Environment;
 import com.google.devtools.build.lib.syntax.EvalException;
@@ -36,6 +35,8 @@
 import com.google.devtools.build.lib.syntax.SkylarkSignature;
 import com.google.devtools.build.lib.syntax.SkylarkSignature.Param;
 import com.google.devtools.build.lib.syntax.SkylarkSignatureProcessor;
+import com.google.devtools.build.lib.syntax.Type;
+import com.google.devtools.build.lib.syntax.Type.ConversionException;
 import com.google.devtools.build.lib.syntax.UserDefinedFunction;
 import com.google.devtools.build.lib.util.FileTypeSet;
 
@@ -155,7 +156,7 @@
         throw new EvalException(
             ast.getLocation(), "allow_files should be a boolean or a filetype object.");
       }
-    } else if (type.equals(Type.LABEL) || type.equals(Type.LABEL_LIST)) {
+    } else if (type.equals(BuildType.LABEL) || type.equals(BuildType.LABEL_LIST)) {
       builder.allowedFileTypes(FileTypeSet.NO_FILE);
     }
 
@@ -376,7 +377,7 @@
                   singleFile,
                   CONFIGURATION_ARG,
                   cfg),
-              Type.LABEL,
+              BuildType.LABEL,
               ast,
               env);
         }
@@ -556,7 +557,7 @@
                   nonEmpty,
                   CONFIGURATION_ARG,
                   cfg),
-              Type.LABEL_LIST,
+              BuildType.LABEL_LIST,
               ast,
               env);
         }
@@ -619,7 +620,7 @@
           env.checkLoadingPhase("attr.output", ast.getLocation());
           return createAttribute(
               EvalUtils.optionMap(DEFAULT_ARG, defaultO, MANDATORY_ARG, mandatory),
-              Type.OUTPUT,
+              BuildType.OUTPUT,
               ast,
               env);
         }
@@ -661,7 +662,7 @@
           return createAttribute(
               EvalUtils.optionMap(
                   DEFAULT_ARG, defaultList, MANDATORY_ARG, mandatory, NON_EMPTY_ARG, nonEmpty),
-              Type.OUTPUT_LIST,
+              BuildType.OUTPUT_LIST,
               ast,
               env);
         }
@@ -726,7 +727,7 @@
           env.checkLoadingPhase("attr.license", ast.getLocation());
           return createAttribute(
               EvalUtils.optionMap(DEFAULT_ARG, defaultO, MANDATORY_ARG, mandatory),
-              Type.LICENSE,
+              BuildType.LICENSE,
               ast,
               env);
         }
diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java
index 066ac52..e2d6e5b 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java
@@ -18,15 +18,15 @@
 import static com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition.HOST;
 import static com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition.NONE;
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.INTEGER;
-import static com.google.devtools.build.lib.packages.Type.LABEL;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.LICENSE;
-import static com.google.devtools.build.lib.packages.Type.STRING;
-import static com.google.devtools.build.lib.packages.Type.STRING_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LICENSE;
 import static com.google.devtools.build.lib.syntax.SkylarkType.castList;
 import static com.google.devtools.build.lib.syntax.SkylarkType.castMap;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
+import static com.google.devtools.build.lib.syntax.Type.INTEGER;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.STRING_LIST;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.cache.CacheBuilder;
@@ -57,8 +57,6 @@
 import com.google.devtools.build.lib.packages.RuleFactory.InvalidRuleException;
 import com.google.devtools.build.lib.packages.TargetUtils;
 import com.google.devtools.build.lib.packages.TestSize;
-import com.google.devtools.build.lib.packages.Type;
-import com.google.devtools.build.lib.packages.Type.ConversionException;
 import com.google.devtools.build.lib.syntax.BaseFunction;
 import com.google.devtools.build.lib.syntax.BuiltinFunction;
 import com.google.devtools.build.lib.syntax.ClassObject;
@@ -77,6 +75,8 @@
 import com.google.devtools.build.lib.syntax.SkylarkSignature;
 import com.google.devtools.build.lib.syntax.SkylarkSignature.Param;
 import com.google.devtools.build.lib.syntax.SkylarkSignatureProcessor;
+import com.google.devtools.build.lib.syntax.Type;
+import com.google.devtools.build.lib.syntax.Type.ConversionException;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
 import java.util.HashMap;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleConfiguredTargetBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleConfiguredTargetBuilder.java
index f9fd58f..a56e6f3 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleConfiguredTargetBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleConfiguredTargetBuilder.java
@@ -30,7 +30,6 @@
 import com.google.devtools.build.lib.events.Location;
 import com.google.devtools.build.lib.packages.Rule;
 import com.google.devtools.build.lib.packages.TargetUtils;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.syntax.BaseFunction;
 import com.google.devtools.build.lib.syntax.ClassObject;
 import com.google.devtools.build.lib.syntax.ClassObject.SkylarkClassObject;
@@ -42,6 +41,7 @@
 import com.google.devtools.build.lib.syntax.Runtime;
 import com.google.devtools.build.lib.syntax.SkylarkNestedSet;
 import com.google.devtools.build.lib.syntax.SkylarkType;
+import com.google.devtools.build.lib.syntax.Type;
 
 /**
  * A helper class to build Rule Configured Targets via runtime loaded rule implementations
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 bc2bbe4..7e0f8fd 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
@@ -36,11 +36,11 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.packages.Attribute;
 import com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.ImplicitOutputsFunction;
 import com.google.devtools.build.lib.packages.ImplicitOutputsFunction.SkylarkImplicitOutputsFunction;
 import com.google.devtools.build.lib.packages.OutputFile;
 import com.google.devtools.build.lib.packages.RawAttributeMapper;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.shell.ShellUtils;
 import com.google.devtools.build.lib.shell.ShellUtils.TokenizationException;
 import com.google.devtools.build.lib.syntax.ClassObject.SkylarkClassObject;
@@ -52,6 +52,7 @@
 import com.google.devtools.build.lib.syntax.SkylarkList.MutableList;
 import com.google.devtools.build.lib.syntax.SkylarkModule;
 import com.google.devtools.build.lib.syntax.SkylarkType;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
 import java.util.ArrayList;
@@ -148,7 +149,7 @@
     for (Attribute a : ruleContext.getRule().getAttributes()) {
       String attrName = a.getName();
       Type<?> type = a.getType();
-      if (type != Type.OUTPUT && type != Type.OUTPUT_LIST) {
+      if (type != BuildType.OUTPUT && type != BuildType.OUTPUT_LIST) {
         continue;
       }
       ImmutableList.Builder<Artifact> artifactsBuilder = ImmutableList.builder();
@@ -159,13 +160,13 @@
       }
       ImmutableList<Artifact> artifacts = artifactsBuilder.build();
 
-      if (type == Type.OUTPUT) {
+      if (type == BuildType.OUTPUT) {
         if (artifacts.size() == 1) {
           addOutput(outputsBuilder, attrName, Iterables.getOnlyElement(artifacts));
         } else {
           addOutput(outputsBuilder, attrName, Runtime.NONE);
         }
-      } else if (type == Type.OUTPUT_LIST) {
+      } else if (type == BuildType.OUTPUT_LIST) {
         addOutput(outputsBuilder, attrName, new MutableList(artifacts));
       } else {
         throw new IllegalArgumentException(
@@ -187,7 +188,7 @@
     for (Attribute a : ruleContext.getRule().getAttributes()) {
       Type<?> type = a.getType();
       Object val = ruleContext.attributes().get(a.getName(), type);
-      if (type != Type.LABEL && type != Type.LABEL_LIST) {
+      if (type != BuildType.LABEL && type != BuildType.LABEL_LIST) {
         attrBuilder.put(a.getPublicName(), val == null ? Runtime.NONE
             // Attribute values should be type safe
             : SkylarkType.convertToSkylark(val, null));
@@ -217,7 +218,7 @@
       }
       filesBuilder.put(skyname, ruleContext.getPrerequisiteArtifacts(a.getName(), mode).list());
       List<?> allPrereq = ruleContext.getPrerequisites(a.getName(), mode);
-      if (type == Type.LABEL) {
+      if (type == BuildType.LABEL) {
         Object prereq = ruleContext.getPrerequisite(a.getName(), mode);
         if (prereq == null) {
           prereq = Runtime.NONE;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleImplementationFunctions.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleImplementationFunctions.java
index b6417d4..ddce8c6 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleImplementationFunctions.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleImplementationFunctions.java
@@ -44,7 +44,6 @@
 import com.google.devtools.build.lib.packages.Attribute;
 import com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition;
 import com.google.devtools.build.lib.packages.AttributeMap;
-import com.google.devtools.build.lib.packages.Type.ConversionException;
 import com.google.devtools.build.lib.syntax.BuiltinFunction;
 import com.google.devtools.build.lib.syntax.Environment;
 import com.google.devtools.build.lib.syntax.EvalException;
@@ -56,6 +55,7 @@
 import com.google.devtools.build.lib.syntax.SkylarkSignature;
 import com.google.devtools.build.lib.syntax.SkylarkSignature.Param;
 import com.google.devtools.build.lib.syntax.SkylarkSignatureProcessor;
+import com.google.devtools.build.lib.syntax.Type.ConversionException;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
 import java.nio.charset.StandardCharsets;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java
index dc47023..73e3b12 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java
@@ -46,8 +46,8 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.collect.nestedset.Order;
 import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.TriState;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
 import com.google.devtools.build.lib.rules.android.AndroidResourcesProvider.ResourceContainer;
 import com.google.devtools.build.lib.rules.android.AndroidRuleClasses.MultidexMode;
@@ -58,6 +58,7 @@
 import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider;
 import com.google.devtools.build.lib.rules.java.JavaSemantics;
 import com.google.devtools.build.lib.rules.java.JavaTargetAttributes;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
 import java.util.ArrayList;
@@ -1249,7 +1250,8 @@
    * Returns whether to use NativeDepsHelper to link native dependencies.
    */
   public static boolean shouldLinkNativeDeps(RuleContext ruleContext) {
-    TriState attributeValue = ruleContext.attributes().get("legacy_native_support", Type.TRISTATE);
+    TriState attributeValue = ruleContext.attributes().get(
+        "legacy_native_support", BuildType.TRISTATE);
     if (attributeValue == TriState.AUTO) {
       return !ruleContext.getFragment(AndroidConfiguration.class).getLegacyNativeSupport();
     } else {
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinaryOnlyRule.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinaryOnlyRule.java
index 5277988..8286681 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinaryOnlyRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinaryOnlyRule.java
@@ -15,9 +15,9 @@
 
 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.Type.LABEL;
-import static com.google.devtools.build.lib.packages.Type.STRING;
-import static com.google.devtools.build.lib.packages.Type.STRING_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.STRING_LIST;
 
 import com.google.devtools.build.lib.analysis.RuleDefinition;
 import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java
index b65014d..95d4721 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java
@@ -38,8 +38,8 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.collect.nestedset.Order;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.ImplicitOutputsFunction.SafeImplicitOutputsFunction;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.android.AndroidResourcesProvider.ResourceContainer;
 import com.google.devtools.build.lib.rules.android.AndroidRuleClasses.MultidexMode;
 import com.google.devtools.build.lib.rules.cpp.CcLinkParams;
@@ -62,6 +62,7 @@
 import com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider;
 import com.google.devtools.build.lib.rules.java.JavaTargetAttributes;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.vfs.FileSystemUtils;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
@@ -222,8 +223,8 @@
     }
 
     for (String attribute : attributes) {
-      if (!ruleContext.attributes().has(attribute, Type.LABEL)
-          && !ruleContext.attributes().has(attribute, Type.LABEL_LIST)) {
+      if (!ruleContext.attributes().has(attribute, BuildType.LABEL)
+          && !ruleContext.attributes().has(attribute, BuildType.LABEL_LIST)) {
         continue;
       }
 
@@ -592,14 +593,14 @@
   }
 
   public static ImmutableList<Artifact> getIdlParcelables(RuleContext ruleContext) {
-    return ruleContext.getRule().isAttrDefined("idl_parcelables", Type.LABEL_LIST)
+    return ruleContext.getRule().isAttrDefined("idl_parcelables", BuildType.LABEL_LIST)
         ? ImmutableList.copyOf(ruleContext.getPrerequisiteArtifacts(
             "idl_parcelables", Mode.TARGET).filter(AndroidRuleClasses.ANDROID_IDL).list())
         : ImmutableList.<Artifact>of();
   }
 
   public static Collection<Artifact> getIdlSrcs(RuleContext ruleContext) {
-    if (!ruleContext.getRule().isAttrDefined("idl_srcs", Type.LABEL_LIST)) {
+    if (!ruleContext.getRule().isAttrDefined("idl_srcs", BuildType.LABEL_LIST)) {
       return ImmutableList.of();
     }
     checkIdlSrcsSamePackage(ruleContext);
@@ -657,7 +658,7 @@
   }
 
   public static AndroidResourcesProvider getAndroidResources(RuleContext ruleContext) {
-    if (!ruleContext.attributes().has("resources", Type.LABEL)) {
+    if (!ruleContext.attributes().has("resources", BuildType.LABEL)) {
       return null;
     }
 
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java
index f6d113e..dad9563 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java
@@ -28,7 +28,6 @@
 import com.google.devtools.build.lib.analysis.config.CompilationMode;
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
 import com.google.devtools.build.lib.rules.android.AndroidLibraryAarProvider.Aar;
 import com.google.devtools.build.lib.rules.android.AndroidResourcesProvider.ResourceContainer;
@@ -41,6 +40,7 @@
 import com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider;
 import com.google.devtools.build.lib.rules.java.JavaTargetAttributes;
 import com.google.devtools.build.lib.rules.java.JavaUtil;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
 import java.util.Collection;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibraryBaseRule.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibraryBaseRule.java
index 551798e..ab706a6 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibraryBaseRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibraryBaseRule.java
@@ -15,10 +15,10 @@
 
 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.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.LABEL;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.STRING;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
 
 import com.google.devtools.build.lib.Constants;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidNeverlinkAspect.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidNeverlinkAspect.java
index 3179e45..102df67 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidNeverlinkAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidNeverlinkAspect.java
@@ -22,7 +22,7 @@
 import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
 import com.google.devtools.build.lib.packages.AspectDefinition;
 import com.google.devtools.build.lib.packages.AspectParameters;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.rules.java.JavaCommon;
 import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider;
 import com.google.devtools.build.lib.rules.java.JavaRuntimeJarProvider;
@@ -58,7 +58,7 @@
     // jars in -libraryjars than is required. The alternative would be somehow getting
     // JavaCommon.getDependencies() here, which would be fugly.
     for (String attribute : ATTRIBUTES) {
-      if (!ruleContext.getRule().getRuleClassObject().hasAttr(attribute, Type.LABEL_LIST)) {
+      if (!ruleContext.getRule().getRuleClassObject().hasAttr(attribute, BuildType.LABEL_LIST)) {
         continue;
       }
 
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceContainerBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceContainerBuilder.java
index 89a5496..dd1094f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceContainerBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourceContainerBuilder.java
@@ -16,9 +16,9 @@
 import com.google.common.base.Preconditions;
 import com.google.devtools.build.lib.actions.Artifact;
 import com.google.devtools.build.lib.analysis.RuleContext;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.android.AndroidResourcesProvider.ResourceContainer;
 import com.google.devtools.build.lib.rules.java.JavaUtil;
+import com.google.devtools.build.lib.syntax.Type;
 
 import javax.annotation.Nullable;
 
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java
index 7928a1b..077fbd9 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java
@@ -15,14 +15,14 @@
 
 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;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.TRISTATE;
 import static com.google.devtools.build.lib.packages.ImplicitOutputsFunction.fromTemplates;
-import static com.google.devtools.build.lib.packages.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.INTEGER;
-import static com.google.devtools.build.lib.packages.Type.LABEL;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.STRING;
-import static com.google.devtools.build.lib.packages.Type.STRING_LIST;
-import static com.google.devtools.build.lib.packages.Type.TRISTATE;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
+import static com.google.devtools.build.lib.syntax.Type.INTEGER;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.STRING_LIST;
 import static com.google.devtools.build.lib.util.FileTypeSet.ANY_FILE;
 
 import com.google.common.collect.ImmutableList;
@@ -43,12 +43,12 @@
 import com.google.devtools.build.lib.packages.RuleClass.Builder;
 import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
 import com.google.devtools.build.lib.packages.TriState;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.android.AndroidConfiguration.ConfigurationDistinguisher;
 import com.google.devtools.build.lib.rules.cpp.CppOptions;
 import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider;
 import com.google.devtools.build.lib.rules.java.JavaSemantics;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.FileType;
 
 import java.util.ArrayList;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java b/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java
index 0e79f5f..7fade53 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java
@@ -29,12 +29,12 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.collect.nestedset.Order;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.android.AndroidResourcesProvider.ResourceContainer;
 import com.google.devtools.build.lib.rules.android.AndroidResourcesProvider.ResourceType;
 import com.google.devtools.build.lib.rules.android.LocalResourceContainer.Builder.InvalidAssetPath;
 import com.google.devtools.build.lib.rules.android.LocalResourceContainer.Builder.InvalidResourcePath;
 import com.google.devtools.build.lib.rules.java.JavaUtil;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
 import java.util.List;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
index 663532b..9c6e8a5 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
@@ -37,7 +37,6 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.collect.nestedset.Order;
 import com.google.devtools.build.lib.packages.TargetUtils;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
 import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration;
 import com.google.devtools.build.lib.rules.cpp.CppConfiguration.DynamicMode;
@@ -46,6 +45,7 @@
 import com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink;
 import com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.FileType;
 import com.google.devtools.build.lib.util.FileTypeSet;
 import com.google.devtools.build.lib.util.OsUtils;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java
index 8028abd..9106fc8 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java
@@ -28,7 +28,7 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.collect.nestedset.Order;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration;
 import com.google.devtools.build.lib.rules.cpp.CppConfiguration.DynamicMode;
 import com.google.devtools.build.lib.rules.cpp.CppConfiguration.HeadersCheckingMode;
@@ -39,6 +39,7 @@
 import com.google.devtools.build.lib.rules.test.InstrumentedFilesProviderImpl;
 import com.google.devtools.build.lib.shell.ShellUtils;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.FileType;
 import com.google.devtools.build.lib.util.FileTypeSet;
 import com.google.devtools.build.lib.util.Pair;
@@ -174,7 +175,7 @@
 
     deps.addAll(ruleContext.getPrerequisites("deps", Mode.TARGET));
 
-    if (ruleContext.attributes().has("malloc", Type.LABEL)) {
+    if (ruleContext.attributes().has("malloc", BuildType.LABEL)) {
       deps.add(CppHelper.mallocForTarget(ruleContext));
     }
 
@@ -211,7 +212,7 @@
     // TODO(bazel-team): Move header processing logic down in the stack (to CcLibraryHelper or
     // such).
     boolean processHeaders = shouldProcessHeaders();
-    if (processHeaders && hasAttribute("hdrs", Type.LABEL_LIST)) {
+    if (processHeaders && hasAttribute("hdrs", BuildType.LABEL_LIST)) {
       providers = Iterables.concat(providers,
           ruleContext.getPrerequisites("hdrs", Mode.TARGET, FileProvider.class));
     }
@@ -376,7 +377,7 @@
     result.add(rulePackage);
 
     // Gather up all the dirs from the rule's srcs as well as any of the srcs outputs.
-    if (hasAttribute("srcs", Type.LABEL_LIST)) {
+    if (hasAttribute("srcs", BuildType.LABEL_LIST)) {
       for (FileProvider src :
           ruleContext.getPrerequisites("srcs", Mode.TARGET, FileProvider.class)) {
         PathFragment packageDir = src.getLabel().getPackageIdentifier().getPathFragment();
@@ -443,7 +444,7 @@
       RuleContext ruleContext, CppCompilationContext context) {
     // TODO(bazel-team): Use context.getCompilationPrerequisites() instead.
     NestedSetBuilder<Artifact> prerequisites = NestedSetBuilder.stableOrder();
-    if (ruleContext.attributes().has("srcs", Type.LABEL_LIST)) {
+    if (ruleContext.attributes().has("srcs", BuildType.LABEL_LIST)) {
       for (FileProvider provider : ruleContext
           .getPrerequisites("srcs", Mode.TARGET, FileProvider.class)) {
         prerequisites.addAll(FileType.filter(provider.getFilesToBuild(), SOURCE_TYPES));
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java
index d938fa7..0c34872 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java
@@ -30,15 +30,16 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.packages.AttributeMap;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.ImplicitOutputsFunction;
 import com.google.devtools.build.lib.packages.RawAttributeMapper;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
 import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration;
 import com.google.devtools.build.lib.rules.cpp.Link.LinkTargetType;
 import com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink;
 import com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.FileType;
 import com.google.devtools.build.lib.util.FileTypeSet;
 import com.google.devtools.build.lib.vfs.PathFragment;
@@ -163,13 +164,13 @@
       }
     }
 
-    if (ruleContext.getRule().isAttrDefined("srcs", Type.LABEL_LIST)) {
+    if (ruleContext.getRule().isAttrDefined("srcs", BuildType.LABEL_LIST)) {
       helper.addPrivateHeaders(FileType.filter(
           ruleContext.getPrerequisiteArtifacts("srcs", Mode.TARGET).list(),
           CppFileTypes.CPP_HEADER));
       ruleContext.checkSrcsSamePackage(true);
     }
-    if (ruleContext.getRule().isAttrDefined("textual_hdrs", Type.LABEL_LIST)) {
+    if (ruleContext.getRule().isAttrDefined("textual_hdrs", BuildType.LABEL_LIST)) {
       helper.addPublicTextualHeaders(
           ruleContext.getPrerequisiteArtifacts("textual_hdrs", Mode.TARGET).list());
     }
@@ -187,7 +188,8 @@
     // where we *do* have the correct value, it may not contain any source files to generate an
     // .so with. If that's the case, register a fake generating action to prevent a "no generating
     // action for this artifact" error.
-    if (!createDynamicLibrary && ruleContext.attributes().isConfigurable("srcs", Type.LABEL_LIST)) {
+    if (!createDynamicLibrary
+        && ruleContext.attributes().isConfigurable("srcs", BuildType.LABEL_LIST)) {
       Artifact solibArtifact = CppHelper.getLinkedArtifact(
           ruleContext, LinkTargetType.DYNAMIC_LIBRARY);
       ruleContext.registerAction(new FailAction(ruleContext.getActionOwner(),
@@ -347,7 +349,7 @@
    * name of a genrule that generates a source file.
    */
   public static boolean appearsToHaveObjectFiles(AttributeMap rule) {
-    if ((rule instanceof RawAttributeMapper) && rule.isConfigurable("srcs", Type.LABEL_LIST)) {
+    if ((rule instanceof RawAttributeMapper) && rule.isConfigurable("srcs", BuildType.LABEL_LIST)) {
       // Since this method gets called by loading phase logic (e.g. the cc_library implicit outputs
       // function), the attribute mapper may not be able to resolve configurable attributes. When
       // that's the case, there's no way to know which value a configurable "srcs" will take, so
@@ -355,7 +357,7 @@
       return true;
     }
 
-    List<Label> srcs = rule.get("srcs", Type.LABEL_LIST);
+    List<Label> srcs = rule.get("srcs", BuildType.LABEL_LIST);
     if (srcs != null) {
       for (Label srcfile : srcs) {
         /*
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java
index c1b111d..52c7571 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java
@@ -34,7 +34,7 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.collect.nestedset.Order;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration;
 import com.google.devtools.build.lib.rules.cpp.CppConfiguration.HeadersCheckingMode;
 import com.google.devtools.build.lib.rules.cpp.Link.LinkTargetType;
@@ -611,7 +611,7 @@
     Preconditions.checkState(
         // 'cc_inc_library' rules do not compile, and thus are not affected by LIPO.
         ruleContext.getRule().getRuleClass().equals("cc_inc_library")
-        || ruleContext.getRule().isAttrDefined(":lipo_context_collector", Type.LABEL));
+        || ruleContext.getRule().isAttrDefined(":lipo_context_collector", BuildType.LABEL));
 
     if (checkDepsGenerateCpp) {
       for (LanguageDependentFragment dep :
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java
index bd39d0f..7abeaf1 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java
@@ -13,7 +13,7 @@
 // limitations under the License.
 package com.google.devtools.build.lib.rules.cpp;
 
-import static com.google.devtools.build.lib.packages.Type.BOOLEAN;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Iterables;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainRule.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainRule.java
index 1ab0316..5ee3df08 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainRule.java
@@ -15,11 +15,11 @@
 
 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.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.LABEL;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.LICENSE;
-import static com.google.devtools.build.lib.packages.Type.STRING;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LICENSE;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuiteRule.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuiteRule.java
index 61922bd..984be2f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuiteRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuiteRule.java
@@ -18,9 +18,10 @@
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
 import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.RuleClass;
 import com.google.devtools.build.lib.packages.RuleClass.Builder;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.syntax.Type;
 
 /**
  * Definition of the {@code cc_toolchain_suite} rule.
@@ -31,7 +32,7 @@
   public RuleClass build(Builder builder, RuleDefinitionEnvironment environment) {
     return builder
         .setUndocumented()
-        .add(attr("toolchains", Type.LABEL_DICT_UNARY)
+        .add(attr("toolchains", BuildType.LABEL_DICT_UNARY)
             .mandatory()
             .nonconfigurable("Used during configuration creation"))
         .add(attr("proto", Type.STRING)
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java
index 96b1add..fab12a3 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java
@@ -26,6 +26,7 @@
 import com.google.devtools.build.lib.analysis.config.FragmentOptions;
 import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
 import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.InputFile;
 import com.google.devtools.build.lib.packages.NoSuchPackageException;
 import com.google.devtools.build.lib.packages.NoSuchTargetException;
@@ -33,7 +34,6 @@
 import com.google.devtools.build.lib.packages.NonconfigurableAttributeMapper;
 import com.google.devtools.build.lib.packages.Rule;
 import com.google.devtools.build.lib.packages.Target;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.syntax.Label;
 import com.google.devtools.build.lib.vfs.FileSystemUtils;
 import com.google.devtools.build.lib.vfs.Path;
@@ -179,7 +179,7 @@
         && ((Rule) crosstoolTop).getRuleClass().equals("cc_toolchain_suite")) {
       Rule ccToolchainSuite = (Rule) crosstoolTop;
       ccToolchainLabel = NonconfigurableAttributeMapper.of(ccToolchainSuite)
-          .get("toolchains", Type.LABEL_DICT_UNARY)
+          .get("toolchains", BuildType.LABEL_DICT_UNARY)
           .get(toolchain.getTargetCpu());
       if (ccToolchainLabel == null) {
         throw new InvalidConfigurationException(String.format(
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
index 1e8b247..5d27e9e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
@@ -32,13 +32,14 @@
 import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
 import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.RuleErrorConsumer;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.cpp.CcLinkParams.Linkstamp;
 import com.google.devtools.build.lib.rules.cpp.CppCompilationContext.Builder;
 import com.google.devtools.build.lib.rules.cpp.Link.LinkTargetType;
 import com.google.devtools.build.lib.shell.ShellUtils;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.FileTypeSet;
 import com.google.devtools.build.lib.util.IncludeScanningUtil;
 import com.google.devtools.build.lib.vfs.PathFragment;
@@ -351,7 +352,7 @@
       scannableBuilder.addTransitive(dep.getTransitiveIncludeScannables());
     }
 
-    if (ruleContext.attributes().has("malloc", Type.LABEL)) {
+    if (ruleContext.attributes().has("malloc", BuildType.LABEL)) {
       TransitiveInfoCollection malloc = mallocForTarget(ruleContext);
       TransitiveLipoInfoProvider provider = malloc.getProvider(TransitiveLipoInfoProvider.class);
       if (provider != null) {
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java
index 4ce8c61..8fa96ad 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java
@@ -25,7 +25,7 @@
 import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
 import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.rules.cpp.CcCompilationOutputs.Builder;
 import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration;
 import com.google.devtools.build.lib.rules.cpp.Link.LinkStaticness;
@@ -794,7 +794,7 @@
       //    readable and can lead to unexpected breakage.
       // b) Traversing the transitive closure for each C++ compile action would require more complex
       //    implementation (with caching results of this method) to avoid O(N^2) slowdown.
-      if (ruleContext.getRule().isAttrDefined("deps", Type.LABEL_LIST)) {
+      if (ruleContext.getRule().isAttrDefined("deps", BuildType.LABEL_LIST)) {
         for (TransitiveInfoCollection dep : ruleContext.getPrerequisites("deps", Mode.TARGET)) {
           if (dep.getProvider(CppCompilationContext.class) != null
               && filter.isIncluded(dep.getLabel().toString())) {
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoader.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoader.java
index 22ae3ec..c475d6f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoader.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoader.java
@@ -31,8 +31,8 @@
 import com.google.devtools.build.lib.packages.Package;
 import com.google.devtools.build.lib.packages.Rule;
 import com.google.devtools.build.lib.packages.Target;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.Fingerprint;
 import com.google.devtools.build.lib.vfs.FileSystemUtils;
 import com.google.devtools.build.lib.vfs.Path;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/extra/ActionListener.java b/src/main/java/com/google/devtools/build/lib/rules/extra/ActionListener.java
index d653c9a..e643f18 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/extra/ActionListener.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/extra/ActionListener.java
@@ -23,8 +23,8 @@
 import com.google.devtools.build.lib.analysis.RunfilesProvider;
 import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
 import com.google.devtools.build.lib.collect.ImmutableSortedKeyListMultimap;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
+import com.google.devtools.build.lib.syntax.Type;
 
 import java.util.ArrayList;
 import java.util.List;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/extra/ExtraActionFactory.java b/src/main/java/com/google/devtools/build/lib/rules/extra/ExtraActionFactory.java
index d7f856e..6543006 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/extra/ExtraActionFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/extra/ExtraActionFactory.java
@@ -27,9 +27,9 @@
 import com.google.devtools.build.lib.analysis.RunfilesProvider;
 import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
 import com.google.devtools.build.lib.packages.TargetUtils;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 
 import java.util.List;
 
diff --git a/src/main/java/com/google/devtools/build/lib/rules/filegroup/Filegroup.java b/src/main/java/com/google/devtools/build/lib/rules/filegroup/Filegroup.java
index a95ff65..915db68 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/filegroup/Filegroup.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/filegroup/Filegroup.java
@@ -27,11 +27,11 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.collect.nestedset.Order;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
 import com.google.devtools.build.lib.rules.test.InstrumentedFilesCollector;
 import com.google.devtools.build.lib.rules.test.InstrumentedFilesCollector.InstrumentationSpec;
 import com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.FileTypeSet;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
diff --git a/src/main/java/com/google/devtools/build/lib/rules/fileset/FilesetLinks.java b/src/main/java/com/google/devtools/build/lib/rules/fileset/FilesetLinks.java
index d523edc..7bd5244 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/fileset/FilesetLinks.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/fileset/FilesetLinks.java
@@ -15,7 +15,7 @@
 package com.google.devtools.build.lib.rules.fileset;
 
 import com.google.common.base.Preconditions;
-import com.google.devtools.build.lib.syntax.FilesetEntry;
+import com.google.devtools.build.lib.packages.FilesetEntry;
 import com.google.devtools.build.lib.vfs.Path;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
diff --git a/src/main/java/com/google/devtools/build/lib/rules/genquery/GenQuery.java b/src/main/java/com/google/devtools/build/lib/rules/genquery/GenQuery.java
index c3e9589..6c271b6 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/genquery/GenQuery.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/genquery/GenQuery.java
@@ -38,11 +38,11 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.collect.nestedset.Order;
 import com.google.devtools.build.lib.events.EventHandler;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.NoSuchPackageException;
 import com.google.devtools.build.lib.packages.NoSuchTargetException;
 import com.google.devtools.build.lib.packages.Package;
 import com.google.devtools.build.lib.packages.Target;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.pkgcache.FilteringPolicies;
 import com.google.devtools.build.lib.pkgcache.FilteringPolicy;
 import com.google.devtools.build.lib.pkgcache.PackageProvider;
@@ -64,6 +64,7 @@
 import com.google.devtools.build.lib.skyframe.TargetPatternValue;
 import com.google.devtools.build.lib.skyframe.TransitiveTargetValue;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.Fingerprint;
 import com.google.devtools.build.lib.util.Pair;
 import com.google.devtools.build.lib.vfs.PathFragment;
@@ -178,7 +179,7 @@
   // The transitive closure of these targets is an upper estimate on the labels
   // the query will touch
   private Set<Target> getScope(RuleContext context) {
-    List<Label> scopeLabels = context.attributes().get("scope", Type.LABEL_LIST);
+    List<Label> scopeLabels = context.attributes().get("scope", BuildType.LABEL_LIST);
     Set<Target> scope = Sets.newHashSetWithExpectedSize(scopeLabels.size());
     for (Label scopePart : scopeLabels) {
       SkyFunction.Environment env = context.getAnalysisEnvironment().getSkyframeEnv();
diff --git a/src/main/java/com/google/devtools/build/lib/rules/genquery/GenQueryRule.java b/src/main/java/com/google/devtools/build/lib/rules/genquery/GenQueryRule.java
index fdff111..ce91435 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/genquery/GenQueryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/genquery/GenQueryRule.java
@@ -15,10 +15,10 @@
 package com.google.devtools.build.lib.rules.genquery;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.STRING;
-import static com.google.devtools.build.lib.packages.Type.STRING_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.STRING_LIST;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaBinary.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaBinary.java
index f6d7b51..072b9f6 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaBinary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaBinary.java
@@ -32,12 +32,13 @@
 import com.google.devtools.build.lib.analysis.actions.FileWriteAction;
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
 import com.google.devtools.build.lib.rules.cpp.CppConfiguration;
 import com.google.devtools.build.lib.rules.cpp.CppHelper;
 import com.google.devtools.build.lib.rules.cpp.LinkerInput;
 import com.google.devtools.build.lib.rules.java.JavaCompilationArgs.ClasspathType;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
 import java.util.ArrayList;
@@ -90,7 +91,7 @@
         collectNativeLibraries(common.targetsTreatedAsDeps(ClasspathType.BOTH)));
 
     // deploy_env is valid for java_binary, but not for java_test.
-    if (ruleContext.getRule().isAttrDefined("deploy_env", Type.LABEL_LIST)) {
+    if (ruleContext.getRule().isAttrDefined("deploy_env", BuildType.LABEL_LIST)) {
       for (JavaRuntimeClasspathProvider envTarget : ruleContext.getPrerequisites(
                "deploy_env", Mode.TARGET, JavaRuntimeClasspathProvider.class)) {
         attributesBuilder.addExcludedArtifacts(envTarget.getRuntimeClasspath());
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java
index 114e221..6aa17e6 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java
@@ -37,8 +37,8 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.collect.nestedset.Order;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.TargetUtils;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.cpp.CppCompilationContext;
 import com.google.devtools.build.lib.rules.cpp.LinkerInput;
 import com.google.devtools.build.lib.rules.java.DirectDependencyProvider.Dependency;
@@ -48,6 +48,7 @@
 import com.google.devtools.build.lib.rules.test.InstrumentedFilesCollector.LocalMetadataCollector;
 import com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.FileType;
 import com.google.devtools.build.lib.util.FileTypeSet;
 import com.google.devtools.build.lib.vfs.FileSystemUtils;
@@ -267,7 +268,7 @@
   public static List<TransitiveInfoCollection> getExports(RuleContext ruleContext) {
     // We need to check here because there are classes inheriting from this class that implement
     // rules that don't have this attribute.
-    if (ruleContext.attributes().has("exports", Type.LABEL_LIST)) {
+    if (ruleContext.attributes().has("exports", BuildType.LABEL_LIST)) {
       return ImmutableList.copyOf(ruleContext.getPrerequisites("exports", Mode.TARGET));
     } else {
       return ImmutableList.of();
@@ -306,7 +307,7 @@
     NativeLibraryNestedSetBuilder builder = new NativeLibraryNestedSetBuilder();
     builder.addJavaTargets(targetsTreatedAsDeps(ClasspathType.BOTH));
 
-    if (ruleContext.getRule().isAttrDefined("data", Type.LABEL_LIST)) {
+    if (ruleContext.getRule().isAttrDefined("data", BuildType.LABEL_LIST)) {
       builder.addJavaTargets(ruleContext.getPrerequisites("data", Mode.DATA));
     }
     return builder.build();
@@ -434,7 +435,7 @@
   private static List<TransitiveInfoCollection> getRuntimeDeps(RuleContext ruleContext) {
     // We need to check here because there are classes inheriting from this class that implement
     // rules that don't have this attribute.
-    if (ruleContext.attributes().has("runtime_deps", Type.LABEL_LIST)) {
+    if (ruleContext.attributes().has("runtime_deps", BuildType.LABEL_LIST)) {
       return ImmutableList.copyOf(ruleContext.getPrerequisites("runtime_deps", Mode.TARGET));
     } else {
       return ImmutableList.of();
@@ -474,7 +475,7 @@
     }
 
     if (disallowDepsWithoutSrcs(ruleContext.getRule().getRuleClass())
-        && ruleContext.attributes().get("srcs", Type.LABEL_LIST).isEmpty()
+        && ruleContext.attributes().get("srcs", BuildType.LABEL_LIST).isEmpty()
         && ruleContext.getRule().isAttributeValueExplicitlySpecified("deps")) {
       ruleContext.attributeError("deps", "deps not allowed without srcs; move to runtime_deps?");
     }
@@ -609,7 +610,7 @@
 
   Iterable<JavaPluginInfoProvider> getPluginInfoProvidersForAttribute(String attribute,
       Mode mode) {
-    if (ruleContext.attributes().has(attribute, Type.LABEL_LIST)) {
+    if (ruleContext.attributes().has(attribute, BuildType.LABEL_LIST)) {
       return ruleContext.getPrerequisites(attribute, mode, JavaPluginInfoProvider.class);
     }
     return ImmutableList.of();
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaHelper.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaHelper.java
index b2a7ca0..754f7ee 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaHelper.java
@@ -17,7 +17,7 @@
 import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
 import com.google.devtools.build.lib.analysis.RuleContext;
 import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.shell.ShellUtils;
 
 import java.util.ArrayList;
@@ -57,9 +57,9 @@
    */
   private static String filterLauncherForTarget(JavaSemantics semantics, RuleContext ruleContext) {
     // BUILD rule "launcher" attribute
-    if (ruleContext.getRule().isAttrDefined("launcher", Type.LABEL)
-        && ruleContext.attributes().get("launcher", Type.LABEL) != null) {
-      if (ruleContext.attributes().get("launcher", Type.LABEL)
+    if (ruleContext.getRule().isAttrDefined("launcher", BuildType.LABEL)
+        && ruleContext.attributes().get("launcher", BuildType.LABEL) != null) {
+      if (ruleContext.attributes().get("launcher", BuildType.LABEL)
           .equals(JavaSemantics.JDK_LAUNCHER_LABEL)) {
         return null;
       }
@@ -67,7 +67,7 @@
     }
     // Blaze flag --java_launcher
     JavaConfiguration javaConfig = ruleContext.getFragment(JavaConfiguration.class);
-    if (ruleContext.getRule().isAttrDefined(":java_launcher", Type.LABEL)
+    if (ruleContext.getRule().isAttrDefined(":java_launcher", BuildType.LABEL)
         && ((javaConfig.getJavaLauncherLabel() != null
                 && !javaConfig.getJavaLauncherLabel().equals(JavaSemantics.JDK_LAUNCHER_LABEL))
             || semantics.forceUseJavaLauncherTarget(ruleContext))) {
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaImportBaseRule.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaImportBaseRule.java
index dc195c7..73e8b72 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaImportBaseRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaImportBaseRule.java
@@ -16,10 +16,10 @@
 
 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.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.LABEL;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.STRING_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
+import static com.google.devtools.build.lib.syntax.Type.STRING_LIST;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibrary.java
index 2991afe..85630d6 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibrary.java
@@ -27,7 +27,7 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.collect.nestedset.Order;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
 import com.google.devtools.build.lib.rules.cpp.CcLinkParams;
 import com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider;
@@ -190,10 +190,10 @@
       runfilesBuilder.add(ruleContext, JavaRunfilesProvider.TO_RUNFILES);
 
       List<TransitiveInfoCollection> depsForRunfiles = new ArrayList<>();
-      if (ruleContext.getRule().isAttrDefined("runtime_deps", Type.LABEL_LIST)) {
+      if (ruleContext.getRule().isAttrDefined("runtime_deps", BuildType.LABEL_LIST)) {
         depsForRunfiles.addAll(ruleContext.getPrerequisites("runtime_deps", Mode.TARGET));
       }
-      if (ruleContext.getRule().isAttrDefined("exports", Type.LABEL_LIST)) {
+      if (ruleContext.getRule().isAttrDefined("exports", BuildType.LABEL_LIST)) {
         depsForRunfiles.addAll(ruleContext.getPrerequisites("exports", Mode.TARGET));
       }
 
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaPlugin.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaPlugin.java
index 526d52c..2a5fa27 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaPlugin.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaPlugin.java
@@ -17,8 +17,8 @@
 import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder;
 import com.google.devtools.build.lib.analysis.RuleContext;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
+import com.google.devtools.build.lib.syntax.Type;
 
 /**
  * Implementation for the java_plugin rule.
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchain.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchain.java
index aac1742..a5d5dc0 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchain.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchain.java
@@ -21,8 +21,8 @@
 import com.google.devtools.build.lib.analysis.RunfilesProvider;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.collect.nestedset.Order;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
+import com.google.devtools.build.lib.syntax.Type;
 
 import java.util.List;
 
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainProvider.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainProvider.java
index 3c2c4f3..1e3657d2 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainProvider.java
@@ -18,7 +18,7 @@
 import com.google.devtools.build.lib.analysis.RuleContext;
 import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
 import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.packages.BuildType;
 
 import java.util.List;
 
@@ -87,7 +87,7 @@
    *         provided by the {@link JavaConfiguration} fragment.
    */
   public static List<String> getDefaultJavacJvmOptions(RuleContext ruleContext) {
-    if (!ruleContext.getRule().isAttrDefined(":java_toolchain", Type.LABEL))  {
+    if (!ruleContext.getRule().isAttrDefined(":java_toolchain", BuildType.LABEL))  {
       // As some rules might not have java_toolchain dependency (e.g., java_import), we silently
       // ignore it. The rules needing it will error in #getDefaultJavacOptions(RuleContext) anyway.
       return ImmutableList.of();
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainRule.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainRule.java
index 00adebe..2bc0aaf 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainRule.java
@@ -14,8 +14,8 @@
 package com.google.devtools.build.lib.rules.java;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.STRING;
-import static com.google.devtools.build.lib.packages.Type.STRING_LIST;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.STRING_LIST;
 
 import com.google.common.collect.ImmutableList;
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JvmConfigurationLoader.java b/src/main/java/com/google/devtools/build/lib/rules/java/JvmConfigurationLoader.java
index ecc013a..8781613 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JvmConfigurationLoader.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JvmConfigurationLoader.java
@@ -24,13 +24,14 @@
 import com.google.devtools.build.lib.analysis.config.FragmentOptions;
 import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
 import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.NoSuchPackageException;
 import com.google.devtools.build.lib.packages.NoSuchTargetException;
 import com.google.devtools.build.lib.packages.RawAttributeMapper;
 import com.google.devtools.build.lib.packages.Rule;
 import com.google.devtools.build.lib.packages.Target;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
 import java.util.List;
@@ -109,11 +110,11 @@
       if ((javaHomeTarget instanceof Rule) &&
           "filegroup".equals(((Rule) javaHomeTarget).getRuleClass())) {
         RawAttributeMapper javaHomeAttributes = RawAttributeMapper.of((Rule) javaHomeTarget);
-        if (javaHomeAttributes.isConfigurable("srcs", Type.LABEL_LIST)) {
+        if (javaHomeAttributes.isConfigurable("srcs", BuildType.LABEL_LIST)) {
           throw new InvalidConfigurationException("\"srcs\" in " + javaHome
               + " is configurable. JAVABASE targets don't support configurable attributes");
         }
-        List<Label> labels = javaHomeAttributes.get("srcs", Type.LABEL_LIST);
+        List<Label> labels = javaHomeAttributes.get("srcs", BuildType.LABEL_LIST);
         for (Label jvmLabel : labels) {
           if (jvmLabel.getName().endsWith("-" + cpu)) {
             jvmLabel = RedirectChaser.followRedirects(
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/BundleSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/BundleSupport.java
index 890d4a8..98756b0 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/BundleSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/BundleSupport.java
@@ -31,10 +31,10 @@
 import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
 import com.google.devtools.build.lib.analysis.actions.SpawnAction;
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.objc.TargetDeviceFamily.InvalidFamilyNameException;
 import com.google.devtools.build.lib.rules.objc.TargetDeviceFamily.RepeatedFamilyNameException;
 import com.google.devtools.build.lib.rules.objc.XcodeProvider.Builder;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.vfs.FileSystemUtils;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/Bundling.java b/src/main/java/com/google/devtools/build/lib/rules/objc/Bundling.java
index b336096..78d5e87 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/Bundling.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/Bundling.java
@@ -37,7 +37,7 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
 import java.util.HashSet;
@@ -106,7 +106,7 @@
      * any such added plists plus some additional information).
      */
     public Builder addInfoplistInputFromRule(RuleContext ruleContext) {
-      if (ruleContext.attributes().has("options", Type.LABEL)) {
+      if (ruleContext.attributes().has("options", BuildType.LABEL)) {
         OptionsProvider optionsProvider = ruleContext
             .getPrerequisite("options", Mode.TARGET, OptionsProvider.class);
         if (optionsProvider != null) {
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
index ea4188c..57de1fd 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
@@ -66,9 +66,9 @@
 import com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction;
 import com.google.devtools.build.lib.analysis.actions.SpawnAction;
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.ImplicitOutputsFunction.SafeImplicitOutputsFunction;
 import com.google.devtools.build.lib.packages.TargetUtils;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.cpp.CppModuleMap;
 import com.google.devtools.build.lib.rules.cpp.CppModuleMapAction;
 import com.google.devtools.build.lib.rules.cpp.LinkerInputs;
@@ -996,7 +996,7 @@
     }
 
     // Check for overlap between srcs and hdrs.
-    if (ruleContext.attributes().has("srcs", Type.LABEL_LIST)) {
+    if (ruleContext.attributes().has("srcs", BuildType.LABEL_LIST)) {
       Set<Artifact> hdrsSet = new HashSet<>(attributes.hdrs());
       Set<Artifact> srcsSet =
           new HashSet<>(ruleContext.getPrerequisiteArtifacts("srcs", Mode.TARGET).list());
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ExperimentalIosTestRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ExperimentalIosTestRule.java
index 8860397..18b5fb3 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ExperimentalIosTestRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ExperimentalIosTestRule.java
@@ -16,9 +16,9 @@
 
 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.Type.LABEL;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.STRING_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.syntax.Type.STRING_LIST;
 
 import com.google.common.collect.ImmutableList;
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosApplicationRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosApplicationRule.java
index b6074ce..265eb40 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosApplicationRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosApplicationRule.java
@@ -16,9 +16,9 @@
 
 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.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.LABEL;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosDevice.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosDevice.java
index fe0587d..a5907c2 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosDevice.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosDevice.java
@@ -14,7 +14,7 @@
 
 package com.google.devtools.build.lib.rules.objc;
 
-import static com.google.devtools.build.lib.packages.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
 
 import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceRule.java
index 9122a0a..a990475 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceRule.java
@@ -15,7 +15,7 @@
 package com.google.devtools.build.lib.rules.objc;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionRule.java
index 6f677c7..4b90733 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionRule.java
@@ -15,7 +15,7 @@
 package com.google.devtools.build.lib.rules.objc;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosFrameworkRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosFrameworkRule.java
index 838c113..0a4edfca 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosFrameworkRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosFrameworkRule.java
@@ -15,8 +15,8 @@
 package com.google.devtools.build.lib.rules.objc;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.LABEL;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java
index fd958c4..ac433a9 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java
@@ -26,10 +26,10 @@
 import com.google.devtools.build.lib.analysis.RuleContext;
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
 import com.google.devtools.build.lib.rules.objc.CompilationSupport.ExtraLinkArgs;
 import com.google.devtools.build.lib.rules.objc.ReleaseBundlingSupport.LinkedBinary;
+import com.google.devtools.build.lib.syntax.Type;
 
 import java.util.ArrayList;
 import java.util.List;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java
index 0db2fc6..0b15f5d 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java
@@ -16,7 +16,7 @@
 
 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.Type.LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
 import static java.nio.charset.StandardCharsets.ISO_8859_1;
 
 import com.google.common.collect.ImmutableList;
@@ -37,7 +37,7 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.packages.AspectDefinition;
 import com.google.devtools.build.lib.packages.AspectParameters;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.rules.java.J2ObjcConfiguration;
 import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider;
 import com.google.devtools.build.lib.rules.java.JavaCompilationHelper;
@@ -244,7 +244,7 @@
   private static void addJ2ObjCMappingsForAttribute(
       ImmutableList.Builder<J2ObjcMappingFileProvider> builder, RuleContext context,
       String attributeName) {
-    if (context.attributes().has(attributeName, Type.LABEL_LIST)) {
+    if (context.attributes().has(attributeName, BuildType.LABEL_LIST)) {
       for (TransitiveInfoCollection dependencyInfoDatum :
           context.getPrerequisites(attributeName, Mode.TARGET)) {
         J2ObjcMappingFileProvider provider =
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcLibrary.java
index b4649b5..bb88b2f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcLibrary.java
@@ -25,10 +25,11 @@
 import com.google.devtools.build.lib.analysis.RuleContext;
 import com.google.devtools.build.lib.analysis.RunfilesProvider;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
 import com.google.devtools.build.lib.rules.cpp.CppModuleMap;
 import com.google.devtools.build.lib.rules.java.J2ObjcConfiguration;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
 import java.util.List;
@@ -71,7 +72,7 @@
             .addDependencies(xcodeProviderBuilder, new Attribute("deps", Mode.TARGET));
 
     if (j2ObjcSrcsProvider.hasProtos()) {
-      if (ruleContext.attributes().has("$protobuf_lib", Type.LABEL)) {
+      if (ruleContext.attributes().has("$protobuf_lib", BuildType.LABEL)) {
         objcProviderBuilder.addTransitiveAndPropagate(
             ruleContext.getPrerequisite("$protobuf_lib", Mode.TARGET, ObjcProvider.class));
         xcodeSupport.addDependencies(
@@ -137,7 +138,7 @@
   }
 
   private static void checkAttributes(RuleContext ruleContext, String attributeName) {
-    if (!ruleContext.attributes().has(attributeName, Type.LABEL_LIST)) {
+    if (!ruleContext.attributes().has(attributeName, BuildType.LABEL_LIST)) {
       return;
     }
 
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcLibraryBaseRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcLibraryBaseRule.java
index 537cccd..3835392 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcLibraryBaseRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcLibraryBaseRule.java
@@ -15,8 +15,8 @@
 package com.google.devtools.build.lib.rules.objc;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.LABEL;
-import static com.google.devtools.build.lib.packages.Type.STRING_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
+import static com.google.devtools.build.lib.syntax.Type.STRING_LIST;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcSrcsProvider.java b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcSrcsProvider.java
index 886721f..a2aaa09 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcSrcsProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcSrcsProvider.java
@@ -20,7 +20,7 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.rules.objc.J2ObjcSource.SourceType;
 
 /**
@@ -81,7 +81,7 @@
      * @return this builder
      */
     public Builder addTransitiveJ2ObjcSrcs(RuleContext ruleContext, String attribute) {
-      if (ruleContext.attributes().has(attribute, Type.LABEL_LIST)) {
+      if (ruleContext.attributes().has(attribute, BuildType.LABEL_LIST)) {
         for (J2ObjcSrcsProvider provider :
             ruleContext.getPrerequisites(attribute, Mode.TARGET, J2ObjcSrcsProvider.class)) {
           addTransitive(provider);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryRule.java
index 411cb60..e5e252e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryRule.java
@@ -16,8 +16,8 @@
 
 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.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBundleRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBundleRule.java
index fffa2d8..6dd7278 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBundleRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBundleRule.java
@@ -15,7 +15,7 @@
 package com.google.devtools.build.lib.rules.objc;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java
index 775c53d..c2c19d5 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java
@@ -61,11 +61,12 @@
 import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
 import com.google.devtools.build.lib.analysis.RuleContext;
 import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.rules.cpp.CcCommon;
 import com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider;
 import com.google.devtools.build.lib.rules.cpp.CppCompilationContext;
 import com.google.devtools.build.lib.rules.cpp.CppModuleMap;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.FileType;
 import com.google.devtools.build.lib.util.RegexFilter;
 import com.google.devtools.build.lib.vfs.PathFragment;
@@ -99,7 +100,7 @@
 
     ImmutableList<Artifact> hdrs() {
       // Some rules may compile but not have the "hdrs" attribute.
-      if (!ruleContext.attributes().has("hdrs", Type.LABEL_LIST)) {
+      if (!ruleContext.attributes().has("hdrs", BuildType.LABEL_LIST)) {
         return ImmutableList.of();
       }
       return ImmutableList.copyOf(CcCommon.getHeaders(ruleContext));
@@ -182,7 +183,7 @@
      * this rule.
      */
     public Iterable<String> optionsCopts() {
-      if (!ruleContext.attributes().has("options", Type.LABEL)) {
+      if (!ruleContext.attributes().has("options", BuildType.LABEL)) {
         return ImmutableList.of();
       }
       OptionsProvider optionsProvider =
@@ -215,7 +216,7 @@
      */
     private void collectModuleMapsFromAttributeIfExists(
         ArrayList<CppModuleMap> moduleMaps, String attribute) {
-      if (ruleContext.attributes().has(attribute, Type.LABEL_LIST)) {
+      if (ruleContext.attributes().has(attribute, BuildType.LABEL_LIST)) {
         Iterable<ObjcProvider> providers =
             ruleContext.getPrerequisites(attribute, Mode.TARGET, ObjcProvider.class);
         for (ObjcProvider provider : providers) {
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcFrameworkRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcFrameworkRule.java
index e3bc19a..4c13f93 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcFrameworkRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcFrameworkRule.java
@@ -15,7 +15,7 @@
 package com.google.devtools.build.lib.rules.objc;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcImport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcImport.java
index 143858d..05c65ea 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcImport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcImport.java
@@ -22,10 +22,10 @@
 import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
 import com.google.devtools.build.lib.analysis.RuleContext;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
 import com.google.devtools.build.lib.rules.objc.ObjcCommon.CompilationAttributes;
 import com.google.devtools.build.lib.rules.objc.ObjcCommon.ResourceAttributes;
+import com.google.devtools.build.lib.syntax.Type;
 
 /**
  * Implementation for {@code objc_import}.
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcImportRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcImportRule.java
index 5187a27..12f672a 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcImportRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcImportRule.java
@@ -15,7 +15,7 @@
 package com.google.devtools.build.lib.rules.objc;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibrary.java
index e03d9ba..048dce7 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibrary.java
@@ -22,12 +22,12 @@
 import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
 import com.google.devtools.build.lib.analysis.RuleContext;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
 import com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider;
 import com.google.devtools.build.lib.rules.cpp.CppCompilationContext;
 import com.google.devtools.build.lib.rules.objc.ObjcCommon.CompilationAttributes;
 import com.google.devtools.build.lib.rules.objc.ObjcCommon.ResourceAttributes;
+import com.google.devtools.build.lib.syntax.Type;
 
 /**
  * Implementation for {@code objc_library}.
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcOptionsRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcOptionsRule.java
index 7f7fbb3..be4c357 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcOptionsRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcOptionsRule.java
@@ -20,9 +20,10 @@
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
 import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.RuleClass;
 import com.google.devtools.build.lib.packages.RuleClass.Builder;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.syntax.Type;
 
 /**
  * Rule definition for {@code objc_options}.
@@ -43,7 +44,7 @@
         projects.
         <i>(List of <a href="build-ref.html#labels">labels</a>; optional)</i>
         <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
-        .add(attr("infoplists", Type.LABEL_LIST)
+        .add(attr("infoplists", BuildType.LABEL_LIST)
             .allowedFileTypes(PLIST_TYPE))
         .build();
   }
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibrary.java
index 8349b48..39cbee7 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibrary.java
@@ -34,9 +34,9 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.collect.nestedset.Order;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
 import com.google.devtools.build.lib.rules.proto.ProtoSourcesProvider;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.FileType;
 import com.google.devtools.build.lib.vfs.FileSystemUtils;
 import com.google.devtools.build.lib.vfs.PathFragment;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java
index 4052cef..55e4cf6 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java
@@ -17,9 +17,9 @@
 import static com.google.devtools.build.lib.packages.Attribute.ComputedDefault;
 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.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.LABEL;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
@@ -27,7 +27,7 @@
 import com.google.devtools.build.lib.packages.AttributeMap;
 import com.google.devtools.build.lib.packages.RuleClass;
 import com.google.devtools.build.lib.packages.RuleClass.Builder;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.FileType;
 
 /**
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java
index 3f4b60c..1ea99e1 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java
@@ -16,11 +16,11 @@
 
 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.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.LABEL;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
-import static com.google.devtools.build.lib.packages.Type.STRING;
-import static com.google.devtools.build.lib.packages.Type.STRING_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
+import static com.google.devtools.build.lib.syntax.Type.STRING;
+import static com.google.devtools.build.lib.syntax.Type.STRING_LIST;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableList;
@@ -41,12 +41,13 @@
 import com.google.devtools.build.lib.packages.Attribute;
 import com.google.devtools.build.lib.packages.Attribute.LateBoundLabel;
 import com.google.devtools.build.lib.packages.AttributeMap;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.Rule;
 import com.google.devtools.build.lib.packages.RuleClass;
 import com.google.devtools.build.lib.packages.RuleClass.Builder;
 import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.FileType;
 import com.google.devtools.build.lib.util.FileTypeSet;
 import com.google.devtools.build.lib.vfs.PathFragment;
@@ -556,7 +557,7 @@
           A header defining the Objective-C interfaces to be exposed in Swift.
           ${SYNOPSIS}
           <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
-          .add(attr("bridging_header", Type.LABEL)
+          .add(attr("bridging_header", BuildType.LABEL)
               .direct_compile_time_input()
               .allowedFileTypes(HDRS_TYPE))
           /* <!-- #BLAZE_RULE($objc_compile_dependency_rule).ATTRIBUTE(includes) -->
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcSdkFrameworks.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcSdkFrameworks.java
index adaae20..1b56ff1 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcSdkFrameworks.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcSdkFrameworks.java
@@ -16,8 +16,8 @@
 
 import com.google.common.collect.ImmutableSet;
 import com.google.devtools.build.lib.analysis.RuleContext;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.SdkFrameworksDependerRule;
+import com.google.devtools.build.lib.syntax.Type;
 
 /**
  * Common logic for rules that inherit from {@link SdkFrameworksDependerRule}.
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcXcodeprojRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcXcodeprojRule.java
index 0363956..3de027e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcXcodeprojRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcXcodeprojRule.java
@@ -15,8 +15,8 @@
 package com.google.devtools.build.lib.rules.objc;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.BOOLEAN;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java
index 78acdae..b6b5340 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java
@@ -45,10 +45,11 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.collect.nestedset.Order;
 import com.google.devtools.build.lib.packages.Attribute.SplitTransition;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.ImplicitOutputsFunction.SafeImplicitOutputsFunction;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.objc.BundleSupport.ExtraActoolArgs;
 import com.google.devtools.build.lib.shell.ShellUtils;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.xcode.xcodegen.proto.XcodeGenProtos.XcodeprojBuildSetting;
 
 import java.util.List;
@@ -882,7 +883,7 @@
 
     ImmutableMap<String, Artifact> cpuSpecificBreakpadFiles() {
       ImmutableMap.Builder<String, Artifact> results = ImmutableMap.builder();
-      if (ruleContext.attributes().has("binary", Type.LABEL)) {
+      if (ruleContext.attributes().has("binary", BuildType.LABEL)) {
         for (TransitiveInfoCollection prerequisite
             : ruleContext.getPrerequisites("binary", Mode.DONT_CHECK)) {
           ObjcProvider prerequisiteProvider =  prerequisite.getProvider(ObjcProvider.class);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/TestSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/TestSupport.java
index 0b91cf4..c882f05 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/TestSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/TestSupport.java
@@ -32,10 +32,10 @@
 import com.google.devtools.build.lib.analysis.actions.TemplateExpansionAction.Substitution;
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.objc.ObjcProvider.Key;
 import com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider;
 import com.google.devtools.build.lib.rules.test.InstrumentedFilesProviderImpl;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.FileType;
 
 import java.util.List;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryRule.java b/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryRule.java
index 2c4f9b4..b6d8178 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryRule.java
@@ -15,7 +15,7 @@
 package com.google.devtools.build.lib.rules.proto;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java
index e0f90ea..22d3a98 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java
@@ -24,7 +24,7 @@
 import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.syntax.Label;
 import com.google.devtools.build.lib.vfs.FileSystemUtils;
 import com.google.devtools.build.lib.vfs.PathFragment;
@@ -91,7 +91,7 @@
   public static void checkSourceFilesAreInSamePackage(RuleContext ruleContext) {
     // TODO(bazel-team): this does not work with filegroups that contain files
     // that are not in the package
-    for (Label source : ruleContext.attributes().get("srcs", Type.LABEL_LIST)) {
+    for (Label source : ruleContext.attributes().get("srcs", BuildType.LABEL_LIST)) {
       if (!isConfiguredTargetInSamePackage(ruleContext, source)) {
         ruleContext.attributeError(
             "srcs",
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java b/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java
index 23f19a9..b5a8ec3 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java
@@ -36,13 +36,14 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.collect.nestedset.Order;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.Rule;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.cpp.CppFileTypes;
 import com.google.devtools.build.lib.rules.test.InstrumentedFilesCollector;
 import com.google.devtools.build.lib.rules.test.InstrumentedFilesCollector.LocalMetadataCollector;
 import com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.FileType;
 import com.google.devtools.build.lib.vfs.PathFragment;
 import com.google.protobuf.GeneratedMessage.GeneratedExtension;
@@ -287,7 +288,7 @@
     Rule target = ruleContext.getRule();
     boolean explicitMain = target.isAttributeValueExplicitlySpecified("main");
     if (explicitMain) {
-      mainSourceName = ruleContext.attributes().get("main", Type.LABEL).getName();
+      mainSourceName = ruleContext.attributes().get("main", BuildType.LABEL).getName();
       if (!mainSourceName.endsWith(".py")) {
         ruleContext.attributeError("main", "main must end in '.py'");
       }
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PyTest.java b/src/main/java/com/google/devtools/build/lib/rules/python/PyTest.java
index 076005a..e8cec79 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/python/PyTest.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/python/PyTest.java
@@ -16,8 +16,8 @@
 import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder;
 import com.google.devtools.build.lib.analysis.RuleContext;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
+import com.google.devtools.build.lib.syntax.Type;
 
 /**
  * An implementation for {@code py_test} rules.
diff --git a/src/main/java/com/google/devtools/build/lib/rules/test/InstrumentedFilesCollector.java b/src/main/java/com/google/devtools/build/lib/rules/test/InstrumentedFilesCollector.java
index e61cafa..b782869 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/test/InstrumentedFilesCollector.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/test/InstrumentedFilesCollector.java
@@ -27,7 +27,7 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.collect.nestedset.Order;
 import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.util.FileType;
 import com.google.devtools.build.lib.util.FileTypeSet;
 
@@ -205,8 +205,8 @@
       RuleContext ruleContext, InstrumentationSpec spec) {
     List<TransitiveInfoCollection> prerequisites = new ArrayList<>();
     for (String attr : spec.instrumentedAttributes) {
-      if (ruleContext.getRule().isAttrDefined(attr, Type.LABEL_LIST) ||
-          ruleContext.getRule().isAttrDefined(attr, Type.LABEL)) {
+      if (ruleContext.getRule().isAttrDefined(attr, BuildType.LABEL_LIST) ||
+          ruleContext.getRule().isAttrDefined(attr, BuildType.LABEL)) {
         prerequisites.addAll(ruleContext.getPrerequisites(attr, Mode.DONT_CHECK));
       }
     }
diff --git a/src/main/java/com/google/devtools/build/lib/rules/test/TestSuite.java b/src/main/java/com/google/devtools/build/lib/rules/test/TestSuite.java
index 9080c9e8..ed9f621 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/test/TestSuite.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/test/TestSuite.java
@@ -22,9 +22,10 @@
 import com.google.devtools.build.lib.analysis.Runfiles;
 import com.google.devtools.build.lib.analysis.RunfilesProvider;
 import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.TestTargetUtils;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.Pair;
 
 import java.util.ArrayList;
@@ -86,7 +87,7 @@
 
   private Iterable<? extends TransitiveInfoCollection> getPrerequisites(
       RuleContext ruleContext, String attributeName) {
-    if (ruleContext.attributes().has(attributeName, Type.LABEL_LIST)) {
+    if (ruleContext.attributes().has(attributeName, BuildType.LABEL_LIST)) {
       return ruleContext.getPrerequisites(attributeName, Mode.TARGET);
     } else {
       return ImmutableList.<TransitiveInfoCollection>of();
@@ -94,7 +95,7 @@
   }
 
   private void checkTestsAndSuites(RuleContext ruleContext, String attributeName) {
-    if (!ruleContext.attributes().has(attributeName, Type.LABEL_LIST)) {
+    if (!ruleContext.attributes().has(attributeName, BuildType.LABEL_LIST)) {
       return;
     }
     for (TransitiveInfoCollection dep : ruleContext.getPrerequisites(attributeName, Mode.TARGET)) {
diff --git a/src/main/java/com/google/devtools/build/lib/rules/test/TestTargetProperties.java b/src/main/java/com/google/devtools/build/lib/rules/test/TestTargetProperties.java
index 0e0befc..654363f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/test/TestTargetProperties.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/test/TestTargetProperties.java
@@ -24,7 +24,7 @@
 import com.google.devtools.build.lib.packages.TargetUtils;
 import com.google.devtools.build.lib.packages.TestSize;
 import com.google.devtools.build.lib.packages.TestTimeout;
-import com.google.devtools.build.lib.packages.Type;
+import com.google.devtools.build.lib.syntax.Type;
 
 import java.util.List;
 import java.util.Map;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/workspace/BindRule.java b/src/main/java/com/google/devtools/build/lib/rules/workspace/BindRule.java
index 45acf44..5a32cac 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/workspace/BindRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/workspace/BindRule.java
@@ -15,7 +15,7 @@
 package com.google.devtools.build.lib.rules.workspace;
 
 import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses.BaseRule;
 import com.google.devtools.build.lib.analysis.RuleDefinition;
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java
index d90d27e..29e5247 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java
@@ -24,10 +24,10 @@
 import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
 import com.google.devtools.build.lib.events.Event;
 import com.google.devtools.build.lib.packages.Attribute;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.ProtoUtils;
 import com.google.devtools.build.lib.packages.RuleClass;
 import com.google.devtools.build.lib.packages.RuleClassProvider;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.pkgcache.PackageCacheOptions;
 import com.google.devtools.build.lib.query2.proto.proto2api.Build.AllowedRuleClassInfo;
 import com.google.devtools.build.lib.query2.proto.proto2api.Build.AttributeDefinition;
@@ -406,7 +406,7 @@
         attrPb.setType(ProtoUtils.getDiscriminatorFromType(attr.getType()));
         attrPb.setMandatory(attr.isMandatory());
 
-        if (Type.isLabelType(attr.getType())) {
+        if (BuildType.isLabelType(attr.getType())) {
           attrPb.setAllowedRuleClasses(getAllowedRuleClasses(ruleClasses, attr));
         }
 
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java
index 2a7276d..0389a34 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java
@@ -38,7 +38,6 @@
 import com.google.devtools.build.lib.packages.Rule;
 import com.google.devtools.build.lib.packages.Target;
 import com.google.devtools.build.lib.packages.TargetUtils;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.pkgcache.LoadingFailedException;
 import com.google.devtools.build.lib.runtime.BlazeCommand;
 import com.google.devtools.build.lib.runtime.BlazeRuntime;
@@ -47,6 +46,7 @@
 import com.google.devtools.build.lib.shell.AbnormalTerminationException;
 import com.google.devtools.build.lib.shell.BadExitStatusException;
 import com.google.devtools.build.lib.shell.CommandException;
+import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.CommandBuilder;
 import com.google.devtools.build.lib.util.CommandDescriptionForm;
 import com.google.devtools.build.lib.util.CommandFailureUtils;
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java
index 43f3521..c9b684a 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java
@@ -50,6 +50,7 @@
 import com.google.devtools.build.lib.packages.AspectParameters;
 import com.google.devtools.build.lib.packages.Attribute;
 import com.google.devtools.build.lib.packages.BuildFileContainsErrorsException;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.InputFile;
 import com.google.devtools.build.lib.packages.NoSuchPackageException;
 import com.google.devtools.build.lib.packages.NoSuchTargetException;
@@ -61,7 +62,6 @@
 import com.google.devtools.build.lib.packages.RuleClassProvider;
 import com.google.devtools.build.lib.packages.Target;
 import com.google.devtools.build.lib.packages.TargetUtils;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.skyframe.AspectFunction.AspectCreationException;
 import com.google.devtools.build.lib.skyframe.SkyframeExecutor.BuildViewProvider;
 import com.google.devtools.build.lib.syntax.EvalException;
@@ -588,7 +588,7 @@
     RawAttributeMapper attributeMap = RawAttributeMapper.of(((Rule) target));
     for (Attribute a : ((Rule) target).getAttributes()) {
       for (Label configLabel : attributeMap.getConfigurabilityKeys(a.getName(), a.getType())) {
-        if (!Type.Selector.isReservedLabel(configLabel)) {
+        if (!BuildType.Selector.isReservedLabel(configLabel)) {
           configLabelMap.put(a, LabelAndConfiguration.of(
               configLabel, ctgValue.getConfiguration()));
         }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PostConfiguredTargetFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/PostConfiguredTargetFunction.java
index a9b226f..ca7fdf3 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PostConfiguredTargetFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PostConfiguredTargetFunction.java
@@ -28,10 +28,10 @@
 import com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider;
 import com.google.devtools.build.lib.packages.AspectParameters;
 import com.google.devtools.build.lib.packages.Attribute;
+import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.RawAttributeMapper;
 import com.google.devtools.build.lib.packages.Rule;
 import com.google.devtools.build.lib.packages.RuleClassProvider;
-import com.google.devtools.build.lib.packages.Type;
 import com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.ConflictException;
 import com.google.devtools.build.lib.syntax.EvalException;
 import com.google.devtools.build.lib.syntax.Label;
@@ -137,7 +137,7 @@
     Set<SkyKey> depKeys = new LinkedHashSet<>();
     for (Attribute attribute : rule.getAttributes()) {
       for (Label label : mapper.getConfigurabilityKeys(attribute.getName(), attribute.getType())) {
-        if (!Type.Selector.isReservedLabel(label)) {
+        if (!BuildType.Selector.isReservedLabel(label)) {
           depKeys.add(ConfiguredTargetValue.key(label, ctg.getConfiguration()));
         }
       }
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BaseFunction.java b/src/main/java/com/google/devtools/build/lib/syntax/BaseFunction.java
index 43c25aa..1fb8747 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/BaseFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/BaseFunction.java
@@ -21,8 +21,8 @@
 import com.google.common.collect.Ordering;
 import com.google.common.collect.Sets;
 import com.google.devtools.build.lib.events.Location;
-import com.google.devtools.build.lib.packages.Type.ConversionException;
 import com.google.devtools.build.lib.syntax.SkylarkList.Tuple;
+import com.google.devtools.build.lib.syntax.Type.ConversionException;
 
 import java.util.ArrayList;
 import java.util.HashMap;
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BinaryOperatorExpression.java b/src/main/java/com/google/devtools/build/lib/syntax/BinaryOperatorExpression.java
index cf98c53..e697454 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/BinaryOperatorExpression.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/BinaryOperatorExpression.java
@@ -278,7 +278,8 @@
     }
 
     if (lval instanceof SelectorValue || rval instanceof SelectorValue
-        || lval instanceof SelectorList || rval instanceof SelectorList) {
+        || lval instanceof SelectorList
+        || rval instanceof SelectorList) {
       return SelectorList.concat(getLocation(), lval, rval);
     }
 
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java b/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java
index eb26e38..7ee555c 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java
@@ -114,7 +114,7 @@
   /**
    * Checks that an Object is a valid key for a Skylark dict.
    * @param o an Object to validate
-   * @throws an EvalException if o is not a valid key
+   * @throws EvalException if o is not a valid key
    */
   static void checkValidDictKey(Object o) throws EvalException {
     // TODO(bazel-team): check that all recursive elements are both Immutable AND Comparable.
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java b/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java
index a6ef07d..2afcbc3 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java
@@ -22,13 +22,12 @@
 import com.google.devtools.build.lib.collect.nestedset.Order;
 import com.google.devtools.build.lib.events.Event;
 import com.google.devtools.build.lib.events.Location;
-import com.google.devtools.build.lib.packages.Type;
-import com.google.devtools.build.lib.packages.Type.ConversionException;
 import com.google.devtools.build.lib.syntax.ClassObject.SkylarkClassObject;
 import com.google.devtools.build.lib.syntax.SkylarkList.MutableList;
 import com.google.devtools.build.lib.syntax.SkylarkList.Tuple;
 import com.google.devtools.build.lib.syntax.SkylarkSignature.Param;
 import com.google.devtools.build.lib.syntax.SkylarkSignatureProcessor.HackHackEitherList;
+import com.google.devtools.build.lib.syntax.Type.ConversionException;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -1322,7 +1321,8 @@
         @Param(name = "x", type = Map.class, doc = "The parameter to convert.")})
   private static final BuiltinFunction select = new BuiltinFunction("select") {
     public Object invoke(Map<?, ?> dict) throws EvalException {
-      return SelectorList.of(new SelectorValue(dict));
+      return SelectorList
+          .of(new SelectorValue(dict));
     }
   };
 
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SelectorList.java b/src/main/java/com/google/devtools/build/lib/syntax/SelectorList.java
index f77f8d7..04c5142 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SelectorList.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SelectorList.java
@@ -38,6 +38,9 @@
  * </pre>
  */
 public final class SelectorList {
+  // TODO(build-team): Selectors are currently split between .packages and .syntax . They should
+  // really all be in .packages, but then we'd need to figure out a way how to extend binary
+  // operators, which is a non-trivial problem.
   private final Class<?> type;
   private final List<Object> elements;
 
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SelectorValue.java b/src/main/java/com/google/devtools/build/lib/syntax/SelectorValue.java
index 5cdbb0b..ccf1f7d 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SelectorValue.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SelectorValue.java
@@ -30,6 +30,9 @@
  * </pre>
  */
 public final class SelectorValue {
+  // TODO(build-team): Selectors are currently split between .packages and .syntax . They should
+  // really all be in .packages, but then we'd need to figure out a way how to extend binary
+  // operators, which is a non-trivial problem.
   private final Map<?, ?> dictionary;
   private final Class<?> type;
 
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkType.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkType.java
index 21db288..1727db2 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkType.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkType.java
@@ -659,7 +659,7 @@
       return ImmutableList.of();
     }
     List<TYPE> results = new ArrayList<>();
-    for (Object object : com.google.devtools.build.lib.packages.Type.LIST.convert(obj, what)) {
+    for (Object object : com.google.devtools.build.lib.syntax.Type.LIST.convert(obj, what)) {
       try {
         results.add(type.cast(object));
       } catch (ClassCastException e) {
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Type.java b/src/main/java/com/google/devtools/build/lib/syntax/Type.java
new file mode 100644
index 0000000..825403e
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Type.java
@@ -0,0 +1,626 @@
+// Copyright 2014 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.syntax;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.devtools.build.lib.util.LoggingUtil;
+import com.google.devtools.build.lib.util.StringCanonicalizer;
+
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.logging.Level;
+
+import javax.annotation.Nullable;
+
+/**
+ *  <p>Root of Type symbol hierarchy for values in the build language.</p>
+ *
+ *  <p>Type symbols are primarily used for their <code>convert</code> method,
+ *  which is a kind of cast operator enabling conversion from untyped (Object)
+ *  references to values in the build language, to typed references.</p>
+ *
+ *  <p>For example, this code type-converts a value <code>x</code> returned by
+ *  the evaluator, to a list of strings:</p>
+ *
+ *  <pre>
+ *  Object x = expr.eval(env);
+ *  List&lt;String&gt; s = Type.STRING_LIST.convert(x);
+ *  </pre>
+ */
+public abstract class Type<T> {
+
+  protected Type() {}
+
+  /**
+   * Converts untyped Object x resulting from the evaluation of an expression in the build language,
+   * into a typed object of type T.
+   *
+   * <p>x must be *directly* convertible to this type. This therefore disqualifies "selector
+   * expressions" of the form "{ config1: 'value1_of_orig_type', config2: 'value2_of_orig_type; }"
+   * (which support configurable attributes). To handle those expressions, see
+   * {@link com.google.devtools.build.lib.packages.BuildType#selectableConvert}.
+   *
+   * @param x the build-interpreter value to convert.
+   * @param what a string description of what x is for; should be included in
+   *    any exception thrown.  Grammatically, must describe a syntactic
+   *    construct, e.g. "attribute 'srcs' of rule foo".
+   * @param context the label of the current BUILD rule; must be non-null if resolution of
+   *    package-relative label strings is required
+   * @throws ConversionException if there was a problem performing the type conversion
+   */
+  public abstract T convert(Object x, String what, @Nullable Object context)
+      throws ConversionException;
+  // TODO(bazel-team): Check external calls (e.g. in PackageFactory), verify they always want
+  // this over selectableConvert.
+
+  /**
+   * Equivalent to {@link #convert(Object, String, Object)} where the label is {@code null}.
+   * Useful for converting values to types that do not involve the type {@code LABEL}
+   * and hence do not require the label of the current package.
+   */
+  public final T convert(Object x, String what) throws ConversionException {
+    return convert(x, what, null);
+  }
+
+  /**
+   * Like {@link #convert(Object, String, Object)}, but converts skylark {@code None}
+   * to given {@code defaultValue}.
+   */
+  @Nullable public final T convertOptional(Object x,
+      String what, @Nullable Object context, T defaultValue)
+      throws ConversionException {
+    if (EvalUtils.isNullOrNone(x)) {
+      return defaultValue;
+    }
+    return convert(x, what, context);
+  }
+
+  /**
+   * Like {@link #convert(Object, String, Object)}, but converts skylark {@code None}
+   * to java {@code null}.
+   */
+  @Nullable public final T convertOptional(Object x, String what, @Nullable Object context)
+      throws ConversionException {
+    return convertOptional(x, what, context, null);
+  }
+
+  /**
+   * Like {@link #convert(Object, String)}, but converts skylark {@code NONE} to java {@code null}.
+   */
+  @Nullable public final T convertOptional(Object x, String what) throws ConversionException {
+    return convertOptional(x, what, null);
+  }
+
+  public abstract T cast(Object value);
+
+  @Override
+  public abstract String toString();
+
+  /**
+   * Returns the default value for this type; may return null iff no default is defined for this
+   * type.
+   */
+  public abstract T getDefaultValue();
+
+  /**
+   * Flatten the an instance of the type if the type is a composite one.
+   *
+   * <p>This is used to support reliable label visitation in
+   * {@link com.google.devtools.build.lib.packages.AbstractAttributeMapper#visitLabels}. To preserve
+   * that reliability, every type should faithfully define its own instance of this method. In other
+   * words, be careful about defining default instances in base types that get auto-inherited by
+   * their children. Keep all definitions as explicit as possible.
+   */
+  public abstract Collection<? extends Object> flatten(Object value);
+
+  /**
+   * {@link #flatten} return value for types that don't contain labels.
+   */
+  protected static final Collection<Object> NOT_COMPOSITE_TYPE = ImmutableList.of();
+
+  /**
+   * Implementation of concatenation for this type (e.g. "val1 + val2"). Returns null to
+   * designate concatenation isn't supported.
+   */
+  public T concat(Iterable<T> elements) {
+    return null;
+  }
+
+  /**
+   * Converts an initialized Type object into a tag set representation.
+   * This operation is only valid for certain sub-Types which are guaranteed
+   * to be properly initialized.
+   *
+   * @param value the actual value
+   * @throws UnsupportedOperationException if the concrete type does not support
+   * tag conversion or if a convertible type has no initialized value.
+   */
+  public Set<String> toTagSet(Object value, String name) {
+    String msg = "Attribute " + name + " does not support tag conversion.";
+    throw new UnsupportedOperationException(msg);
+  }
+
+  /**
+   * The type of an integer.
+   */
+  public static final Type<Integer> INTEGER = new IntegerType();
+
+  /**
+   * The type of a string.
+   */
+  public static final Type<String> STRING = new StringType();
+
+  /**
+   * The type of a boolean.
+   */
+  public static final Type<Boolean> BOOLEAN = new BooleanType();
+
+  /**
+   *  The type of a list of not-yet-typed objects.
+   */
+  public static final ObjectListType OBJECT_LIST = new ObjectListType();
+
+  /**
+   *  The type of a list of {@linkplain #STRING strings}.
+   */
+  public static final ListType<String> STRING_LIST = ListType.create(STRING);
+
+  /**
+   *  The type of a list of {@linkplain #INTEGER strings}.
+   */
+  public static final ListType<Integer> INTEGER_LIST = ListType.create(INTEGER);
+
+  /**
+   *  The type of a dictionary of {@linkplain #STRING strings}.
+   */
+  public static final DictType<String, String> STRING_DICT = DictType.create(STRING, STRING);
+
+  /**
+   * The type of a dictionary of {@linkplain #STRING_LIST label lists}.
+   */
+  public static final DictType<String, List<String>> STRING_LIST_DICT =
+      DictType.create(STRING, STRING_LIST);
+
+  /**
+   * The type of a dictionary of {@linkplain #STRING strings}, where each entry
+   * maps to a single string value.
+   */
+  public static final DictType<String, String> STRING_DICT_UNARY = DictType.create(STRING, STRING);
+
+  /**
+   *  For ListType objects, returns the type of the elements of the list; for
+   *  all other types, returns null.  (This non-obvious implementation strategy
+   *  is necessitated by the wildcard capture rules of the Java type system,
+   *  which disallow conversion from Type{List{ELEM}} to Type{List{?}}.)
+   */
+  public Type<?> getListElementType() {
+    return null;
+  }
+
+  /**
+   *  ConversionException is thrown when a type-conversion fails; it contains
+   *  an explanatory error message.
+   */
+  public static class ConversionException extends EvalException {
+    private static String message(Type<?> type, Object value, String what) {
+      StringBuilder builder = new StringBuilder();
+      builder.append("expected value of type '").append(type).append("'");
+      if (what != null) {
+        builder.append(" for ").append(what);
+      }
+      builder.append(", but got ");
+      Printer.write(builder, value);
+      builder.append(" (").append(EvalUtils.getDataTypeName(value)).append(")");
+      return builder.toString();
+    }
+
+    public ConversionException(Type<?> type, Object value, String what) {
+      super(null, message(type, value, what));
+    }
+
+    public ConversionException(String message) {
+      super(null, message);
+    }
+  }
+
+  /********************************************************************
+   *                                                                  *
+   *                            Subclasses                            *
+   *                                                                  *
+   ********************************************************************/
+
+  private static class ObjectType extends Type<Object> {
+    @Override
+    public Object cast(Object value) {
+      return value;
+    }
+
+    @Override
+    public String getDefaultValue() {
+      throw new UnsupportedOperationException(
+          "ObjectType has no default value");
+    }
+
+    @Override
+    public Collection<Object> flatten(Object value) {
+      return NOT_COMPOSITE_TYPE;
+    }
+
+    @Override
+    public String toString() {
+      return "object";
+    }
+
+    @Override
+    public Object convert(Object x, String what, Object context) {
+      return x;
+    }
+  }
+
+  private static class IntegerType extends Type<Integer> {
+    @Override
+    public Integer cast(Object value) {
+      return (Integer) value;
+    }
+
+    @Override
+    public Integer getDefaultValue() {
+      return 0;
+    }
+
+    @Override
+    public Collection<Object> flatten(Object value) {
+      return NOT_COMPOSITE_TYPE;
+    }
+
+    @Override
+    public String toString() {
+      return "int";
+    }
+
+    @Override
+    public Integer convert(Object x, String what, Object context)
+        throws ConversionException {
+      if (!(x instanceof Integer)) {
+        throw new ConversionException(this, x, what);
+      }
+      return (Integer) x;
+    }
+
+    @Override
+    public Integer concat(Iterable<Integer> elements) {
+      int ans = 0;
+      for (Integer elem : elements) {
+        ans += elem;
+      }
+      return Integer.valueOf(ans);
+    }
+  }
+
+  private static class BooleanType extends Type<Boolean> {
+    @Override
+    public Boolean cast(Object value) {
+      return (Boolean) value;
+    }
+
+    @Override
+    public Boolean getDefaultValue() {
+      return false;
+    }
+
+    @Override
+    public Collection<Object> flatten(Object value) {
+      return NOT_COMPOSITE_TYPE;
+    }
+
+    @Override
+    public String toString() {
+      return "boolean";
+    }
+
+    // Conversion to boolean must also tolerate integers of 0 and 1 only.
+    @Override
+    public Boolean convert(Object x, String what, Object context)
+        throws ConversionException {
+      if (x instanceof Boolean) {
+        return (Boolean) x;
+      }
+      Integer xAsInteger = INTEGER.convert(x, what, context);
+      if (xAsInteger == 0) {
+        return false;
+      } else if (xAsInteger == 1) {
+        return true;
+      }
+      throw new ConversionException("boolean is not one of [0, 1]");
+    }
+
+    /**
+     * Booleans attributes are converted to tags based on their names.
+     */
+    @Override
+    public Set<String> toTagSet(Object value, String name) {
+      if (value == null) {
+        String msg = "Illegal tag conversion from null on Attribute " + name  + ".";
+        throw new IllegalStateException(msg);
+      }
+      String tag = (Boolean) value ? name : "no" + name;
+      return ImmutableSet.of(tag);
+    }
+  }
+
+  private static class StringType extends Type<String> {
+    @Override
+    public String cast(Object value) {
+      return (String) value;
+    }
+
+    @Override
+    public String getDefaultValue() {
+      return "";
+    }
+
+    @Override
+    public Collection<Object> flatten(Object value) {
+      return NOT_COMPOSITE_TYPE;
+    }
+
+    @Override
+    public String toString() {
+      return "string";
+    }
+
+    @Override
+    public String convert(Object x, String what, Object context)
+        throws ConversionException {
+      if (!(x instanceof String)) {
+        throw new ConversionException(this, x, what);
+      }
+      return StringCanonicalizer.intern((String) x);
+    }
+
+    @Override
+    public String concat(Iterable<String> elements) {
+      return Joiner.on("").join(elements);
+    }
+
+    /**
+     * A String is representable as a set containing its value.
+     */
+    @Override
+    public Set<String> toTagSet(Object value, String name) {
+      if (value == null) {
+        String msg = "Illegal tag conversion from null on Attribute " + name + ".";
+        throw new IllegalStateException(msg);
+      }
+      return ImmutableSet.of((String) value);
+    }
+  }
+
+  /**
+   * A type to support dictionary attributes.
+   */
+  public static class DictType<KeyT, ValueT> extends Type<Map<KeyT, ValueT>> {
+
+    private final Type<KeyT> keyType;
+    private final Type<ValueT> valueType;
+
+    private final Map<KeyT, ValueT> empty = ImmutableMap.of();
+
+    public static <KEY, VALUE> DictType<KEY, VALUE> create(
+        Type<KEY> keyType, Type<VALUE> valueType) {
+      return new DictType<>(keyType, valueType);
+    }
+
+    private DictType(Type<KeyT> keyType, Type<ValueT> valueType) {
+      this.keyType = keyType;
+      this.valueType = valueType;
+    }
+
+    public Type<KeyT> getKeyType() {
+      return keyType;
+    }
+
+    public Type<ValueT> getValueType() {
+      return valueType;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public Map<KeyT, ValueT> cast(Object value) {
+      return (Map<KeyT, ValueT>) value;
+    }
+
+    @Override
+    public String toString() {
+      return "dict(" + keyType + ", " + valueType + ")";
+    }
+
+    @Override
+    public Map<KeyT, ValueT> convert(Object x, String what, Object context)
+        throws ConversionException {
+      if (!(x instanceof Map<?, ?>)) {
+        throw new ConversionException(String.format(
+            "Expected a map for dictionary but got a %s", x.getClass().getName())); 
+      }
+      // Order the keys so the return value will be independent of insertion order.
+      Map<KeyT, ValueT> result = new TreeMap<>();
+      Map<?, ?> o = (Map<?, ?>) x;
+      for (Entry<?, ?> elem : o.entrySet()) {
+        result.put(
+            keyType.convert(elem.getKey(), "dict key element", context),
+            valueType.convert(elem.getValue(), "dict value element", context));
+      }
+      return ImmutableMap.copyOf(result);
+    }
+
+    @Override
+    public Map<KeyT, ValueT> getDefaultValue() {
+      return empty;
+    }
+
+    @Override
+    public Collection<Object> flatten(Object value) {
+      ImmutableList.Builder<Object> result = ImmutableList.builder();
+      for (Map.Entry<KeyT, ValueT> entry : cast(value).entrySet()) {
+        result.addAll(keyType.flatten(entry.getKey()));
+        result.addAll(valueType.flatten(entry.getValue()));
+      }
+      return result.build();
+    }
+  }
+
+  /** A type for lists of a given element type */
+  public static class ListType<ElemT> extends Type<List<ElemT>> {
+
+    private final Type<ElemT> elemType;
+
+    private final List<ElemT> empty = ImmutableList.of();
+
+    public static <ELEM> ListType<ELEM> create(Type<ELEM> elemType) {
+      return new ListType<>(elemType);
+    }
+
+    private ListType(Type<ElemT> elemType) {
+      this.elemType = elemType;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public List<ElemT> cast(Object value) {
+      return (List<ElemT>) value;
+    }
+
+    @Override
+    public Type<ElemT> getListElementType() {
+      return elemType;
+    }
+
+    @Override
+    public List<ElemT> getDefaultValue() {
+      return empty;
+    }
+
+    @Override
+    public Collection<Object> flatten(Object value) {
+      ImmutableList.Builder<Object> labels = ImmutableList.builder();
+      for (ElemT entry : cast(value)) {
+        labels.addAll(elemType.flatten(entry));
+      }
+      return labels.build();
+    }
+
+    @Override
+    public String toString() {
+      return "list(" + elemType + ")";
+    }
+
+    @Override
+    public List<ElemT> convert(Object x, String what, Object context)
+        throws ConversionException {
+      if (!(x instanceof Iterable<?>)) {
+        throw new ConversionException(this, x, what);
+      }
+      int index = 0;
+      Iterable<?> iterable = (Iterable<?>) x;
+      List<ElemT> result = Lists.newArrayListWithExpectedSize(Iterables.size(iterable));
+      for (Object elem : iterable) {
+        ElemT converted = elemType.convert(elem, "element " + index + " of " + what, context);
+        if (converted != null) {
+          result.add(converted);
+        } else {
+          // shouldn't happen but it does, rarely
+          String message = "Converting a list with a null element: "
+              + "element " + index + " of " + what + " in " + context;
+          LoggingUtil.logToRemote(Level.WARNING, message,
+              new ConversionException(message));
+        }
+        ++index;
+      }
+      if (x instanceof GlobList<?>) {
+        return new GlobList<>(((GlobList<?>) x).getCriteria(), result);
+      } else {
+        return result;
+      }
+    }
+
+    @Override
+    public List<ElemT> concat(Iterable<List<ElemT>> elements) {
+      ImmutableList.Builder<ElemT> builder = ImmutableList.builder();
+      for (List<ElemT> list : elements) {
+        builder.addAll(list);
+      }
+      return builder.build();
+    }
+
+    /**
+     * A list is representable as a tag set as the contents of itself expressed
+     * as Strings. So a {@code List<String>} is effectively converted to a {@code Set<String>}.
+     */
+    @Override
+    public Set<String> toTagSet(Object items, String name) {
+      if (items == null) {
+        String msg = "Illegal tag conversion from null on Attribute" + name + ".";
+        throw new IllegalStateException(msg);
+      }
+      Set<String> tags = new LinkedHashSet<>();
+      @SuppressWarnings("unchecked")
+      List<ElemT> itemsAsListofElem = (List<ElemT>) items;
+      for (ElemT element : itemsAsListofElem) {
+        tags.add(element.toString());
+      }
+      return tags;
+    }
+  }
+
+  /** Type for lists of arbitrary objects */
+  public static class ObjectListType extends ListType<Object> {
+
+    private static final Type<Object> elemType = new ObjectType();
+
+    private ObjectListType() {
+      super(elemType);
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public List<Object> convert(Object x, String what, Object context)
+        throws ConversionException {
+      if (x instanceof SkylarkList) {
+        return ((SkylarkList) x).getList();
+      } else if (x instanceof List) {
+        return (List<Object>) x;
+      } else if (x instanceof Iterable) {
+        return ImmutableList.copyOf((Iterable<?>) x);
+      } else {
+        throw new ConversionException(this, x, what);
+      }
+    }
+  }
+
+  /**
+   * The type of a general list.
+   */
+  public static final ListType<Object> LIST = new ListType<>(new ObjectType());
+}