From b33dbfe9b17291267225d220b5f8eb53edf5a840 Mon Sep 17 00:00:00 2001 From: Jacob Szwejbka Date: Tue, 15 Jul 2025 09:16:59 -0700 Subject: [PATCH] Expose a method getter api in Module (#11929) Summary: It is sometimes useful for modules to be passed around in user space for user convenience, but for utilities those users interact with to operate on the methods directly. This is a bit of a layering violation but it allows us to define narrower scoped helpers so I think its worth the risk that the user finds a way to trash the internal method object. In general method should be fairly robust to being trashed anyway since itself is a blessed front end api from the team. Reviewed By: larryliu0820 Differential Revision: D77248983 --- extension/module/module.cpp | 10 ++++++++++ extension/module/module.h | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/extension/module/module.cpp b/extension/module/module.cpp index 3212077d2ee..9af975657c0 100644 --- a/extension/module/module.cpp +++ b/extension/module/module.cpp @@ -228,6 +228,16 @@ runtime::Error Module::load_method( return runtime::Error::Ok; } +ET_NODISCARD runtime::Result Module::method( + const std::string& method_name) { + ET_CHECK_OR_RETURN_ERROR( + methods_.count(method_name) > 0, + InvalidArgument, + "no such method in program: %s", + method_name.c_str()); + return methods_[method_name].method.get(); +} + runtime::Result Module::method_meta( const std::string& method_name) { ET_CHECK_OK_OR_RETURN_ERROR(load()); diff --git a/extension/module/module.h b/extension/module/module.h index b7ccaacc516..312115c9e4a 100644 --- a/extension/module/module.h +++ b/extension/module/module.h @@ -194,6 +194,18 @@ class Module { return load_method(method_name, nullptr, event_tracer); } + /** + * Get a method by it's name. Not recommended to use this method directly as + * an end user. It's exposed to allow for composability of module in apis that + * operate on method. + * + * @param[in] method_name The name of the method to get. + * + * @returns A Result object containing either a pointer to the requested + * method or an error to indicate failure. + */ + ET_NODISCARD runtime::Result method(const std::string& method_name); + /** * Load the 'forward' method from the program and set up memory management if * needed. The loaded method is cached to reuse the next time it's executed.