Skip to content

Commit 21d7eec

Browse files
committed
refactor(where): consolidate reflection cache into partial CachedMethods
np.where's IL kernel had ~35 MethodInfo fields scattered across the file using `Array.Find(...)!` null-forgiveness, which throws NullReferenceException at first use if a framework method ever gets renamed/removed. The existing CachedMethods nested class in ILKernelGenerator.cs follows a fail-fast `?? throw new MissingMethodException(type, name)` pattern, keyed per MethodInfo, and is the project convention for every other kernel partial. Changes: - Make `CachedMethods` a `partial` nested class so Where-specific reflection can live alongside the kernel file it serves. (ILKernelGenerator.cs: 1 line.) - Delete the 35 `_v128*/_v256*/_avx2*/_sse41*` private fields from ILKernelGenerator.Where.cs and move them into a new "Where Kernel Methods" region inside a partial `CachedMethods` declaration at the bottom of that file. Renamed to PascalCase (e.g. _v256LoadByte -> V256LoadByte) to match the existing CachedMethods naming convention. - Introduce three small helpers inside CachedMethods: - FindGenericMethod(Type, string name, int? paramCount) - wraps the `Array.Find(GetMethods(), m => m.IsGenericMethodDefinition && ...)` pattern with a MissingMethodException fail-fast throw. Handles the overload count disambiguation for Load/Store. - FindMethodExact(Type, string name, Type[] argTypes) - wraps GetMethod with a fail-fast throw. Used for Avx2/Sse41 specific overloads. - GetZeroGetter(Type vectorOfT) - wraps Property("Zero").GetMethod with a fail-fast throw. Used for the 8 Vector*<T>.Zero getters. - Update all 41 call sites in EmitInlineMaskCreationV256/V128 and EmitWhereV256/V128BodyWithOffset to use CachedMethods.Xxx. Behaviour unchanged; 180 np.where + np.asanyarray tests still pass on net8.0 + net10.0. The single real benefit is earlier and clearer failure if any of the ~35 framework API names change in a future .NET release.
1 parent 3811960 commit 21d7eec

2 files changed

Lines changed: 136 additions & 135 deletions

File tree

0 commit comments

Comments
 (0)