[tint][wgsl] Replace size_t with uint32_t for IDs, Source.

These are used by all AST nodes, and substantially bloat the size of
each and every node. Reducing the size of these substantially reduces
the amount of memory held by a Program, and provides a decent
performance increase due to better cache locality and fewer heap
allocations.

Bug: tint:2129
Change-Id: I204f4f0fa6ce68828c389132b198d6e97f5e1578
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/171802
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/tint/lang/spirv/validate/validate.cc b/src/tint/lang/spirv/validate/validate.cc
index 8d85413..c692a53 100644
--- a/src/tint/lang/spirv/validate/validate.cc
+++ b/src/tint/lang/spirv/validate/validate.cc
@@ -44,8 +44,8 @@
         [&](spv_message_level_t level, const char*, const spv_position_t& pos, const char* msg) {
             diag::Diagnostic diag;
             diag.message = msg;
-            diag.source.range.begin.line = pos.line + 1;
-            diag.source.range.begin.column = pos.column + 1;
+            diag.source.range.begin.line = static_cast<uint32_t>(pos.line) + 1;
+            diag.source.range.begin.column = static_cast<uint32_t>(pos.column) + 1;
             diag.source.range.end = diag.source.range.begin;
             switch (level) {
                 case SPV_MSG_FATAL:
diff --git a/src/tint/lang/wgsl/ast/node_id.h b/src/tint/lang/wgsl/ast/node_id.h
index 556f6fe..36096c3 100644
--- a/src/tint/lang/wgsl/ast/node_id.h
+++ b/src/tint/lang/wgsl/ast/node_id.h
@@ -29,6 +29,7 @@
 #define SRC_TINT_LANG_WGSL_AST_NODE_ID_H_
 
 #include <stddef.h>
+#include <stdint.h>
 
 namespace tint::ast {
 
@@ -46,7 +47,7 @@
     bool operator<(NodeID other) const { return value < other.value; }
 
     /// The numerical value for the node identifier
-    size_t value = 0;
+    uint32_t value = 0;
 };
 
 }  // namespace tint::ast
diff --git a/src/tint/lang/wgsl/reader/parser/const_literal_test.cc b/src/tint/lang/wgsl/reader/parser/const_literal_test.cc
index 4cb239f..eff472c 100644
--- a/src/tint/lang/wgsl/reader/parser/const_literal_test.cc
+++ b/src/tint/lang/wgsl/reader/parser/const_literal_test.cc
@@ -147,7 +147,8 @@
         EXPECT_EQ(c->As<ast::FloatLiteralExpression>()->suffix,
                   ast::FloatLiteralExpression::Suffix::kNone);
     }
-    EXPECT_EQ(c->source.range, (Source::Range{{1u, 1u}, {1u, 1u + params.input.size()}}));
+    EXPECT_EQ(c->source.range,
+              (Source::Range{{1u, 1u}, {1u, 1u + static_cast<uint32_t>(params.input.size())}}));
 }
 using FloatLiteralTestCaseList = std::vector<FloatLiteralTestCase>;
 
diff --git a/src/tint/lang/wgsl/reader/parser/lexer.cc b/src/tint/lang/wgsl/reader/parser/lexer.cc
index a133cb6..1ee2bcb 100644
--- a/src/tint/lang/wgsl/reader/parser/lexer.cc
+++ b/src/tint/lang/wgsl/reader/parser/lexer.cc
@@ -58,7 +58,10 @@
 // programs and being a bit bigger then those need (atan2-const-eval is the outlier here).
 static constexpr size_t kDefaultListSize = 4092;
 
