symbol: Add operator<()

Change-Id: I8e3eafd775a3aaa20cf8425e45f5bcae1e9e9851
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/60206
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/symbol.cc b/src/symbol.cc
index e77c699..9dc5726 100644
--- a/src/symbol.cc
+++ b/src/symbol.cc
@@ -37,6 +37,12 @@
   return val_ == other.val_;
 }
 
+bool Symbol::operator<(const Symbol& other) const {
+  TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(Symbol, program_id_,
+                                         other.program_id_);
+  return val_ < other.val_;
+}
+
 std::string Symbol::to_str() const {
   return "$" + std::to_string(val_);
 }
diff --git a/src/symbol.h b/src/symbol.h
index 286e20d..4567ca8 100644
--- a/src/symbol.h
+++ b/src/symbol.h
@@ -54,6 +54,11 @@
   /// @returns true if the symbols are the same
   bool operator==(const Symbol& o) const;
 
+  /// Less-than operator
+  /// @param o the other symbol
+  /// @returns true if this symbol is ordered before symbol `o`
+  bool operator<(const Symbol& o) const;
+
   /// @returns true if the symbol is valid
   bool IsValid() const { return val_ != static_cast<uint32_t>(-1); }