[tint] Use explicitly (small) sized enums

Reduces memory usage of these enums.

Change-Id: Id04602611168bf6836ec7e2f99d4a651574d5ccc
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/145542
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
diff --git a/src/tint/lang/core/access.h b/src/tint/lang/core/access.h
index cd9303f..40e11c6 100644
--- a/src/tint/lang/core/access.h
+++ b/src/tint/lang/core/access.h
@@ -28,7 +28,7 @@
 namespace tint::core {
 
 /// Address space of a given pointer.
-enum class Access {
+enum class Access : uint8_t {
     kUndefined,
     kRead,
     kReadWrite,
diff --git a/src/tint/lang/core/address_space.h b/src/tint/lang/core/address_space.h
index dcd601c..ee0a638 100644
--- a/src/tint/lang/core/address_space.h
+++ b/src/tint/lang/core/address_space.h
@@ -28,7 +28,7 @@
 namespace tint::core {
 
 /// Address space of a given pointer.
-enum class AddressSpace {
+enum class AddressSpace : uint8_t {
     kUndefined,
     kIn,
     kOut,
diff --git a/src/tint/lang/core/attribute.h b/src/tint/lang/core/attribute.h
index c451522..4b2b6ab 100644
--- a/src/tint/lang/core/attribute.h
+++ b/src/tint/lang/core/attribute.h
@@ -31,7 +31,7 @@
 namespace tint::core {
 
 /// Address space of a given pointer.
-enum class Attribute {
+enum class Attribute : uint8_t {
     kUndefined,
     kAlign,
     kBinding,
diff --git a/src/tint/lang/core/builtin.h b/src/tint/lang/core/builtin.h
index bb364ec..34abb0e 100644
--- a/src/tint/lang/core/builtin.h
+++ b/src/tint/lang/core/builtin.h
@@ -28,7 +28,7 @@
 namespace tint::core {
 
 /// An enumerator of builtin builtin.
-enum class Builtin {
+enum class Builtin : uint8_t {
     kUndefined,
     kAtomicCompareExchangeResultI32,
     kAtomicCompareExchangeResultU32,
diff --git a/src/tint/lang/core/builtin_value.h b/src/tint/lang/core/builtin_value.h
index 835febb..d50da40 100644
--- a/src/tint/lang/core/builtin_value.h
+++ b/src/tint/lang/core/builtin_value.h
@@ -28,7 +28,7 @@
 namespace tint::core {
 
 /// Builtin value defined with `@builtin(<name>)`.
-enum class BuiltinValue {
+enum class BuiltinValue : uint8_t {
     kUndefined,
     kPointSize,
     kFragDepth,
diff --git a/src/tint/lang/core/diagnostic_rule.h b/src/tint/lang/core/diagnostic_rule.h
index cac3095..f1cbf50 100644
--- a/src/tint/lang/core/diagnostic_rule.h
+++ b/src/tint/lang/core/diagnostic_rule.h
@@ -31,7 +31,7 @@
 namespace tint::core {
 
 /// WGSL core diagnostic rules.
-enum class CoreDiagnosticRule {
+enum class CoreDiagnosticRule : uint8_t {
     kUndefined,
     kDerivativeUniformity,
 };
@@ -58,7 +58,7 @@
 };
 
 /// Chromium-specific diagnostic rules.
-enum class ChromiumDiagnosticRule {
+enum class ChromiumDiagnosticRule : uint8_t {
     kUndefined,
     kUnreachableCode,
 };
diff --git a/src/tint/lang/core/diagnostic_severity.h b/src/tint/lang/core/diagnostic_severity.h
index 95424d6..1ff5b5f 100644
--- a/src/tint/lang/core/diagnostic_severity.h
+++ b/src/tint/lang/core/diagnostic_severity.h
@@ -33,7 +33,7 @@
 namespace tint::core {
 
 /// The diagnostic severity control.
-enum class DiagnosticSeverity {
+enum class DiagnosticSeverity : uint8_t {
     kUndefined,
     kError,
     kInfo,
diff --git a/src/tint/lang/core/extension.h b/src/tint/lang/core/extension.h
index 5d5a38c..5a3b6d8 100644
--- a/src/tint/lang/core/extension.h
+++ b/src/tint/lang/core/extension.h
@@ -30,7 +30,7 @@
 
 /// An enumerator of WGSL extensions
 /// @see src/tint/lang/wgsl/intrinsics.def for extension descriptions
-enum class Extension {
+enum class Extension : uint8_t {
     kUndefined,
     kChromiumDisableUniformityAnalysis,
     kChromiumExperimentalDp4A,
diff --git a/src/tint/lang/core/function.h b/src/tint/lang/core/function.h
index c6a077e..c7a3263 100644
--- a/src/tint/lang/core/function.h
+++ b/src/tint/lang/core/function.h
@@ -31,8 +31,7 @@
 namespace tint::core {
 
 /// Enumerator of all builtin functions
-enum class Function {
-    kNone = -1,
+enum class Function : uint8_t {
     kAbs,
     kAcos,
     kAcosh,
@@ -148,6 +147,7 @@
     kAtomicCompareExchangeWeak,
     kSubgroupBallot,
     kTintMaterialize,
+    kNone,
 };
 
 /// Matches the Function by name
diff --git a/src/tint/lang/core/function.h.tmpl b/src/tint/lang/core/function.h.tmpl
index f0cd8b3..c040e1a 100644
--- a/src/tint/lang/core/function.h.tmpl
+++ b/src/tint/lang/core/function.h.tmpl
@@ -24,11 +24,11 @@
 namespace tint::core {
 
 /// Enumerator of all builtin functions
-enum class Function {
-    kNone = -1,
+enum class Function : uint8_t {
 {{- range $I.Sem.Builtins }}
     k{{PascalCase .Name}},
 {{- end }}
+    kNone,
 };
 
 /// Matches the Function by name
diff --git a/src/tint/lang/core/interpolation_sampling.h b/src/tint/lang/core/interpolation_sampling.h
index d907bbd..6fabea3 100644
--- a/src/tint/lang/core/interpolation_sampling.h
+++ b/src/tint/lang/core/interpolation_sampling.h
@@ -30,7 +30,7 @@
 namespace tint::core {
 
 /// The interpolation sampling.
-enum class InterpolationSampling {
+enum class InterpolationSampling : uint8_t {
     kUndefined,
     kCenter,
     kCentroid,
diff --git a/src/tint/lang/core/interpolation_type.h b/src/tint/lang/core/interpolation_type.h
index e90dd71..546f3c1 100644
--- a/src/tint/lang/core/interpolation_type.h
+++ b/src/tint/lang/core/interpolation_type.h
@@ -30,7 +30,7 @@
 namespace tint::core {
 
 /// The interpolation type.
-enum class InterpolationType {
+enum class InterpolationType : uint8_t {
     kUndefined,
     kFlat,
     kLinear,
diff --git a/src/tint/lang/core/intrinsic/ctor_conv.h b/src/tint/lang/core/intrinsic/ctor_conv.h
index 3e7e762..67ff261 100644
--- a/src/tint/lang/core/intrinsic/ctor_conv.h
+++ b/src/tint/lang/core/intrinsic/ctor_conv.h
@@ -29,8 +29,7 @@
 
 /// CtorConv is an enumerator of types that have a constructor or converter overload
 /// declared in the intrinsic table.
-enum class CtorConv {
-    kNone = -1,
+enum class CtorConv : uint8_t {
     kI32,
     kU32,
     kF32,
@@ -49,6 +48,7 @@
     kMat4x3,
     kMat4x4,
     kPackedVec3,
+    kNone,
 };
 
 /// @returns the name of the type.
diff --git a/src/tint/lang/core/intrinsic/ctor_conv.h.tmpl b/src/tint/lang/core/intrinsic/ctor_conv.h.tmpl
index b61ae9a..bf99e91 100644
--- a/src/tint/lang/core/intrinsic/ctor_conv.h.tmpl
+++ b/src/tint/lang/core/intrinsic/ctor_conv.h.tmpl
@@ -22,11 +22,11 @@
 
 /// CtorConv is an enumerator of types that have a constructor or converter overload
 /// declared in the intrinsic table.
-enum class CtorConv {
-    kNone = -1,
+enum class CtorConv : uint8_t {
 {{- range $I.Sem.ConstructorsAndConverters }}
     k{{Title .Name}},
 {{- end }}
+    kNone,
 };
 
 /// @returns the name of the type.
diff --git a/src/tint/lang/core/parameter_usage.h b/src/tint/lang/core/parameter_usage.h
index 53c2604..1173c68 100644
--- a/src/tint/lang/core/parameter_usage.h
+++ b/src/tint/lang/core/parameter_usage.h
@@ -31,8 +31,7 @@
 
 /// ParameterUsage is extra metadata for identifying a parameter based on its
 /// overload position
-enum class ParameterUsage {
-    kNone = -1,
+enum class ParameterUsage : uint8_t {
     kArrayIndex,
     kBias,
     kComponent,
@@ -55,6 +54,7 @@
     kZ,
     kZw,
     kZyw,
+    kNone,
 };
 
 /// @param value the enum value
diff --git a/src/tint/lang/core/parameter_usage.h.tmpl b/src/tint/lang/core/parameter_usage.h.tmpl
index 7c3af98..06c9fe2 100644
--- a/src/tint/lang/core/parameter_usage.h.tmpl
+++ b/src/tint/lang/core/parameter_usage.h.tmpl
@@ -24,11 +24,11 @@
 
 /// ParameterUsage is extra metadata for identifying a parameter based on its
 /// overload position
-enum class ParameterUsage {
-    kNone = -1,
+enum class ParameterUsage : uint8_t {
 {{- range $I.Sem.UniqueParameterNames  }}
     k{{PascalCase .}},
 {{- end  }}
+    kNone,
 };
 
 /// @param value the enum value
diff --git a/src/tint/lang/core/texel_format.h b/src/tint/lang/core/texel_format.h
index 4a9f38c..dced90e 100644
--- a/src/tint/lang/core/texel_format.h
+++ b/src/tint/lang/core/texel_format.h
@@ -28,7 +28,7 @@
 namespace tint::core {
 
 /// Enumerator of texel formats
-enum class TexelFormat {
+enum class TexelFormat : uint8_t {
     kUndefined,
     kBgra8Unorm,
     kR32Float,
diff --git a/src/tint/lang/core/type/texture_dimension.h b/src/tint/lang/core/type/texture_dimension.h
index f77c796..6bab7bd 100644
--- a/src/tint/lang/core/type/texture_dimension.h
+++ b/src/tint/lang/core/type/texture_dimension.h
@@ -21,9 +21,7 @@
 namespace tint::core::type {
 
 /// The dimensionality of the texture
-enum class TextureDimension {
-    /// Invalid texture
-    kNone = -1,
+enum class TextureDimension : uint8_t {
     /// 1 dimensional texture
     k1d,
     /// 2 dimensional texture
@@ -36,6 +34,8 @@
     kCube,
     /// cube array texture
     kCubeArray,
+    /// Invalid texture
+    kNone,
 };
 
 /// @param dim the enum value
diff --git a/src/tint/lang/wgsl/ast/pipeline_stage.h b/src/tint/lang/wgsl/ast/pipeline_stage.h
index 8d0c7c3..2dbb905 100644
--- a/src/tint/lang/wgsl/ast/pipeline_stage.h
+++ b/src/tint/lang/wgsl/ast/pipeline_stage.h
@@ -21,7 +21,7 @@
 namespace tint::ast {
 
 /// The pipeline stage
-enum class PipelineStage { kNone = -1, kVertex, kFragment, kCompute };
+enum class PipelineStage : uint8_t { kVertex, kFragment, kCompute, kNone };
 
 /// @param stage the enum value
 /// @returns the string for the given enum value
diff --git a/src/tint/lang/wgsl/inspector/entry_point.h b/src/tint/lang/wgsl/inspector/entry_point.h
index f3616af..4194ec9 100644
--- a/src/tint/lang/wgsl/inspector/entry_point.h
+++ b/src/tint/lang/wgsl/inspector/entry_point.h
@@ -28,28 +28,28 @@
 namespace tint::inspector {
 
 /// Base component type of a stage variable.
-enum class ComponentType {
-    kUnknown = -1,
+enum class ComponentType : uint8_t {
     kF32,
     kU32,
     kI32,
     kF16,
+    kUnknown,
 };
 
 /// Composition of components of a stage variable.
-enum class CompositionType {
-    kUnknown = -1,
+enum class CompositionType : uint8_t {
     kScalar,
     kVec2,
     kVec3,
     kVec4,
+    kUnknown,
 };
 
 /// Type of interpolation of a stage variable.
-enum class InterpolationType { kUnknown = -1, kPerspective, kLinear, kFlat };
+enum class InterpolationType : uint8_t { kPerspective, kLinear, kFlat, kUnknown };
 
 /// Type of interpolation sampling of a stage variable.
-enum class InterpolationSampling { kUnknown = -1, kNone, kCenter, kCentroid, kSample };
+enum class InterpolationSampling : uint8_t { kNone, kCenter, kCentroid, kSample, kUnknown };
 
 /// Reflection data about an entry point input or output.
 struct StageVariable {
diff --git a/src/tint/lang/wgsl/inspector/resource_binding.h b/src/tint/lang/wgsl/inspector/resource_binding.h
index c9d372c..ed7e70d 100644
--- a/src/tint/lang/wgsl/inspector/resource_binding.h
+++ b/src/tint/lang/wgsl/inspector/resource_binding.h
@@ -26,9 +26,7 @@
 /// Container for information about how a resource is bound
 struct ResourceBinding {
     /// The dimensionality of a texture
-    enum class TextureDimension {
-        /// Invalid texture
-        kNone = -1,
+    enum class TextureDimension : uint8_t {
         /// 1 dimensional texture
         k1d,
         /// 2 dimensional texture
@@ -41,16 +39,16 @@
         kCube,
         /// cube array texture
         kCubeArray,
+        /// Invalid texture
+        kNone,
     };
 
     /// Component type of the texture's data. Same as the Sampled Type parameter
     /// in SPIR-V OpTypeImage.
-    enum class SampledKind { kUnknown = -1, kFloat, kUInt, kSInt };
+    enum class SampledKind : uint8_t { kFloat, kUInt, kSInt, kUnknown };
 
     /// Enumerator of texel image formats
-    enum class TexelFormat {
-        kNone = -1,
-
+    enum class TexelFormat : uint8_t {
         kBgra8Unorm,
         kRgba8Unorm,
         kRgba8Snorm,
@@ -68,6 +66,7 @@
         kRgba32Uint,
         kRgba32Sint,
         kRgba32Float,
+        kNone,
     };
 
     /// kXXX maps to entries returned by GetXXXResourceBindings call.
diff --git a/src/tint/lang/wgsl/sem/type_mappings.h b/src/tint/lang/wgsl/sem/type_mappings.h
index d8f3cc2..2dfb6ac 100644
--- a/src/tint/lang/wgsl/sem/type_mappings.h
+++ b/src/tint/lang/wgsl/sem/type_mappings.h
@@ -47,7 +47,7 @@
 class UnaryOpExpression;
 }  // namespace tint::ast
 namespace tint::core {
-enum class BuiltinValue;
+enum class BuiltinValue : uint8_t;
 }
 namespace tint::sem {
 class Expression;
diff --git a/src/tint/lang/wgsl/writer/ast_printer/ast_printer.h b/src/tint/lang/wgsl/writer/ast_printer/ast_printer.h
index c84fa13..525b683 100644
--- a/src/tint/lang/wgsl/writer/ast_printer/ast_printer.h
+++ b/src/tint/lang/wgsl/writer/ast_printer/ast_printer.h
@@ -67,7 +67,7 @@
 }  // namespace tint::ast
 
 namespace tint::core {
-enum class TexelFormat;
+enum class TexelFormat : uint8_t;
 }  // namespace tint::core
 
 namespace tint::wgsl::writer {
diff --git a/src/tint/lang/wgsl/writer/syntax_tree_printer/syntax_tree_printer.h b/src/tint/lang/wgsl/writer/syntax_tree_printer/syntax_tree_printer.h
index 94e0522..4ef93a1 100644
--- a/src/tint/lang/wgsl/writer/syntax_tree_printer/syntax_tree_printer.h
+++ b/src/tint/lang/wgsl/writer/syntax_tree_printer/syntax_tree_printer.h
@@ -66,7 +66,7 @@
 class WhileStatement;
 }  // namespace tint::ast
 namespace tint::core {
-enum class TexelFormat;
+enum class TexelFormat : uint8_t;
 }  // namespace tint::core
 
 namespace tint::wgsl::writer {
diff --git a/src/tint/utils/templates/enums.tmpl.inc b/src/tint/utils/templates/enums.tmpl.inc
index 47a3435..5bd899e 100644
--- a/src/tint/utils/templates/enums.tmpl.inc
+++ b/src/tint/utils/templates/enums.tmpl.inc
@@ -40,7 +40,7 @@
 {{- /* Declares the 'enum class' for the provided sem.Enum argument.      */ -}}
 {{- /* ------------------------------------------------------------------ */ -}}
 {{- $enum := Eval "EnumName" $ -}}
-enum class {{$enum}} {
+enum class {{$enum}} : uint8_t {
     kUndefined,
 {{-   range $entry := $.Entries }}
     k{{PascalCase $entry.Name}},{{if $entry.IsInternal}}  // Tint-internal enum entry - not parsed{{end}}