[tint] Replace std containers with Tint's containers in nodes

Bug: tint:2129
Change-Id: Ia3a2ad733c914465df339b0b7d0c4962c2090fc2
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/171660
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
diff --git a/src/tint/lang/core/type/struct.h b/src/tint/lang/core/type/struct.h
index eec7dab..9ce105a 100644
--- a/src/tint/lang/core/type/struct.h
+++ b/src/tint/lang/core/type/struct.h
@@ -31,7 +31,6 @@
 #include <cstdint>
 #include <optional>
 #include <string>
-#include <unordered_set>
 #include <utility>
 
 #include "src/tint/lang/core/address_space.h"
@@ -39,6 +38,7 @@
 #include "src/tint/lang/core/interpolation.h"
 #include "src/tint/lang/core/type/node.h"
 #include "src/tint/lang/core/type/type.h"
+#include "src/tint/utils/containers/hashset.h"
 #include "src/tint/utils/containers/vector.h"
 #include "src/tint/utils/symbol/symbol.h"
 
@@ -136,16 +136,14 @@
 
     /// Adds the AddressSpace usage to the structure.
     /// @param usage the storage usage
-    void AddUsage(core::AddressSpace usage) { address_space_usage_.emplace(usage); }
+    void AddUsage(core::AddressSpace usage) { address_space_usage_.Add(usage); }
 
     /// @returns the set of address space uses of this structure
-    const std::unordered_set<core::AddressSpace>& AddressSpaceUsage() const {
-        return address_space_usage_;
-    }
+    const Hashset<core::AddressSpace, 1>& AddressSpaceUsage() const { return address_space_usage_; }
 
     /// @param usage the AddressSpace usage type to query
     /// @returns true iff this structure has been used as the given address space
-    bool UsedAs(core::AddressSpace usage) const { return address_space_usage_.count(usage) > 0; }
+    bool UsedAs(core::AddressSpace usage) const { return address_space_usage_.Contains(usage); }
 
     /// @returns true iff this structure has been used by address space that's
     /// host-shareable.
@@ -160,12 +158,10 @@
 
     /// Adds the pipeline stage usage to the structure.
     /// @param usage the storage usage
-    void AddUsage(PipelineStageUsage usage) { pipeline_stage_uses_.emplace(usage); }
+    void AddUsage(PipelineStageUsage usage) { pipeline_stage_uses_.Add(usage); }
 
     /// @returns the set of entry point uses of this structure
-    const std::unordered_set<PipelineStageUsage>& PipelineStageUses() const {
-        return pipeline_stage_uses_;
-    }
+    const Hashset<PipelineStageUsage, 1>& PipelineStageUses() const { return pipeline_stage_uses_; }
 
     /// @returns the name for this type that closely resembles how it would be
     /// declared in WGSL.
@@ -201,8 +197,8 @@
     const uint32_t size_;
     const uint32_t size_no_padding_;
     core::type::StructFlags struct_flags_;
-    std::unordered_set<core::AddressSpace> address_space_usage_;
-    std::unordered_set<PipelineStageUsage> pipeline_stage_uses_;
+    Hashset<core::AddressSpace, 1> address_space_usage_;
+    Hashset<PipelineStageUsage, 1> pipeline_stage_uses_;
     tint::Vector<const Struct*, 2> concrete_types_;
 };
 
