Fix TypesBuilder::builder pointer initialization

When copying or moving a ProgramBuilder, we always want the ProgramBuilder::ty to point back to the owner.
We were previously std::move()'ing the ty field, which is not correct - this will result in the TypesBuilder pointing to the wrong ProgramBuilder.

I'm not sure why we've not seen any issues with this using clang, but running under MSVC immediately highlighted this brokenness.

Change-Id: I4293bb00ac4fbdfa66d12b1504a7bd060e014cd6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41861
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
diff --git a/src/program_builder.cc b/src/program_builder.cc
index 11b960d..bee3f29 100644
--- a/src/program_builder.cc
+++ b/src/program_builder.cc
@@ -28,11 +28,10 @@
 namespace tint {
 
 ProgramBuilder::ProgramBuilder()
-    : ty(this), ast_(ast_nodes_.Create<ast::Module>(Source{})) {}
+    : ast_(ast_nodes_.Create<ast::Module>(Source{})) {}
 
 ProgramBuilder::ProgramBuilder(ProgramBuilder&& rhs)
-    : ty(std::move(rhs.ty)),
-      types_(std::move(rhs.types_)),
+    : types_(std::move(rhs.types_)),
       ast_nodes_(std::move(rhs.ast_nodes_)),
       sem_nodes_(std::move(rhs.sem_nodes_)),
       ast_(rhs.ast_),
@@ -46,7 +45,6 @@
 ProgramBuilder& ProgramBuilder::operator=(ProgramBuilder&& rhs) {
   rhs.MarkAsMoved();
   AssertNotMoved();
-  ty = std::move(rhs.ty);
   types_ = std::move(rhs.types_);
   ast_nodes_ = std::move(rhs.ast_nodes_);
   sem_nodes_ = std::move(rhs.sem_nodes_);
diff --git a/src/program_builder.h b/src/program_builder.h
index f0ecfb3..24a0186 100644
--- a/src/program_builder.h
+++ b/src/program_builder.h
@@ -477,7 +477,7 @@
     template <typename T>
     struct CToAST {};
 
-    ProgramBuilder* builder;
+    ProgramBuilder* const builder;
   };
 
   //////////////////////////////////////////////////////////////////////////////
@@ -1101,7 +1101,7 @@
   void WrapInFunction(ast::StatementList stmts);
 
   /// The builder types
-  TypesBuilder ty;
+  TypesBuilder const ty{this};
 
  protected:
   /// Asserts that the builder has not been moved.