[Runtime][CoreML] Fix FFI casts in CoreML runtime#19762
Conversation
The CoreML runtime still used legacy packed argument conversions, including direct AnyView-to-string conversion, type_code checks, and old tensor handle constants. After the FFI update, enabling USE_COREML failed to compile and the runtime create function was not registered. Update the runtime to use current PackedArgs cast helpers for strings, indices, and DLTensor arguments, and use the Objective-C NSArray type for CoreML metadata inputs. This restores the CoreML runtime registration when USE_COREML is enabled.
There was a problem hiding this comment.
Code Review
This pull request refactors the CoreML runtime implementation to utilize the new TVM FFI casting mechanism (args[i].cast<T>()) and simplifies the input/output tensor copying logic. The review feedback highlights several critical safety improvements, specifically recommending that you validate the argument count (args.size()) and the parsed JSON metadata to prevent potential unsigned underflow, out-of-bounds access, or null-pointer crashes.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
The CoreML runtime still used legacy packed argument conversions, including direct AnyView-to-string conversion, type_code checks, and old tensor handle constants. After the FFI update, enabling USE_COREML failed to compile and the runtime create function was not registered.
This pr updates the runtime to use current PackedArgs cast helpers for strings, indices, and DLTensor arguments, and use the Objective-C NSArray type for CoreML metadata inputs. This restores the CoreML runtime registration when USE_COREML is enabled.