[type-determiner] Move ast::Module to constructor.

This CL moves the ast::Module to be provided to the type determiner
constructor so we can access it for things like the imports.

Change-Id: I110fffe669a8a007461bf84d30d85d70405e37be
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19761
Reviewed-by: David Neto <dneto@google.com>
diff --git a/samples/main.cc b/samples/main.cc
index e481030..ebc0c6d 100644
--- a/samples/main.cc
+++ b/samples/main.cc
@@ -305,8 +305,8 @@
     return 1;
   }
 
-  tint::TypeDeterminer td(&ctx);
-  if (!td.Determine(&mod)) {
+  tint::TypeDeterminer td(&ctx, &mod);
+  if (!td.Determine()) {
     std::cerr << td.error() << std::endl;
     return 1;
   }
diff --git a/src/type_determiner.cc b/src/type_determiner.cc
index aa9d026..e3d2a8a 100644
--- a/src/type_determiner.cc
+++ b/src/type_determiner.cc
@@ -48,7 +48,8 @@
 
 namespace tint {
 
-TypeDeterminer::TypeDeterminer(Context* ctx) : ctx_(*ctx) {}
+TypeDeterminer::TypeDeterminer(Context* ctx, ast::Module* mod)
+    : ctx_(*ctx), mod_(mod) {}
 
 TypeDeterminer::~TypeDeterminer() = default;
 
@@ -61,16 +62,16 @@
   error_ += msg;
 }
 
-bool TypeDeterminer::Determine(ast::Module* mod) {
-  for (const auto& var : mod->global_variables()) {
+bool TypeDeterminer::Determine() {
+  for (const auto& var : mod_->global_variables()) {
     variable_stack_.set_global(var->name(), var.get());
   }
 
-  for (const auto& func : mod->functions()) {
+  for (const auto& func : mod_->functions()) {
     name_to_function_[func->name()] = func.get();
   }
 
-  if (!DetermineFunctions(mod->functions())) {
+  if (!DetermineFunctions(mod_->functions())) {
     return false;
   }
   return true;
diff --git a/src/type_determiner.h b/src/type_determiner.h
index 132dd21..4ad39b1 100644
--- a/src/type_determiner.h
+++ b/src/type_determiner.h
@@ -46,16 +46,15 @@
  public:
   /// Constructor
   /// @param ctx the tint context
-  explicit TypeDeterminer(Context* ctx);
+  /// @param mod the module to update with typing information
+  TypeDeterminer(Context* ctx, ast::Module* mod);
   ~TypeDeterminer();
 
   /// @returns error messages from the type determiner
   const std::string& error() { return error_; }
 
-  /// Runs the type determiner
-  /// @param mod the module to update with typing information
   /// @returns true if the type determiner was successful
-  bool Determine(ast::Module* mod);
+  bool Determine();
   /// Determines type information for functions
   /// @param funcs the functions to check
   /// @returns true if the determination was successful
@@ -104,6 +103,7 @@
   bool DetermineUnaryOp(ast::UnaryOpExpression* expr);
 
   Context& ctx_;
+  ast::Module* mod_;
   std::string error_;
   ScopeStack<ast::Variable*> variable_stack_;
   std::unordered_map<std::string, ast::Function*> name_to_function_;
diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc
index c999d85..1fab3b3 100644
--- a/src/type_determiner_test.cc
+++ b/src/type_determiner_test.cc
@@ -70,7 +70,8 @@
 
 class TypeDeterminerHelper {
  public:
-  TypeDeterminerHelper() : td_(std::make_unique<TypeDeterminer>(&ctx_)) {}
+  TypeDeterminerHelper()
+      : td_(std::make_unique<TypeDeterminer>(&ctx_, &mod_)) {}
 
   TypeDeterminer* td() const { return td_.get(); }
   ast::Module* mod() { return &mod_; }
@@ -435,7 +436,7 @@
   mod()->AddGlobalVariable(std::move(var));
 
   // Register the global
-  EXPECT_TRUE(td()->Determine(mod()));
+  EXPECT_TRUE(td()->Determine());
 
   ast::ArrayAccessorExpression acc(
       std::make_unique<ast::IdentifierExpression>("my_var"), std::move(idx));
@@ -456,7 +457,7 @@
   mod()->AddGlobalVariable(std::move(var));
 
   // Register the global
-  EXPECT_TRUE(td()->Determine(mod()));
+  EXPECT_TRUE(td()->Determine());
 
   ast::ArrayAccessorExpression acc(
       std::make_unique<ast::IdentifierExpression>("my_var"), std::move(idx));
@@ -480,7 +481,7 @@
   mod()->AddGlobalVariable(std::move(var));
 
   // Register the global
-  EXPECT_TRUE(td()->Determine(mod()));
+  EXPECT_TRUE(td()->Determine());
 
   ast::ArrayAccessorExpression acc(
       std::make_unique<ast::ArrayAccessorExpression>(
@@ -505,7 +506,7 @@
   mod()->AddGlobalVariable(std::move(var));
 
   // Register the global
-  EXPECT_TRUE(td()->Determine(mod()));
+  EXPECT_TRUE(td()->Determine());
 
   ast::ArrayAccessorExpression acc(
       std::make_unique<ast::IdentifierExpression>("my_var"), std::move(idx));
@@ -533,7 +534,7 @@
   mod()->AddFunction(std::move(func));
 
   // Register the function
-  EXPECT_TRUE(td()->Determine(mod()));
+  EXPECT_TRUE(td()->Determine());
 
   ast::ExpressionList call_params;
   ast::CallExpression call(
@@ -553,7 +554,7 @@
   mod()->AddFunction(std::move(func));
 
   // Register the function
-  EXPECT_TRUE(td()->Determine(mod()));
+  EXPECT_TRUE(td()->Determine());
 
   ast::ExpressionList call_params;
   call_params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
@@ -617,7 +618,7 @@
   mod()->AddGlobalVariable(std::move(var));
 
   // Register the global
-  EXPECT_TRUE(td()->Determine(mod()));
+  EXPECT_TRUE(td()->Determine());
 
   ast::IdentifierExpression ident("my_var");
   EXPECT_TRUE(td()->DetermineResultType(&ident));
@@ -658,7 +659,7 @@
   mod()->AddFunction(std::move(func));
 
   // Register the function
-  EXPECT_TRUE(td()->Determine(mod()));
+  EXPECT_TRUE(td()->Determine());
 
   ast::IdentifierExpression ident("my_func");
   EXPECT_TRUE(td()->DetermineResultType(&ident));
@@ -688,7 +689,7 @@
   mod()->AddGlobalVariable(std::move(var));
 
   // Register the global
-  EXPECT_TRUE(td()->Determine(mod()));
+  EXPECT_TRUE(td()->Determine());
 
   auto ident = std::make_unique<ast::IdentifierExpression>("my_struct");
   auto mem_ident = std::make_unique<ast::IdentifierExpression>("second_member");
@@ -708,7 +709,7 @@
   mod()->AddGlobalVariable(std::move(var));
 
   // Register the global
-  EXPECT_TRUE(td()->Determine(mod()));
+  EXPECT_TRUE(td()->Determine());
 
   auto ident = std::make_unique<ast::IdentifierExpression>("my_vec");
   auto swizzle = std::make_unique<ast::IdentifierExpression>("xy");
@@ -776,7 +777,7 @@
   mod()->AddGlobalVariable(std::move(var));
 
   // Register the global
-  EXPECT_TRUE(td()->Determine(mod()));
+  EXPECT_TRUE(td()->Determine());
 
   auto ident = std::make_unique<ast::IdentifierExpression>("c");
   auto mem_ident = std::make_unique<ast::IdentifierExpression>("mem");
@@ -811,7 +812,7 @@
   mod()->AddGlobalVariable(std::move(var));
 
   // Register the global
-  ASSERT_TRUE(td()->Determine(mod())) << td()->error();
+  ASSERT_TRUE(td()->Determine()) << td()->error();
 
   ast::BinaryExpression expr(
       op, std::make_unique<ast::IdentifierExpression>("val"),
@@ -833,7 +834,7 @@
   mod()->AddGlobalVariable(std::move(var));
 
   // Register the global
-  ASSERT_TRUE(td()->Determine(mod())) << td()->error();
+  ASSERT_TRUE(td()->Determine()) << td()->error();
 
   ast::BinaryExpression expr(
       op, std::make_unique<ast::IdentifierExpression>("val"),
@@ -869,7 +870,7 @@
   mod()->AddGlobalVariable(std::move(var));
 
   // Register the global
-  ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
+  ASSERT_TRUE(td()->Determine()) << td()->error();
 
   ast::BinaryExpression expr(
       op, std::make_unique<ast::IdentifierExpression>("val"),
@@ -891,7 +892,7 @@
   mod()->AddGlobalVariable(std::move(var));
 
   // Register the global
-  ASSERT_TRUE(td()->Determine(mod())) << td()->error();
+  ASSERT_TRUE(td()->Determine()) << td()->error();
 
   ast::BinaryExpression expr(
       op, std::make_unique<ast::IdentifierExpression>("val"),
@@ -919,7 +920,7 @@
   mod()->AddGlobalVariable(std::move(var));
 
   // Register the global
-  ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
+  ASSERT_TRUE(td()->Determine()) << td()->error();
 
   ast::BinaryExpression expr(
       op, std::make_unique<ast::IdentifierExpression>("val"),
@@ -941,7 +942,7 @@
   mod()->AddGlobalVariable(std::move(var));
 
   // Register the global
-  ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
+  ASSERT_TRUE(td()->Determine()) << td()->error();
 
   ast::BinaryExpression expr(
       op, std::make_unique<ast::IdentifierExpression>("val"),
@@ -970,7 +971,7 @@
   mod()->AddGlobalVariable(std::move(var));
 
   // Register the global
-  ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
+  ASSERT_TRUE(td()->Determine()) << td()->error();
 
   ast::BinaryExpression expr(
       ast::BinaryOp::kMultiply,
@@ -994,7 +995,7 @@
   mod()->AddGlobalVariable(std::move(vector));
 
   // Register the global
-  ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
+  ASSERT_TRUE(td()->Determine()) << td()->error();
 
   ast::BinaryExpression expr(
       ast::BinaryOp::kMultiply,
@@ -1020,7 +1021,7 @@
   mod()->AddGlobalVariable(std::move(vector));
 
   // Register the global
-  ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
+  ASSERT_TRUE(td()->Determine()) << td()->error();
 
   ast::BinaryExpression expr(
       ast::BinaryOp::kMultiply,
@@ -1043,7 +1044,7 @@
   mod()->AddGlobalVariable(std::move(vector));
 
   // Register the global
-  ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
+  ASSERT_TRUE(td()->Determine()) << td()->error();
 
   ast::BinaryExpression expr(
       ast::BinaryOp::kMultiply,
@@ -1069,7 +1070,7 @@
   mod()->AddGlobalVariable(std::move(matrix));
 
   // Register the global
-  ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
+  ASSERT_TRUE(td()->Determine()) << td()->error();
 
   ast::BinaryExpression expr(
       ast::BinaryOp::kMultiply,
@@ -1098,7 +1099,7 @@
   mod()->AddGlobalVariable(std::move(matrix));
 
   // Register the global
-  ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
+  ASSERT_TRUE(td()->Determine()) << td()->error();
 
   ast::BinaryExpression expr(
       ast::BinaryOp::kMultiply,
@@ -1128,7 +1129,7 @@
   mod()->AddGlobalVariable(std::move(matrix));
 
   // Register the global
-  ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
+  ASSERT_TRUE(td()->Determine()) << td()->error();
 
   ast::BinaryExpression expr(
       ast::BinaryOp::kMultiply,
@@ -1155,7 +1156,7 @@
   mod()->AddGlobalVariable(std::move(matrix));
 
   // Register the global
-  ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
+  ASSERT_TRUE(td()->Determine()) << td()->error();
 
   ast::BinaryExpression expr(
       ast::BinaryOp::kMultiply,
@@ -1182,7 +1183,7 @@
   mod()->AddGlobalVariable(std::move(matrix2));
 
   // Register the global
-  ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
+  ASSERT_TRUE(td()->Determine()) << td()->error();
 
   ast::BinaryExpression expr(
       ast::BinaryOp::kMultiply,
@@ -1213,7 +1214,7 @@
   mod()->AddGlobalVariable(std::move(var));
 
   // Register the global
-  EXPECT_TRUE(td()->Determine((mod())));
+  EXPECT_TRUE(td()->Determine());
 
   ast::UnaryDerivativeExpression der(
       derivative, ast::DerivativeModifier::kNone,
@@ -1248,7 +1249,7 @@
   ast::UnaryMethodExpression exp(op, std::move(params));
 
   // Register the variable
-  EXPECT_TRUE(td()->Determine((mod())));
+  EXPECT_TRUE(td()->Determine());
 
   EXPECT_TRUE(td()->DetermineResultType(&exp));
   ASSERT_NE(exp.result_type(), nullptr);
@@ -1277,7 +1278,7 @@
   ast::UnaryMethodExpression exp(op, std::move(params));
 
   // Register the variable
-  EXPECT_TRUE(td()->Determine((mod())));
+  EXPECT_TRUE(td()->Determine());
 
   EXPECT_TRUE(td()->DetermineResultType(&exp));
   ASSERT_NE(exp.result_type(), nullptr);
@@ -1300,7 +1301,7 @@
   ast::UnaryMethodExpression exp(op, std::move(params));
 
   // Register the variable
-  EXPECT_TRUE(td()->Determine((mod())));
+  EXPECT_TRUE(td()->Determine());
 
   EXPECT_TRUE(td()->DetermineResultType(&exp));
   ASSERT_NE(exp.result_type(), nullptr);
@@ -1328,7 +1329,7 @@
   ast::UnaryMethodExpression exp(ast::UnaryMethod::kDot, std::move(params));
 
   // Register the variable
-  EXPECT_TRUE(td()->Determine((mod())));
+  EXPECT_TRUE(td()->Determine());
 
   EXPECT_TRUE(td()->DetermineResultType(&exp));
   ASSERT_NE(exp.result_type(), nullptr);
@@ -1355,7 +1356,7 @@
                                  std::move(params));
 
   // Register the variable
-  EXPECT_TRUE(td()->Determine((mod())));
+  EXPECT_TRUE(td()->Determine());
 
   EXPECT_TRUE(td()->DetermineResultType(&exp));
   ASSERT_NE(exp.result_type(), nullptr);
@@ -1379,7 +1380,7 @@
   mod()->AddGlobalVariable(std::move(var));
 
   // Register the global
-  EXPECT_TRUE(td()->Determine((mod())));
+  EXPECT_TRUE(td()->Determine());
 
   ast::UnaryOpExpression der(
       op, std::make_unique<ast::IdentifierExpression>("ident"));
@@ -1410,7 +1411,7 @@
 
   mod()->AddFunction(std::move(func));
 
-  EXPECT_TRUE(td()->Determine((mod()))) << td()->error();
+  EXPECT_TRUE(td()->Determine()) << td()->error();
   EXPECT_EQ(var_ptr->storage_class(), ast::StorageClass::kFunction);
 }
 
@@ -1431,7 +1432,7 @@
 
   mod()->AddFunction(std::move(func));
 
-  EXPECT_TRUE(td()->Determine((mod()))) << td()->error();
+  EXPECT_TRUE(td()->Determine()) << td()->error();
   EXPECT_EQ(var_ptr->storage_class(), ast::StorageClass::kNone);
 }
 
@@ -1450,7 +1451,7 @@
 
   mod()->AddFunction(std::move(func));
 
-  EXPECT_FALSE(td()->Determine((mod())));
+  EXPECT_FALSE(td()->Determine());
   EXPECT_EQ(td()->error(),
             "function variable has a non-function storage class");
 }
diff --git a/src/writer/spirv/builder_binary_expression_test.cc b/src/writer/spirv/builder_binary_expression_test.cc
index 4d8df69..bf73129 100644
--- a/src/writer/spirv/builder_binary_expression_test.cc
+++ b/src/writer/spirv/builder_binary_expression_test.cc
@@ -61,10 +61,10 @@
   ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
 
@@ -102,13 +102,13 @@
       std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
 
   ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
 
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
 
@@ -151,10 +151,10 @@
   ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
 
@@ -192,13 +192,13 @@
       std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
 
   ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
 
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
 
@@ -241,10 +241,10 @@
   ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
 
@@ -283,13 +283,13 @@
       std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
 
   ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
 
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
 
@@ -325,10 +325,10 @@
   ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
 
@@ -368,13 +368,13 @@
       std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
 
   ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
 
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
 
@@ -414,10 +414,10 @@
   ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
 
@@ -457,13 +457,13 @@
       std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
 
   ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
 
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
 
@@ -503,10 +503,10 @@
   ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
 
@@ -546,13 +546,13 @@
       std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
 
   ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
 
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
 
@@ -596,14 +596,14 @@
       std::make_unique<ast::FloatLiteral>(&f32, 1.f));
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
 
   ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
                              std::move(rhs));
 
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
 
@@ -635,14 +635,14 @@
       std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
 
   ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
                              std::move(rhs));
 
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
 
@@ -667,7 +667,8 @@
       std::make_unique<ast::FloatLiteral>(&f32, 1.f));
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
   td.RegisterVariableForTesting(var.get());
 
   ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
@@ -675,7 +676,6 @@
 
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
   ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
@@ -705,7 +705,8 @@
   auto rhs = std::make_unique<ast::IdentifierExpression>("mat");
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
   td.RegisterVariableForTesting(var.get());
 
   ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
@@ -713,7 +714,6 @@
 
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
   ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
@@ -752,7 +752,8 @@
       std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
   td.RegisterVariableForTesting(var.get());
 
   ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
@@ -760,7 +761,6 @@
 
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
   ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
@@ -801,7 +801,8 @@
   auto rhs = std::make_unique<ast::IdentifierExpression>("mat");
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
   td.RegisterVariableForTesting(var.get());
 
   ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
@@ -809,7 +810,6 @@
 
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
   ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
@@ -840,7 +840,8 @@
   auto rhs = std::make_unique<ast::IdentifierExpression>("mat");
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
   td.RegisterVariableForTesting(var.get());
 
   ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
@@ -848,7 +849,6 @@
 
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
   ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
diff --git a/src/writer/spirv/builder_ident_expression_test.cc b/src/writer/spirv/builder_ident_expression_test.cc
index 81f3330..05222eb 100644
--- a/src/writer/spirv/builder_ident_expression_test.cc
+++ b/src/writer/spirv/builder_ident_expression_test.cc
@@ -151,7 +151,8 @@
   ast::type::I32Type i32;
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
 
   ast::Variable var("var", ast::StorageClass::kPrivate, &i32);
 
@@ -165,7 +166,6 @@
 
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
   ASSERT_TRUE(b.GenerateGlobalVariable(&var)) << b.error();
@@ -186,7 +186,8 @@
   ast::type::I32Type i32;
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
 
   ast::Variable var("var", ast::StorageClass::kNone, &i32);
   var.set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
@@ -203,7 +204,6 @@
 
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
   ASSERT_TRUE(b.GenerateGlobalVariable(&var)) << b.error();
diff --git a/src/writer/spirv/builder_if_test.cc b/src/writer/spirv/builder_if_test.cc
index bbb2ff7..bd9ada5 100644
--- a/src/writer/spirv/builder_if_test.cc
+++ b/src/writer/spirv/builder_if_test.cc
@@ -47,10 +47,10 @@
   ast::IfStatement expr(std::move(cond), ast::StatementList{});
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
 
@@ -89,12 +89,12 @@
   ast::IfStatement expr(std::move(cond), std::move(body));
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
   td.RegisterVariableForTesting(var.get());
 
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
   ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
@@ -152,12 +152,12 @@
   expr.set_else_statements(std::move(else_stmts));
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
   td.RegisterVariableForTesting(var.get());
 
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
   ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
@@ -222,12 +222,12 @@
   expr.set_else_statements(std::move(else_stmts));
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
   td.RegisterVariableForTesting(var.get());
 
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
   ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
@@ -316,12 +316,12 @@
   expr.set_else_statements(std::move(else_stmts));
 
   Context ctx;
-  TypeDeterminer td(&ctx);
+  ast::Module mod;
+  TypeDeterminer td(&ctx, &mod);
   td.RegisterVariableForTesting(var.get());
 
   ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
 
-  ast::Module mod;
   Builder b(&mod);
   b.push_function(Function{});
   ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();