-bool read_blankspace(std::string_view str, size_t i, bool* is_blankspace, size_t* blankspace_size) {
+bool read_blankspace(std::string_view str,
+                     size_t i,
+                     bool* is_blankspace,
+                     uint32_t* blankspace_size) {
     // See https://www.w3.org/TR/WGSL/#blankspace
 
     auto* utf8 = reinterpret_cast<const uint8_t*>(&str[i]);
@@ -75,7 +78,7 @@
 
     if (cp == kSpace || cp == kHTab || cp == kL2R || cp == kR2L) {
         *is_blankspace = true;
-        *blankspace_size = n;
+        *blankspace_size = static_cast<uint32_t>(n);
         return true;
     }
 
@@ -139,15 +142,15 @@
     return file_->content.lines[location_.line - 1];
 }
 
-size_t Lexer::pos() const {
+uint32_t Lexer::pos() const {
     return location_.column - 1;
 }
 
-size_t Lexer::length() const {
-    return line().size();
+uint32_t Lexer::length() const {
+    return static_cast<uint32_t>(line().size());
 }
 
-const char& Lexer::at(size_t pos) const {
+const char& Lexer::at(uint32_t pos) const {
     auto l = line();
     // Unlike for std::string, if pos == l.size(), indexing `l[pos]` is UB for
     // std::string_view.
@@ -158,15 +161,15 @@
     return l[pos];
 }
 
-std::string_view Lexer::substr(size_t offset, size_t count) {
+std::string_view Lexer::substr(uint32_t offset, uint32_t count) {
     return line().substr(offset, count);
 }
 
-void Lexer::advance(size_t offset) {
+void Lexer::advance(uint32_t offset) {
     location_.column += offset;
 }
 
-void Lexer::set_pos(size_t pos) {
+void Lexer::set_pos(uint32_t pos) {
     location_.column = pos + 1;
 }
 
@@ -235,19 +238,18 @@
 bool Lexer::is_digit(char ch) const {
     return std::isdigit(static_cast<unsigned char>(ch));
 }
-
 bool Lexer::is_hex(char ch) const {
     return std::isxdigit(static_cast<unsigned char>(ch));
 }
 
-bool Lexer::matches(size_t pos, std::string_view sub_string) {
+bool Lexer::matches(uint32_t pos, std::string_view sub_string) {
     if (pos >= length()) {
         return false;
     }
-    return substr(pos, sub_string.size()) == sub_string;
+    return substr(pos, static_cast<uint32_t>(sub_string.size())) == sub_string;
 }
 
-bool Lexer::matches(size_t pos, char ch) {
+bool Lexer::matches(uint32_t pos, char ch) {
     if (pos >= length()) {
         return false;
     }
@@ -264,7 +266,7 @@
             }
 
             bool is_blankspace;
-            size_t blankspace_size;
+            uint32_t blankspace_size;
             if (!read_blankspace(line(), pos(), &is_blankspace, &blankspace_size)) {
                 return Token{Token::Type::kError, begin_source(), "invalid UTF-8"};
             }
@@ -383,7 +385,7 @@
     }
 
     // Parse the exponent if one exists
-    std::optional<size_t> exponent_value_position;
+    std::optional<uint32_t> exponent_value_position;
     bool negative_exponent = false;
     if (end < length() && (matches(end, 'e') || matches(end, 'E'))) {
         end++;
@@ -893,8 +895,8 @@
 }
 
 Token Lexer::build_token_from_int_if_possible(Source source,
-                                              size_t start,
-                                              size_t prefix_count,
+                                              uint32_t start,
+                                              uint32_t prefix_count,
                                               int32_t base) {
     const char* start_ptr = &at(start);
     // The call to `from_chars` will return the pointer to just after the last parsed character.
@@ -907,7 +909,7 @@
     int64_t value = 0;
     auto res = std::from_chars(start_ptr, end_ptr, value, base);
     const bool overflow = res.ec != std::errc();
-    advance(static_cast<size_t>(res.ptr - start_ptr) + prefix_count);
+    advance(static_cast<uint32_t>(res.ptr - start_ptr) + prefix_count);
 
     if (matches(pos(), 'u')) {
         if (!overflow && core::CheckedConvert<u32>(AInt(value)) == Success) {
@@ -993,7 +995,7 @@
             return {};
         }
         // Consume start codepoint
-        advance(n);
+        advance(static_cast<uint32_t>(n));
     }
 
     while (!is_eol()) {
@@ -1009,7 +1011,7 @@
         }
 
         // Consume continuing codepoint
-        advance(n);
+        advance(static_cast<uint32_t>(n));
 
         if (pos() - start == 2 && substr(start, 2) == "__") {
             // Identifiers prefixed with two or more underscores are not allowed.
diff --git a/src/tint/lang/wgsl/reader/parser/lexer.h b/src/tint/lang/wgsl/reader/parser/lexer.h
index 6e97551..50cce07 100644
--- a/src/tint/lang/wgsl/reader/parser/lexer.h
+++ b/src/tint/lang/wgsl/reader/parser/lexer.h
@@ -61,8 +61,8 @@
     std::optional<Token> skip_comment();
 
     Token build_token_from_int_if_possible(Source source,
-                                           size_t start,
-                                           size_t prefix_count,
+                                           uint32_t start,
+                                           uint32_t prefix_count,
                                            int32_t base);
 
     std::optional<Token::Type> parse_keyword(std::string_view);
@@ -88,17 +88,17 @@
     /// @returns view of current line
     std::string_view line() const;
     /// @returns position in current line
-    size_t pos() const;
+    uint32_t pos() const;
     /// @returns length of current line
-    size_t length() const;
+    uint32_t length() const;
     /// @returns reference to character at `pos` within current line
-    const char& at(size_t pos) const;
+    const char& at(uint32_t pos) const;
     /// @returns substring view at `offset` within current line of length `count`
-    std::string_view substr(size_t offset, size_t count);
+    std::string_view substr(uint32_t offset, uint32_t count);
     /// advances current position by `offset` within current line
-    void advance(size_t offset = 1);
+    void advance(uint32_t offset = 1);
     /// sets current position to `pos` within current line
-    void set_pos(size_t pos);
+    void set_pos(uint32_t pos);
     /// advances current position to next line
     void advance_line();
     /// @returns true if the end of the input has been reached.
@@ -115,9 +115,9 @@
     /// @returns true if 'ch' is a hexadecimal digit
     bool is_hex(char ch) const;
     /// @returns true if string at `pos` matches `substr`
-    bool matches(size_t pos, std::string_view substr);
+    bool matches(uint32_t pos, std::string_view substr);
     /// @returns true if char at `pos` matches `ch`
-    bool matches(size_t pos, char ch);
+    bool matches(uint32_t pos, char ch);
     /// The source file content
     Source::File const* const file_;
     /// The current location within the input
diff --git a/src/tint/lang/wgsl/reader/reader.cc b/src/tint/lang/wgsl/reader/reader.cc
index 3ddc2ae..77289d1 100644
--- a/src/tint/lang/wgsl/reader/reader.cc
+++ b/src/tint/lang/wgsl/reader/reader.cc
@@ -27,6 +27,7 @@
 
 #include "src/tint/lang/wgsl/reader/reader.h"
 
+#include <limits>
 #include <utility>
 
 #include "src/tint/lang/wgsl/reader/lower/lower.h"
@@ -37,6 +38,13 @@
 namespace tint::wgsl::reader {
 
 Program Parse(const Source::File* file, const Options& options) {
+    if (TINT_UNLIKELY(file->content.data.size() >
+                      static_cast<size_t>(std::numeric_limits<uint32_t>::max()))) {
+        ProgramBuilder b;
+        b.Diagnostics().add_error(tint::diag::System::Reader,
+                                  "WGSL source must be 0xffffffff bytes or fewer");
+        return Program(std::move(b));
+    }
     Parser parser(file);
     parser.Parse();
     return resolver::Resolve(parser.builder(), options.allowed_features);
diff --git a/src/tint/lang/wgsl/resolver/resolver.cc b/src/tint/lang/wgsl/resolver/resolver.cc
index 81b8c22..e8b9bcc 100644
--- a/src/tint/lang/wgsl/resolver/resolver.cc
+++ b/src/tint/lang/wgsl/resolver/resolver.cc
@@ -3527,8 +3527,9 @@
                         swizzle.Push(3u);
                         break;
                     default:
-                        AddError("invalid vector swizzle character",
-                                 expr->member->source.Begin() + swizzle.Length());
+                        AddError(
+                            "invalid vector swizzle character",
+                            expr->member->source.Begin() + static_cast<uint32_t>(swizzle.Length()));
                         return nullptr;
                 }
 
diff --git a/src/tint/lang/wgsl/resolver/resolver_test.cc b/src/tint/lang/wgsl/resolver/resolver_test.cc
index 365b595..8eb0457 100644
--- a/src/tint/lang/wgsl/resolver/resolver_test.cc
+++ b/src/tint/lang/wgsl/resolver/resolver_test.cc
@@ -2469,7 +2469,7 @@
 
 TEST_F(ResolverTest, ScopeDepth_NestedBlocks) {
     const ast::Statement* stmt = Return();
-    for (size_t i = 0; i < 150; i++) {
+    for (uint32_t i = 0; i < 150; i++) {
         stmt = Block(Source{{i, 1}}, stmt);
     }
     WrapInFunction(stmt);
@@ -2481,7 +2481,7 @@
 
 TEST_F(ResolverTest, ScopeDepth_NestedIf) {
     const ast::Statement* stmt = Return();
-    for (size_t i = 0; i < 150; i++) {
+    for (uint32_t i = 0; i < 150; i++) {
         stmt = If(Source{{i, 1}}, false, Block(Source{{i, 2}}, stmt));
     }
     WrapInFunction(stmt);
@@ -2493,7 +2493,7 @@
 
 TEST_F(ResolverTest, ScopeDepth_IfElseChain) {
     const ast::Statement* stmt = nullptr;
-    for (size_t i = 0; i < 150; i++) {
+    for (uint32_t i = 0; i < 150; i++) {
         stmt = If(Source{{i, 1}}, false, Block(Source{{i, 2}}), Else(stmt));
     }
     WrapInFunction(stmt);
@@ -2545,13 +2545,13 @@
     EXPECT_TRUE(r()->Resolve()) << r()->error();
 }
 
-size_t kMaxNestDepthOfCompositeType = 255;
+uint32_t kMaxNestDepthOfCompositeType = 255;
 
 TEST_F(ResolverTest, MaxNestDepthOfCompositeType_Structs_Valid) {
     auto* s = Structure("S", Vector{Member("m", ty.i32())});
-    size_t depth = 1;  // Depth of struct
-    size_t iterations = kMaxNestDepthOfCompositeType - depth;
-    for (size_t i = 0; i < iterations; ++i) {
+    uint32_t depth = 1;  // Depth of struct
+    uint32_t iterations = kMaxNestDepthOfCompositeType - depth;
+    for (uint32_t i = 0; i < iterations; ++i) {
         s = Structure("S" + std::to_string(i), Vector{Member("m", ty.Of(s))});
     }
     EXPECT_TRUE(r()->Resolve()) << r()->error();
@@ -2559,9 +2559,9 @@
 
 TEST_F(ResolverTest, MaxNestDepthOfCompositeType_Structs_Invalid) {
     auto* s = Structure("S", Vector{Member("m", ty.i32())});
-    size_t depth = 1;  // Depth of struct
-    size_t iterations = kMaxNestDepthOfCompositeType - depth + 1;
-    for (size_t i = 0; i < iterations; ++i) {
+    uint32_t depth = 1;  // Depth of struct
+    uint32_t iterations = kMaxNestDepthOfCompositeType - depth + 1;
+    for (uint32_t i = 0; i < iterations; ++i) {
         auto source = i == iterations - 1 ? Source{{12, 34}} : Source{{0, i}};
         s = Structure(source, "S" + std::to_string(i), Vector{Member("m", ty.Of(s))});
     }
@@ -2571,9 +2571,9 @@
 
 TEST_F(ResolverTest, MaxNestDepthOfCompositeType_StructsWithVector_Valid) {
     auto* s = Structure("S", Vector{Member("m", ty.vec3<i32>())});
-    size_t depth = 2;  // Despth of struct + vector
-    size_t iterations = kMaxNestDepthOfCompositeType - depth;
-    for (size_t i = 0; i < iterations; ++i) {
+    uint32_t depth = 2;  // Despth of struct + vector
+    uint32_t iterations = kMaxNestDepthOfCompositeType - depth;
+    for (uint32_t i = 0; i < iterations; ++i) {
         s = Structure("S" + std::to_string(i), Vector{Member("m", ty.Of(s))});
     }
     EXPECT_TRUE(r()->Resolve()) << r()->error();
@@ -2581,9 +2581,9 @@
 
 TEST_F(ResolverTest, MaxNestDepthOfCompositeType_StructsWithVector_Invalid) {
     auto* s = Structure("S", Vector{Member("m", ty.vec3<i32>())});
-    size_t depth = 2;  // Despth of struct + vector
-    size_t iterations = kMaxNestDepthOfCompositeType - depth + 1;
-    for (size_t i = 0; i < iterations; ++i) {
+    uint32_t depth = 2;  // Despth of struct + vector
+    uint32_t iterations = kMaxNestDepthOfCompositeType - depth + 1;
+    for (uint32_t i = 0; i < iterations; ++i) {
         auto source = i == iterations - 1 ? Source{{12, 34}} : Source{{0, i}};
         s = Structure(source, "S" + std::to_string(i), Vector{Member("m", ty.Of(s))});
     }
@@ -2593,9 +2593,9 @@
 
 TEST_F(ResolverTest, MaxNestDepthOfCompositeType_StructsWithMatrix_Valid) {
     auto* s = Structure("S", Vector{Member("m", ty.mat3x3<f32>())});
-    size_t depth = 3;  // Depth of struct + matrix
-    size_t iterations = kMaxNestDepthOfCompositeType - depth;
-    for (size_t i = 0; i < iterations; ++i) {
+    uint32_t depth = 3;  // Depth of struct + matrix
+    uint32_t iterations = kMaxNestDepthOfCompositeType - depth;
+    for (uint32_t i = 0; i < iterations; ++i) {
         s = Structure("S" + std::to_string(i), Vector{Member("m", ty.Of(s))});
     }
     EXPECT_TRUE(r()->Resolve()) << r()->error();
@@ -2603,9 +2603,9 @@
 
 TEST_F(ResolverTest, MaxNestDepthOfCompositeType_StructsWithMatrix_Invalid) {
     auto* s = Structure("S", Vector{Member("m", ty.mat3x3<f32>())});
-    size_t depth = 3;  // Depth of struct + matrix
-    size_t iterations = kMaxNestDepthOfCompositeType - depth + 1;
-    for (size_t i = 0; i < iterations; ++i) {
+    uint32_t depth = 3;  // Depth of struct + matrix
+    uint32_t iterations = kMaxNestDepthOfCompositeType - depth + 1;
+    for (uint32_t i = 0; i < iterations; ++i) {
         auto source = i == iterations - 1 ? Source{{12, 34}} : Source{{0, i}};
         s = Structure(source, "S" + std::to_string(i), Vector{Member("m", ty.Of(s))});
     }
@@ -2615,9 +2615,9 @@
 
 TEST_F(ResolverTest, MaxNestDepthOfCompositeType_Arrays_Valid) {
     auto a = ty.array(ty.i32(), 10_u);
-    size_t depth = 1;  // Depth of array
-    size_t iterations = kMaxNestDepthOfCompositeType - depth;
-    for (size_t i = 0; i < iterations; ++i) {
+    uint32_t depth = 1;  // Depth of array
+    uint32_t iterations = kMaxNestDepthOfCompositeType - depth;
+    for (uint32_t i = 0; i < iterations; ++i) {
         a = ty.array(a, 1_u);
     }
     Alias("a", a);
@@ -2626,9 +2626,9 @@
 
 TEST_F(ResolverTest, MaxNestDepthOfCompositeType_Arrays_Invalid) {
     auto a = ty.array(Source{{99, 88}}, ty.i32(), 10_u);
-    size_t depth = 1;  // Depth of array
-    size_t iterations = kMaxNestDepthOfCompositeType - depth + 1;
-    for (size_t i = 0; i < iterations; ++i) {
+    uint32_t depth = 1;  // Depth of array
+    uint32_t iterations = kMaxNestDepthOfCompositeType - depth + 1;
+    for (uint32_t i = 0; i < iterations; ++i) {
         auto source = (i == iterations - 1) ? Source{{12, 34}} : Source{{0, i}};
         a = ty.array(source, a, 1_u);
     }
@@ -2639,9 +2639,9 @@
 
 TEST_F(ResolverTest, MaxNestDepthOfCompositeType_ArraysOfVector_Valid) {
     auto a = ty.array<vec3<i32>, 10>();
-    size_t depth = 2;  // Depth of array + vector
-    size_t iterations = kMaxNestDepthOfCompositeType - depth;
-    for (size_t i = 0; i < iterations; ++i) {
+    uint32_t depth = 2;  // Depth of array + vector
+    uint32_t iterations = kMaxNestDepthOfCompositeType - depth;
+    for (uint32_t i = 0; i < iterations; ++i) {
         a = ty.array(a, 1_u);
     }
     Alias("a", a);
@@ -2650,9 +2650,9 @@
 
 TEST_F(ResolverTest, MaxNestDepthOfCompositeType_ArraysOfVector_Invalid) {
     auto a = ty.array(Source{{99, 88}}, ty.vec3<i32>(), 10_u);
-    size_t depth = 2;  // Depth of array + vector
-    size_t iterations = kMaxNestDepthOfCompositeType - depth + 1;
-    for (size_t i = 0; i < iterations; ++i) {
+    uint32_t depth = 2;  // Depth of array + vector
+    uint32_t iterations = kMaxNestDepthOfCompositeType - depth + 1;
+    for (uint32_t i = 0; i < iterations; ++i) {
         auto source = (i == iterations - 1) ? Source{{12, 34}} : Source{{0, i}};
         a = ty.array(source, a, 1_u);
     }
@@ -2663,9 +2663,9 @@
 
 TEST_F(ResolverTest, MaxNestDepthOfCompositeType_ArraysOfMatrix_Valid) {
     auto a = ty.array(ty.mat3x3<f32>(), 10_u);
-    size_t depth = 3;  // Depth of array + matrix
-    size_t iterations = kMaxNestDepthOfCompositeType - depth;
-    for (size_t i = 0; i < iterations; ++i) {
+    uint32_t depth = 3;  // Depth of array + matrix
+    uint32_t iterations = kMaxNestDepthOfCompositeType - depth;
+    for (uint32_t i = 0; i < iterations; ++i) {
         a = ty.array(a, 1_u);
     }
     Alias("a", a);
@@ -2674,9 +2674,9 @@
 
 TEST_F(ResolverTest, MaxNestDepthOfCompositeType_ArraysOfMatrix_Invalid) {
     auto a = ty.array(ty.mat3x3<f32>(), 10_u);
-    size_t depth = 3;  // Depth of array + matrix
-    size_t iterations = kMaxNestDepthOfCompositeType - depth + 1;
-    for (size_t i = 0; i < iterations; ++i) {
+    uint32_t depth = 3;  // Depth of array + matrix
+    uint32_t iterations = kMaxNestDepthOfCompositeType - depth + 1;
+    for (uint32_t i = 0; i < iterations; ++i) {
         auto source = (i == iterations - 1) ? Source{{12, 34}} : Source{{0, i}};
         a = ty.array(source, a, 1_u);
     }
@@ -2688,9 +2688,9 @@
 TEST_F(ResolverTest, MaxNestDepthOfCompositeType_StructsOfArray_Valid) {
     auto a = ty.array(ty.mat3x3<f32>(), 10_u);
     auto* s = Structure("S", Vector{Member("m", a)});
-    size_t depth = 4;  // Depth of struct + array + matrix
-    size_t iterations = kMaxNestDepthOfCompositeType - depth;
-    for (size_t i = 0; i < iterations; ++i) {
+    uint32_t depth = 4;  // Depth of struct + array + matrix
+    uint32_t iterations = kMaxNestDepthOfCompositeType - depth;
+    for (uint32_t i = 0; i < iterations; ++i) {
         s = Structure("S" + std::to_string(i), Vector{Member("m", ty.Of(s))});
     }
     EXPECT_TRUE(r()->Resolve()) << r()->error();
@@ -2699,9 +2699,9 @@
 TEST_F(ResolverTest, MaxNestDepthOfCompositeType_StructsOfArray_Invalid) {
     auto a = ty.array(ty.mat3x3<f32>(), 10_u);
     auto* s = Structure("S", Vector{Member("m", a)});
-    size_t depth = 4;  // Depth of struct + array + matrix
-    size_t iterations = kMaxNestDepthOfCompositeType - depth + 1;
-    for (size_t i = 0; i < iterations; ++i) {
+    uint32_t depth = 4;  // Depth of struct + array + matrix
+    uint32_t iterations = kMaxNestDepthOfCompositeType - depth + 1;
+    for (uint32_t i = 0; i < iterations; ++i) {
         auto source = i == iterations - 1 ? Source{{12, 34}} : Source{{0, i}};
         s = Structure(source, "S" + std::to_string(i), Vector{Member("m", ty.Of(s))});
     }
@@ -2712,9 +2712,9 @@
 TEST_F(ResolverTest, MaxNestDepthOfCompositeType_ArraysOfStruct_Valid) {
     auto* s = Structure("S", Vector{Member("m", ty.mat3x3<f32>())});
     auto a = ty.array(ty.Of(s), 10_u);
-    size_t depth = 4;  // Depth of array + struct + matrix
-    size_t iterations = kMaxNestDepthOfCompositeType - depth;
-    for (size_t i = 0; i < iterations; ++i) {
+    uint32_t depth = 4;  // Depth of array + struct + matrix
+    uint32_t iterations = kMaxNestDepthOfCompositeType - depth;
+    for (uint32_t i = 0; i < iterations; ++i) {
         a = ty.array(a, 1_u);
     }
     Alias("a", a);
@@ -2724,9 +2724,9 @@
 TEST_F(ResolverTest, MaxNestDepthOfCompositeType_ArraysOfStruct_Invalid) {
     auto* s = Structure("S", Vector{Member("m", ty.mat3x3<f32>())});
     auto a = ty.array(ty.Of(s), 10_u);
-    size_t depth = 4;  // Depth of array + struct + matrix
-    size_t iterations = kMaxNestDepthOfCompositeType - depth + 1;
-    for (size_t i = 0; i < iterations; ++i) {
+    uint32_t depth = 4;  // Depth of array + struct + matrix
+    uint32_t iterations = kMaxNestDepthOfCompositeType - depth + 1;
+    for (uint32_t i = 0; i < iterations; ++i) {
         auto source = (i == iterations - 1) ? Source{{12, 34}} : Source{{0, i}};
         a = ty.array(source, a, 1_u);
     }
diff --git a/src/tint/lang/wgsl/resolver/value_constructor_validation_test.cc b/src/tint/lang/wgsl/resolver/value_constructor_validation_test.cc
index 3f0e1ca..027b471 100644
--- a/src/tint/lang/wgsl/resolver/value_constructor_validation_test.cc
+++ b/src/tint/lang/wgsl/resolver/value_constructor_validation_test.cc
@@ -2626,7 +2626,7 @@
         }
         args_tys << "vec" << param.rows << "<" + element_type_name + ">";
     }
-    const size_t kInvalidLoc = 2 * (param.columns - 1);
+    const uint32_t kInvalidLoc = 2 * (param.columns - 1);
     auto invalid_vec_type = ty.vec(param.create_element_ast_type(*this), param.rows - 1);
     args.Push(Call(Source{{12, kInvalidLoc}}, invalid_vec_type));
     args_tys << ", vec" << (param.rows - 1) << "<" + element_type_name + ">";
diff --git a/src/tint/lang/wgsl/sem/info.h b/src/tint/lang/wgsl/sem/info.h
index 111e544..bd2daf4 100644
--- a/src/tint/lang/wgsl/sem/info.h
+++ b/src/tint/lang/wgsl/sem/info.h
@@ -80,7 +80,7 @@
 
     /// @param highest_node_id the last allocated (numerically highest) AST node identifier.
     void Reserve(ast::NodeID highest_node_id) {
-        nodes_.Resize(std::max(highest_node_id.value + 1, nodes_.Length()));
+        nodes_.Resize(std::max(highest_node_id.value + 1, static_cast<uint32_t>(nodes_.Length())));
     }
 
     /// Get looks up the semantic information for the AST node `ast_node`.
diff --git a/src/tint/utils/diagnostic/source.h b/src/tint/utils/diagnostic/source.h
index 4c2fc9a..8400921 100644
--- a/src/tint/utils/diagnostic/source.h
+++ b/src/tint/utils/diagnostic/source.h
@@ -89,10 +89,10 @@
     class Location {
       public:
         /// the 1-based line number. 0 represents no line information.
-        size_t line = 0;
+        uint32_t line = 0;
         /// the 1-based column number in utf8-code units (bytes).
         /// 0 represents no column information.
-        size_t column = 0;
+        uint32_t column = 0;
 
         /// Returns true if `this` location is lexicographically less than `rhs`
         /// @param rhs location to compare against
@@ -132,7 +132,7 @@
         /// Return a column-shifted Range
         /// @param n the number of characters to shift by
         /// @returns a Range with a #begin and #end column shifted by `n`
-        inline Range operator+(size_t n) const {
+        inline Range operator+(uint32_t n) const {
             return Range{{begin.line, begin.column + n}, {end.line, end.column + n}};
         }
 
@@ -179,7 +179,7 @@
     /// Return a column-shifted Source
     /// @param n the number of characters to shift by
     /// @returns a Source with the range's columns shifted by `n`
-    inline Source operator+(size_t n) const { return Source(range + n, file); }
+    inline Source operator+(uint32_t n) const { return Source(range + n, file); }
 
     /// Returns true of `this` Source is lexicographically less than `rhs`
     /// @param rhs source to compare against