diff --git a/src/tint/BUILD.gn b/src/tint/BUILD.gn index c0c0b62236..825741c6a5 100644 --- a/src/tint/BUILD.gn +++ b/src/tint/BUILD.gn @@ -287,6 +287,7 @@ libtint_source_set("libtint_core_all_src") { "ast/module.h", "ast/multisampled_texture.cc", "ast/multisampled_texture.h", + "ast/node_id.h", "ast/node.cc", "ast/node.h", "ast/override.cc", diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt index 6c611c306a..ec0e78e8e5 100644 --- a/src/tint/CMakeLists.txt +++ b/src/tint/CMakeLists.txt @@ -157,6 +157,7 @@ set(TINT_LIB_SRCS ast/module.h ast/multisampled_texture.cc ast/multisampled_texture.h + ast/node_id.h ast/node.cc ast/node.h ast/override.cc diff --git a/src/tint/ast/alias.cc b/src/tint/ast/alias.cc index fa98cd486b..8a23e8f45d 100644 --- a/src/tint/ast/alias.cc +++ b/src/tint/ast/alias.cc @@ -20,8 +20,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Alias); namespace tint::ast { -Alias::Alias(ProgramID pid, const Source& src, const Symbol& n, const Type* subtype) - : Base(pid, src, n), type(subtype) { +Alias::Alias(ProgramID pid, NodeID nid, const Source& src, const Symbol& n, const Type* subtype) + : Base(pid, nid, src, n), type(subtype) { TINT_ASSERT(AST, type); } diff --git a/src/tint/ast/alias.h b/src/tint/ast/alias.h index 87ce57874d..74d91b04c2 100644 --- a/src/tint/ast/alias.h +++ b/src/tint/ast/alias.h @@ -26,10 +26,11 @@ class Alias final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param name the symbol for the alias /// @param subtype the alias'd type - Alias(ProgramID pid, const Source& src, const Symbol& name, const Type* subtype); + Alias(ProgramID pid, NodeID nid, const Source& src, const Symbol& name, const Type* subtype); /// Move constructor Alias(Alias&&); /// Destructor diff --git a/src/tint/ast/array.cc b/src/tint/ast/array.cc index 0389ed0d9c..cd1fc26783 100644 --- a/src/tint/ast/array.cc +++ b/src/tint/ast/array.cc @@ -38,11 +38,12 @@ std::string SizeExprToString(const Expression* size, const SymbolTable& symbols) } // namespace Array::Array(ProgramID pid, + NodeID nid, const Source& src, const Type* subtype, const Expression* cnt, AttributeList attrs) - : Base(pid, src), type(subtype), count(cnt), attributes(attrs) {} + : Base(pid, nid, src), type(subtype), count(cnt), attributes(attrs) {} Array::Array(Array&&) = default; diff --git a/src/tint/ast/array.h b/src/tint/ast/array.h index e92902d4cb..ccc31ab229 100644 --- a/src/tint/ast/array.h +++ b/src/tint/ast/array.h @@ -32,12 +32,14 @@ class Array final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param subtype the type of the array elements /// @param count the number of elements in the array. nullptr represents a /// runtime-sized array. /// @param attributes the array attributes Array(ProgramID pid, + NodeID nid, const Source& src, const Type* subtype, const Expression* count, diff --git a/src/tint/ast/assignment_statement.cc b/src/tint/ast/assignment_statement.cc index d7d7bc582a..6a835b88ec 100644 --- a/src/tint/ast/assignment_statement.cc +++ b/src/tint/ast/assignment_statement.cc @@ -21,10 +21,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::AssignmentStatement); namespace tint::ast { AssignmentStatement::AssignmentStatement(ProgramID pid, + NodeID nid, const Source& src, const Expression* l, const Expression* r) - : Base(pid, src), lhs(l), rhs(r) { + : Base(pid, nid, src), lhs(l), rhs(r) { TINT_ASSERT(AST, lhs); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs, program_id); TINT_ASSERT(AST, rhs); diff --git a/src/tint/ast/assignment_statement.h b/src/tint/ast/assignment_statement.h index 9def075e76..6b8c412f47 100644 --- a/src/tint/ast/assignment_statement.h +++ b/src/tint/ast/assignment_statement.h @@ -24,11 +24,13 @@ namespace tint::ast { class AssignmentStatement final : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param source the assignment statement source /// @param lhs the left side of the expression /// @param rhs the right side of the expression - AssignmentStatement(ProgramID program_id, + AssignmentStatement(ProgramID pid, + NodeID nid, const Source& source, const Expression* lhs, const Expression* rhs); diff --git a/src/tint/ast/ast_type.cc b/src/tint/ast/ast_type.cc index ec247c9460..768493f90a 100644 --- a/src/tint/ast/ast_type.cc +++ b/src/tint/ast/ast_type.cc @@ -30,7 +30,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Type); namespace tint::ast { -Type::Type(ProgramID pid, const Source& src) : Base(pid, src) {} +Type::Type(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {} Type::Type(Type&&) = default; diff --git a/src/tint/ast/atomic.cc b/src/tint/ast/atomic.cc index ce7019b853..9914c6a8bc 100644 --- a/src/tint/ast/atomic.cc +++ b/src/tint/ast/atomic.cc @@ -20,8 +20,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Atomic); namespace tint::ast { -Atomic::Atomic(ProgramID pid, const Source& src, const Type* const subtype) - : Base(pid, src), type(subtype) {} +Atomic::Atomic(ProgramID pid, NodeID nid, const Source& src, const Type* const subtype) + : Base(pid, nid, src), type(subtype) {} std::string Atomic::FriendlyName(const SymbolTable& symbols) const { std::ostringstream out; diff --git a/src/tint/ast/atomic.h b/src/tint/ast/atomic.h index 5f634222f1..689871e1cf 100644 --- a/src/tint/ast/atomic.h +++ b/src/tint/ast/atomic.h @@ -26,9 +26,10 @@ class Atomic final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param subtype the pointee type - Atomic(ProgramID pid, const Source& src, const Type* const subtype); + Atomic(ProgramID pid, NodeID nid, const Source& src, const Type* const subtype); /// Move constructor Atomic(Atomic&&); ~Atomic() override; diff --git a/src/tint/ast/attribute.h b/src/tint/ast/attribute.h index cb9bf766d4..68c4435085 100644 --- a/src/tint/ast/attribute.h +++ b/src/tint/ast/attribute.h @@ -33,8 +33,9 @@ class Attribute : public Castable { protected: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node - Attribute(ProgramID pid, const Source& src) : Base(pid, src) {} + Attribute(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {} }; /// A list of attributes diff --git a/src/tint/ast/binary_expression.cc b/src/tint/ast/binary_expression.cc index e3ccd8b882..ebf704eee0 100644 --- a/src/tint/ast/binary_expression.cc +++ b/src/tint/ast/binary_expression.cc @@ -21,11 +21,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BinaryExpression); namespace tint::ast { BinaryExpression::BinaryExpression(ProgramID pid, + NodeID nid, const Source& src, BinaryOp o, const Expression* l, const Expression* r) - : Base(pid, src), op(o), lhs(l), rhs(r) { + : Base(pid, nid, src), op(o), lhs(l), rhs(r) { TINT_ASSERT(AST, lhs); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs, program_id); TINT_ASSERT(AST, rhs); diff --git a/src/tint/ast/binary_expression.h b/src/tint/ast/binary_expression.h index ad59da401d..cdc5960f3c 100644 --- a/src/tint/ast/binary_expression.h +++ b/src/tint/ast/binary_expression.h @@ -46,12 +46,14 @@ enum class BinaryOp { class BinaryExpression final : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param source the binary expression source /// @param op the operation type /// @param lhs the left side of the expression /// @param rhs the right side of the expression - BinaryExpression(ProgramID program_id, + BinaryExpression(ProgramID pid, + NodeID nid, const Source& source, BinaryOp op, const Expression* lhs, diff --git a/src/tint/ast/binding_attribute.cc b/src/tint/ast/binding_attribute.cc index b9282f2aee..8180f99fa1 100644 --- a/src/tint/ast/binding_attribute.cc +++ b/src/tint/ast/binding_attribute.cc @@ -22,8 +22,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BindingAttribute); namespace tint::ast { -BindingAttribute::BindingAttribute(ProgramID pid, const Source& src, uint32_t val) - : Base(pid, src), value(val) {} +BindingAttribute::BindingAttribute(ProgramID pid, NodeID nid, const Source& src, uint32_t val) + : Base(pid, nid, src), value(val) {} BindingAttribute::~BindingAttribute() = default; diff --git a/src/tint/ast/binding_attribute.h b/src/tint/ast/binding_attribute.h index 33c5f69542..b5379b8bb4 100644 --- a/src/tint/ast/binding_attribute.h +++ b/src/tint/ast/binding_attribute.h @@ -26,9 +26,10 @@ class BindingAttribute final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param value the binding value - BindingAttribute(ProgramID pid, const Source& src, uint32_t value); + BindingAttribute(ProgramID pid, NodeID nid, const Source& src, uint32_t value); ~BindingAttribute() override; /// @returns the WGSL name for the attribute diff --git a/src/tint/ast/bitcast_expression.cc b/src/tint/ast/bitcast_expression.cc index a81c5dd47e..5cabf67e02 100644 --- a/src/tint/ast/bitcast_expression.cc +++ b/src/tint/ast/bitcast_expression.cc @@ -21,10 +21,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BitcastExpression); namespace tint::ast { BitcastExpression::BitcastExpression(ProgramID pid, + NodeID nid, const Source& src, const Type* t, const Expression* e) - : Base(pid, src), type(t), expr(e) { + : Base(pid, nid, src), type(t), expr(e) { TINT_ASSERT(AST, type); TINT_ASSERT(AST, expr); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, expr, program_id); diff --git a/src/tint/ast/bitcast_expression.h b/src/tint/ast/bitcast_expression.h index a231cd286c..66952b7247 100644 --- a/src/tint/ast/bitcast_expression.h +++ b/src/tint/ast/bitcast_expression.h @@ -28,11 +28,13 @@ namespace tint::ast { class BitcastExpression final : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param source the bitcast expression source /// @param type the type /// @param expr the expr - BitcastExpression(ProgramID program_id, + BitcastExpression(ProgramID pid, + NodeID nid, const Source& source, const Type* type, const Expression* expr); diff --git a/src/tint/ast/block_statement.cc b/src/tint/ast/block_statement.cc index 7d4f49237a..4b3912103d 100644 --- a/src/tint/ast/block_statement.cc +++ b/src/tint/ast/block_statement.cc @@ -20,8 +20,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BlockStatement); namespace tint::ast { -BlockStatement::BlockStatement(ProgramID pid, const Source& src, const StatementList& stmts) - : Base(pid, src), statements(std::move(stmts)) { +BlockStatement::BlockStatement(ProgramID pid, + NodeID nid, + const Source& src, + const StatementList& stmts) + : Base(pid, nid, src), statements(std::move(stmts)) { for (auto* stmt : statements) { TINT_ASSERT(AST, stmt); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, stmt, program_id); diff --git a/src/tint/ast/block_statement.h b/src/tint/ast/block_statement.h index 48ea35a0fe..c67ecd0bf0 100644 --- a/src/tint/ast/block_statement.h +++ b/src/tint/ast/block_statement.h @@ -25,10 +25,14 @@ namespace tint::ast { class BlockStatement final : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param source the block statement source /// @param statements the statements - BlockStatement(ProgramID program_id, const Source& source, const StatementList& statements); + BlockStatement(ProgramID pid, + NodeID nid, + const Source& source, + const StatementList& statements); /// Move constructor BlockStatement(BlockStatement&&); ~BlockStatement() override; diff --git a/src/tint/ast/bool.cc b/src/tint/ast/bool.cc index af951e7538..9b326eb044 100644 --- a/src/tint/ast/bool.cc +++ b/src/tint/ast/bool.cc @@ -20,7 +20,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Bool); namespace tint::ast { -Bool::Bool(ProgramID pid, const Source& src) : Base(pid, src) {} +Bool::Bool(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {} Bool::Bool(Bool&&) = default; diff --git a/src/tint/ast/bool.h b/src/tint/ast/bool.h index bfe3b78123..d61e49d6af 100644 --- a/src/tint/ast/bool.h +++ b/src/tint/ast/bool.h @@ -32,8 +32,9 @@ class Bool final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node - Bool(ProgramID pid, const Source& src); + Bool(ProgramID pid, NodeID nid, const Source& src); /// Move constructor Bool(Bool&&); ~Bool() override; diff --git a/src/tint/ast/bool_literal_expression.cc b/src/tint/ast/bool_literal_expression.cc index cfaacb95ae..10ab4f0723 100644 --- a/src/tint/ast/bool_literal_expression.cc +++ b/src/tint/ast/bool_literal_expression.cc @@ -20,8 +20,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BoolLiteralExpression); namespace tint::ast { -BoolLiteralExpression::BoolLiteralExpression(ProgramID pid, const Source& src, bool val) - : Base(pid, src), value(val) {} +BoolLiteralExpression::BoolLiteralExpression(ProgramID pid, NodeID nid, const Source& src, bool val) + : Base(pid, nid, src), value(val) {} BoolLiteralExpression::~BoolLiteralExpression() = default; diff --git a/src/tint/ast/bool_literal_expression.h b/src/tint/ast/bool_literal_expression.h index f2c4c3f84c..bebd924a7f 100644 --- a/src/tint/ast/bool_literal_expression.h +++ b/src/tint/ast/bool_literal_expression.h @@ -26,9 +26,10 @@ class BoolLiteralExpression final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node - BreakStatement(ProgramID pid, const Source& src); + BreakStatement(ProgramID pid, NodeID nid, const Source& src); /// Move constructor BreakStatement(BreakStatement&&); ~BreakStatement() override; diff --git a/src/tint/ast/builtin_attribute.cc b/src/tint/ast/builtin_attribute.cc index 03e47b6074..30e7cc6610 100644 --- a/src/tint/ast/builtin_attribute.cc +++ b/src/tint/ast/builtin_attribute.cc @@ -22,8 +22,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BuiltinAttribute); namespace tint::ast { -BuiltinAttribute::BuiltinAttribute(ProgramID pid, const Source& src, Builtin b) - : Base(pid, src), builtin(b) {} +BuiltinAttribute::BuiltinAttribute(ProgramID pid, NodeID nid, const Source& src, Builtin b) + : Base(pid, nid, src), builtin(b) {} BuiltinAttribute::~BuiltinAttribute() = default; diff --git a/src/tint/ast/builtin_attribute.h b/src/tint/ast/builtin_attribute.h index 75898be596..d0b3208906 100644 --- a/src/tint/ast/builtin_attribute.h +++ b/src/tint/ast/builtin_attribute.h @@ -27,9 +27,10 @@ class BuiltinAttribute final : public Castable { public: /// constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param builtin the builtin value - BuiltinAttribute(ProgramID pid, const Source& src, Builtin builtin); + BuiltinAttribute(ProgramID pid, NodeID nid, const Source& src, Builtin builtin); ~BuiltinAttribute() override; /// @returns the WGSL name for the attribute diff --git a/src/tint/ast/call_expression.cc b/src/tint/ast/call_expression.cc index 68b6dc344a..03eecf526d 100644 --- a/src/tint/ast/call_expression.cc +++ b/src/tint/ast/call_expression.cc @@ -34,10 +34,11 @@ CallExpression::Target ToTarget(const Type* type) { } // namespace CallExpression::CallExpression(ProgramID pid, + NodeID nid, const Source& src, const IdentifierExpression* name, ExpressionList a) - : Base(pid, src), target(ToTarget(name)), args(a) { + : Base(pid, nid, src), target(ToTarget(name)), args(a) { TINT_ASSERT(AST, name); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, name, program_id); for (auto* arg : args) { @@ -46,8 +47,12 @@ CallExpression::CallExpression(ProgramID pid, } } -CallExpression::CallExpression(ProgramID pid, const Source& src, const Type* type, ExpressionList a) - : Base(pid, src), target(ToTarget(type)), args(a) { +CallExpression::CallExpression(ProgramID pid, + NodeID nid, + const Source& src, + const Type* type, + ExpressionList a) + : Base(pid, nid, src), target(ToTarget(type)), args(a) { TINT_ASSERT(AST, type); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, type, program_id); for (auto* arg : args) { diff --git a/src/tint/ast/call_expression.h b/src/tint/ast/call_expression.h index 9f197114a5..e020429c4a 100644 --- a/src/tint/ast/call_expression.h +++ b/src/tint/ast/call_expression.h @@ -33,21 +33,25 @@ namespace tint::ast { class CallExpression final : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param source the call expression source /// @param name the function or type name /// @param args the arguments - CallExpression(ProgramID program_id, + CallExpression(ProgramID pid, + NodeID nid, const Source& source, const IdentifierExpression* name, ExpressionList args); /// Constructor - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param source the call expression source /// @param type the type /// @param args the arguments - CallExpression(ProgramID program_id, + CallExpression(ProgramID pid, + NodeID nid, const Source& source, const Type* type, ExpressionList args); diff --git a/src/tint/ast/call_statement.cc b/src/tint/ast/call_statement.cc index 5e98fc9f33..597e30fe3a 100644 --- a/src/tint/ast/call_statement.cc +++ b/src/tint/ast/call_statement.cc @@ -20,8 +20,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::CallStatement); namespace tint::ast { -CallStatement::CallStatement(ProgramID pid, const Source& src, const CallExpression* call) - : Base(pid, src), expr(call) { +CallStatement::CallStatement(ProgramID pid, + NodeID nid, + const Source& src, + const CallExpression* call) + : Base(pid, nid, src), expr(call) { TINT_ASSERT(AST, expr); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, expr, program_id); } diff --git a/src/tint/ast/call_statement.h b/src/tint/ast/call_statement.h index d0d9f5301b..daf0b3f1af 100644 --- a/src/tint/ast/call_statement.h +++ b/src/tint/ast/call_statement.h @@ -25,9 +25,10 @@ class CallStatement final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node for the statement /// @param call the function - CallStatement(ProgramID pid, const Source& src, const CallExpression* call); + CallStatement(ProgramID pid, NodeID nid, const Source& src, const CallExpression* call); /// Move constructor CallStatement(CallStatement&&); ~CallStatement() override; diff --git a/src/tint/ast/case_statement.cc b/src/tint/ast/case_statement.cc index bf1f0bf797..55be8e3cdb 100644 --- a/src/tint/ast/case_statement.cc +++ b/src/tint/ast/case_statement.cc @@ -21,10 +21,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::CaseStatement); namespace tint::ast { CaseStatement::CaseStatement(ProgramID pid, + NodeID nid, const Source& src, CaseSelectorList s, const BlockStatement* b) - : Base(pid, src), selectors(s), body(b) { + : Base(pid, nid, src), selectors(s), body(b) { TINT_ASSERT(AST, body); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id); for (auto* selector : selectors) { diff --git a/src/tint/ast/case_statement.h b/src/tint/ast/case_statement.h index 19ca69308f..613b72171e 100644 --- a/src/tint/ast/case_statement.h +++ b/src/tint/ast/case_statement.h @@ -30,10 +30,12 @@ class CaseStatement final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param selectors the case selectors /// @param body the case body CaseStatement(ProgramID pid, + NodeID nid, const Source& src, CaseSelectorList selectors, const BlockStatement* body); diff --git a/src/tint/ast/compound_assignment_statement.cc b/src/tint/ast/compound_assignment_statement.cc index 848d500391..f7528625f2 100644 --- a/src/tint/ast/compound_assignment_statement.cc +++ b/src/tint/ast/compound_assignment_statement.cc @@ -21,11 +21,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::CompoundAssignmentStatement); namespace tint::ast { CompoundAssignmentStatement::CompoundAssignmentStatement(ProgramID pid, + NodeID nid, const Source& src, const Expression* l, const Expression* r, BinaryOp o) - : Base(pid, src), lhs(l), rhs(r), op(o) { + : Base(pid, nid, src), lhs(l), rhs(r), op(o) { TINT_ASSERT(AST, lhs); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs, program_id); TINT_ASSERT(AST, rhs); diff --git a/src/tint/ast/compound_assignment_statement.h b/src/tint/ast/compound_assignment_statement.h index ba9a558a6b..9fbd22c2b3 100644 --- a/src/tint/ast/compound_assignment_statement.h +++ b/src/tint/ast/compound_assignment_statement.h @@ -25,12 +25,14 @@ namespace tint::ast { class CompoundAssignmentStatement final : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param source the compound assignment statement source /// @param lhs the left side of the expression /// @param rhs the right side of the expression /// @param op the binary operator - CompoundAssignmentStatement(ProgramID program_id, + CompoundAssignmentStatement(ProgramID pid, + NodeID nid, const Source& source, const Expression* lhs, const Expression* rhs, diff --git a/src/tint/ast/const.cc b/src/tint/ast/const.cc index e13cc25b30..4dbbb86fe6 100644 --- a/src/tint/ast/const.cc +++ b/src/tint/ast/const.cc @@ -21,12 +21,13 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Const); namespace tint::ast { Const::Const(ProgramID pid, + NodeID nid, const Source& src, const Symbol& sym, const ast::Type* ty, const Expression* ctor, AttributeList attrs) - : Base(pid, src, sym, ty, ctor, attrs) { + : Base(pid, nid, src, sym, ty, ctor, attrs) { TINT_ASSERT(AST, ctor != nullptr); } diff --git a/src/tint/ast/const.h b/src/tint/ast/const.h index 32e3ddd835..48cbab8e1d 100644 --- a/src/tint/ast/const.h +++ b/src/tint/ast/const.h @@ -33,13 +33,15 @@ namespace tint::ast { class Const final : public Castable { public: /// Create a 'const' creation-time value variable. - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param source the variable source /// @param sym the variable symbol /// @param type the declared variable type /// @param constructor the constructor expression. Must not be nullptr. /// @param attributes the variable attributes - Const(ProgramID program_id, + Const(ProgramID pid, + NodeID nid, const Source& source, const Symbol& sym, const ast::Type* type, diff --git a/src/tint/ast/continue_statement.cc b/src/tint/ast/continue_statement.cc index 8ae4b9c1ee..53bd6a9a2f 100644 --- a/src/tint/ast/continue_statement.cc +++ b/src/tint/ast/continue_statement.cc @@ -20,7 +20,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::ContinueStatement); namespace tint::ast { -ContinueStatement::ContinueStatement(ProgramID pid, const Source& src) : Base(pid, src) {} +ContinueStatement::ContinueStatement(ProgramID pid, NodeID nid, const Source& src) + : Base(pid, nid, src) {} ContinueStatement::ContinueStatement(ContinueStatement&&) = default; diff --git a/src/tint/ast/continue_statement.h b/src/tint/ast/continue_statement.h index 17d8586d90..09b8254373 100644 --- a/src/tint/ast/continue_statement.h +++ b/src/tint/ast/continue_statement.h @@ -24,8 +24,9 @@ class ContinueStatement final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node - ContinueStatement(ProgramID pid, const Source& src); + ContinueStatement(ProgramID pid, NodeID nid, const Source& src); /// Move constructor ContinueStatement(ContinueStatement&&); ~ContinueStatement() override; diff --git a/src/tint/ast/depth_multisampled_texture.cc b/src/tint/ast/depth_multisampled_texture.cc index 66c5a86c52..64998b5170 100644 --- a/src/tint/ast/depth_multisampled_texture.cc +++ b/src/tint/ast/depth_multisampled_texture.cc @@ -28,9 +28,10 @@ bool IsValidDepthDimension(TextureDimension dim) { } // namespace DepthMultisampledTexture::DepthMultisampledTexture(ProgramID pid, + NodeID nid, const Source& src, TextureDimension d) - : Base(pid, src, d) { + : Base(pid, nid, src, d) { TINT_ASSERT(AST, IsValidDepthDimension(dim)); } diff --git a/src/tint/ast/depth_multisampled_texture.h b/src/tint/ast/depth_multisampled_texture.h index d15ac7a7de..2cc8d78bd6 100644 --- a/src/tint/ast/depth_multisampled_texture.h +++ b/src/tint/ast/depth_multisampled_texture.h @@ -26,9 +26,10 @@ class DepthMultisampledTexture final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param dim the dimensionality of the texture - DepthTexture(ProgramID pid, const Source& src, TextureDimension dim); + DepthTexture(ProgramID pid, NodeID nid, const Source& src, TextureDimension dim); /// Move constructor DepthTexture(DepthTexture&&); ~DepthTexture() override; diff --git a/src/tint/ast/disable_validation_attribute.cc b/src/tint/ast/disable_validation_attribute.cc index c5a6545b68..1f58799dd9 100644 --- a/src/tint/ast/disable_validation_attribute.cc +++ b/src/tint/ast/disable_validation_attribute.cc @@ -20,8 +20,10 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::DisableValidationAttribute); namespace tint::ast { -DisableValidationAttribute::DisableValidationAttribute(ProgramID pid, DisabledValidation val) - : Base(pid), validation(val) {} +DisableValidationAttribute::DisableValidationAttribute(ProgramID pid, + NodeID nid, + DisabledValidation val) + : Base(pid, nid), validation(val) {} DisableValidationAttribute::~DisableValidationAttribute() = default; @@ -46,7 +48,8 @@ std::string DisableValidationAttribute::InternalName() const { } const DisableValidationAttribute* DisableValidationAttribute::Clone(CloneContext* ctx) const { - return ctx->dst->ASTNodes().Create(ctx->dst->ID(), validation); + return ctx->dst->ASTNodes().Create( + ctx->dst->ID(), ctx->dst->AllocateNodeID(), validation); } } // namespace tint::ast diff --git a/src/tint/ast/disable_validation_attribute.h b/src/tint/ast/disable_validation_attribute.h index e44f7b8906..a109d18d4a 100644 --- a/src/tint/ast/disable_validation_attribute.h +++ b/src/tint/ast/disable_validation_attribute.h @@ -51,9 +51,10 @@ class DisableValidationAttribute final : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param validation the validation to disable - explicit DisableValidationAttribute(ProgramID program_id, DisabledValidation validation); + explicit DisableValidationAttribute(ProgramID pid, NodeID nid, DisabledValidation validation); /// Destructor ~DisableValidationAttribute() override; diff --git a/src/tint/ast/discard_statement.cc b/src/tint/ast/discard_statement.cc index 7ca673f629..fc9e75bbff 100644 --- a/src/tint/ast/discard_statement.cc +++ b/src/tint/ast/discard_statement.cc @@ -20,7 +20,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::DiscardStatement); namespace tint::ast { -DiscardStatement::DiscardStatement(ProgramID pid, const Source& src) : Base(pid, src) {} +DiscardStatement::DiscardStatement(ProgramID pid, NodeID nid, const Source& src) + : Base(pid, nid, src) {} DiscardStatement::DiscardStatement(DiscardStatement&&) = default; diff --git a/src/tint/ast/discard_statement.h b/src/tint/ast/discard_statement.h index 9d18c74454..272cc2dbf2 100644 --- a/src/tint/ast/discard_statement.h +++ b/src/tint/ast/discard_statement.h @@ -24,8 +24,9 @@ class DiscardStatement final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node - DiscardStatement(ProgramID pid, const Source& src); + DiscardStatement(ProgramID pid, NodeID nid, const Source& src); /// Move constructor DiscardStatement(DiscardStatement&&); ~DiscardStatement() override; diff --git a/src/tint/ast/enable.cc b/src/tint/ast/enable.cc index ef43200c05..9da44c7520 100644 --- a/src/tint/ast/enable.cc +++ b/src/tint/ast/enable.cc @@ -21,7 +21,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Enable); namespace tint::ast { -Enable::Enable(ProgramID pid, const Source& src, Extension ext) : Base(pid, src), extension(ext) {} +Enable::Enable(ProgramID pid, NodeID nid, const Source& src, Extension ext) + : Base(pid, nid, src), extension(ext) {} Enable::Enable(Enable&&) = default; diff --git a/src/tint/ast/enable.h b/src/tint/ast/enable.h index 674d9cb42f..df8c5e90e1 100644 --- a/src/tint/ast/enable.h +++ b/src/tint/ast/enable.h @@ -33,9 +33,10 @@ class Enable final : public Castable { public: /// Create a extension /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param ext the extension - Enable(ProgramID pid, const Source& src, Extension ext); + Enable(ProgramID pid, NodeID nid, const Source& src, Extension ext); /// Move constructor Enable(Enable&&); diff --git a/src/tint/ast/expression.cc b/src/tint/ast/expression.cc index a7f23aace4..17b3dc2b11 100644 --- a/src/tint/ast/expression.cc +++ b/src/tint/ast/expression.cc @@ -21,7 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Expression); namespace tint::ast { -Expression::Expression(ProgramID pid, const Source& src) : Base(pid, src) {} +Expression::Expression(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {} Expression::Expression(Expression&&) = default; diff --git a/src/tint/ast/expression.h b/src/tint/ast/expression.h index dc69ff8e4e..2690b93159 100644 --- a/src/tint/ast/expression.h +++ b/src/tint/ast/expression.h @@ -31,8 +31,9 @@ class Expression : public Castable { protected: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node - Expression(ProgramID pid, const Source& src); + Expression(ProgramID pid, NodeID nid, const Source& src); /// Move constructor Expression(Expression&&); }; diff --git a/src/tint/ast/external_texture.cc b/src/tint/ast/external_texture.cc index b88de9055a..488191389d 100644 --- a/src/tint/ast/external_texture.cc +++ b/src/tint/ast/external_texture.cc @@ -21,8 +21,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::ExternalTexture); namespace tint::ast { // ExternalTexture::ExternalTexture() : Base(ast::TextureDimension::k2d) {} -ExternalTexture::ExternalTexture(ProgramID pid, const Source& src) - : Base(pid, src, ast::TextureDimension::k2d) {} +ExternalTexture::ExternalTexture(ProgramID pid, NodeID nid, const Source& src) + : Base(pid, nid, src, ast::TextureDimension::k2d) {} ExternalTexture::ExternalTexture(ExternalTexture&&) = default; diff --git a/src/tint/ast/external_texture.h b/src/tint/ast/external_texture.h index 17224cffcf..f2d68b42b4 100644 --- a/src/tint/ast/external_texture.h +++ b/src/tint/ast/external_texture.h @@ -26,8 +26,9 @@ class ExternalTexture final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node - ExternalTexture(ProgramID pid, const Source& src); + ExternalTexture(ProgramID pid, NodeID nid, const Source& src); /// Move constructor ExternalTexture(ExternalTexture&&); diff --git a/src/tint/ast/f16.cc b/src/tint/ast/f16.cc index 0eb1be5fdd..dd3e48e67a 100644 --- a/src/tint/ast/f16.cc +++ b/src/tint/ast/f16.cc @@ -20,7 +20,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::F16); namespace tint::ast { -F16::F16(ProgramID pid, const Source& src) : Base(pid, src) {} +F16::F16(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {} F16::F16(F16&&) = default; diff --git a/src/tint/ast/f16.h b/src/tint/ast/f16.h index 1b84f09529..c444a20f65 100644 --- a/src/tint/ast/f16.h +++ b/src/tint/ast/f16.h @@ -26,8 +26,9 @@ class F16 : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node - F16(ProgramID pid, const Source& src); + F16(ProgramID pid, NodeID nid, const Source& src); /// Move constructor F16(F16&&); ~F16() override; diff --git a/src/tint/ast/f32.cc b/src/tint/ast/f32.cc index b731e65c9d..0ae354ad00 100644 --- a/src/tint/ast/f32.cc +++ b/src/tint/ast/f32.cc @@ -20,7 +20,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::F32); namespace tint::ast { -F32::F32(ProgramID pid, const Source& src) : Base(pid, src) {} +F32::F32(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {} F32::F32(F32&&) = default; diff --git a/src/tint/ast/f32.h b/src/tint/ast/f32.h index db81491d81..5176c45e3d 100644 --- a/src/tint/ast/f32.h +++ b/src/tint/ast/f32.h @@ -26,8 +26,9 @@ class F32 final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node - F32(ProgramID pid, const Source& src); + F32(ProgramID pid, NodeID nid, const Source& src); /// Move constructor F32(F32&&); ~F32() override; diff --git a/src/tint/ast/fallthrough_statement.cc b/src/tint/ast/fallthrough_statement.cc index 446534d354..0d30ae3ec2 100644 --- a/src/tint/ast/fallthrough_statement.cc +++ b/src/tint/ast/fallthrough_statement.cc @@ -20,7 +20,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::FallthroughStatement); namespace tint::ast { -FallthroughStatement::FallthroughStatement(ProgramID pid, const Source& src) : Base(pid, src) {} +FallthroughStatement::FallthroughStatement(ProgramID pid, NodeID nid, const Source& src) + : Base(pid, nid, src) {} FallthroughStatement::FallthroughStatement(FallthroughStatement&&) = default; diff --git a/src/tint/ast/fallthrough_statement.h b/src/tint/ast/fallthrough_statement.h index b313efbd6d..da2fd3d88b 100644 --- a/src/tint/ast/fallthrough_statement.h +++ b/src/tint/ast/fallthrough_statement.h @@ -24,8 +24,9 @@ class FallthroughStatement final : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param source the for loop statement source /// @param initializer the optional loop initializer statement /// @param condition the optional loop condition expression /// @param continuing the optional continuing statement /// @param body the loop body - ForLoopStatement(ProgramID program_id, - Source const& source, + ForLoopStatement(ProgramID pid, + NodeID nid, + const Source& source, const Statement* initializer, const Expression* condition, const Statement* continuing, diff --git a/src/tint/ast/function.cc b/src/tint/ast/function.cc index 84d80d798a..49bfb9b34e 100644 --- a/src/tint/ast/function.cc +++ b/src/tint/ast/function.cc @@ -23,6 +23,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Function); namespace tint::ast { Function::Function(ProgramID pid, + NodeID nid, const Source& src, Symbol sym, ParameterList parameters, @@ -30,7 +31,7 @@ Function::Function(ProgramID pid, const BlockStatement* b, AttributeList attrs, AttributeList return_type_attrs) - : Base(pid, src), + : Base(pid, nid, src), symbol(sym), params(std::move(parameters)), return_type(return_ty), diff --git a/src/tint/ast/function.h b/src/tint/ast/function.h index d849486ee8..ed7f5b26c2 100644 --- a/src/tint/ast/function.h +++ b/src/tint/ast/function.h @@ -35,7 +35,8 @@ namespace tint::ast { class Function final : public Castable { public: /// Create a function - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param source the variable source /// @param symbol the function symbol /// @param params the function parameters @@ -43,7 +44,8 @@ class Function final : public Castable { /// @param body the function body /// @param attributes the function attributes /// @param return_type_attributes the return type attributes - Function(ProgramID program_id, + Function(ProgramID pid, + NodeID nid, const Source& source, Symbol symbol, ParameterList params, diff --git a/src/tint/ast/group_attribute.cc b/src/tint/ast/group_attribute.cc index 394a690771..9d011114ca 100644 --- a/src/tint/ast/group_attribute.cc +++ b/src/tint/ast/group_attribute.cc @@ -22,8 +22,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::GroupAttribute); namespace tint::ast { -GroupAttribute::GroupAttribute(ProgramID pid, const Source& src, uint32_t val) - : Base(pid, src), value(val) {} +GroupAttribute::GroupAttribute(ProgramID pid, NodeID nid, const Source& src, uint32_t val) + : Base(pid, nid, src), value(val) {} GroupAttribute::~GroupAttribute() = default; diff --git a/src/tint/ast/group_attribute.h b/src/tint/ast/group_attribute.h index a55946177b..66d6ccb409 100644 --- a/src/tint/ast/group_attribute.h +++ b/src/tint/ast/group_attribute.h @@ -26,9 +26,10 @@ class GroupAttribute final : public Castable { public: /// constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param value the group value - GroupAttribute(ProgramID pid, const Source& src, uint32_t value); + GroupAttribute(ProgramID pid, NodeID nid, const Source& src, uint32_t value); ~GroupAttribute() override; /// @returns the WGSL name for the attribute diff --git a/src/tint/ast/i32.cc b/src/tint/ast/i32.cc index 46fe75ed78..ffdf30dedf 100644 --- a/src/tint/ast/i32.cc +++ b/src/tint/ast/i32.cc @@ -20,7 +20,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::I32); namespace tint::ast { -I32::I32(ProgramID pid, const Source& src) : Base(pid, src) {} +I32::I32(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {} I32::I32(I32&&) = default; diff --git a/src/tint/ast/i32.h b/src/tint/ast/i32.h index acafd37cfd..d2c951c3f0 100644 --- a/src/tint/ast/i32.h +++ b/src/tint/ast/i32.h @@ -26,8 +26,9 @@ class I32 final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node - I32(ProgramID pid, const Source& src); + I32(ProgramID pid, NodeID nid, const Source& src); /// Move constructor I32(I32&&); ~I32() override; diff --git a/src/tint/ast/id_attribute.cc b/src/tint/ast/id_attribute.cc index b6e19574b3..75d62c6cd0 100644 --- a/src/tint/ast/id_attribute.cc +++ b/src/tint/ast/id_attribute.cc @@ -22,8 +22,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::IdAttribute); namespace tint::ast { -IdAttribute::IdAttribute(ProgramID pid, const Source& src, uint32_t val) - : Base(pid, src), value(val) {} +IdAttribute::IdAttribute(ProgramID pid, NodeID nid, const Source& src, uint32_t val) + : Base(pid, nid, src), value(val) {} IdAttribute::~IdAttribute() = default; diff --git a/src/tint/ast/id_attribute.h b/src/tint/ast/id_attribute.h index 5e3ec12f78..ca2a35822d 100644 --- a/src/tint/ast/id_attribute.h +++ b/src/tint/ast/id_attribute.h @@ -26,9 +26,10 @@ class IdAttribute final : public Castable { public: /// Create an id attribute. /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param val the numeric id value - IdAttribute(ProgramID pid, const Source& src, uint32_t val); + IdAttribute(ProgramID pid, NodeID nid, const Source& src, uint32_t val); ~IdAttribute() override; /// @returns the WGSL name for the attribute diff --git a/src/tint/ast/identifier_expression.cc b/src/tint/ast/identifier_expression.cc index 453ae69662..34eadeb07b 100644 --- a/src/tint/ast/identifier_expression.cc +++ b/src/tint/ast/identifier_expression.cc @@ -20,8 +20,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::IdentifierExpression); namespace tint::ast { -IdentifierExpression::IdentifierExpression(ProgramID pid, const Source& src, Symbol sym) - : Base(pid, src), symbol(sym) { +IdentifierExpression::IdentifierExpression(ProgramID pid, NodeID nid, const Source& src, Symbol sym) + : Base(pid, nid, src), symbol(sym) { TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, symbol, program_id); TINT_ASSERT(AST, symbol.IsValid()); } diff --git a/src/tint/ast/identifier_expression.h b/src/tint/ast/identifier_expression.h index c3e1c30e54..b583807ba2 100644 --- a/src/tint/ast/identifier_expression.h +++ b/src/tint/ast/identifier_expression.h @@ -24,9 +24,10 @@ class IdentifierExpression final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param condition the if condition /// @param body the if body /// @param else_stmt the else statement, or nullptr IfStatement(ProgramID pid, + NodeID nid, const Source& src, const Expression* condition, const BlockStatement* body, diff --git a/src/tint/ast/increment_decrement_statement.cc b/src/tint/ast/increment_decrement_statement.cc index 99c65cb4f7..5b10e5fb8c 100644 --- a/src/tint/ast/increment_decrement_statement.cc +++ b/src/tint/ast/increment_decrement_statement.cc @@ -21,10 +21,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::IncrementDecrementStatement); namespace tint::ast { IncrementDecrementStatement::IncrementDecrementStatement(ProgramID pid, + NodeID nid, const Source& src, const Expression* l, bool inc) - : Base(pid, src), lhs(l), increment(inc) { + : Base(pid, nid, src), lhs(l), increment(inc) { TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs, program_id); } diff --git a/src/tint/ast/increment_decrement_statement.h b/src/tint/ast/increment_decrement_statement.h index 05b8478e94..ec9923ab69 100644 --- a/src/tint/ast/increment_decrement_statement.h +++ b/src/tint/ast/increment_decrement_statement.h @@ -25,10 +25,15 @@ class IncrementDecrementStatement final : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param source the index accessor source /// @param obj the object /// @param idx the index expression - IndexAccessorExpression(ProgramID program_id, + IndexAccessorExpression(ProgramID pid, + NodeID nid, const Source& source, const Expression* obj, const Expression* idx); diff --git a/src/tint/ast/int_literal_expression.cc b/src/tint/ast/int_literal_expression.cc index 7e11f7ec5a..502ea9d0db 100644 --- a/src/tint/ast/int_literal_expression.cc +++ b/src/tint/ast/int_literal_expression.cc @@ -21,10 +21,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::IntLiteralExpression); namespace tint::ast { IntLiteralExpression::IntLiteralExpression(ProgramID pid, + NodeID nid, const Source& src, int64_t val, Suffix suf) - : Base(pid, src), value(val), suffix(suf) {} + : Base(pid, nid, src), value(val), suffix(suf) {} IntLiteralExpression::~IntLiteralExpression() = default; diff --git a/src/tint/ast/int_literal_expression.h b/src/tint/ast/int_literal_expression.h index 8ff58eaf22..b4e184a925 100644 --- a/src/tint/ast/int_literal_expression.h +++ b/src/tint/ast/int_literal_expression.h @@ -34,10 +34,11 @@ class IntLiteralExpression : public Castable { public: /// Constructor /// @param program_id the identifier of the program that owns this node - explicit InternalAttribute(ProgramID program_id); + /// @param nid the unique node identifier + explicit InternalAttribute(ProgramID program_id, NodeID nid); /// Destructor ~InternalAttribute() override; diff --git a/src/tint/ast/interpolate_attribute.cc b/src/tint/ast/interpolate_attribute.cc index 909e827d59..29e3bfed42 100644 --- a/src/tint/ast/interpolate_attribute.cc +++ b/src/tint/ast/interpolate_attribute.cc @@ -23,10 +23,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::InterpolateAttribute); namespace tint::ast { InterpolateAttribute::InterpolateAttribute(ProgramID pid, + NodeID nid, const Source& src, InterpolationType ty, InterpolationSampling smpl) - : Base(pid, src), type(ty), sampling(smpl) {} + : Base(pid, nid, src), type(ty), sampling(smpl) {} InterpolateAttribute::~InterpolateAttribute() = default; diff --git a/src/tint/ast/interpolate_attribute.h b/src/tint/ast/interpolate_attribute.h index 4b2a2df787..4f9ea9de4b 100644 --- a/src/tint/ast/interpolate_attribute.h +++ b/src/tint/ast/interpolate_attribute.h @@ -33,10 +33,12 @@ class InterpolateAttribute final : public Castable public: /// constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node - InvariantAttribute(ProgramID pid, const Source& src); + InvariantAttribute(ProgramID pid, NodeID nid, const Source& src); ~InvariantAttribute() override; /// @returns the WGSL name for the attribute diff --git a/src/tint/ast/let.cc b/src/tint/ast/let.cc index 8db8ec1a9b..b42e6e6afa 100644 --- a/src/tint/ast/let.cc +++ b/src/tint/ast/let.cc @@ -21,12 +21,13 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Let); namespace tint::ast { Let::Let(ProgramID pid, + NodeID nid, const Source& src, const Symbol& sym, const ast::Type* ty, const Expression* ctor, AttributeList attrs) - : Base(pid, src, sym, ty, ctor, attrs) { + : Base(pid, nid, src, sym, ty, ctor, attrs) { TINT_ASSERT(AST, ctor != nullptr); } diff --git a/src/tint/ast/let.h b/src/tint/ast/let.h index 2c1ad7c591..0f71da205a 100644 --- a/src/tint/ast/let.h +++ b/src/tint/ast/let.h @@ -30,13 +30,15 @@ namespace tint::ast { class Let final : public Castable { public: /// Create a 'let' variable - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param source the variable source /// @param sym the variable symbol /// @param type the declared variable type /// @param constructor the constructor expression /// @param attributes the variable attributes - Let(ProgramID program_id, + Let(ProgramID pid, + NodeID nid, const Source& source, const Symbol& sym, const ast::Type* type, diff --git a/src/tint/ast/literal_expression.cc b/src/tint/ast/literal_expression.cc index d05279d0f7..bcf62adb08 100644 --- a/src/tint/ast/literal_expression.cc +++ b/src/tint/ast/literal_expression.cc @@ -18,7 +18,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::LiteralExpression); namespace tint::ast { -LiteralExpression::LiteralExpression(ProgramID pid, const Source& src) : Base(pid, src) {} +LiteralExpression::LiteralExpression(ProgramID pid, NodeID nid, const Source& src) + : Base(pid, nid, src) {} LiteralExpression::~LiteralExpression() = default; diff --git a/src/tint/ast/literal_expression.h b/src/tint/ast/literal_expression.h index 56fc1f0f80..b4b2b097a1 100644 --- a/src/tint/ast/literal_expression.h +++ b/src/tint/ast/literal_expression.h @@ -29,8 +29,9 @@ class LiteralExpression : public Castable { protected: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the input source - LiteralExpression(ProgramID pid, const Source& src); + LiteralExpression(ProgramID pid, NodeID nid, const Source& src); }; } // namespace tint::ast diff --git a/src/tint/ast/location_attribute.cc b/src/tint/ast/location_attribute.cc index 1eae823ade..2ea2d5d24d 100644 --- a/src/tint/ast/location_attribute.cc +++ b/src/tint/ast/location_attribute.cc @@ -22,8 +22,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::LocationAttribute); namespace tint::ast { -LocationAttribute::LocationAttribute(ProgramID pid, const Source& src, uint32_t val) - : Base(pid, src), value(val) {} +LocationAttribute::LocationAttribute(ProgramID pid, NodeID nid, const Source& src, uint32_t val) + : Base(pid, nid, src), value(val) {} LocationAttribute::~LocationAttribute() = default; diff --git a/src/tint/ast/location_attribute.h b/src/tint/ast/location_attribute.h index 3646c544fc..97c6feaf84 100644 --- a/src/tint/ast/location_attribute.h +++ b/src/tint/ast/location_attribute.h @@ -26,9 +26,10 @@ class LocationAttribute final : public Castable { public: /// constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param value the location value - LocationAttribute(ProgramID pid, const Source& src, uint32_t value); + LocationAttribute(ProgramID pid, NodeID nid, const Source& src, uint32_t value); ~LocationAttribute() override; /// @returns the WGSL name for the attribute diff --git a/src/tint/ast/loop_statement.cc b/src/tint/ast/loop_statement.cc index 9d14960c97..b7e7a1bd71 100644 --- a/src/tint/ast/loop_statement.cc +++ b/src/tint/ast/loop_statement.cc @@ -21,10 +21,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::LoopStatement); namespace tint::ast { LoopStatement::LoopStatement(ProgramID pid, + NodeID nid, const Source& src, const BlockStatement* b, const BlockStatement* cont) - : Base(pid, src), body(b), continuing(cont) { + : Base(pid, nid, src), body(b), continuing(cont) { TINT_ASSERT(AST, body); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, continuing, program_id); diff --git a/src/tint/ast/loop_statement.h b/src/tint/ast/loop_statement.h index 5a044fead8..d4b24cf7bc 100644 --- a/src/tint/ast/loop_statement.h +++ b/src/tint/ast/loop_statement.h @@ -23,11 +23,13 @@ namespace tint::ast { class LoopStatement final : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param source the loop statement source /// @param body the body statements /// @param continuing the continuing statements - LoopStatement(ProgramID program_id, + LoopStatement(ProgramID pid, + NodeID nid, const Source& source, const BlockStatement* body, const BlockStatement* continuing); diff --git a/src/tint/ast/matrix.cc b/src/tint/ast/matrix.cc index 1f74a26ec0..69371274f9 100644 --- a/src/tint/ast/matrix.cc +++ b/src/tint/ast/matrix.cc @@ -20,8 +20,13 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Matrix); namespace tint::ast { -Matrix::Matrix(ProgramID pid, const Source& src, const Type* subtype, uint32_t r, uint32_t c) - : Base(pid, src), type(subtype), rows(r), columns(c) { +Matrix::Matrix(ProgramID pid, + NodeID nid, + const Source& src, + const Type* subtype, + uint32_t r, + uint32_t c) + : Base(pid, nid, src), type(subtype), rows(r), columns(c) { TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, subtype, program_id); TINT_ASSERT(AST, rows > 1); TINT_ASSERT(AST, rows < 5); diff --git a/src/tint/ast/matrix.h b/src/tint/ast/matrix.h index 620f28a38c..e778738d8c 100644 --- a/src/tint/ast/matrix.h +++ b/src/tint/ast/matrix.h @@ -26,13 +26,19 @@ class Matrix final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param subtype the declared type of the matrix components. May be null for /// matrix constructors, where the element type will be inferred from /// the constructor arguments /// @param rows the number of rows in the matrix /// @param columns the number of columns in the matrix - Matrix(ProgramID pid, const Source& src, const Type* subtype, uint32_t rows, uint32_t columns); + Matrix(ProgramID pid, + NodeID nid, + const Source& src, + const Type* subtype, + uint32_t rows, + uint32_t columns); /// Move constructor Matrix(Matrix&&); ~Matrix() override; diff --git a/src/tint/ast/member_accessor_expression.cc b/src/tint/ast/member_accessor_expression.cc index a087ea458c..b895e3bec0 100644 --- a/src/tint/ast/member_accessor_expression.cc +++ b/src/tint/ast/member_accessor_expression.cc @@ -21,10 +21,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::MemberAccessorExpression); namespace tint::ast { MemberAccessorExpression::MemberAccessorExpression(ProgramID pid, + NodeID nid, const Source& src, const Expression* str, const IdentifierExpression* mem) - : Base(pid, src), structure(str), member(mem) { + : Base(pid, nid, src), structure(str), member(mem) { TINT_ASSERT(AST, structure); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, structure, program_id); TINT_ASSERT(AST, member); diff --git a/src/tint/ast/member_accessor_expression.h b/src/tint/ast/member_accessor_expression.h index 07054caddb..33284fe7ac 100644 --- a/src/tint/ast/member_accessor_expression.h +++ b/src/tint/ast/member_accessor_expression.h @@ -23,11 +23,13 @@ namespace tint::ast { class MemberAccessorExpression final : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param source the member accessor expression source /// @param structure the structure /// @param member the member - MemberAccessorExpression(ProgramID program_id, + MemberAccessorExpression(ProgramID pid, + NodeID nid, const Source& source, const Expression* structure, const IdentifierExpression* member); diff --git a/src/tint/ast/module.cc b/src/tint/ast/module.cc index 40dff98599..7cf9282030 100644 --- a/src/tint/ast/module.cc +++ b/src/tint/ast/module.cc @@ -23,10 +23,13 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Module); namespace tint::ast { -Module::Module(ProgramID pid, const Source& src) : Base(pid, src) {} +Module::Module(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {} -Module::Module(ProgramID pid, const Source& src, std::vector global_decls) - : Base(pid, src), global_declarations_(std::move(global_decls)) { +Module::Module(ProgramID pid, + NodeID nid, + const Source& src, + std::vector global_decls) + : Base(pid, nid, src), global_declarations_(std::move(global_decls)) { for (auto* decl : global_declarations_) { if (decl == nullptr) { continue; diff --git a/src/tint/ast/module.h b/src/tint/ast/module.h index 17cf353e8f..27c62dc29f 100644 --- a/src/tint/ast/module.h +++ b/src/tint/ast/module.h @@ -32,15 +32,17 @@ class Module final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node - Module(ProgramID pid, const Source& src); + Module(ProgramID pid, NodeID nid, const Source& src); /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param global_decls the list of global types, functions, and variables, in /// the order they were declared in the source program - Module(ProgramID pid, const Source& src, std::vector global_decls); + Module(ProgramID pid, NodeID nid, const Source& src, std::vector global_decls); /// Destructor ~Module() override; diff --git a/src/tint/ast/multisampled_texture.cc b/src/tint/ast/multisampled_texture.cc index 91f8edf5dd..0c4485754d 100644 --- a/src/tint/ast/multisampled_texture.cc +++ b/src/tint/ast/multisampled_texture.cc @@ -21,10 +21,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::MultisampledTexture); namespace tint::ast { MultisampledTexture::MultisampledTexture(ProgramID pid, + NodeID nid, const Source& src, TextureDimension d, const Type* ty) - : Base(pid, src, d), type(ty) { + : Base(pid, nid, src, d), type(ty) { TINT_ASSERT(AST, type); } diff --git a/src/tint/ast/multisampled_texture.h b/src/tint/ast/multisampled_texture.h index 1d95505614..6887045fc5 100644 --- a/src/tint/ast/multisampled_texture.h +++ b/src/tint/ast/multisampled_texture.h @@ -26,10 +26,15 @@ class MultisampledTexture final : public Castable public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param dim the dimensionality of the texture /// @param type the data type of the multisampled texture - MultisampledTexture(ProgramID pid, const Source& src, TextureDimension dim, const Type* type); + MultisampledTexture(ProgramID pid, + NodeID nid, + const Source& src, + TextureDimension dim, + const Type* type); /// Move constructor MultisampledTexture(MultisampledTexture&&); ~MultisampledTexture() override; diff --git a/src/tint/ast/node.cc b/src/tint/ast/node.cc index 2368791d3d..ce3a71d1b9 100644 --- a/src/tint/ast/node.cc +++ b/src/tint/ast/node.cc @@ -18,7 +18,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Node); namespace tint::ast { -Node::Node(ProgramID pid, const Source& src) : program_id(pid), source(src) {} +Node::Node(ProgramID pid, NodeID nid, const Source& src) + : program_id(pid), node_id(nid), source(src) {} Node::Node(Node&&) = default; diff --git a/src/tint/ast/node.h b/src/tint/ast/node.h index 19d768228a..6eaa1e94f0 100644 --- a/src/tint/ast/node.h +++ b/src/tint/ast/node.h @@ -17,6 +17,7 @@ #include +#include "src/tint/ast/node_id.h" #include "src/tint/clone_context.h" namespace tint::ast { @@ -29,14 +30,18 @@ class Node : public Castable { /// The identifier of the program that owns this node const ProgramID program_id; + /// The node identifier, unique for the program. + const NodeID node_id; + /// The node source data const Source source; protected: /// Create a new node /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the input source for the node - Node(ProgramID pid, const Source& src); + Node(ProgramID pid, NodeID nid, const Source& src); /// Move constructor Node(Node&&); diff --git a/src/tint/ast/node_id.h b/src/tint/ast/node_id.h new file mode 100644 index 0000000000..79683b0348 --- /dev/null +++ b/src/tint/ast/node_id.h @@ -0,0 +1,36 @@ +// Copyright 2022 The Tint Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef SRC_TINT_AST_NODE_ID_H_ +#define SRC_TINT_AST_NODE_ID_H_ + +#include + +namespace tint::ast { + +/// NodeID is a unique node identifier for a given Program. +/// NodeIDs are sequentially allocated, starting at 0. +struct NodeID { + /// Equality operator + /// @param other the other NodeID + /// @returns true if the NodeIDs are the same + bool operator==(const NodeID& other) const { return value == other.value; } + + /// The numerical value for the node identifier + size_t value = 0; +}; + +} // namespace tint::ast + +#endif // SRC_TINT_AST_NODE_ID_H_ diff --git a/src/tint/ast/override.cc b/src/tint/ast/override.cc index efd048d02e..b7ee064103 100644 --- a/src/tint/ast/override.cc +++ b/src/tint/ast/override.cc @@ -21,12 +21,13 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Override); namespace tint::ast { Override::Override(ProgramID pid, + NodeID nid, const Source& src, const Symbol& sym, const ast::Type* ty, const Expression* ctor, AttributeList attrs) - : Base(pid, src, sym, ty, ctor, attrs) {} + : Base(pid, nid, src, sym, ty, ctor, attrs) {} Override::Override(Override&&) = default; diff --git a/src/tint/ast/override.h b/src/tint/ast/override.h index 98319e5bf6..e97f14c9c0 100644 --- a/src/tint/ast/override.h +++ b/src/tint/ast/override.h @@ -31,13 +31,15 @@ namespace tint::ast { class Override final : public Castable { public: /// Create an 'override' pipeline-overridable constant. - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param source the variable source /// @param sym the variable symbol /// @param type the declared variable type /// @param constructor the constructor expression /// @param attributes the variable attributes - Override(ProgramID program_id, + Override(ProgramID pid, + NodeID nid, const Source& source, const Symbol& sym, const ast::Type* type, diff --git a/src/tint/ast/parameter.cc b/src/tint/ast/parameter.cc index ea3c51fef1..bab272979c 100644 --- a/src/tint/ast/parameter.cc +++ b/src/tint/ast/parameter.cc @@ -21,11 +21,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Parameter); namespace tint::ast { Parameter::Parameter(ProgramID pid, + NodeID nid, const Source& src, const Symbol& sym, const ast::Type* ty, AttributeList attrs) - : Base(pid, src, sym, ty, nullptr, attrs) {} + : Base(pid, nid, src, sym, ty, nullptr, attrs) {} Parameter::Parameter(Parameter&&) = default; diff --git a/src/tint/ast/parameter.h b/src/tint/ast/parameter.h index eb4b688333..4a9bb938c7 100644 --- a/src/tint/ast/parameter.h +++ b/src/tint/ast/parameter.h @@ -34,12 +34,14 @@ namespace tint::ast { class Parameter final : public Castable { public: /// Create a 'parameter' creation-time value variable. - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param source the variable source /// @param sym the variable symbol /// @param type the declared variable type /// @param attributes the variable attributes - Parameter(ProgramID program_id, + Parameter(ProgramID pid, + NodeID nid, const Source& source, const Symbol& sym, const ast::Type* type, diff --git a/src/tint/ast/phony_expression.cc b/src/tint/ast/phony_expression.cc index a3fd4fd946..6bce1bf3a5 100644 --- a/src/tint/ast/phony_expression.cc +++ b/src/tint/ast/phony_expression.cc @@ -20,7 +20,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::PhonyExpression); namespace tint::ast { -PhonyExpression::PhonyExpression(ProgramID pid, const Source& src) : Base(pid, src) {} +PhonyExpression::PhonyExpression(ProgramID pid, NodeID nid, const Source& src) + : Base(pid, nid, src) {} PhonyExpression::PhonyExpression(PhonyExpression&&) = default; diff --git a/src/tint/ast/phony_expression.h b/src/tint/ast/phony_expression.h index 4fc32dd53d..d429a51db2 100644 --- a/src/tint/ast/phony_expression.h +++ b/src/tint/ast/phony_expression.h @@ -25,8 +25,9 @@ class PhonyExpression final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node - PhonyExpression(ProgramID pid, const Source& src); + PhonyExpression(ProgramID pid, NodeID nid, const Source& src); /// Move constructor PhonyExpression(PhonyExpression&&); ~PhonyExpression() override; diff --git a/src/tint/ast/pointer.cc b/src/tint/ast/pointer.cc index 42c3fa9e86..796fe8587e 100644 --- a/src/tint/ast/pointer.cc +++ b/src/tint/ast/pointer.cc @@ -21,11 +21,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Pointer); namespace tint::ast { Pointer::Pointer(ProgramID pid, + NodeID nid, const Source& src, const Type* const subtype, ast::StorageClass sc, ast::Access ac) - : Base(pid, src), type(subtype), storage_class(sc), access(ac) {} + : Base(pid, nid, src), type(subtype), storage_class(sc), access(ac) {} std::string Pointer::FriendlyName(const SymbolTable& symbols) const { std::ostringstream out; diff --git a/src/tint/ast/pointer.h b/src/tint/ast/pointer.h index 030e844eb3..61eff88efa 100644 --- a/src/tint/ast/pointer.h +++ b/src/tint/ast/pointer.h @@ -28,11 +28,13 @@ class Pointer final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param subtype the pointee type /// @param storage_class the storage class of the pointer /// @param access the access control of the pointer Pointer(ProgramID pid, + NodeID nid, const Source& src, const Type* const subtype, ast::StorageClass storage_class, diff --git a/src/tint/ast/return_statement.cc b/src/tint/ast/return_statement.cc index 976c063ca4..459bb721fc 100644 --- a/src/tint/ast/return_statement.cc +++ b/src/tint/ast/return_statement.cc @@ -20,11 +20,14 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::ReturnStatement); namespace tint::ast { -ReturnStatement::ReturnStatement(ProgramID pid, const Source& src) - : Base(pid, src), value(nullptr) {} +ReturnStatement::ReturnStatement(ProgramID pid, NodeID nid, const Source& src) + : Base(pid, nid, src), value(nullptr) {} -ReturnStatement::ReturnStatement(ProgramID pid, const Source& src, const Expression* val) - : Base(pid, src), value(val) { +ReturnStatement::ReturnStatement(ProgramID pid, + NodeID nid, + const Source& src, + const Expression* val) + : Base(pid, nid, src), value(val) { TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, value, program_id); } diff --git a/src/tint/ast/return_statement.h b/src/tint/ast/return_statement.h index 34d8678236..571a738c67 100644 --- a/src/tint/ast/return_statement.h +++ b/src/tint/ast/return_statement.h @@ -25,14 +25,16 @@ class ReturnStatement final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node - ReturnStatement(ProgramID pid, const Source& src); + ReturnStatement(ProgramID pid, NodeID nid, const Source& src); /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param value the return value - ReturnStatement(ProgramID pid, const Source& src, const Expression* value); + ReturnStatement(ProgramID pid, NodeID nid, const Source& src, const Expression* value); /// Move constructor ReturnStatement(ReturnStatement&&); ~ReturnStatement() override; diff --git a/src/tint/ast/sampled_texture.cc b/src/tint/ast/sampled_texture.cc index 9c4cea631f..b8dfd61aee 100644 --- a/src/tint/ast/sampled_texture.cc +++ b/src/tint/ast/sampled_texture.cc @@ -20,8 +20,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::SampledTexture); namespace tint::ast { -SampledTexture::SampledTexture(ProgramID pid, const Source& src, TextureDimension d, const Type* ty) - : Base(pid, src, d), type(ty) { +SampledTexture::SampledTexture(ProgramID pid, + NodeID nid, + const Source& src, + TextureDimension d, + const Type* ty) + : Base(pid, nid, src, d), type(ty) { TINT_ASSERT(AST, type); } diff --git a/src/tint/ast/sampled_texture.h b/src/tint/ast/sampled_texture.h index f68fccf57a..1f33af3b6b 100644 --- a/src/tint/ast/sampled_texture.h +++ b/src/tint/ast/sampled_texture.h @@ -26,10 +26,15 @@ class SampledTexture final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param dim the dimensionality of the texture /// @param type the data type of the sampled texture - SampledTexture(ProgramID pid, const Source& src, TextureDimension dim, const Type* type); + SampledTexture(ProgramID pid, + NodeID nid, + const Source& src, + TextureDimension dim, + const Type* type); /// Move constructor SampledTexture(SampledTexture&&); ~SampledTexture() override; diff --git a/src/tint/ast/sampler.cc b/src/tint/ast/sampler.cc index 5d88bf8606..5237380a19 100644 --- a/src/tint/ast/sampler.cc +++ b/src/tint/ast/sampler.cc @@ -32,7 +32,8 @@ std::ostream& operator<<(std::ostream& out, SamplerKind kind) { return out; } -Sampler::Sampler(ProgramID pid, const Source& src, SamplerKind k) : Base(pid, src), kind(k) {} +Sampler::Sampler(ProgramID pid, NodeID nid, const Source& src, SamplerKind k) + : Base(pid, nid, src), kind(k) {} Sampler::Sampler(Sampler&&) = default; diff --git a/src/tint/ast/sampler.h b/src/tint/ast/sampler.h index 067fc38618..bcdf7511f5 100644 --- a/src/tint/ast/sampler.h +++ b/src/tint/ast/sampler.h @@ -39,9 +39,10 @@ class Sampler final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param kind the kind of sampler - Sampler(ProgramID pid, const Source& src, SamplerKind kind); + Sampler(ProgramID pid, NodeID nid, const Source& src, SamplerKind kind); /// Move constructor Sampler(Sampler&&); ~Sampler() override; diff --git a/src/tint/ast/stage_attribute.cc b/src/tint/ast/stage_attribute.cc index 51cfe8c262..c7009509fd 100644 --- a/src/tint/ast/stage_attribute.cc +++ b/src/tint/ast/stage_attribute.cc @@ -22,8 +22,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::StageAttribute); namespace tint::ast { -StageAttribute::StageAttribute(ProgramID pid, const Source& src, PipelineStage s) - : Base(pid, src), stage(s) {} +StageAttribute::StageAttribute(ProgramID pid, NodeID nid, const Source& src, PipelineStage s) + : Base(pid, nid, src), stage(s) {} StageAttribute::~StageAttribute() = default; diff --git a/src/tint/ast/stage_attribute.h b/src/tint/ast/stage_attribute.h index a447d1f78c..0bf9d9e932 100644 --- a/src/tint/ast/stage_attribute.h +++ b/src/tint/ast/stage_attribute.h @@ -26,10 +26,11 @@ namespace tint::ast { class StageAttribute final : public Castable { public: /// constructor - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param stage the pipeline stage /// @param source the source of this attribute - StageAttribute(ProgramID program_id, const Source& source, PipelineStage stage); + StageAttribute(ProgramID pid, NodeID nid, const Source& source, PipelineStage stage); ~StageAttribute() override; /// @returns the WGSL name for the attribute diff --git a/src/tint/ast/statement.cc b/src/tint/ast/statement.cc index 12a1cc9406..6acfff31a4 100644 --- a/src/tint/ast/statement.cc +++ b/src/tint/ast/statement.cc @@ -30,7 +30,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Statement); namespace tint::ast { -Statement::Statement(ProgramID pid, const Source& src) : Base(pid, src) {} +Statement::Statement(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {} Statement::Statement(Statement&&) = default; diff --git a/src/tint/ast/statement.h b/src/tint/ast/statement.h index 94de247241..e3a96d1a58 100644 --- a/src/tint/ast/statement.h +++ b/src/tint/ast/statement.h @@ -32,8 +32,9 @@ class Statement : public Castable { protected: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of the expression - Statement(ProgramID pid, const Source& src); + Statement(ProgramID pid, NodeID nid, const Source& src); /// Move constructor Statement(Statement&&); }; diff --git a/src/tint/ast/storage_texture.cc b/src/tint/ast/storage_texture.cc index ccc250d9fb..d75bb0f80e 100644 --- a/src/tint/ast/storage_texture.cc +++ b/src/tint/ast/storage_texture.cc @@ -83,12 +83,13 @@ std::ostream& operator<<(std::ostream& out, TexelFormat format) { } StorageTexture::StorageTexture(ProgramID pid, + NodeID nid, const Source& src, TextureDimension d, TexelFormat fmt, const Type* subtype, Access ac) - : Base(pid, src, d), format(fmt), type(subtype), access(ac) {} + : Base(pid, nid, src, d), format(fmt), type(subtype), access(ac) {} StorageTexture::StorageTexture(StorageTexture&&) = default; diff --git a/src/tint/ast/storage_texture.h b/src/tint/ast/storage_texture.h index 3cf779e244..ac7fee1b09 100644 --- a/src/tint/ast/storage_texture.h +++ b/src/tint/ast/storage_texture.h @@ -53,12 +53,14 @@ class StorageTexture final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param dim the dimensionality of the texture /// @param format the image format of the texture /// @param subtype the storage subtype. Use SubtypeFor() to calculate this. /// @param access_control the access control for the texture. StorageTexture(ProgramID pid, + NodeID nid, const Source& src, TextureDimension dim, TexelFormat format, diff --git a/src/tint/ast/stride_attribute.cc b/src/tint/ast/stride_attribute.cc index 14a0733319..408ee44176 100644 --- a/src/tint/ast/stride_attribute.cc +++ b/src/tint/ast/stride_attribute.cc @@ -22,8 +22,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::StrideAttribute); namespace tint::ast { -StrideAttribute::StrideAttribute(ProgramID pid, const Source& src, uint32_t s) - : Base(pid, src), stride(s) {} +StrideAttribute::StrideAttribute(ProgramID pid, NodeID nid, const Source& src, uint32_t s) + : Base(pid, nid, src), stride(s) {} StrideAttribute::~StrideAttribute() = default; diff --git a/src/tint/ast/stride_attribute.h b/src/tint/ast/stride_attribute.h index 4315f21748..90146774d1 100644 --- a/src/tint/ast/stride_attribute.h +++ b/src/tint/ast/stride_attribute.h @@ -28,9 +28,10 @@ class StrideAttribute final : public Castable { public: /// constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param stride the stride value - StrideAttribute(ProgramID pid, const Source& src, uint32_t stride); + StrideAttribute(ProgramID pid, NodeID nid, const Source& src, uint32_t stride); ~StrideAttribute() override; /// @returns the WGSL name for the attribute diff --git a/src/tint/ast/struct.cc b/src/tint/ast/struct.cc index 19a30de926..326718ab62 100644 --- a/src/tint/ast/struct.cc +++ b/src/tint/ast/struct.cc @@ -22,8 +22,13 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Struct); namespace tint::ast { -Struct::Struct(ProgramID pid, const Source& src, Symbol n, StructMemberList m, AttributeList attrs) - : Base(pid, src, n), members(std::move(m)), attributes(std::move(attrs)) { +Struct::Struct(ProgramID pid, + NodeID nid, + const Source& src, + Symbol n, + StructMemberList m, + AttributeList attrs) + : Base(pid, nid, src, n), members(std::move(m)), attributes(std::move(attrs)) { for (auto* mem : members) { TINT_ASSERT(AST, mem); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, mem, program_id); diff --git a/src/tint/ast/struct.h b/src/tint/ast/struct.h index 5c28b4cd3a..5d55b8c19b 100644 --- a/src/tint/ast/struct.h +++ b/src/tint/ast/struct.h @@ -29,11 +29,13 @@ class Struct final : public Castable { public: /// Create a new struct statement /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node for the import statement /// @param name The name of the structure /// @param members The struct members /// @param attributes The struct attributes Struct(ProgramID pid, + NodeID nid, const Source& src, Symbol name, StructMemberList members, diff --git a/src/tint/ast/struct_member.cc b/src/tint/ast/struct_member.cc index 611348420d..72acd337dc 100644 --- a/src/tint/ast/struct_member.cc +++ b/src/tint/ast/struct_member.cc @@ -21,11 +21,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::StructMember); namespace tint::ast { StructMember::StructMember(ProgramID pid, + NodeID nid, const Source& src, const Symbol& sym, const ast::Type* ty, AttributeList attrs) - : Base(pid, src), symbol(sym), type(ty), attributes(std::move(attrs)) { + : Base(pid, nid, src), symbol(sym), type(ty), attributes(std::move(attrs)) { TINT_ASSERT(AST, type); TINT_ASSERT(AST, symbol.IsValid()); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, symbol, program_id); diff --git a/src/tint/ast/struct_member.h b/src/tint/ast/struct_member.h index 022a34cafe..39c8532b8a 100644 --- a/src/tint/ast/struct_member.h +++ b/src/tint/ast/struct_member.h @@ -32,11 +32,13 @@ class StructMember final : public Castable { public: /// Create a new struct member statement /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node for the struct member statement /// @param sym The struct member symbol /// @param type The struct member type /// @param attributes The struct member attributes StructMember(ProgramID pid, + NodeID nid, const Source& src, const Symbol& sym, const ast::Type* type, diff --git a/src/tint/ast/struct_member_align_attribute.cc b/src/tint/ast/struct_member_align_attribute.cc index f586e7eea7..d8ed4fcf3c 100644 --- a/src/tint/ast/struct_member_align_attribute.cc +++ b/src/tint/ast/struct_member_align_attribute.cc @@ -23,8 +23,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::StructMemberAlignAttribute); namespace tint::ast { -StructMemberAlignAttribute::StructMemberAlignAttribute(ProgramID pid, const Source& src, uint32_t a) - : Base(pid, src), align(a) {} +StructMemberAlignAttribute::StructMemberAlignAttribute(ProgramID pid, + NodeID nid, + const Source& src, + uint32_t a) + : Base(pid, nid, src), align(a) {} StructMemberAlignAttribute::~StructMemberAlignAttribute() = default; diff --git a/src/tint/ast/struct_member_align_attribute.h b/src/tint/ast/struct_member_align_attribute.h index 10a6507d47..efff21b203 100644 --- a/src/tint/ast/struct_member_align_attribute.h +++ b/src/tint/ast/struct_member_align_attribute.h @@ -27,9 +27,10 @@ class StructMemberAlignAttribute final : public Castable(ID())); + attrs.push_back(ASTNodes().Create(ID(), AllocateNodeID())); auto* s = create(name, StructMemberList{Member("a", ty.i32())}, attrs); EXPECT_EQ(s->name, name); @@ -64,10 +64,10 @@ TEST_F(AstStructTest, Creation_WithAttributes) { TEST_F(AstStructTest, CreationWithSourceAndAttributes) { auto name = Sym("s"); - auto* s = - create(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}}, - name, StructMemberList{Member("a", ty.i32())}, - AttributeList{ASTNodes().Create(ID())}); + auto* s = create( + Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}}, name, + StructMemberList{Member("a", ty.i32())}, + AttributeList{ASTNodes().Create(ID(), AllocateNodeID())}); EXPECT_EQ(s->name, name); EXPECT_EQ(s->members.size(), 1u); ASSERT_EQ(s->attributes.size(), 1u); @@ -115,7 +115,8 @@ TEST_F(AstStructTest, Assert_DifferentProgramID_Attribute) { ProgramBuilder b1; ProgramBuilder b2; b1.create(b1.Sym("S"), StructMemberList{b1.Member("a", b1.ty.i32())}, - AttributeList{b2.ASTNodes().Create(b2.ID())}); + AttributeList{b2.ASTNodes().Create( + b2.ID(), b2.AllocateNodeID())}); }, "internal compiler error"); } diff --git a/src/tint/ast/switch_statement.cc b/src/tint/ast/switch_statement.cc index 08095a109c..7abf0c063a 100644 --- a/src/tint/ast/switch_statement.cc +++ b/src/tint/ast/switch_statement.cc @@ -21,10 +21,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::SwitchStatement); namespace tint::ast { SwitchStatement::SwitchStatement(ProgramID pid, + NodeID nid, const Source& src, const Expression* cond, CaseStatementList b) - : Base(pid, src), condition(cond), body(b) { + : Base(pid, nid, src), condition(cond), body(b) { TINT_ASSERT(AST, condition); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, condition, program_id); for (auto* stmt : body) { diff --git a/src/tint/ast/switch_statement.h b/src/tint/ast/switch_statement.h index 5ac13b7b3e..c13ac8802a 100644 --- a/src/tint/ast/switch_statement.h +++ b/src/tint/ast/switch_statement.h @@ -25,10 +25,12 @@ class SwitchStatement final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param condition the switch condition /// @param body the switch body SwitchStatement(ProgramID pid, + NodeID nid, const Source& src, const Expression* condition, CaseStatementList body); diff --git a/src/tint/ast/texture.cc b/src/tint/ast/texture.cc index 27eb094793..f3c01dff29 100644 --- a/src/tint/ast/texture.cc +++ b/src/tint/ast/texture.cc @@ -77,7 +77,8 @@ int NumCoordinateAxes(TextureDimension dim) { return 0; } -Texture::Texture(ProgramID pid, const Source& src, TextureDimension d) : Base(pid, src), dim(d) {} +Texture::Texture(ProgramID pid, NodeID nid, const Source& src, TextureDimension d) + : Base(pid, nid, src), dim(d) {} Texture::Texture(Texture&&) = default; diff --git a/src/tint/ast/texture.h b/src/tint/ast/texture.h index 9a4199bcd7..fcfa3340ff 100644 --- a/src/tint/ast/texture.h +++ b/src/tint/ast/texture.h @@ -65,9 +65,10 @@ class Texture : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param dim the dimensionality of the texture - Texture(ProgramID pid, const Source& src, TextureDimension dim); + Texture(ProgramID pid, NodeID nid, const Source& src, TextureDimension dim); /// Move constructor Texture(Texture&&); ~Texture() override; diff --git a/src/tint/ast/type.h b/src/tint/ast/type.h index 4fee565e1a..4f1f276974 100644 --- a/src/tint/ast/type.h +++ b/src/tint/ast/type.h @@ -42,8 +42,9 @@ class Type : public Castable { protected: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node - Type(ProgramID pid, const Source& src); + Type(ProgramID pid, NodeID nid, const Source& src); }; } // namespace tint::ast diff --git a/src/tint/ast/type_decl.cc b/src/tint/ast/type_decl.cc index a1a0605846..0b7652461e 100644 --- a/src/tint/ast/type_decl.cc +++ b/src/tint/ast/type_decl.cc @@ -20,7 +20,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::TypeDecl); namespace tint::ast { -TypeDecl::TypeDecl(ProgramID pid, const Source& src, Symbol n) : Base(pid, src), name(n) { +TypeDecl::TypeDecl(ProgramID pid, NodeID nid, const Source& src, Symbol n) + : Base(pid, nid, src), name(n) { TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, name, program_id); } diff --git a/src/tint/ast/type_decl.h b/src/tint/ast/type_decl.h index 2b8487a4ca..e3266c69e2 100644 --- a/src/tint/ast/type_decl.h +++ b/src/tint/ast/type_decl.h @@ -26,9 +26,10 @@ class TypeDecl : public Castable { public: /// Create a new struct statement /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node for the import statement /// @param name The name of the structure - TypeDecl(ProgramID pid, const Source& src, Symbol name); + TypeDecl(ProgramID pid, NodeID nid, const Source& src, Symbol name); /// Move constructor TypeDecl(TypeDecl&&); diff --git a/src/tint/ast/type_name.cc b/src/tint/ast/type_name.cc index 8eb7a1ad00..852abf87c3 100644 --- a/src/tint/ast/type_name.cc +++ b/src/tint/ast/type_name.cc @@ -20,7 +20,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::TypeName); namespace tint::ast { -TypeName::TypeName(ProgramID pid, const Source& src, Symbol n) : Base(pid, src), name(n) {} +TypeName::TypeName(ProgramID pid, NodeID nid, const Source& src, Symbol n) + : Base(pid, nid, src), name(n) {} TypeName::~TypeName() = default; diff --git a/src/tint/ast/type_name.h b/src/tint/ast/type_name.h index 3bb556a9b9..ed7e2f23c5 100644 --- a/src/tint/ast/type_name.h +++ b/src/tint/ast/type_name.h @@ -26,9 +26,10 @@ class TypeName final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param name the type name - TypeName(ProgramID pid, const Source& src, Symbol name); + TypeName(ProgramID pid, NodeID nid, const Source& src, Symbol name); /// Move constructor TypeName(TypeName&&); /// Destructor diff --git a/src/tint/ast/u32.cc b/src/tint/ast/u32.cc index ac9c4908f0..c99dc4f284 100644 --- a/src/tint/ast/u32.cc +++ b/src/tint/ast/u32.cc @@ -20,7 +20,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::U32); namespace tint::ast { -U32::U32(ProgramID pid, const Source& src) : Base(pid, src) {} +U32::U32(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {} U32::~U32() = default; diff --git a/src/tint/ast/u32.h b/src/tint/ast/u32.h index 8ede11cbb4..9237278de3 100644 --- a/src/tint/ast/u32.h +++ b/src/tint/ast/u32.h @@ -26,8 +26,9 @@ class U32 final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node - U32(ProgramID pid, const Source& src); + U32(ProgramID pid, NodeID nid, const Source& src); /// Move constructor U32(U32&&); ~U32() override; diff --git a/src/tint/ast/unary_op_expression.cc b/src/tint/ast/unary_op_expression.cc index 80e4e9061a..eec69a05ab 100644 --- a/src/tint/ast/unary_op_expression.cc +++ b/src/tint/ast/unary_op_expression.cc @@ -21,10 +21,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::UnaryOpExpression); namespace tint::ast { UnaryOpExpression::UnaryOpExpression(ProgramID pid, + NodeID nid, const Source& src, UnaryOp o, const Expression* e) - : Base(pid, src), op(o), expr(e) { + : Base(pid, nid, src), op(o), expr(e) { TINT_ASSERT(AST, expr); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, expr, program_id); } diff --git a/src/tint/ast/unary_op_expression.h b/src/tint/ast/unary_op_expression.h index 22093fbd1e..a5c2be937e 100644 --- a/src/tint/ast/unary_op_expression.h +++ b/src/tint/ast/unary_op_expression.h @@ -24,11 +24,13 @@ namespace tint::ast { class UnaryOpExpression final : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param source the unary op expression source /// @param op the op /// @param expr the expr - UnaryOpExpression(ProgramID program_id, + UnaryOpExpression(ProgramID pid, + NodeID nid, const Source& source, UnaryOp op, const Expression* expr); diff --git a/src/tint/ast/var.cc b/src/tint/ast/var.cc index 854503e73f..763949f851 100644 --- a/src/tint/ast/var.cc +++ b/src/tint/ast/var.cc @@ -21,6 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Var); namespace tint::ast { Var::Var(ProgramID pid, + NodeID nid, const Source& src, const Symbol& sym, const ast::Type* ty, @@ -28,7 +29,7 @@ Var::Var(ProgramID pid, Access access, const Expression* ctor, AttributeList attrs) - : Base(pid, src, sym, ty, ctor, attrs), + : Base(pid, nid, src, sym, ty, ctor, attrs), declared_storage_class(storage_class), declared_access(access) {} diff --git a/src/tint/ast/var.h b/src/tint/ast/var.h index 565ebbb6fd..cd12ff498f 100644 --- a/src/tint/ast/var.h +++ b/src/tint/ast/var.h @@ -42,7 +42,8 @@ namespace tint::ast { class Var final : public Castable { public: /// Create a 'var' variable - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param source the variable source /// @param sym the variable symbol /// @param type the declared variable type @@ -50,7 +51,8 @@ class Var final : public Castable { /// @param declared_access the declared access control /// @param constructor the constructor expression /// @param attributes the variable attributes - Var(ProgramID program_id, + Var(ProgramID pid, + NodeID nid, const Source& source, const Symbol& sym, const ast::Type* type, diff --git a/src/tint/ast/variable.cc b/src/tint/ast/variable.cc index a9ae829ce7..b16b2aa88c 100644 --- a/src/tint/ast/variable.cc +++ b/src/tint/ast/variable.cc @@ -21,12 +21,13 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Variable); namespace tint::ast { Variable::Variable(ProgramID pid, + NodeID nid, const Source& src, const Symbol& sym, const ast::Type* ty, const Expression* ctor, AttributeList attrs) - : Base(pid, src), symbol(sym), type(ty), constructor(ctor), attributes(std::move(attrs)) { + : Base(pid, nid, src), symbol(sym), type(ty), constructor(ctor), attributes(std::move(attrs)) { TINT_ASSERT(AST, symbol.IsValid()); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, symbol, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, constructor, program_id); diff --git a/src/tint/ast/variable.h b/src/tint/ast/variable.h index 631fbe5785..30313188d7 100644 --- a/src/tint/ast/variable.h +++ b/src/tint/ast/variable.h @@ -54,13 +54,15 @@ struct VariableBindingPoint { class Variable : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param source the variable source /// @param sym the variable symbol /// @param type the declared variable type /// @param constructor the constructor expression /// @param attributes the variable attributes - Variable(ProgramID program_id, + Variable(ProgramID pid, + NodeID nid, const Source& source, const Symbol& sym, const ast::Type* type, diff --git a/src/tint/ast/variable_decl_statement.cc b/src/tint/ast/variable_decl_statement.cc index fdde149f03..79ee92606c 100644 --- a/src/tint/ast/variable_decl_statement.cc +++ b/src/tint/ast/variable_decl_statement.cc @@ -20,8 +20,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::VariableDeclStatement); namespace tint::ast { -VariableDeclStatement::VariableDeclStatement(ProgramID pid, const Source& src, const Variable* var) - : Base(pid, src), variable(var) { +VariableDeclStatement::VariableDeclStatement(ProgramID pid, + NodeID nid, + const Source& src, + const Variable* var) + : Base(pid, nid, src), variable(var) { TINT_ASSERT(AST, variable); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, variable, program_id); } diff --git a/src/tint/ast/variable_decl_statement.h b/src/tint/ast/variable_decl_statement.h index 3f3ae273e3..b71d0b2acc 100644 --- a/src/tint/ast/variable_decl_statement.h +++ b/src/tint/ast/variable_decl_statement.h @@ -24,10 +24,14 @@ namespace tint::ast { class VariableDeclStatement final : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param source the variable statement source /// @param variable the variable - VariableDeclStatement(ProgramID program_id, const Source& source, const Variable* variable); + VariableDeclStatement(ProgramID pid, + NodeID nid, + const Source& source, + const Variable* variable); /// Move constructor VariableDeclStatement(VariableDeclStatement&&); ~VariableDeclStatement() override; diff --git a/src/tint/ast/vector.cc b/src/tint/ast/vector.cc index 43478dfda4..d49da33126 100644 --- a/src/tint/ast/vector.cc +++ b/src/tint/ast/vector.cc @@ -20,8 +20,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Vector); namespace tint::ast { -Vector::Vector(ProgramID pid, Source const& src, const Type* subtype, uint32_t w) - : Base(pid, src), type(subtype), width(w) { +Vector::Vector(ProgramID pid, NodeID nid, Source const& src, const Type* subtype, uint32_t w) + : Base(pid, nid, src), type(subtype), width(w) { TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, subtype, program_id); TINT_ASSERT(AST, width > 1); TINT_ASSERT(AST, width < 5); diff --git a/src/tint/ast/vector.h b/src/tint/ast/vector.h index 6b2d9141b8..111602de52 100644 --- a/src/tint/ast/vector.h +++ b/src/tint/ast/vector.h @@ -26,12 +26,13 @@ class Vector final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param subtype the declared type of the vector components. May be null /// for vector constructors, where the element type will be inferred /// from the constructor arguments /// @param width the number of elements in the vector - Vector(ProgramID pid, Source const& src, const Type* subtype, uint32_t width); + Vector(ProgramID pid, NodeID nid, Source const& src, const Type* subtype, uint32_t width); /// Move constructor Vector(Vector&&); ~Vector() override; diff --git a/src/tint/ast/void.cc b/src/tint/ast/void.cc index 5cc89635a7..ead89efe42 100644 --- a/src/tint/ast/void.cc +++ b/src/tint/ast/void.cc @@ -20,7 +20,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Void); namespace tint::ast { -Void::Void(ProgramID pid, const Source& src) : Base(pid, src) {} +Void::Void(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {} Void::Void(Void&&) = default; diff --git a/src/tint/ast/void.h b/src/tint/ast/void.h index 33f5b5bd1d..dba20f11e4 100644 --- a/src/tint/ast/void.h +++ b/src/tint/ast/void.h @@ -26,8 +26,9 @@ class Void final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node - Void(ProgramID pid, const Source& src); + Void(ProgramID pid, NodeID nid, const Source& src); /// Move constructor Void(Void&&); ~Void() override; diff --git a/src/tint/ast/while_statement.cc b/src/tint/ast/while_statement.cc index 3666baf3bd..160af4b582 100644 --- a/src/tint/ast/while_statement.cc +++ b/src/tint/ast/while_statement.cc @@ -21,10 +21,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::WhileStatement); namespace tint::ast { WhileStatement::WhileStatement(ProgramID pid, + NodeID nid, const Source& src, const Expression* cond, const BlockStatement* b) - : Base(pid, src), condition(cond), body(b) { + : Base(pid, nid, src), condition(cond), body(b) { TINT_ASSERT(AST, cond); TINT_ASSERT(AST, body); diff --git a/src/tint/ast/while_statement.h b/src/tint/ast/while_statement.h index 9a7a6b0347..4e8dd7e2a1 100644 --- a/src/tint/ast/while_statement.h +++ b/src/tint/ast/while_statement.h @@ -25,12 +25,14 @@ class Expression; class WhileStatement final : public Castable { public: /// Constructor - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param source the for loop statement source /// @param condition the optional loop condition expression /// @param body the loop body - WhileStatement(ProgramID program_id, - Source const& source, + WhileStatement(ProgramID pid, + NodeID nid, + const Source& source, const Expression* condition, const BlockStatement* body); /// Move constructor diff --git a/src/tint/ast/workgroup_attribute.cc b/src/tint/ast/workgroup_attribute.cc index 74ecdbe019..7cb67dc586 100644 --- a/src/tint/ast/workgroup_attribute.cc +++ b/src/tint/ast/workgroup_attribute.cc @@ -23,11 +23,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::WorkgroupAttribute); namespace tint::ast { WorkgroupAttribute::WorkgroupAttribute(ProgramID pid, + NodeID nid, const Source& src, const ast::Expression* x_, const ast::Expression* y_, const ast::Expression* z_) - : Base(pid, src), x(x_), y(y_), z(z_) {} + : Base(pid, nid, src), x(x_), y(y_), z(z_) {} WorkgroupAttribute::~WorkgroupAttribute() = default; diff --git a/src/tint/ast/workgroup_attribute.h b/src/tint/ast/workgroup_attribute.h index 536ce155fd..e27e77e900 100644 --- a/src/tint/ast/workgroup_attribute.h +++ b/src/tint/ast/workgroup_attribute.h @@ -32,11 +32,13 @@ class WorkgroupAttribute final : public Castable public: /// constructor /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param src the source of this node /// @param x the workgroup x dimension expression /// @param y the optional workgroup y dimension expression /// @param z the optional workgroup z dimension expression WorkgroupAttribute(ProgramID pid, + NodeID nid, const Source& src, const ast::Expression* x, const ast::Expression* y = nullptr, diff --git a/src/tint/program.cc b/src/tint/program.cc index 1afbd460ec..6109c20664 100644 --- a/src/tint/program.cc +++ b/src/tint/program.cc @@ -35,6 +35,7 @@ Program::Program() = default; Program::Program(Program&& program) : id_(std::move(program.id_)), + highest_node_id_(std::move(program.highest_node_id_)), types_(std::move(program.types_)), ast_nodes_(std::move(program.ast_nodes_)), sem_nodes_(std::move(program.sem_nodes_)), @@ -50,6 +51,7 @@ Program::Program(Program&& program) Program::Program(ProgramBuilder&& builder) { id_ = builder.ID(); + highest_node_id_ = builder.LastAllocatedNodeID(); is_valid_ = builder.IsValid(); if (builder.ResolveOnBuild() && builder.IsValid()) { @@ -85,6 +87,7 @@ Program& Program::operator=(Program&& program) { program.moved_ = true; moved_ = false; id_ = std::move(program.id_); + highest_node_id_ = std::move(program.highest_node_id_); types_ = std::move(program.types_); ast_nodes_ = std::move(program.ast_nodes_); sem_nodes_ = std::move(program.sem_nodes_); diff --git a/src/tint/program.h b/src/tint/program.h index 5fd31ddd74..ea884701ef 100644 --- a/src/tint/program.h +++ b/src/tint/program.h @@ -69,6 +69,9 @@ class Program { /// @returns the unique identifier for this program ProgramID ID() const { return id_; } + /// @returns the last allocated (numerically highest) AST node identifier. + ast::NodeID HighestASTNodeID() const { return highest_node_id_; } + /// @returns a reference to the program's types const sem::Manager& Types() const { AssertNotMoved(); @@ -161,6 +164,7 @@ class Program { void AssertNotMoved() const; ProgramID id_; + ast::NodeID highest_node_id_; sem::Manager types_; ASTNodeAllocator ast_nodes_; SemNodeAllocator sem_nodes_; diff --git a/src/tint/program_builder.cc b/src/tint/program_builder.cc index aed6ec8cde..19f20b479c 100644 --- a/src/tint/program_builder.cc +++ b/src/tint/program_builder.cc @@ -29,14 +29,16 @@ namespace tint { ProgramBuilder::VarOptionals::~VarOptionals() = default; ProgramBuilder::ProgramBuilder() - : id_(ProgramID::New()), ast_(ast_nodes_.Create(id_, Source{})) {} + : id_(ProgramID::New()), + ast_(ast_nodes_.Create(id_, AllocateNodeID(), Source{})) {} ProgramBuilder::ProgramBuilder(ProgramBuilder&& rhs) : id_(std::move(rhs.id_)), + last_ast_node_id_(std::move(rhs.last_ast_node_id_)), types_(std::move(rhs.types_)), ast_nodes_(std::move(rhs.ast_nodes_)), sem_nodes_(std::move(rhs.sem_nodes_)), - ast_(rhs.ast_), + ast_(std::move(rhs.ast_)), sem_(std::move(rhs.sem_)), symbols_(std::move(rhs.symbols_)), diagnostics_(std::move(rhs.diagnostics_)) { @@ -49,10 +51,11 @@ ProgramBuilder& ProgramBuilder::operator=(ProgramBuilder&& rhs) { rhs.MarkAsMoved(); AssertNotMoved(); id_ = std::move(rhs.id_); + last_ast_node_id_ = std::move(rhs.last_ast_node_id_); types_ = std::move(rhs.types_); ast_nodes_ = std::move(rhs.ast_nodes_); sem_nodes_ = std::move(rhs.sem_nodes_); - ast_ = rhs.ast_; + ast_ = std::move(rhs.ast_); sem_ = std::move(rhs.sem_); symbols_ = std::move(rhs.symbols_); diagnostics_ = std::move(rhs.diagnostics_); @@ -63,6 +66,7 @@ ProgramBuilder& ProgramBuilder::operator=(ProgramBuilder&& rhs) { ProgramBuilder ProgramBuilder::Wrap(const Program* program) { ProgramBuilder builder; builder.id_ = program->ID(); + builder.last_ast_node_id_ = program->HighestASTNodeID(); builder.types_ = sem::Manager::Wrap(program->Types()); builder.ast_ = builder.create(program->AST().source, program->AST().GlobalDeclarations()); diff --git a/src/tint/program_builder.h b/src/tint/program_builder.h index 9a4f7cab2d..c6b163f3dc 100644 --- a/src/tint/program_builder.h +++ b/src/tint/program_builder.h @@ -299,6 +299,16 @@ class ProgramBuilder { /// information bool IsValid() const; + /// @returns the last allocated (numerically highest) AST node identifier. + ast::NodeID LastAllocatedNodeID() const { return last_ast_node_id_; } + + /// @returns the next sequentially unique node identifier. + ast::NodeID AllocateNodeID() { + auto out = ast::NodeID{last_ast_node_id_.value + 1}; + last_ast_node_id_ = out; + return out; + } + /// Creates a new ast::Node owned by the ProgramBuilder. When the /// ProgramBuilder is destructed, the ast::Node will also be destructed. /// @param source the Source of the node @@ -307,7 +317,7 @@ class ProgramBuilder { template traits::EnableIfIsType* create(const Source& source, ARGS&&... args) { AssertNotMoved(); - return ast_nodes_.Create(id_, source, std::forward(args)...); + return ast_nodes_.Create(id_, AllocateNodeID(), source, std::forward(args)...); } /// Creates a new ast::Node owned by the ProgramBuilder, injecting the current @@ -319,7 +329,7 @@ class ProgramBuilder { template traits::EnableIfIsType* create() { AssertNotMoved(); - return ast_nodes_.Create(id_, source_); + return ast_nodes_.Create(id_, AllocateNodeID(), source_); } /// Creates a new ast::Node owned by the ProgramBuilder, injecting the current @@ -337,7 +347,7 @@ class ProgramBuilder { T>* create(ARG0&& arg0, ARGS&&... args) { AssertNotMoved(); - return ast_nodes_.Create(id_, source_, std::forward(arg0), + return ast_nodes_.Create(id_, AllocateNodeID(), source_, std::forward(arg0), std::forward(args)...); } @@ -2665,7 +2675,8 @@ class ProgramBuilder { /// @param validation the validation to disable /// @returns the disable validation attribute pointer const ast::DisableValidationAttribute* Disable(ast::DisabledValidation validation) { - return ASTNodes().Create(ID(), validation); + return ASTNodes().Create(ID(), AllocateNodeID(), + validation); } /// Sets the current builder source to `src` @@ -2774,6 +2785,7 @@ class ProgramBuilder { private: ProgramID id_; + ast::NodeID last_ast_node_id_ = ast::NodeID{static_cast(0) - 1}; sem::Manager types_; ASTNodeAllocator ast_nodes_; SemNodeAllocator sem_nodes_; diff --git a/src/tint/reader/spirv/function.cc b/src/tint/reader/spirv/function.cc index 2bcae95368..7c10f89310 100644 --- a/src/tint/reader/spirv/function.cc +++ b/src/tint/reader/spirv/function.cc @@ -5481,8 +5481,8 @@ bool FunctionEmitter::EmitAtomicOp(const spvtools::opt::Instruction& inst) { // Emit stub, will be removed by transform::SpirvAtomic auto sym = builder_.Symbols().New(std::string("stub_") + sem::str(builtin)); - auto* stub_deco = - builder_.ASTNodes().Create(builder_.ID(), builtin); + auto* stub_deco = builder_.ASTNodes().Create( + builder_.ID(), builder_.AllocateNodeID(), builtin); auto* stub = create(Source{}, sym, std::move(params), ret_type, /* body */ nullptr, diff --git a/src/tint/reader/spirv/function.h b/src/tint/reader/spirv/function.h index ae9ef31405..ae7a9a1ec2 100644 --- a/src/tint/reader/spirv/function.h +++ b/src/tint/reader/spirv/function.h @@ -376,7 +376,7 @@ inline std::ostream& operator<<(std::ostream& o, const DefInfo& di) { class StatementBuilder : public Castable { public: /// Constructor - StatementBuilder() : Base(ProgramID(), Source{}) {} + StatementBuilder() : Base(ProgramID(), ast::NodeID(), Source{}) {} /// @param builder the program builder /// @returns the build AST node diff --git a/src/tint/reader/spirv/parser_impl.cc b/src/tint/reader/spirv/parser_impl.cc index 11c439dc59..9803162c0d 100644 --- a/src/tint/reader/spirv/parser_impl.cc +++ b/src/tint/reader/spirv/parser_impl.cc @@ -513,7 +513,8 @@ ast::AttributeList ParserImpl::ConvertMemberDecoration(uint32_t struct_type_id, return { create(Source{}, decoration[1]), builder_.ASTNodes().Create( - builder_.ID(), ast::DisabledValidation::kIgnoreStrideAttribute), + builder_.ID(), builder_.AllocateNodeID(), + ast::DisabledValidation::kIgnoreStrideAttribute), }; } default: diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc index cd28072830..611f240f3c 100644 --- a/src/tint/resolver/resolver.cc +++ b/src/tint/resolver/resolver.cc @@ -103,8 +103,7 @@ bool Resolver::Resolve() { return false; } - // Pre-allocate the ast -> sem map with the total number of AST nodes. - builder_->Sem().Reserve(builder_->ASTNodes().Count()); + builder_->Sem().Reserve(builder_->LastAllocatedNodeID()); if (!DependencyGraph::Build(builder_->AST(), builder_->Symbols(), builder_->Diagnostics(), dependencies_)) { diff --git a/src/tint/resolver/validation_test.cc b/src/tint/resolver/validation_test.cc index 20cf1ea833..24f420bdd9 100644 --- a/src/tint/resolver/validation_test.cc +++ b/src/tint/resolver/validation_test.cc @@ -50,13 +50,13 @@ using ResolverValidationTest = ResolverTest; class FakeStmt final : public Castable { public: - FakeStmt(ProgramID pid, Source src) : Base(pid, src) {} + FakeStmt(ProgramID pid, ast::NodeID nid, Source src) : Base(pid, nid, src) {} FakeStmt* Clone(CloneContext*) const override { return nullptr; } }; class FakeExpr final : public Castable { public: - FakeExpr(ProgramID pid, Source src) : Base(pid, src) {} + FakeExpr(ProgramID pid, ast::NodeID nid, Source src) : Base(pid, nid, src) {} FakeExpr* Clone(CloneContext*) const override { return nullptr; } }; diff --git a/src/tint/sem/info.h b/src/tint/sem/info.h index aa98ff0c92..894b408fe0 100644 --- a/src/tint/sem/info.h +++ b/src/tint/sem/info.h @@ -15,9 +15,12 @@ #ifndef SRC_TINT_SEM_INFO_H_ #define SRC_TINT_SEM_INFO_H_ +#include #include #include +#include +#include "src/tint/ast/node.h" #include "src/tint/debug.h" #include "src/tint/sem/node.h" #include "src/tint/sem/type_mappings.h" @@ -55,40 +58,42 @@ class Info { /// @return this Program Info& operator=(Info&& rhs); - /// Pre-allocates the AST -> semantic node map to fit at least the given number of nodes. - /// @param num_ast_nodes the number of AST nodes to pre-allocate the map for. - void Reserve(size_t num_ast_nodes) { map_.reserve(num_ast_nodes); } + /// @param highest_node_id the last allocated (numerically highest) AST node identifier. + void Reserve(ast::NodeID highest_node_id) { + nodes_.resize(std::max(highest_node_id.value + 1, nodes_.size())); + } - /// Get looks up the semantic information for the AST node `node`. + /// Get looks up the semantic information for the AST node `ast_node`. /// @param ast_node the AST node /// @returns a pointer to the semantic node if found, otherwise nullptr template > const RESULT* Get(const AST* ast_node) const { - auto it = map_.find(ast_node); - if (it == map_.end()) { - return nullptr; + if (ast_node && ast_node->node_id.value < nodes_.size()) { + return As(nodes_[ast_node->node_id.value]); } - return As(it->second); + return nullptr; } - /// Add registers the semantic node `sem_node` for the AST node `node`. + /// Add registers the semantic node `sem_node` for the AST node `ast_node`. /// @param ast_node the AST node /// @param sem_node the semantic node template void Add(const AST* ast_node, const SemanticNodeTypeFor* sem_node) { - // Check there's no semantic info already existing for the node - TINT_ASSERT(Semantic, map_.find(ast_node) == map_.end()); - map_.emplace(ast_node, sem_node); + Reserve(ast_node->node_id); + // Check there's no semantic info already existing for the AST node + TINT_ASSERT(Semantic, nodes_[ast_node->node_id.value] == nullptr); + nodes_[ast_node->node_id.value] = sem_node; } - /// Replace replaces any existing semantic node `sem_node` for the AST node `node`. + /// Replace replaces any existing semantic node `sem_node` for the AST node `ast_node`. /// @param ast_node the AST node /// @param sem_node the new semantic node template void Replace(const AST* ast_node, const SemanticNodeTypeFor* sem_node) { - map_[ast_node] = sem_node; + Reserve(ast_node->node_id); + nodes_[ast_node->node_id.value] = sem_node; } /// Wrap returns a new Info created with the contents of `inner`. @@ -100,7 +105,7 @@ class Info { /// @return the Info that wraps `inner` static Info Wrap(const Info& inner) { Info out; - out.map_ = inner.map_; + out.nodes_ = inner.nodes_; out.module_ = inner.module_; return out; } @@ -113,8 +118,8 @@ class Info { const sem::Module* Module() const { return module_; } private: - // The map of AST node to semantic node - std::unordered_map map_; + // AST node index to semantic node + std::vector nodes_; // The semantic module sem::Module* module_ = nullptr; }; diff --git a/src/tint/symbol.cc b/src/tint/symbol.cc index 09656975ee..925ab5b24c 100644 --- a/src/tint/symbol.cc +++ b/src/tint/symbol.cc @@ -23,7 +23,7 @@ Symbol::Symbol() = default; Symbol::Symbol(uint32_t val, tint::ProgramID program_id) : val_(val), program_id_(program_id) {} #if TINT_SYMBOL_STORE_DEBUG_NAME -Symbol::Symbol(uint32_t val, tint::ProgramID program_id, std::string debug_name) +Symbol::Symbol(uint32_t val, tint::ProgramID pid, NodeID nid, std::string debug_name) : val_(val), program_id_(program_id), debug_name_(std::move(debug_name)) {} #endif diff --git a/src/tint/symbol.h b/src/tint/symbol.h index 1cbc6b2245..512deba147 100644 --- a/src/tint/symbol.h +++ b/src/tint/symbol.h @@ -43,7 +43,7 @@ class Symbol { /// @param val the symbol value /// @param program_id the identifier of the program that owns this Symbol /// @param debug_name name of symbols used only for debugging - Symbol(uint32_t val, tint::ProgramID program_id, std::string debug_name); + Symbol(uint32_t val, tint::ProgramID pid, NodeID nid, std::string debug_name); #endif /// Copy constructor /// @param o the symbol to copy diff --git a/src/tint/transform/add_spirv_block_attribute.cc b/src/tint/transform/add_spirv_block_attribute.cc index a62f9c7bfc..85c20c3ae3 100644 --- a/src/tint/transform/add_spirv_block_attribute.cc +++ b/src/tint/transform/add_spirv_block_attribute.cc @@ -70,7 +70,8 @@ void AddSpirvBlockAttribute::Run(CloneContext& ctx, const DataMap&, DataMap&) co // This is a non-struct or a struct that is nested somewhere else, so we // need to wrap it first. auto* wrapper = utils::GetOrCreate(wrapper_structs, ty, [&]() { - auto* block = ctx.dst->ASTNodes().Create(ctx.dst->ID()); + auto* block = ctx.dst->ASTNodes().Create( + ctx.dst->ID(), ctx.dst->AllocateNodeID()); auto wrapper_name = ctx.src->Symbols().NameFor(var->symbol) + "_block"; auto* ret = ctx.dst->create( ctx.dst->Symbols().New(wrapper_name), @@ -89,7 +90,8 @@ void AddSpirvBlockAttribute::Run(CloneContext& ctx, const DataMap&, DataMap&) co } } else { // Add a block attribute to this struct directly. - auto* block = ctx.dst->ASTNodes().Create(ctx.dst->ID()); + auto* block = ctx.dst->ASTNodes().Create( + ctx.dst->ID(), ctx.dst->AllocateNodeID()); ctx.InsertFront(str->Declaration()->attributes, block); } } @@ -97,7 +99,8 @@ void AddSpirvBlockAttribute::Run(CloneContext& ctx, const DataMap&, DataMap&) co ctx.Clone(); } -AddSpirvBlockAttribute::SpirvBlockAttribute::SpirvBlockAttribute(ProgramID pid) : Base(pid) {} +AddSpirvBlockAttribute::SpirvBlockAttribute::SpirvBlockAttribute(ProgramID pid, ast::NodeID nid) + : Base(pid, nid) {} AddSpirvBlockAttribute::SpirvBlockAttribute::~SpirvBlockAttribute() = default; std::string AddSpirvBlockAttribute::SpirvBlockAttribute::InternalName() const { return "spirv_block"; @@ -105,7 +108,8 @@ std::string AddSpirvBlockAttribute::SpirvBlockAttribute::InternalName() const { const AddSpirvBlockAttribute::SpirvBlockAttribute* AddSpirvBlockAttribute::SpirvBlockAttribute::Clone(CloneContext* ctx) const { - return ctx->dst->ASTNodes().Create(ctx->dst->ID()); + return ctx->dst->ASTNodes().Create( + ctx->dst->ID(), ctx->dst->AllocateNodeID()); } } // namespace tint::transform diff --git a/src/tint/transform/add_spirv_block_attribute.h b/src/tint/transform/add_spirv_block_attribute.h index 67faaa5ec1..51409c8a23 100644 --- a/src/tint/transform/add_spirv_block_attribute.h +++ b/src/tint/transform/add_spirv_block_attribute.h @@ -35,7 +35,8 @@ class AddSpirvBlockAttribute final : public Castabledst->ASTNodes().Create(ctx->dst->ID()); + return ctx->dst->ASTNodes().Create( + ctx->dst->ID(), ctx->dst->AllocateNodeID()); } CalculateArrayLength::CalculateArrayLength() = default; @@ -109,7 +111,8 @@ void CalculateArrayLength::Run(CloneContext& ctx, const DataMap&, DataMap&) cons }, ctx.dst->ty.void_(), nullptr, ast::AttributeList{ - ctx.dst->ASTNodes().Create(ctx.dst->ID()), + ctx.dst->ASTNodes().Create(ctx.dst->ID(), + ctx.dst->AllocateNodeID()), }, ast::AttributeList{})); diff --git a/src/tint/transform/calculate_array_length.h b/src/tint/transform/calculate_array_length.h index 401e081aa7..8db8dcceca 100644 --- a/src/tint/transform/calculate_array_length.h +++ b/src/tint/transform/calculate_array_length.h @@ -40,7 +40,8 @@ class CalculateArrayLength final : public CastableASTNodes().Create( - builder->ID(), DecomposeMemoryAccess::Intrinsic::Op::kLoad, storage_class, type); + builder->ID(), builder->AllocateNodeID(), DecomposeMemoryAccess::Intrinsic::Op::kLoad, + storage_class, type); } /// @returns a DecomposeMemoryAccess::Intrinsic attribute that can be applied @@ -215,7 +216,8 @@ DecomposeMemoryAccess::Intrinsic* IntrinsicStoreFor(ProgramBuilder* builder, return nullptr; } return builder->ASTNodes().Create( - builder->ID(), DecomposeMemoryAccess::Intrinsic::Op::kStore, storage_class, type); + builder->ID(), builder->AllocateNodeID(), DecomposeMemoryAccess::Intrinsic::Op::kStore, + storage_class, type); } /// @returns a DecomposeMemoryAccess::Intrinsic attribute that can be applied @@ -270,7 +272,7 @@ DecomposeMemoryAccess::Intrinsic* IntrinsicAtomicFor(ProgramBuilder* builder, return nullptr; } return builder->ASTNodes().Create( - builder->ID(), op, ast::StorageClass::kStorage, type); + builder->ID(), builder->AllocateNodeID(), op, ast::StorageClass::kStorage, type); } /// BufferAccess describes a single storage or uniform buffer access @@ -681,8 +683,12 @@ struct DecomposeMemoryAccess::State { } }; -DecomposeMemoryAccess::Intrinsic::Intrinsic(ProgramID pid, Op o, ast::StorageClass sc, DataType ty) - : Base(pid), op(o), storage_class(sc), type(ty) {} +DecomposeMemoryAccess::Intrinsic::Intrinsic(ProgramID pid, + ast::NodeID nid, + Op o, + ast::StorageClass sc, + DataType ty) + : Base(pid, nid), op(o), storage_class(sc), type(ty) {} DecomposeMemoryAccess::Intrinsic::~Intrinsic() = default; std::string DecomposeMemoryAccess::Intrinsic::InternalName() const { std::stringstream ss; @@ -771,8 +777,8 @@ std::string DecomposeMemoryAccess::Intrinsic::InternalName() const { const DecomposeMemoryAccess::Intrinsic* DecomposeMemoryAccess::Intrinsic::Clone( CloneContext* ctx) const { - return ctx->dst->ASTNodes().Create(ctx->dst->ID(), op, - storage_class, type); + return ctx->dst->ASTNodes().Create( + ctx->dst->ID(), ctx->dst->AllocateNodeID(), op, storage_class, type); } bool DecomposeMemoryAccess::Intrinsic::IsAtomic() const { diff --git a/src/tint/transform/decompose_memory_access.h b/src/tint/transform/decompose_memory_access.h index 76cb23e2ff..1d95dc493d 100644 --- a/src/tint/transform/decompose_memory_access.h +++ b/src/tint/transform/decompose_memory_access.h @@ -72,11 +72,12 @@ class DecomposeMemoryAccess final : public Castabledst->ASTNodes().Create(ctx->dst->ID(), builtin); + return ctx->dst->ASTNodes().Create(ctx->dst->ID(), + ctx->dst->AllocateNodeID(), builtin); } bool SpirvAtomic::ShouldRun(const Program* program, const DataMap&) const { diff --git a/src/tint/transform/spirv_atomic.h b/src/tint/transform/spirv_atomic.h index 36ac842854..e1311c5952 100644 --- a/src/tint/transform/spirv_atomic.h +++ b/src/tint/transform/spirv_atomic.h @@ -43,9 +43,10 @@ class SpirvAtomic final : public Castable { /// translated to an atomic builtin. class Stub final : public Castable { public: - /// @param program_id the identifier of the program that owns this node + /// @param pid the identifier of the program that owns this node + /// @param nid the unique node identifier /// @param builtin the atomic builtin this stub represents - Stub(ProgramID program_id, sem::BuiltinType builtin); + Stub(ProgramID pid, ast::NodeID nid, sem::BuiltinType builtin); /// Destructor ~Stub() override; diff --git a/src/tint/transform/spirv_atomic_test.cc b/src/tint/transform/spirv_atomic_test.cc index 7f07d062da..cbd8a263a5 100644 --- a/src/tint/transform/spirv_atomic_test.cc +++ b/src/tint/transform/spirv_atomic_test.cc @@ -49,14 +49,14 @@ class SpirvAtomicTest : public TransformTest { b.Param("p1", b.ty.u32()), }, b.ty.u32(), {b.Return(0_u)}, - {b.ASTNodes().Create(b.ID(), a)}); + {b.ASTNodes().Create(b.ID(), b.AllocateNodeID(), a)}); b.Func(std::string{"stub_"} + sem::str(a) + "_i32", { b.Param("p0", b.ty.i32()), b.Param("p1", b.ty.i32()), }, b.ty.i32(), {b.Return(0_i)}, - {b.ASTNodes().Create(b.ID(), a)}); + {b.ASTNodes().Create(b.ID(), b.AllocateNodeID(), a)}); } b.Func("stub_atomicLoad_u32", @@ -65,7 +65,8 @@ class SpirvAtomicTest : public TransformTest { }, b.ty.u32(), {b.Return(0_u)}, { - b.ASTNodes().Create(b.ID(), sem::BuiltinType::kAtomicLoad), + b.ASTNodes().Create(b.ID(), b.AllocateNodeID(), + sem::BuiltinType::kAtomicLoad), }); b.Func("stub_atomicLoad_i32", { @@ -73,7 +74,8 @@ class SpirvAtomicTest : public TransformTest { }, b.ty.i32(), {b.Return(0_i)}, { - b.ASTNodes().Create(b.ID(), sem::BuiltinType::kAtomicLoad), + b.ASTNodes().Create(b.ID(), b.AllocateNodeID(), + sem::BuiltinType::kAtomicLoad), }); b.Func("stub_atomicStore_u32", @@ -83,7 +85,8 @@ class SpirvAtomicTest : public TransformTest { }, b.ty.void_(), {}, { - b.ASTNodes().Create(b.ID(), sem::BuiltinType::kAtomicStore), + b.ASTNodes().Create(b.ID(), b.AllocateNodeID(), + sem::BuiltinType::kAtomicStore), }); b.Func("stub_atomicStore_i32", { @@ -92,7 +95,8 @@ class SpirvAtomicTest : public TransformTest { }, b.ty.void_(), {}, { - b.ASTNodes().Create(b.ID(), sem::BuiltinType::kAtomicStore), + b.ASTNodes().Create(b.ID(), b.AllocateNodeID(), + sem::BuiltinType::kAtomicStore), }); b.Func("stub_atomic_compare_exchange_weak_u32", @@ -104,14 +108,14 @@ class SpirvAtomicTest : public TransformTest { b.ty.u32(), {b.Return(0_u)}, { b.ASTNodes().Create( - b.ID(), sem::BuiltinType::kAtomicCompareExchangeWeak), + b.ID(), b.AllocateNodeID(), sem::BuiltinType::kAtomicCompareExchangeWeak), }); b.Func("stub_atomic_compare_exchange_weak_i32", {b.Param("p0", b.ty.i32()), b.Param("p1", b.ty.i32()), b.Param("p2", b.ty.i32())}, b.ty.i32(), {b.Return(0_i)}, { b.ASTNodes().Create( - b.ID(), sem::BuiltinType::kAtomicCompareExchangeWeak), + b.ID(), b.AllocateNodeID(), sem::BuiltinType::kAtomicCompareExchangeWeak), }); // Keep this pointer alive after Transform() returns diff --git a/src/tint/writer/glsl/generator_impl.cc b/src/tint/writer/glsl/generator_impl.cc index 88eec26319..e9c0c4a2b8 100644 --- a/src/tint/writer/glsl/generator_impl.cc +++ b/src/tint/writer/glsl/generator_impl.cc @@ -2210,7 +2210,7 @@ bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) { } if (!Is(func->body->Last())) { - ast::ReturnStatement ret(ProgramID(), Source{}); + ast::ReturnStatement ret(ProgramID{}, ast::NodeID{}, Source{}); if (!EmitStatement(&ret)) { return false; } diff --git a/src/tint/writer/hlsl/generator_impl.cc b/src/tint/writer/hlsl/generator_impl.cc index e8ab2c7c55..4516a98c90 100644 --- a/src/tint/writer/hlsl/generator_impl.cc +++ b/src/tint/writer/hlsl/generator_impl.cc @@ -3106,7 +3106,7 @@ bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) { } if (!Is(func->body->Last())) { - ast::ReturnStatement ret(ProgramID(), Source{}); + ast::ReturnStatement ret(ProgramID(), ast::NodeID{}, Source{}); if (!EmitStatement(&ret)) { return false; } diff --git a/src/tint/writer/msl/generator_impl.cc b/src/tint/writer/msl/generator_impl.cc index 2af36c9348..68151e180d 100644 --- a/src/tint/writer/msl/generator_impl.cc +++ b/src/tint/writer/msl/generator_impl.cc @@ -2039,7 +2039,7 @@ bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) { } if (!Is(func->body->Last())) { - ast::ReturnStatement ret(ProgramID{}, Source{}); + ast::ReturnStatement ret(ProgramID{}, ast::NodeID{}, Source{}); if (!EmitStatement(&ret)) { return false; } diff --git a/src/tint/writer/spirv/builder.cc b/src/tint/writer/spirv/builder.cc index 92fcf785ba..31ed539bab 100644 --- a/src/tint/writer/spirv/builder.cc +++ b/src/tint/writer/spirv/builder.cc @@ -778,22 +778,22 @@ bool Builder::GenerateGlobalVariable(const ast::Variable* v) { init_id = Switch( type, // [&](const sem::F32*) { - ast::FloatLiteralExpression l(ProgramID{}, Source{}, 0, + ast::FloatLiteralExpression l(ProgramID{}, ast::NodeID{}, Source{}, 0, ast::FloatLiteralExpression::Suffix::kF); return GenerateLiteralIfNeeded(override, &l); }, [&](const sem::U32*) { - ast::IntLiteralExpression l(ProgramID{}, Source{}, 0, + ast::IntLiteralExpression l(ProgramID{}, ast::NodeID{}, Source{}, 0, ast::IntLiteralExpression::Suffix::kU); return GenerateLiteralIfNeeded(override, &l); }, [&](const sem::I32*) { - ast::IntLiteralExpression l(ProgramID{}, Source{}, 0, + ast::IntLiteralExpression l(ProgramID{}, ast::NodeID{}, Source{}, 0, ast::IntLiteralExpression::Suffix::kI); return GenerateLiteralIfNeeded(override, &l); }, [&](const sem::Bool*) { - ast::BoolLiteralExpression l(ProgramID{}, Source{}, false); + ast::BoolLiteralExpression l(ProgramID{}, ast::NodeID{}, Source{}, false); return GenerateLiteralIfNeeded(override, &l); }, [&](Default) {