Skip to content

Add Module API to query for the number of methods #9441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions extension/module/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ runtime::Error Module::load(const runtime::Program::Verification verification) {
return runtime::Error::Ok;
}

runtime::Result<size_t> Module::num_methods() {
ET_CHECK_OK_OR_RETURN_ERROR(load());
return program_->num_methods();
}

runtime::Result<std::unordered_set<std::string>> Module::method_names() {
ET_CHECK_OK_OR_RETURN_ERROR(load());
const auto method_count = program_->num_methods();
Expand Down
8 changes: 8 additions & 0 deletions extension/module/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ class Module {
return program_;
}

/**
* Get the number of methods available in the loaded program.
*
* @returns A Result object containing either the number of methods available
* or an error to indicate failure.
*/
runtime::Result<size_t> num_methods();

/**
* Get a list of method names available in the loaded program.
* Loads the program and method if needed.
Expand Down
8 changes: 8 additions & 0 deletions extension/module/test/module_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ TEST_F(ModuleTest, TestMethodNames) {
EXPECT_EQ(method_names.get(), std::unordered_set<std::string>{"forward"});
}

TEST_F(ModuleTest, TestNumMethods) {
Module module(model_path_);

const auto num_methods = module.num_methods();
EXPECT_EQ(num_methods.error(), Error::Ok);
EXPECT_EQ(num_methods.get(), 1);
}

TEST_F(ModuleTest, TestNonExistentMethodNames) {
Module module("/path/to/nonexistent/file.pte");

Expand Down
Loading