From 4537cd160286e5f0c249e141fe1ce1791c682a66 Mon Sep 17 00:00:00 2001 From: Jacob Szwejbka Date: Mon, 19 May 2025 10:19:55 -0700 Subject: [PATCH] support function + method variants Summary: Previously think we didnt need this so just threw an exception. Now we are adding index_put_ and other inplace ops besides copy_ (which is only function variant) so adding it. Differential Revision: D75006941 --- codegen/gen.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/codegen/gen.py b/codegen/gen.py index 7541a6e9705..43dc296a317 100644 --- a/codegen/gen.py +++ b/codegen/gen.py @@ -134,15 +134,14 @@ def __call__(self, f: NativeFunction) -> str | None: if not self.selector.is_root_operator(f"{f.namespace}::{f.func.name}"): return None - if Variant.function not in f.variants and Variant.method in f.variants: - is_method_variant = True - - # only valid remaining case is only function is in f.variants - elif not (Variant.function in f.variants and Variant.method not in f.variants): + if Variant.function not in f.variants and Variant.method not in f.variants: raise Exception( # noqa: TRY002 - f"Can't handle native function {f.func} with the following variant specification {f.variants}." + f"Expected one of function or method to be in variants for {f.func.name}" ) + if Variant.function not in f.variants and Variant.method in f.variants: + is_method_variant = True + sig: CppSignature | ExecutorchCppSignature = ( CppSignatureGroup.from_native_function( f, method=False, fallback_binding=f.manual_cpp_binding