Phased C Rust migration#1
Conversation
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
Co-authored-by: Diggory Rycroft <dddiggory@users.noreply.github.com>
|
Cursor Agent can help with this pull request. Just |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix prepared fixes for both issues found in the latest run.
- ✅ Fixed: Dead code: Default assignments immediately overwritten by Rust
- Removed the dead code assignments to Default implementations that were immediately overwritten by Rust implementations.
- ✅ Fixed: Unrelated kernel misused for ratio cap check
- Replaced the fragile misuse of vector_rust_hnsw_should_update_element_max_distance_kernel with a direct ratio > 1.0 comparison.
Or push these changes by commenting:
@cursor push 8537f92ebf
Preview (8537f92ebf)
diff --git a/src/halfutils.c b/src/halfutils.c
--- a/src/halfutils.c
+++ b/src/halfutils.c
@@ -307,11 +307,6 @@
* Could skip pointer when single function, but no difference in
* performance
*/
- HalfvecL2SquaredDistance = HalfvecL2SquaredDistanceDefault;
- HalfvecInnerProduct = HalfvecInnerProductDefault;
- HalfvecCosineSimilarity = HalfvecCosineSimilarityDefault;
- HalfvecL1Distance = HalfvecL1DistanceDefault;
-
HalfvecL2SquaredDistance = HalfvecL2SquaredDistanceRust;
HalfvecInnerProduct = HalfvecInnerProductRust;
HalfvecCosineSimilarity = HalfvecCosineSimilarityRust;
diff --git a/src/hnsw.c b/src/hnsw.c
--- a/src/hnsw.c
+++ b/src/hnsw.c
@@ -218,7 +218,7 @@
HnswShouldCapRatioAtOne(double ratio, bool useRust)
{
(void) useRust;
- return vector_rust_hnsw_should_update_element_max_distance_kernel(true, true, 1, ratio);
+ return ratio > 1.0;
}
FUNCTION_PREFIX PG_FUNCTION_INFO_V1(vector_hnsw_clamp_ratio);| HalfvecCosineSimilarity = HalfvecCosineSimilarityDefault; | ||
| HalfvecL1Distance = HalfvecL1DistanceDefault; | ||
|
|
||
| HalfvecL2SquaredDistance = HalfvecL2SquaredDistanceRust; |
There was a problem hiding this comment.
Dead code: Default assignments immediately overwritten by Rust
Low Severity
In HalfvecInit, the four function pointer assignments to *Default (lines 310–313) are immediately overwritten by the Rust wrapper assignments (lines 315–318). The Default assignments are now dead stores that serve no purpose — the Rust versions unconditionally replace them before the SIMD dispatch check.
| { | ||
| (void) useRust; | ||
| return vector_rust_hnsw_should_update_element_max_distance_kernel(true, true, 1, ratio); | ||
| } |
There was a problem hiding this comment.
Unrelated kernel misused for ratio cap check
Low Severity
HnswShouldCapRatioAtOne calls vector_rust_hnsw_should_update_element_max_distance_kernel(true, true, 1, ratio) to check if ratio > 1.0. This repurposes a completely unrelated kernel with carefully chosen constant arguments to produce the desired boolean result. The coupling is fragile — any change to the distance kernel's logic would silently break the ratio check.



This pull request contains changes generated by a Cursor Cloud Agent
Note
High Risk
High risk because it changes core distance/math routines and parts of HNSW planner logic to call into a new Rust static library via FFI, which can impact correctness, performance, and cross-platform builds.
Overview
Introduces a new Rust
staticlib(rust/) and wires it into the extension build/link process (Makefile +Makefile.win), making Rust a required build dependency and updating CI to install a stable toolchain.Moves a growing set of performance-critical kernels to Rust via
rust_ffi.h/ffi.rs, and switches C call sites (notablybitutils,halfvec/halfutils, and parts ofhnswcost/initialization) to usevector_rust_*implementations, adding SQL-callable parity wrapper functions likevector_rust_*for validation/debugging.Written by Cursor Bugbot for commit 53d127d. This will update automatically on new commits. Configure here.