From 89ea705766b0758ad23799e065768fa9ad155f22 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 2 Dec 2020 18:19:28 +0000 Subject: [PATCH] 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 Commit-Queue: Ben Clayton --- src/ast/access_decoration.cc | 2 ++ src/ast/array_accessor_expression.cc | 2 ++ src/ast/array_decoration.cc | 2 ++ src/ast/assignment_statement.cc | 2 ++ src/ast/binary_expression.cc | 2 ++ src/ast/binding_decoration.cc | 2 ++ src/ast/bitcast_expression.cc | 2 ++ src/ast/block_statement.cc | 2 ++ src/ast/bool_literal.cc | 2 ++ src/ast/break_statement.cc | 2 ++ src/ast/builtin_decoration.cc | 2 ++ src/ast/call_expression.cc | 2 ++ src/ast/call_statement.cc | 2 ++ src/ast/case_statement.cc | 2 ++ src/ast/constant_id_decoration.cc | 2 ++ src/ast/constructor_expression.cc | 2 ++ src/ast/continue_statement.cc | 2 ++ src/ast/decorated_variable.cc | 2 ++ src/ast/decoration.cc | 2 ++ src/ast/discard_statement.cc | 2 ++ src/ast/else_statement.cc | 2 ++ src/ast/expression.cc | 2 ++ src/ast/fallthrough_statement.cc | 2 ++ src/ast/float_literal.cc | 2 ++ src/ast/function.cc | 2 ++ src/ast/function_decoration.cc | 2 ++ src/ast/identifier_expression.cc | 2 ++ src/ast/if_statement.cc | 2 ++ src/ast/int_literal.cc | 2 ++ src/ast/literal.cc | 2 ++ src/ast/location_decoration.cc | 2 ++ src/ast/loop_statement.cc | 2 ++ src/ast/member_accessor_expression.cc | 2 ++ src/ast/node.cc | 2 ++ src/ast/null_literal.cc | 2 ++ src/ast/return_statement.cc | 2 ++ src/ast/scalar_constructor_expression.cc | 2 ++ src/ast/set_decoration.cc | 2 ++ src/ast/sint_literal.cc | 2 ++ src/ast/stage_decoration.cc | 2 ++ src/ast/statement.cc | 2 ++ src/ast/stride_decoration.cc | 2 ++ src/ast/struct.cc | 2 ++ src/ast/struct_block_decoration.cc | 2 ++ src/ast/struct_decoration.cc | 2 ++ src/ast/struct_member.cc | 2 ++ src/ast/struct_member_decoration.cc | 2 ++ src/ast/struct_member_offset_decoration.cc | 2 ++ src/ast/switch_statement.cc | 2 ++ src/ast/type/access_control_type.cc | 2 ++ src/ast/type/alias_type.cc | 2 ++ src/ast/type/array_type.cc | 2 ++ src/ast/type/bool_type.cc | 2 ++ src/ast/type/depth_texture_type.cc | 2 ++ src/ast/type/f32_type.cc | 2 ++ src/ast/type/i32_type.cc | 2 ++ src/ast/type/matrix_type.cc | 2 ++ src/ast/type/multisampled_texture_type.cc | 2 ++ src/ast/type/pointer_type.cc | 2 ++ src/ast/type/sampled_texture_type.cc | 2 ++ src/ast/type/sampler_type.cc | 2 ++ src/ast/type/storage_texture_type.cc | 2 ++ src/ast/type/struct_type.cc | 2 ++ src/ast/type/texture_type.cc | 2 ++ src/ast/type/type.cc | 2 ++ src/ast/type/u32_type.cc | 2 ++ src/ast/type/vector_type.cc | 2 ++ src/ast/type/void_type.cc | 2 ++ src/ast/type_constructor_expression.cc | 2 ++ src/ast/type_decoration.cc | 2 ++ src/ast/uint_literal.cc | 2 ++ src/ast/unary_op_expression.cc | 2 ++ src/ast/variable.cc | 2 ++ src/ast/variable_decl_statement.cc | 2 ++ src/ast/variable_decoration.cc | 2 ++ src/ast/workgroup_decoration.cc | 2 ++ src/castable.cc | 2 ++ src/castable.h | 24 ++++++++++++------- src/castable_test.cc | 27 +++++++++++++--------- 79 files changed, 186 insertions(+), 19 deletions(-) diff --git a/src/ast/access_decoration.cc b/src/ast/access_decoration.cc index 45c8760ab4..6d5e726c60 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 75f3bf545c..bfdfddc60a 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 2bdefd46b1..7a5733a670 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 fe72839cfc..1d89d32094 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 e6f3555b34..67179e8632 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 bb64cc1e23..127e6001ad 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 8d30b6aa7c..50ab4f3674 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 ee636a67d9..a851e37263 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 3e481d501f..4c6af63923 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 cbccb00066..1affc2790b 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 4070be8761..051761cdde 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 fdee36ef1a..be197714c4 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 9158fbb988..4bc7952b00 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 35227a8a1a..03c803e7b8 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 f6de69cf25..dbdd8ff3a4 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 33266566f3..74ba721b0c 100644 --- a/src/ast/constructor_expression.cc +++ b/src/ast/constructor_expression.cc @@ -16,6 +16,8 @@ #include +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 0e5d825242..77377d4cfd 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 63ddbbbd11..e8e4874db8 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 f507183972..42abdde902 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 7db671d276..66c0e19948 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 21d804b6a0..fbcc2cac01 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 b21a903ef0..d92067b7b9 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 f193a8d829..5aff216859 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 6d182ba196..d6f30c7841 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 5f53799db3..173f1edeee 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 25476a5906..e81258fb76 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 6952d31f31..d4770db557 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 5bdf9ce9c0..451c123eb2 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 afb8a296f2..aa35f3cdc3 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 19fa71758e..77a7612573 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 3abffc958a..64990a85f6 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 72b9a973e9..014d0aeaef 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 8f8184631d..9fdbef32b5 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 2c7395be2b..18306cd4d7 100644 --- a/src/ast/node.cc +++ b/src/ast/node.cc @@ -16,6 +16,8 @@ #include +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 cb2bf9496c..4ae8324c78 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 698daf3fc2..43a2ac5877 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 7a68042e6b..23bec02016 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 0c53618498..3b5ea5eb88 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 6bded6f6bf..0b3b4b3924 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 8613167d86..d66817f464 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 aa4587638b..9abbba024f 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 f41ac20224..094ec56fac 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 bb076475af..4297a3906c 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 22df5c443e..58f18bddd3 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 4b372fd2d9..cb9a502500 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 cefbeded7e..a04045008c 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 353f1ca5d3..2396d3ddde 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 974b5fde7a..abd21619f9 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 18140b6c32..01a99e9e95 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 7a7a6768b9..44e7cbe784 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 e07ed100d1..aca486661b 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 34cec86a03..bc22cf5ba2 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 da095dca9a..7c26c86379 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 c4b1530cd1..95b55aa464 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 50823b25c2..bfcdc6996c 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 303b93eb9d..6b47eb33e1 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 c0210bc84d..ed865a70e0 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 a321684aba..2ec43209ae 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 604eb8b892..67c0cfaab5 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 0fa62d7f82..9a95c121a4 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 d3eaff19b9..f1070d468a 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 af6c7d5dd9..da44ac6d41 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 c4756ec79a..7ce4b14ed1 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 cd81de51ba..24a80bd723 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 e424ee7a46..329812f82a 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 18bbb73654..37364d7b30 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 9f52bdc769..3697e4e286 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 6eaaec97c7..62ce40297e 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 8717833cfb..bf7dbfee6b 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 e1d872dbd8..68c7e89812 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 bf00090aac..f361e4ac70 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 c5bc38c520..9e9ad5d6a7 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 01ae068d41..53c0f032fe 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 f1ec4d35af..fc9763c23d 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 ea8d2681aa..b79ed55436 100644 --- a/src/ast/variable_decoration.cc +++ b/src/ast/variable_decoration.cc @@ -16,6 +16,8 @@ #include +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 22a78f2d1f..b1935b9026 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 0ddfdb2fd7..9b50383f52 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 518a854947..0740b1fa18 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::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 + struct Unique { + static const char token; + }; + public: /// @returns the unique ClassID for the type T. template 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(&s)}; + // Take the address of a static variable to produce a unique identifier for + // the type T. + return ClassID{reinterpret_cast(&Unique::token)}; } /// Equality operator diff --git a/src/castable_test.cc b/src/castable_test.cc index 5c7a9bd3ac..c591049113 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 { +struct Animal : public tint::Castable { explicit Animal(std::string n) : name(n) {} const std::string name; }; -struct Amphibian : public Castable { +struct Amphibian : public tint::Castable { explicit Amphibian(std::string n) : Base(n) {} }; -struct Mammal : public Castable { +struct Mammal : public tint::Castable { explicit Mammal(std::string n) : Base(n) {} }; -struct Reptile : public Castable { +struct Reptile : public tint::Castable { explicit Reptile(std::string n) : Base(n) {} }; -struct Frog : public Castable { +struct Frog : public tint::Castable { Frog() : Base("Frog") {} }; -struct Bear : public Castable { +struct Bear : public tint::Castable { Bear() : Base("Bear") {} }; -struct Gecko : public Castable { +struct Gecko : public tint::Castable { 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 frog = std::make_unique();