diff --git a/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc b/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc
index 5a43388..1f5d4bb 100644
--- a/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc
+++ b/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc
@@ -425,9 +425,9 @@
             [&](const ast::Struct* str) {
                 auto* ty = builder_.Sem().Get(str);
                 auto address_space_uses = ty->AddressSpaceUsage();
-                if (address_space_uses.size() !=
-                    (address_space_uses.count(core::AddressSpace::kStorage) +
-                     address_space_uses.count(core::AddressSpace::kUniform))) {
+                if (address_space_uses.Count() !=
+                    ((address_space_uses.Contains(core::AddressSpace::kStorage) ? 1u : 0u) +
+                     (address_space_uses.Contains(core::AddressSpace::kUniform) ? 1u : 0u))) {
                     // The structure is used as something other than a storage buffer or
                     // uniform buffer, so it needs to be emitted.
                     // Storage buffer are read and written to via a ByteAddressBuffer
@@ -4554,18 +4554,18 @@
 
             if (auto location = attributes.location) {
                 auto& pipeline_stage_uses = str->PipelineStageUses();
-                if (TINT_UNLIKELY(pipeline_stage_uses.size() != 1)) {
+                if (TINT_UNLIKELY(pipeline_stage_uses.Count() != 1)) {
                     TINT_ICE() << "invalid entry point IO struct uses";
                 }
-                if (pipeline_stage_uses.count(core::type::PipelineStageUsage::kVertexInput)) {
+                if (pipeline_stage_uses.Contains(core::type::PipelineStageUsage::kVertexInput)) {
                     post += " : TEXCOORD" + std::to_string(location.value());
-                } else if (pipeline_stage_uses.count(
+                } else if (pipeline_stage_uses.Contains(
                                core::type::PipelineStageUsage::kVertexOutput)) {
                     post += " : TEXCOORD" + std::to_string(location.value());
-                } else if (pipeline_stage_uses.count(
+                } else if (pipeline_stage_uses.Contains(
                                core::type::PipelineStageUsage::kFragmentInput)) {
                     post += " : TEXCOORD" + std::to_string(location.value());
-                } else if (TINT_LIKELY(pipeline_stage_uses.count(
+                } else if (TINT_LIKELY(pipeline_stage_uses.Contains(
                                core::type::PipelineStageUsage::kFragmentOutput))) {
                     if (auto index = attributes.index) {
                         post += " : SV_Target" + std::to_string(location.value() + index.value());
diff --git a/src/tint/lang/msl/writer/ast_printer/ast_printer.cc b/src/tint/lang/msl/writer/ast_printer/ast_printer.cc
index 81caedb..d19aa2e 100644
--- a/src/tint/lang/msl/writer/ast_printer/ast_printer.cc
+++ b/src/tint/lang/msl/writer/ast_printer/ast_printer.cc
@@ -2798,18 +2798,20 @@
 
         if (auto location = attributes.location) {
             auto& pipeline_stage_uses = str->PipelineStageUses();
-            if (TINT_UNLIKELY(pipeline_stage_uses.size() != 1)) {
+            if (TINT_UNLIKELY(pipeline_stage_uses.Count() != 1)) {
                 TINT_ICE() << "invalid entry point IO struct uses for " << str->Name().NameView();
                 return false;
             }
 
-            if (pipeline_stage_uses.count(core::type::PipelineStageUsage::kVertexInput)) {
+            if (pipeline_stage_uses.Contains(core::type::PipelineStageUsage::kVertexInput)) {
                 out << " [[attribute(" + std::to_string(location.value()) + ")]]";
-            } else if (pipeline_stage_uses.count(core::type::PipelineStageUsage::kVertexOutput)) {
+            } else if (pipeline_stage_uses.Contains(
+                           core::type::PipelineStageUsage::kVertexOutput)) {
                 out << " [[user(locn" + std::to_string(location.value()) + ")]]";
-            } else if (pipeline_stage_uses.count(core::type::PipelineStageUsage::kFragmentInput)) {
+            } else if (pipeline_stage_uses.Contains(
+                           core::type::PipelineStageUsage::kFragmentInput)) {
                 out << " [[user(locn" + std::to_string(location.value()) + ")]]";
-            } else if (TINT_LIKELY(pipeline_stage_uses.count(
+            } else if (TINT_LIKELY(pipeline_stage_uses.Contains(
                            core::type::PipelineStageUsage::kFragmentOutput))) {
                 if (auto index = attributes.index) {
                     out << " [[color(" + std::to_string(location.value()) + ") index(" +
diff --git a/src/tint/lang/msl/writer/printer/printer.cc b/src/tint/lang/msl/writer/printer/printer.cc
index e2950c5..0e8988e 100644
--- a/src/tint/lang/msl/writer/printer/printer.cc
+++ b/src/tint/lang/msl/writer/printer/printer.cc
@@ -1263,20 +1263,20 @@
 
             if (auto location = attributes.location) {
                 auto& pipeline_stage_uses = str->PipelineStageUses();
-                if (TINT_UNLIKELY(pipeline_stage_uses.size() != 1)) {
+                if (TINT_UNLIKELY(pipeline_stage_uses.Count() != 1)) {
                     TINT_IR_ICE(ir_) << "invalid entry point IO struct uses";
                     return;
                 }
 
-                if (pipeline_stage_uses.count(core::type::PipelineStageUsage::kVertexInput)) {
+                if (pipeline_stage_uses.Contains(core::type::PipelineStageUsage::kVertexInput)) {
                     out << " [[attribute(" + std::to_string(location.value()) + ")]]";
-                } else if (pipeline_stage_uses.count(
+                } else if (pipeline_stage_uses.Contains(
                                core::type::PipelineStageUsage::kVertexOutput)) {
                     out << " [[user(locn" + std::to_string(location.value()) + ")]]";
-                } else if (pipeline_stage_uses.count(
+                } else if (pipeline_stage_uses.Contains(
                                core::type::PipelineStageUsage::kFragmentInput)) {
                     out << " [[user(locn" + std::to_string(location.value()) + ")]]";
-                } else if (TINT_LIKELY(pipeline_stage_uses.count(
+                } else if (TINT_LIKELY(pipeline_stage_uses.Contains(
                                core::type::PipelineStageUsage::kFragmentOutput))) {
                     out << " [[color(" + std::to_string(location.value()) + ")]]";
                 } else {
diff --git a/src/tint/lang/wgsl/diagnostic_severity.h b/src/tint/lang/wgsl/diagnostic_severity.h
index dfccb5d..88eba28 100644
--- a/src/tint/lang/wgsl/diagnostic_severity.h
+++ b/src/tint/lang/wgsl/diagnostic_severity.h
@@ -38,9 +38,9 @@
 #define SRC_TINT_LANG_WGSL_DIAGNOSTIC_SEVERITY_H_
 
 #include <string>
-#include <unordered_map>
 
 #include "src/tint/lang/wgsl/diagnostic_rule.h"
+#include "src/tint/utils/containers/hashmap.h"
 #include "src/tint/utils/diagnostic/diagnostic.h"
 #include "src/tint/utils/traits/traits.h"
 
@@ -83,7 +83,7 @@
 diag::Severity ToSeverity(DiagnosticSeverity sc);
 
 /// DiagnosticRuleSeverities is a map from diagnostic rule to diagnostic severity.
-using DiagnosticRuleSeverities = std::unordered_map<DiagnosticRule, DiagnosticSeverity>;
+using DiagnosticRuleSeverities = Hashmap<DiagnosticRule, DiagnosticSeverity, 1>;
 
 }  // namespace tint::wgsl
 
diff --git a/src/tint/lang/wgsl/diagnostic_severity.h.tmpl b/src/tint/lang/wgsl/diagnostic_severity.h.tmpl
index 045591f..40714cb 100644
--- a/src/tint/lang/wgsl/diagnostic_severity.h.tmpl
+++ b/src/tint/lang/wgsl/diagnostic_severity.h.tmpl
@@ -15,11 +15,11 @@
 #define SRC_TINT_LANG_WGSL_DIAGNOSTIC_SEVERITY_H_
 
 #include <string>
-#include <unordered_map>
 
-#include "src/tint/utils/traits/traits.h"
 #include "src/tint/lang/wgsl/diagnostic_rule.h"
+#include "src/tint/utils/containers/hashmap.h"
 #include "src/tint/utils/diagnostic/diagnostic.h"
+#include "src/tint/utils/traits/traits.h"
 
 namespace tint::wgsl {
 
@@ -30,7 +30,7 @@
 diag::Severity ToSeverity(DiagnosticSeverity sc);
 
 /// DiagnosticRuleSeverities is a map from diagnostic rule to diagnostic severity.
-using DiagnosticRuleSeverities = std::unordered_map<DiagnosticRule, DiagnosticSeverity>;
+using DiagnosticRuleSeverities = Hashmap<DiagnosticRule, DiagnosticSeverity, 1>;
 
 }  // namespace tint::wgsl
 
diff --git a/src/tint/lang/wgsl/resolver/resolver.cc b/src/tint/lang/wgsl/resolver/resolver.cc
index ea351a2..d8d4754 100644
--- a/src/tint/lang/wgsl/resolver/resolver.cc
+++ b/src/tint/lang/wgsl/resolver/resolver.cc
@@ -4879,7 +4879,7 @@
     ty = const_cast<core::type::Type*>(ty->UnwrapRef());
 
     if (auto* str = ty->As<sem::Struct>()) {
-        if (str->AddressSpaceUsage().count(address_space)) {
+        if (str->AddressSpaceUsage().Contains(address_space)) {
             return true;  // Already applied
         }
 
diff --git a/src/tint/lang/wgsl/resolver/struct_address_space_use_test.cc b/src/tint/lang/wgsl/resolver/struct_address_space_use_test.cc
index bf5f835..5e017fc 100644
--- a/src/tint/lang/wgsl/resolver/struct_address_space_use_test.cc
+++ b/src/tint/lang/wgsl/resolver/struct_address_space_use_test.cc
@@ -47,7 +47,7 @@
 
     auto* sem = TypeOf(s)->As<core::type::Struct>();
     ASSERT_NE(sem, nullptr);
-    EXPECT_TRUE(sem->AddressSpaceUsage().empty());
+    EXPECT_TRUE(sem->AddressSpaceUsage().IsEmpty());
 }
 
 TEST_F(ResolverAddressSpaceUseTest, StructReachableFromParameter) {
diff --git a/src/tint/lang/wgsl/resolver/struct_pipeline_stage_use_test.cc b/src/tint/lang/wgsl/resolver/struct_pipeline_stage_use_test.cc
index d3537db..cb0adab 100644
--- a/src/tint/lang/wgsl/resolver/struct_pipeline_stage_use_test.cc
+++ b/src/tint/lang/wgsl/resolver/struct_pipeline_stage_use_test.cc
@@ -49,7 +49,7 @@
 
     auto* sem = TypeOf(s)->As<core::type::Struct>();
     ASSERT_NE(sem, nullptr);
-    EXPECT_TRUE(sem->PipelineStageUses().empty());
+    EXPECT_TRUE(sem->PipelineStageUses().IsEmpty());
 }
 
 TEST_F(ResolverPipelineStageUseTest, StructUsedAsNonEntryPointParam) {
@@ -61,7 +61,7 @@
 
     auto* sem = TypeOf(s)->As<core::type::Struct>();
     ASSERT_NE(sem, nullptr);
-    EXPECT_TRUE(sem->PipelineStageUses().empty());
+    EXPECT_TRUE(sem->PipelineStageUses().IsEmpty());
 }
 
 TEST_F(ResolverPipelineStageUseTest, StructUsedAsNonEntryPointReturnType) {
@@ -73,7 +73,7 @@
 
     auto* sem = TypeOf(s)->As<core::type::Struct>();
     ASSERT_NE(sem, nullptr);
-    EXPECT_TRUE(sem->PipelineStageUses().empty());
+    EXPECT_TRUE(sem->PipelineStageUses().IsEmpty());
 }
 
 TEST_F(ResolverPipelineStageUseTest, StructUsedAsVertexShaderParam) {
diff --git a/src/tint/lang/wgsl/sem/function.cc b/src/tint/lang/wgsl/sem/function.cc
index 9a56376..311c903 100644
--- a/src/tint/lang/wgsl/sem/function.cc
+++ b/src/tint/lang/wgsl/sem/function.cc
@@ -201,4 +201,8 @@
     return ret;
 }
 
+void Function::SetDiagnosticSeverity(wgsl::DiagnosticRule rule, wgsl::DiagnosticSeverity severity) {
+    diagnostic_severities_.Add(rule, severity);
+}
+
 }  // namespace tint::sem
diff --git a/src/tint/lang/wgsl/sem/function.h b/src/tint/lang/wgsl/sem/function.h
index a2a87ae..797dbef 100644
--- a/src/tint/lang/wgsl/sem/function.h
+++ b/src/tint/lang/wgsl/sem/function.h
@@ -278,9 +278,7 @@
     /// Modifies the severity of a specific diagnostic rule for this function.
     /// @param rule the diagnostic rule
     /// @param severity the new diagnostic severity
-    void SetDiagnosticSeverity(wgsl::DiagnosticRule rule, wgsl::DiagnosticSeverity severity) {
-        diagnostic_severities_[rule] = severity;
-    }
+    void SetDiagnosticSeverity(wgsl::DiagnosticRule rule, wgsl::DiagnosticSeverity severity);
 
     /// @returns the diagnostic severity modifications applied to this function
     const wgsl::DiagnosticRuleSeverities& DiagnosticSeverities() const {
diff --git a/src/tint/lang/wgsl/sem/info.cc b/src/tint/lang/wgsl/sem/info.cc
index e9b59be..bfd6c0d 100644
--- a/src/tint/lang/wgsl/sem/info.cc
+++ b/src/tint/lang/wgsl/sem/info.cc
@@ -47,10 +47,8 @@
                                                   wgsl::DiagnosticRule rule) const {
     // Get the diagnostic severity modification for a node.
     auto check = [&](auto* node) {
-        auto& severities = node->DiagnosticSeverities();
-        auto itr = severities.find(rule);
-        if (itr != severities.end()) {
-            return itr->second;
+        if (auto severity = node->DiagnosticSeverities().Get(rule)) {
+            return *severity;
         }
         return wgsl::DiagnosticSeverity::kUndefined;
     };
diff --git a/src/tint/lang/wgsl/sem/module.cc b/src/tint/lang/wgsl/sem/module.cc
index 6e04901..178d662 100644
--- a/src/tint/lang/wgsl/sem/module.cc
+++ b/src/tint/lang/wgsl/sem/module.cc
@@ -39,4 +39,8 @@
 
 Module::~Module() = default;
 
+void Module::SetDiagnosticSeverity(wgsl::DiagnosticRule rule, wgsl::DiagnosticSeverity severity) {
+    diagnostic_severities_.Add(rule, severity);
+}
+
 }  // namespace tint::sem
diff --git a/src/tint/lang/wgsl/sem/module.h b/src/tint/lang/wgsl/sem/module.h
index c95798e..98c1022 100644
--- a/src/tint/lang/wgsl/sem/module.h
+++ b/src/tint/lang/wgsl/sem/module.h
@@ -61,9 +61,7 @@
     /// Modifies the severity of a specific diagnostic rule for this module.
     /// @param rule the diagnostic rule
     /// @param severity the new diagnostic severity
-    void SetDiagnosticSeverity(wgsl::DiagnosticRule rule, wgsl::DiagnosticSeverity severity) {
-        diagnostic_severities_[rule] = severity;
-    }
+    void SetDiagnosticSeverity(wgsl::DiagnosticRule rule, wgsl::DiagnosticSeverity severity);
 
     /// @returns the diagnostic severity modifications applied to this module
     const wgsl::DiagnosticRuleSeverities& DiagnosticSeverities() const {
diff --git a/src/tint/lang/wgsl/sem/statement.cc b/src/tint/lang/wgsl/sem/statement.cc
index 8497bb4..0e1a8c7 100644
--- a/src/tint/lang/wgsl/sem/statement.cc
+++ b/src/tint/lang/wgsl/sem/statement.cc
@@ -52,6 +52,11 @@
     return FindFirstParent<BlockStatement>();
 }
 
+void Statement::SetDiagnosticSeverity(wgsl::DiagnosticRule rule,
+                                      wgsl::DiagnosticSeverity severity) {
+    diagnostic_severities_.Add(rule, severity);
+}
+
 CompoundStatement::CompoundStatement(const ast::Statement* declaration,
                                      const CompoundStatement* parent,
                                      const sem::Function* function)
diff --git a/src/tint/lang/wgsl/sem/statement.h b/src/tint/lang/wgsl/sem/statement.h
index 88e1685..2e023fc 100644
--- a/src/tint/lang/wgsl/sem/statement.h
+++ b/src/tint/lang/wgsl/sem/statement.h
@@ -126,9 +126,7 @@
     /// Modifies the severity of a specific diagnostic rule for this statement.
     /// @param rule the diagnostic rule
     /// @param severity the new diagnostic severity
-    void SetDiagnosticSeverity(wgsl::DiagnosticRule rule, wgsl::DiagnosticSeverity severity) {
-        diagnostic_severities_[rule] = severity;
-    }
+    void SetDiagnosticSeverity(wgsl::DiagnosticRule rule, wgsl::DiagnosticSeverity severity);
 
     /// @returns the diagnostic severity modifications applied to this statement
     const wgsl::DiagnosticRuleSeverities& DiagnosticSeverities() const {