Add ClassID::Unique template and TINT_INSTANTIATE_CLASS_ID
We're seeing some chrome bots fail unittests in ways that suspiciously
look like dynamic casts are doing Wrong Things.
The ClassID::Of() logic depends on the linker folding away duplicate
compilation unit definitions based on ODR rules. If we were to somehow
end up with different definitions, then we'd have two or more different
ClassIDs for the same T type - leading to issues similar to what we're
seeing.
I'm not entirely sure why/how this could happen - and we've so far been
entirely unable to locally reproduce - but it _might_ have something to
do with the goma cache.
In an attempt to work around this, move the static symbol definition out
of a header-local-static and into the .cc file for each of the types.
Change-Id: If914d3045b9dac6fbe8824dac71153a768cfceb9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34563
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/src/ast/access_decoration.cc b/src/ast/access_decoration.cc
index 45c8760..6d5e726 100644
--- a/src/ast/access_decoration.cc
+++ b/src/ast/access_decoration.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::AccessDecoration);
+
namespace tint {
namespace ast {
diff --git a/src/ast/array_accessor_expression.cc b/src/ast/array_accessor_expression.cc
index 75f3bf5..bfdfddc 100644
--- a/src/ast/array_accessor_expression.cc
+++ b/src/ast/array_accessor_expression.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::ArrayAccessorExpression);
+
namespace tint {
namespace ast {
diff --git a/src/ast/array_decoration.cc b/src/ast/array_decoration.cc
index 2bdefd4..7a5733a 100644
--- a/src/ast/array_decoration.cc
+++ b/src/ast/array_decoration.cc
@@ -18,6 +18,8 @@
#include "src/ast/stride_decoration.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::ArrayDecoration);
+
namespace tint {
namespace ast {
diff --git a/src/ast/assignment_statement.cc b/src/ast/assignment_statement.cc
index fe72839..1d89d32 100644
--- a/src/ast/assignment_statement.cc
+++ b/src/ast/assignment_statement.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::AssignmentStatement);
+
namespace tint {
namespace ast {
diff --git a/src/ast/binary_expression.cc b/src/ast/binary_expression.cc
index e6f3555..67179e8 100644
--- a/src/ast/binary_expression.cc
+++ b/src/ast/binary_expression.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::BinaryExpression);
+
namespace tint {
namespace ast {
diff --git a/src/ast/binding_decoration.cc b/src/ast/binding_decoration.cc
index bb64cc1..127e600 100644
--- a/src/ast/binding_decoration.cc
+++ b/src/ast/binding_decoration.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::BindingDecoration);
+
namespace tint {
namespace ast {
diff --git a/src/ast/bitcast_expression.cc b/src/ast/bitcast_expression.cc
index 8d30b6a..50ab4f3 100644
--- a/src/ast/bitcast_expression.cc
+++ b/src/ast/bitcast_expression.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::BitcastExpression);
+
namespace tint {
namespace ast {
diff --git a/src/ast/block_statement.cc b/src/ast/block_statement.cc
index ee636a6..a851e37 100644
--- a/src/ast/block_statement.cc
+++ b/src/ast/block_statement.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::BlockStatement);
+
namespace tint {
namespace ast {
diff --git a/src/ast/bool_literal.cc b/src/ast/bool_literal.cc
index 3e481d5..4c6af63 100644
--- a/src/ast/bool_literal.cc
+++ b/src/ast/bool_literal.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::BoolLiteral);
+
namespace tint {
namespace ast {
diff --git a/src/ast/break_statement.cc b/src/ast/break_statement.cc
index cbccb00..1affc27 100644
--- a/src/ast/break_statement.cc
+++ b/src/ast/break_statement.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::BreakStatement);
+
namespace tint {
namespace ast {
diff --git a/src/ast/builtin_decoration.cc b/src/ast/builtin_decoration.cc
index 4070be8..051761c 100644
--- a/src/ast/builtin_decoration.cc
+++ b/src/ast/builtin_decoration.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::BuiltinDecoration);
+
namespace tint {
namespace ast {
diff --git a/src/ast/call_expression.cc b/src/ast/call_expression.cc
index fdee36e..be19771 100644
--- a/src/ast/call_expression.cc
+++ b/src/ast/call_expression.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::CallExpression);
+
namespace tint {
namespace ast {
diff --git a/src/ast/call_statement.cc b/src/ast/call_statement.cc
index 9158fbb..4bc7952 100644
--- a/src/ast/call_statement.cc
+++ b/src/ast/call_statement.cc
@@ -18,6 +18,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::CallStatement);
+
namespace tint {
namespace ast {
diff --git a/src/ast/case_statement.cc b/src/ast/case_statement.cc
index 35227a8..03c803e 100644
--- a/src/ast/case_statement.cc
+++ b/src/ast/case_statement.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::CaseStatement);
+
namespace tint {
namespace ast {
diff --git a/src/ast/constant_id_decoration.cc b/src/ast/constant_id_decoration.cc
index f6de69c..dbdd8ff 100644
--- a/src/ast/constant_id_decoration.cc
+++ b/src/ast/constant_id_decoration.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::ConstantIdDecoration);
+
namespace tint {
namespace ast {
diff --git a/src/ast/constructor_expression.cc b/src/ast/constructor_expression.cc
index 3326656..74ba721 100644
--- a/src/ast/constructor_expression.cc
+++ b/src/ast/constructor_expression.cc
@@ -16,6 +16,8 @@
#include <assert.h>
+TINT_INSTANTIATE_CLASS_ID(tint::ast::ConstructorExpression);
+
namespace tint {
namespace ast {
diff --git a/src/ast/continue_statement.cc b/src/ast/continue_statement.cc
index 0e5d825..77377d4 100644
--- a/src/ast/continue_statement.cc
+++ b/src/ast/continue_statement.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::ContinueStatement);
+
namespace tint {
namespace ast {
diff --git a/src/ast/decorated_variable.cc b/src/ast/decorated_variable.cc
index 63ddbbb..e8e4874 100644
--- a/src/ast/decorated_variable.cc
+++ b/src/ast/decorated_variable.cc
@@ -22,6 +22,8 @@
#include "src/ast/location_decoration.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::DecoratedVariable);
+
namespace tint {
namespace ast {
diff --git a/src/ast/decoration.cc b/src/ast/decoration.cc
index f507183..42abdde 100644
--- a/src/ast/decoration.cc
+++ b/src/ast/decoration.cc
@@ -14,6 +14,8 @@
#include "src/ast/decoration.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::Decoration);
+
namespace tint {
namespace ast {
diff --git a/src/ast/discard_statement.cc b/src/ast/discard_statement.cc
index 7db671d..66c0e19 100644
--- a/src/ast/discard_statement.cc
+++ b/src/ast/discard_statement.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::DiscardStatement);
+
namespace tint {
namespace ast {
diff --git a/src/ast/else_statement.cc b/src/ast/else_statement.cc
index 21d804b..fbcc2ca 100644
--- a/src/ast/else_statement.cc
+++ b/src/ast/else_statement.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::ElseStatement);
+
namespace tint {
namespace ast {
diff --git a/src/ast/expression.cc b/src/ast/expression.cc
index b21a903..d92067b 100644
--- a/src/ast/expression.cc
+++ b/src/ast/expression.cc
@@ -14,6 +14,8 @@
#include "src/ast/expression.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::Expression);
+
namespace tint {
namespace ast {
diff --git a/src/ast/fallthrough_statement.cc b/src/ast/fallthrough_statement.cc
index f193a8d..5aff216 100644
--- a/src/ast/fallthrough_statement.cc
+++ b/src/ast/fallthrough_statement.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::FallthroughStatement);
+
namespace tint {
namespace ast {
diff --git a/src/ast/float_literal.cc b/src/ast/float_literal.cc
index 6d182ba..d6f30c7 100644
--- a/src/ast/float_literal.cc
+++ b/src/ast/float_literal.cc
@@ -20,6 +20,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::FloatLiteral);
+
namespace tint {
namespace ast {
diff --git a/src/ast/function.cc b/src/ast/function.cc
index 5f53799..173f1ed 100644
--- a/src/ast/function.cc
+++ b/src/ast/function.cc
@@ -25,6 +25,8 @@
#include "src/ast/type/texture_type.h"
#include "src/ast/workgroup_decoration.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::Function);
+
namespace tint {
namespace ast {
diff --git a/src/ast/function_decoration.cc b/src/ast/function_decoration.cc
index 25476a5..e81258f 100644
--- a/src/ast/function_decoration.cc
+++ b/src/ast/function_decoration.cc
@@ -14,6 +14,8 @@
#include "src/ast/function_decoration.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::FunctionDecoration);
+
namespace tint {
namespace ast {
diff --git a/src/ast/identifier_expression.cc b/src/ast/identifier_expression.cc
index 6952d31..d4770db 100644
--- a/src/ast/identifier_expression.cc
+++ b/src/ast/identifier_expression.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::IdentifierExpression);
+
namespace tint {
namespace ast {
diff --git a/src/ast/if_statement.cc b/src/ast/if_statement.cc
index 5bdf9ce..451c123 100644
--- a/src/ast/if_statement.cc
+++ b/src/ast/if_statement.cc
@@ -18,6 +18,8 @@
#include "src/ast/else_statement.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::IfStatement);
+
namespace tint {
namespace ast {
diff --git a/src/ast/int_literal.cc b/src/ast/int_literal.cc
index afb8a29..aa35f3c 100644
--- a/src/ast/int_literal.cc
+++ b/src/ast/int_literal.cc
@@ -14,6 +14,8 @@
#include "src/ast/int_literal.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::IntLiteral);
+
namespace tint {
namespace ast {
diff --git a/src/ast/literal.cc b/src/ast/literal.cc
index 19fa717..77a7612 100644
--- a/src/ast/literal.cc
+++ b/src/ast/literal.cc
@@ -14,6 +14,8 @@
#include "src/ast/literal.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::Literal);
+
namespace tint {
namespace ast {
diff --git a/src/ast/location_decoration.cc b/src/ast/location_decoration.cc
index 3abffc9..64990a8 100644
--- a/src/ast/location_decoration.cc
+++ b/src/ast/location_decoration.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::LocationDecoration);
+
namespace tint {
namespace ast {
diff --git a/src/ast/loop_statement.cc b/src/ast/loop_statement.cc
index 72b9a97..014d0ae 100644
--- a/src/ast/loop_statement.cc
+++ b/src/ast/loop_statement.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::LoopStatement);
+
namespace tint {
namespace ast {
diff --git a/src/ast/member_accessor_expression.cc b/src/ast/member_accessor_expression.cc
index 8f81846..9fdbef3 100644
--- a/src/ast/member_accessor_expression.cc
+++ b/src/ast/member_accessor_expression.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::MemberAccessorExpression);
+
namespace tint {
namespace ast {
diff --git a/src/ast/node.cc b/src/ast/node.cc
index 2c7395b..18306cd 100644
--- a/src/ast/node.cc
+++ b/src/ast/node.cc
@@ -16,6 +16,8 @@
#include <sstream>
+TINT_INSTANTIATE_CLASS_ID(tint::ast::Node);
+
namespace tint {
namespace ast {
diff --git a/src/ast/null_literal.cc b/src/ast/null_literal.cc
index cb2bf94..4ae8324 100644
--- a/src/ast/null_literal.cc
+++ b/src/ast/null_literal.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::NullLiteral);
+
namespace tint {
namespace ast {
diff --git a/src/ast/return_statement.cc b/src/ast/return_statement.cc
index 698daf3..43a2ac5 100644
--- a/src/ast/return_statement.cc
+++ b/src/ast/return_statement.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::ReturnStatement);
+
namespace tint {
namespace ast {
diff --git a/src/ast/scalar_constructor_expression.cc b/src/ast/scalar_constructor_expression.cc
index 7a68042..23bec02 100644
--- a/src/ast/scalar_constructor_expression.cc
+++ b/src/ast/scalar_constructor_expression.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::ScalarConstructorExpression);
+
namespace tint {
namespace ast {
diff --git a/src/ast/set_decoration.cc b/src/ast/set_decoration.cc
index 0c53618..3b5ea5e 100644
--- a/src/ast/set_decoration.cc
+++ b/src/ast/set_decoration.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::SetDecoration);
+
namespace tint {
namespace ast {
diff --git a/src/ast/sint_literal.cc b/src/ast/sint_literal.cc
index 6bded6f..0b3b4b3 100644
--- a/src/ast/sint_literal.cc
+++ b/src/ast/sint_literal.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::SintLiteral);
+
namespace tint {
namespace ast {
diff --git a/src/ast/stage_decoration.cc b/src/ast/stage_decoration.cc
index 8613167..d66817f 100644
--- a/src/ast/stage_decoration.cc
+++ b/src/ast/stage_decoration.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::StageDecoration);
+
namespace tint {
namespace ast {
diff --git a/src/ast/statement.cc b/src/ast/statement.cc
index aa45876..9abbba0 100644
--- a/src/ast/statement.cc
+++ b/src/ast/statement.cc
@@ -31,6 +31,8 @@
#include "src/ast/switch_statement.h"
#include "src/ast/variable_decl_statement.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::Statement);
+
namespace tint {
namespace ast {
diff --git a/src/ast/stride_decoration.cc b/src/ast/stride_decoration.cc
index f41ac20..094ec56 100644
--- a/src/ast/stride_decoration.cc
+++ b/src/ast/stride_decoration.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::StrideDecoration);
+
namespace tint {
namespace ast {
diff --git a/src/ast/struct.cc b/src/ast/struct.cc
index bb07647..4297a39 100644
--- a/src/ast/struct.cc
+++ b/src/ast/struct.cc
@@ -18,6 +18,8 @@
#include "src/ast/module.h"
#include "src/ast/struct_block_decoration.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::Struct);
+
namespace tint {
namespace ast {
diff --git a/src/ast/struct_block_decoration.cc b/src/ast/struct_block_decoration.cc
index 22df5c4..58f18bd 100644
--- a/src/ast/struct_block_decoration.cc
+++ b/src/ast/struct_block_decoration.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::StructBlockDecoration);
+
namespace tint {
namespace ast {
diff --git a/src/ast/struct_decoration.cc b/src/ast/struct_decoration.cc
index 4b372fd..cb9a502 100644
--- a/src/ast/struct_decoration.cc
+++ b/src/ast/struct_decoration.cc
@@ -14,6 +14,8 @@
#include "src/ast/struct_decoration.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::StructDecoration);
+
namespace tint {
namespace ast {
diff --git a/src/ast/struct_member.cc b/src/ast/struct_member.cc
index cefbede..a040450 100644
--- a/src/ast/struct_member.cc
+++ b/src/ast/struct_member.cc
@@ -18,6 +18,8 @@
#include "src/ast/module.h"
#include "src/ast/struct_member_offset_decoration.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::StructMember);
+
namespace tint {
namespace ast {
diff --git a/src/ast/struct_member_decoration.cc b/src/ast/struct_member_decoration.cc
index 353f1ca..2396d3d 100644
--- a/src/ast/struct_member_decoration.cc
+++ b/src/ast/struct_member_decoration.cc
@@ -18,6 +18,8 @@
#include "src/ast/struct_member_offset_decoration.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::StructMemberDecoration);
+
namespace tint {
namespace ast {
diff --git a/src/ast/struct_member_offset_decoration.cc b/src/ast/struct_member_offset_decoration.cc
index 974b5fd..abd2161 100644
--- a/src/ast/struct_member_offset_decoration.cc
+++ b/src/ast/struct_member_offset_decoration.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::StructMemberOffsetDecoration);
+
namespace tint {
namespace ast {
diff --git a/src/ast/switch_statement.cc b/src/ast/switch_statement.cc
index 18140b6..01a99e9 100644
--- a/src/ast/switch_statement.cc
+++ b/src/ast/switch_statement.cc
@@ -18,6 +18,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::SwitchStatement);
+
namespace tint {
namespace ast {
diff --git a/src/ast/type/access_control_type.cc b/src/ast/type/access_control_type.cc
index 7a7a676..44e7cbe 100644
--- a/src/ast/type/access_control_type.cc
+++ b/src/ast/type/access_control_type.cc
@@ -19,6 +19,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::type::AccessControl);
+
namespace tint {
namespace ast {
namespace type {
diff --git a/src/ast/type/alias_type.cc b/src/ast/type/alias_type.cc
index e07ed10..aca4866 100644
--- a/src/ast/type/alias_type.cc
+++ b/src/ast/type/alias_type.cc
@@ -19,6 +19,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::type::Alias);
+
namespace tint {
namespace ast {
namespace type {
diff --git a/src/ast/type/array_type.cc b/src/ast/type/array_type.cc
index 34cec86..bc22cf5 100644
--- a/src/ast/type/array_type.cc
+++ b/src/ast/type/array_type.cc
@@ -22,6 +22,8 @@
#include "src/ast/stride_decoration.h"
#include "src/ast/type/vector_type.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::type::Array);
+
namespace tint {
namespace ast {
namespace type {
diff --git a/src/ast/type/bool_type.cc b/src/ast/type/bool_type.cc
index da095dc..7c26c86 100644
--- a/src/ast/type/bool_type.cc
+++ b/src/ast/type/bool_type.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::type::Bool);
+
namespace tint {
namespace ast {
namespace type {
diff --git a/src/ast/type/depth_texture_type.cc b/src/ast/type/depth_texture_type.cc
index c4b1530..95b55aa 100644
--- a/src/ast/type/depth_texture_type.cc
+++ b/src/ast/type/depth_texture_type.cc
@@ -20,6 +20,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::type::DepthTexture);
+
namespace tint {
namespace ast {
namespace type {
diff --git a/src/ast/type/f32_type.cc b/src/ast/type/f32_type.cc
index 50823b2..bfcdc69 100644
--- a/src/ast/type/f32_type.cc
+++ b/src/ast/type/f32_type.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::type::F32);
+
namespace tint {
namespace ast {
namespace type {
diff --git a/src/ast/type/i32_type.cc b/src/ast/type/i32_type.cc
index 303b93e..6b47eb3 100644
--- a/src/ast/type/i32_type.cc
+++ b/src/ast/type/i32_type.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::type::I32);
+
namespace tint {
namespace ast {
namespace type {
diff --git a/src/ast/type/matrix_type.cc b/src/ast/type/matrix_type.cc
index c0210bc..ed865a7 100644
--- a/src/ast/type/matrix_type.cc
+++ b/src/ast/type/matrix_type.cc
@@ -21,6 +21,8 @@
#include "src/ast/type/array_type.h"
#include "src/ast/type/vector_type.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::type::Matrix);
+
namespace tint {
namespace ast {
namespace type {
diff --git a/src/ast/type/multisampled_texture_type.cc b/src/ast/type/multisampled_texture_type.cc
index a321684..2ec4320 100644
--- a/src/ast/type/multisampled_texture_type.cc
+++ b/src/ast/type/multisampled_texture_type.cc
@@ -20,6 +20,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::type::MultisampledTexture);
+
namespace tint {
namespace ast {
namespace type {
diff --git a/src/ast/type/pointer_type.cc b/src/ast/type/pointer_type.cc
index 604eb8b..67c0cfa 100644
--- a/src/ast/type/pointer_type.cc
+++ b/src/ast/type/pointer_type.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::type::Pointer);
+
namespace tint {
namespace ast {
namespace type {
diff --git a/src/ast/type/sampled_texture_type.cc b/src/ast/type/sampled_texture_type.cc
index 0fa62d7..9a95c12 100644
--- a/src/ast/type/sampled_texture_type.cc
+++ b/src/ast/type/sampled_texture_type.cc
@@ -20,6 +20,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::type::SampledTexture);
+
namespace tint {
namespace ast {
namespace type {
diff --git a/src/ast/type/sampler_type.cc b/src/ast/type/sampler_type.cc
index d3eaff1..f1070d4 100644
--- a/src/ast/type/sampler_type.cc
+++ b/src/ast/type/sampler_type.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::type::Sampler);
+
namespace tint {
namespace ast {
namespace type {
diff --git a/src/ast/type/storage_texture_type.cc b/src/ast/type/storage_texture_type.cc
index af6c7d5..da44ac6 100644
--- a/src/ast/type/storage_texture_type.cc
+++ b/src/ast/type/storage_texture_type.cc
@@ -20,6 +20,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::type::StorageTexture);
+
namespace tint {
namespace ast {
namespace type {
diff --git a/src/ast/type/struct_type.cc b/src/ast/type/struct_type.cc
index c4756ec..7ce4b14 100644
--- a/src/ast/type/struct_type.cc
+++ b/src/ast/type/struct_type.cc
@@ -24,6 +24,8 @@
#include "src/ast/type/matrix_type.h"
#include "src/ast/type/vector_type.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::type::Struct);
+
namespace tint {
namespace ast {
namespace type {
diff --git a/src/ast/type/texture_type.cc b/src/ast/type/texture_type.cc
index cd81de5..24a80bd 100644
--- a/src/ast/type/texture_type.cc
+++ b/src/ast/type/texture_type.cc
@@ -19,6 +19,8 @@
#include "src/ast/type/multisampled_texture_type.h"
#include "src/ast/type/sampled_texture_type.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::type::Texture);
+
namespace tint {
namespace ast {
namespace type {
diff --git a/src/ast/type/type.cc b/src/ast/type/type.cc
index e424ee7..329812f 100644
--- a/src/ast/type/type.cc
+++ b/src/ast/type/type.cc
@@ -31,6 +31,8 @@
#include "src/ast/type/vector_type.h"
#include "src/ast/type/void_type.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::type::Type);
+
namespace tint {
namespace ast {
namespace type {
diff --git a/src/ast/type/u32_type.cc b/src/ast/type/u32_type.cc
index 18bbb73..37364d7 100644
--- a/src/ast/type/u32_type.cc
+++ b/src/ast/type/u32_type.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::type::U32);
+
namespace tint {
namespace ast {
namespace type {
diff --git a/src/ast/type/vector_type.cc b/src/ast/type/vector_type.cc
index 9f52bdc..3697e4e 100644
--- a/src/ast/type/vector_type.cc
+++ b/src/ast/type/vector_type.cc
@@ -20,6 +20,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::type::Vector);
+
namespace tint {
namespace ast {
namespace type {
diff --git a/src/ast/type/void_type.cc b/src/ast/type/void_type.cc
index 6eaaec9..62ce402 100644
--- a/src/ast/type/void_type.cc
+++ b/src/ast/type/void_type.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::type::Void);
+
namespace tint {
namespace ast {
namespace type {
diff --git a/src/ast/type_constructor_expression.cc b/src/ast/type_constructor_expression.cc
index 8717833..bf7dbfe 100644
--- a/src/ast/type_constructor_expression.cc
+++ b/src/ast/type_constructor_expression.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::TypeConstructorExpression);
+
namespace tint {
namespace ast {
diff --git a/src/ast/type_decoration.cc b/src/ast/type_decoration.cc
index e1d872d..68c7e89 100644
--- a/src/ast/type_decoration.cc
+++ b/src/ast/type_decoration.cc
@@ -18,6 +18,8 @@
#include "src/ast/access_decoration.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::TypeDecoration);
+
namespace tint {
namespace ast {
diff --git a/src/ast/uint_literal.cc b/src/ast/uint_literal.cc
index bf00090..f361e4a 100644
--- a/src/ast/uint_literal.cc
+++ b/src/ast/uint_literal.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::UintLiteral);
+
namespace tint {
namespace ast {
diff --git a/src/ast/unary_op_expression.cc b/src/ast/unary_op_expression.cc
index c5bc38c..9e9ad5d 100644
--- a/src/ast/unary_op_expression.cc
+++ b/src/ast/unary_op_expression.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::UnaryOpExpression);
+
namespace tint {
namespace ast {
diff --git a/src/ast/variable.cc b/src/ast/variable.cc
index 01ae068..53c0f03 100644
--- a/src/ast/variable.cc
+++ b/src/ast/variable.cc
@@ -20,6 +20,8 @@
#include "src/ast/decorated_variable.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::Variable);
+
namespace tint {
namespace ast {
diff --git a/src/ast/variable_decl_statement.cc b/src/ast/variable_decl_statement.cc
index f1ec4d3..fc9763c 100644
--- a/src/ast/variable_decl_statement.cc
+++ b/src/ast/variable_decl_statement.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::VariableDeclStatement);
+
namespace tint {
namespace ast {
diff --git a/src/ast/variable_decoration.cc b/src/ast/variable_decoration.cc
index ea8d268..b79ed55 100644
--- a/src/ast/variable_decoration.cc
+++ b/src/ast/variable_decoration.cc
@@ -16,6 +16,8 @@
#include <assert.h>
+TINT_INSTANTIATE_CLASS_ID(tint::ast::VariableDecoration);
+
namespace tint {
namespace ast {
diff --git a/src/ast/workgroup_decoration.cc b/src/ast/workgroup_decoration.cc
index 22a78f2..b1935b9 100644
--- a/src/ast/workgroup_decoration.cc
+++ b/src/ast/workgroup_decoration.cc
@@ -17,6 +17,8 @@
#include "src/ast/clone_context.h"
#include "src/ast/module.h"
+TINT_INSTANTIATE_CLASS_ID(tint::ast::WorkgroupDecoration);
+
namespace tint {
namespace ast {
diff --git a/src/castable.cc b/src/castable.cc
index 0ddfdb2..9b50383 100644
--- a/src/castable.cc
+++ b/src/castable.cc
@@ -14,6 +14,8 @@
#include "src/castable.h"
+TINT_INSTANTIATE_CLASS_ID(tint::CastableBase);
+
namespace tint {
bool CastableBase::Is(ClassID id) const {
diff --git a/src/castable.h b/src/castable.h
index 518a854..0740b1f 100644
--- a/src/castable.h
+++ b/src/castable.h
@@ -21,20 +21,28 @@
namespace tint {
+/// Helper macro to instantiate the ClassID for `CLASS`.
+#define TINT_INSTANTIATE_CLASS_ID(CLASS) \
+ template <> \
+ const char tint::ClassID::Unique<CLASS>::token = 0
+
/// ClassID represents a unique, comparable identifier for a C++ type.
class ClassID {
+ private:
+ /// Helper template that holds a single static field, which is used by Of()
+ /// to obtain a unique identifier by taking the field's address.
+ template <typename T>
+ struct Unique {
+ static const char token;
+ };
+
public:
/// @returns the unique ClassID for the type T.
template <typename T>
static ClassID Of() {
- // Take the address of a static local variable to produce a unique
- // identifier for the type T.
- // We use a short name here as this method is instantiated for every
- // castable class, and so we'll have a fully qualified name in the
- // executable symbol table for every castable type. A shorter name produces
- // a smaller executable when unstripped.
- static char s;
- return ClassID{reinterpret_cast<uintptr_t>(&s)};
+ // Take the address of a static variable to produce a unique identifier for
+ // the type T.
+ return ClassID{reinterpret_cast<uintptr_t>(&Unique<T>::token)};
}
/// Equality operator
diff --git a/src/castable_test.cc b/src/castable_test.cc
index 5c7a9bd..c591049 100644
--- a/src/castable_test.cc
+++ b/src/castable_test.cc
@@ -19,39 +19,44 @@
#include "gtest/gtest.h"
-namespace tint {
-namespace {
-
-struct Animal : public Castable<Animal> {
+struct Animal : public tint::Castable<Animal> {
explicit Animal(std::string n) : name(n) {}
const std::string name;
};
-struct Amphibian : public Castable<Amphibian, Animal> {
+struct Amphibian : public tint::Castable<Amphibian, Animal> {
explicit Amphibian(std::string n) : Base(n) {}
};
-struct Mammal : public Castable<Mammal, Animal> {
+struct Mammal : public tint::Castable<Mammal, Animal> {
explicit Mammal(std::string n) : Base(n) {}
};
-struct Reptile : public Castable<Reptile, Animal> {
+struct Reptile : public tint::Castable<Reptile, Animal> {
explicit Reptile(std::string n) : Base(n) {}
};
-struct Frog : public Castable<Frog, Amphibian> {
+struct Frog : public tint::Castable<Frog, Amphibian> {
Frog() : Base("Frog") {}
};
-struct Bear : public Castable<Bear, Mammal> {
+struct Bear : public tint::Castable<Bear, Mammal> {
Bear() : Base("Bear") {}
};
-struct Gecko : public Castable<Gecko, Reptile> {
+struct Gecko : public tint::Castable<Gecko, Reptile> {
Gecko() : Base("Gecko") {}
};
-} // namespace
+TINT_INSTANTIATE_CLASS_ID(Animal);
+TINT_INSTANTIATE_CLASS_ID(Amphibian);
+TINT_INSTANTIATE_CLASS_ID(Mammal);
+TINT_INSTANTIATE_CLASS_ID(Reptile);
+TINT_INSTANTIATE_CLASS_ID(Frog);
+TINT_INSTANTIATE_CLASS_ID(Bear);
+TINT_INSTANTIATE_CLASS_ID(Gecko);
+
+namespace tint {
TEST(CastableBase, Is) {
std::unique_ptr<CastableBase> frog = std::make_unique<Frog>();