[tint][utils] Change SymbolTable::Wrap() to be a static method
It doesn't make much sense for this to be called on an existing SymbolTable.
Matches type::Manager::Wrap().
Change-Id: I53f176c22152298ed0fd607704941722cb2a9f72
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/161007
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/src/tint/lang/core/type/manager.h b/src/tint/lang/core/type/manager.h
index 6d204c4..ada8c7e 100644
--- a/src/tint/lang/core/type/manager.h
+++ b/src/tint/lang/core/type/manager.h
@@ -84,8 +84,8 @@
/// Wrap returns a new Manager created with the types of `inner`.
/// The Manager returned by Wrap is intended to temporarily extend the types
/// of an existing immutable Manager.
- /// As the copied types are owned by `inner`, `inner` must not be destructed
- /// or assigned while using the returned Manager.
+ /// @warning As the copied types are owned by `inner`, `inner` must not be destructed or
+ /// assigned while using the returned Manager.
/// TODO(bclayton) - Evaluate whether there are safer alternatives to this
/// function. See crbug.com/tint/460.
/// @param inner the immutable Manager to extend
diff --git a/src/tint/lang/wgsl/program/program_builder.cc b/src/tint/lang/wgsl/program/program_builder.cc
index 596aa84..7f68f22 100644
--- a/src/tint/lang/wgsl/program/program_builder.cc
+++ b/src/tint/lang/wgsl/program/program_builder.cc
@@ -67,7 +67,7 @@
builder.ast_ =
builder.create<ast::Module>(program.AST().source, program.AST().GlobalDeclarations());
builder.sem_ = sem::Info::Wrap(program.Sem());
- builder.symbols_.Wrap(program.Symbols());
+ builder.symbols_ = SymbolTable::Wrap(program.Symbols());
builder.diagnostics_ = program.Diagnostics();
return builder;
}
diff --git a/src/tint/utils/symbol/symbol_table.h b/src/tint/utils/symbol/symbol_table.h
index 9e2c455..7c39512 100644
--- a/src/tint/utils/symbol/symbol_table.h
+++ b/src/tint/utils/symbol/symbol_table.h
@@ -53,17 +53,19 @@
/// @returns the symbol table
SymbolTable& operator=(SymbolTable&& other);
- /// Wrap sets this symbol table to hold symbols which point to the allocated names in @p o.
- /// The symbol table after Wrap is intended to temporarily extend the objects
- /// of an existing immutable SymbolTable
- /// As the copied objects are owned by @p o, @p o must not be destructed
- /// or assigned while using this symbol table.
+ /// @returns a symbol table to hold symbols which point to the allocated names in @p o.
+ /// The symbol table after Wrap is intended to temporarily extend the objects of an existing
+ /// immutable SymbolTable.
+ /// @warning As the copied objects are owned by @p o, @p o must not be destructed or assigned
+ /// while using this symbol table.
/// @param o the immutable SymbolTable to extend
- void Wrap(const SymbolTable& o) {
- next_symbol_ = o.next_symbol_;
- name_to_symbol_ = o.name_to_symbol_;
- last_prefix_to_index_ = o.last_prefix_to_index_;
- generation_id_ = o.generation_id_;
+ static SymbolTable Wrap(const SymbolTable& o) {
+ SymbolTable out(o.generation_id_);
+ out.next_symbol_ = o.next_symbol_;
+ out.name_to_symbol_ = o.name_to_symbol_;
+ out.last_prefix_to_index_ = o.last_prefix_to_index_;
+ out.generation_id_ = o.generation_id_;
+ return out;
}
/// Registers a name into the symbol table, returning the Symbol.