Skip to content

Commit 7272659

Browse files
dplassgitcopybara-github
authored andcommitted
Improve const-ness of module in run routines, and some of its methods.
PiperOrigin-RevId: 756032997
1 parent 2a18242 commit 7272659

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

xls/dslx/frontend/module.cc

+9-6
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ std::vector<const AstNode*> Module::FindContained(const Span& target) const {
130130
return found;
131131
}
132132

133-
std::optional<Function*> Module::GetFunction(std::string_view target_name) {
134-
for (ModuleMember& member : top_) {
133+
std::optional<Function*> Module::GetFunction(
134+
std::string_view target_name) const {
135+
for (const ModuleMember& member : top_) {
135136
if (std::holds_alternative<Function*>(member)) {
136137
Function* f = std::get<Function*>(member);
137138
if (f->identifier() == target_name) {
@@ -142,8 +143,9 @@ std::optional<Function*> Module::GetFunction(std::string_view target_name) {
142143
return std::nullopt;
143144
}
144145

145-
absl::StatusOr<TestFunction*> Module::GetTest(std::string_view target_name) {
146-
for (ModuleMember& member : top_) {
146+
absl::StatusOr<TestFunction*> Module::GetTest(
147+
std::string_view target_name) const {
148+
for (const ModuleMember& member : top_) {
147149
if (std::holds_alternative<TestFunction*>(member)) {
148150
TestFunction* t = std::get<TestFunction*>(member);
149151
if (t->identifier() == target_name) {
@@ -155,8 +157,9 @@ absl::StatusOr<TestFunction*> Module::GetTest(std::string_view target_name) {
155157
"No test in module %s with name \"%s\"", name_, target_name));
156158
}
157159

158-
absl::StatusOr<TestProc*> Module::GetTestProc(std::string_view target_name) {
159-
for (ModuleMember& member : top_) {
160+
absl::StatusOr<TestProc*> Module::GetTestProc(
161+
std::string_view target_name) const {
162+
for (const ModuleMember& member : top_) {
160163
if (std::holds_alternative<TestProc*>(member)) {
161164
auto* t = std::get<TestProc*>(member);
162165
if (t->proc()->identifier() == target_name) {

xls/dslx/frontend/module.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ class Module : public AstNode {
179179
T::GetDebugTypeName(), name_, target_name));
180180
}
181181

182-
std::optional<Function*> GetFunction(std::string_view target_name);
182+
std::optional<Function*> GetFunction(std::string_view target_name) const;
183183

184184
// Gets a test construct in this module with the given "target_name", or
185185
// returns a NotFoundError.
186-
absl::StatusOr<TestFunction*> GetTest(std::string_view target_name);
187-
absl::StatusOr<TestProc*> GetTestProc(std::string_view target_name);
186+
absl::StatusOr<TestFunction*> GetTest(std::string_view target_name) const;
187+
absl::StatusOr<TestProc*> GetTestProc(std::string_view target_name) const;
188188

189189
absl::Span<ModuleMember const> top() const { return top_; }
190190
absl::Span<ModuleMember> top() { return absl::MakeSpan(top_); }

xls/dslx/run_routines/run_routines.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void HandleError(TestResultData& result, const absl::Status& status,
164164
};
165165

166166
absl::Status RunDslxTestFunction(ImportData* import_data, TypeInfo* type_info,
167-
Module* module, TestFunction* tf,
167+
const Module* module, TestFunction* tf,
168168
const BytecodeInterpreterOptions& options) {
169169
auto cache = std::make_unique<BytecodeCache>();
170170
import_data->SetBytecodeCache(std::move(cache));
@@ -181,7 +181,7 @@ absl::Status RunDslxTestFunction(ImportData* import_data, TypeInfo* type_info,
181181
}
182182

183183
absl::Status RunDslxTestProc(ImportData* import_data, TypeInfo* type_info,
184-
Module* module, TestProc* tp,
184+
const Module* module, TestProc* tp,
185185
const BytecodeInterpreterOptions& options) {
186186
auto cache = std::make_unique<BytecodeCache>();
187187
import_data->SetBytecodeCache(std::move(cache));

xls/dslx/run_routines/run_routines.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class DslxInterpreterTestRunner final : public AbstractTestRunner {
253253
class DslxInterpreterParsedTestRunner : public AbstractParsedTestRunner {
254254
public:
255255
DslxInterpreterParsedTestRunner(ImportData* import_data, TypeInfo* type_info,
256-
Module* entry_module)
256+
const Module* entry_module)
257257
: import_data_(import_data),
258258
type_info_(type_info),
259259
entry_module_(entry_module) {}
@@ -268,7 +268,7 @@ class DslxInterpreterParsedTestRunner : public AbstractParsedTestRunner {
268268
private:
269269
ImportData* import_data_;
270270
TypeInfo* type_info_;
271-
Module* entry_module_;
271+
const Module* entry_module_;
272272
};
273273

274274
struct ParseAndProveResult {

0 commit comments

Comments
 (0)