[tint][sem] Replace more uses of std::vector with tint::Vector
Bug: tint:2129
Change-Id: I0cd4e32be5855bd2371d357ba2e8521253898b8d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/171662
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
diff --git a/src/tint/lang/wgsl/inspector/inspector.cc b/src/tint/lang/wgsl/inspector/inspector.cc
index bc78781..6c5d935 100644
--- a/src/tint/lang/wgsl/inspector/inspector.cc
+++ b/src/tint/lang/wgsl/inspector/inspector.cc
@@ -814,14 +814,14 @@
}
auto* call_func = call->Stmt()->Function();
- std::vector<const sem::Function*> entry_points;
+ Vector<const sem::Function*, 4> entry_points;
if (call_func->Declaration()->IsEntryPoint()) {
entry_points = {call_func};
} else {
entry_points = call_func->AncestorEntryPoints();
}
- if (entry_points.empty()) {
+ if (entry_points.IsEmpty()) {
continue;
}
@@ -974,7 +974,7 @@
globals[i] = global;
} else if (auto* param = root_ident->As<sem::Parameter>()) {
auto* func = tint::As<sem::Function>(param->Owner());
- if (func->CallSites().empty()) {
+ if (func->CallSites().IsEmpty()) {
// One or more of the expressions is a parameter, but this function
// is not called. Ignore.
return;
diff --git a/src/tint/lang/wgsl/resolver/resolver_test.cc b/src/tint/lang/wgsl/resolver/resolver_test.cc
index f8bcdb4..365b595 100644
--- a/src/tint/lang/wgsl/resolver/resolver_test.cc
+++ b/src/tint/lang/wgsl/resolver/resolver_test.cc
@@ -1069,13 +1069,13 @@
auto* foo_sem = Sem().Get(foo);
ASSERT_NE(foo_sem, nullptr);
- ASSERT_EQ(foo_sem->CallSites().size(), 2u);
+ ASSERT_EQ(foo_sem->CallSites().Length(), 2u);
EXPECT_EQ(foo_sem->CallSites()[0]->Declaration(), call_1);
EXPECT_EQ(foo_sem->CallSites()[1]->Declaration(), call_2);
auto* bar_sem = Sem().Get(bar);
ASSERT_NE(bar_sem, nullptr);
- EXPECT_EQ(bar_sem->CallSites().size(), 0u);
+ EXPECT_EQ(bar_sem->CallSites().Length(), 0u);
}
TEST_F(ResolverTest, Function_WorkgroupSize_NotSet) {
@@ -2009,21 +2009,21 @@
EXPECT_EQ(func_c_sem->Parameters().Length(), 0u);
const auto& b_eps = func_b_sem->AncestorEntryPoints();
- ASSERT_EQ(2u, b_eps.size());
+ ASSERT_EQ(2u, b_eps.Length());
EXPECT_EQ(Symbols().Register("ep_1"), b_eps[0]->Declaration()->name->symbol);
EXPECT_EQ(Symbols().Register("ep_2"), b_eps[1]->Declaration()->name->symbol);
const auto& a_eps = func_a_sem->AncestorEntryPoints();
- ASSERT_EQ(1u, a_eps.size());
+ ASSERT_EQ(1u, a_eps.Length());
EXPECT_EQ(Symbols().Register("ep_1"), a_eps[0]->Declaration()->name->symbol);
const auto& c_eps = func_c_sem->AncestorEntryPoints();
- ASSERT_EQ(2u, c_eps.size());
+ ASSERT_EQ(2u, c_eps.Length());
EXPECT_EQ(Symbols().Register("ep_1"), c_eps[0]->Declaration()->name->symbol);
EXPECT_EQ(Symbols().Register("ep_2"), c_eps[1]->Declaration()->name->symbol);
- EXPECT_TRUE(ep_1_sem->AncestorEntryPoints().empty());
- EXPECT_TRUE(ep_2_sem->AncestorEntryPoints().empty());
+ EXPECT_TRUE(ep_1_sem->AncestorEntryPoints().IsEmpty());
+ EXPECT_TRUE(ep_2_sem->AncestorEntryPoints().IsEmpty());
}
// Check for linear-time traversal of functions reachable from entry points.
diff --git a/src/tint/lang/wgsl/sem/function.h b/src/tint/lang/wgsl/sem/function.h
index 797dbef..88b3c3d 100644
--- a/src/tint/lang/wgsl/sem/function.h
+++ b/src/tint/lang/wgsl/sem/function.h
@@ -155,12 +155,12 @@
/// @returns the list of direct calls to functions / builtins made by this
/// function
- std::vector<const Call*> DirectCalls() const { return direct_calls_; }
+ const Vector<const Call*, 1>& DirectCalls() const { return direct_calls_; }
/// Adds a record of the direct function / builtin calls made by this
/// function
/// @param call the call
- void AddDirectCall(const Call* call) { direct_calls_.emplace_back(call); }
+ void AddDirectCall(const Call* call) { direct_calls_.Push(call); }
/// @param target the target of a call
/// @returns the Call to the given CallTarget, or nullptr the target was not
@@ -175,21 +175,19 @@
}
/// @returns the list of callsites to this function
- std::vector<const Call*> CallSites() const { return callsites_; }
+ const Vector<const Call*, 1>& CallSites() const { return callsites_; }
/// Adds a record of a callsite to this function
/// @param call the callsite
- void AddCallSite(const Call* call) { callsites_.emplace_back(call); }
+ void AddCallSite(const Call* call) { callsites_.Push(call); }
/// @returns the ancestor entry points
- const std::vector<const Function*>& AncestorEntryPoints() const {
- return ancestor_entry_points_;
- }
+ const Vector<const Function*, 1>& AncestorEntryPoints() const { return ancestor_entry_points_; }
/// Adds a record that the given entry point transitively calls this function
/// @param entry_point the entry point that transtively calls this function
void AddAncestorEntryPoint(const sem::Function* entry_point) {
- ancestor_entry_points_.emplace_back(entry_point);
+ ancestor_entry_points_.Push(entry_point);
}
/// Retrieves any referenced location variables
@@ -300,9 +298,9 @@
UniqueVector<const Function*, 8> transitively_called_functions_;
UniqueVector<const BuiltinFn*, 4> directly_called_builtins_;
UniqueVector<VariablePair, 8> texture_sampler_pairs_;
- std::vector<const Call*> direct_calls_;
- std::vector<const Call*> callsites_;
- std::vector<const Function*> ancestor_entry_points_;
+ Vector<const Call*, 1> direct_calls_;
+ Vector<const Call*, 1> callsites_;
+ Vector<const Function*, 1> ancestor_entry_points_;
const Statement* discard_stmt_ = nullptr;
sem::Behaviors behaviors_{sem::Behavior::kNext};
wgsl::DiagnosticRuleSeverities diagnostic_severities_;
diff --git a/src/tint/lang/wgsl/sem/info.h b/src/tint/lang/wgsl/sem/info.h
index f63fa1c..111e544 100644
--- a/src/tint/lang/wgsl/sem/info.h
+++ b/src/tint/lang/wgsl/sem/info.h
@@ -80,7 +80,7 @@
/// @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()));
+ nodes_.Resize(std::max(highest_node_id.value + 1, nodes_.Length()));
}
/// Get looks up the semantic information for the AST node `ast_node`.
@@ -93,7 +93,7 @@
static_assert(std::is_same_v<SEM, InferFromAST> ||
!tint::traits::IsTypeOrDerived<SemanticNodeTypeFor<AST>, SEM>,
"explicit template argument is unnecessary");
- if (ast_node && ast_node->node_id.value < nodes_.size()) {
+ if (ast_node && ast_node->node_id.value < nodes_.Length()) {
return As<RESULT>(nodes_[ast_node->node_id.value]);
}
return nullptr;
@@ -157,7 +157,7 @@
private:
// AST node index to semantic node
- std::vector<const CastableBase*> nodes_;
+ tint::Vector<const CastableBase*, 0> nodes_;
// The semantic module
sem::Module* module_ = nullptr;
};