Skip to content

Rust Implementation of RSSortingVector - MOD-9985#6311

Merged
DarthB merged 28 commits intomasterfrom
rp-rssortingvector
Jul 10, 2025
Merged

Rust Implementation of RSSortingVector - MOD-9985#6311
DarthB merged 28 commits intomasterfrom
rp-rssortingvector

Conversation

@DarthB
Copy link
Copy Markdown
Contributor

@DarthB DarthB commented Jun 13, 2025

Describe the changes in the pull request

The PR introduces two changes:
Adds RSSortingVector Rust implementation + Unit Tests

More detailed changes

  • Implements the RSSortingVector as a Boxed Slice in Rust
  • Extracts C-Code normalizeStr which implements utf case folding based on nulibI
  • Add an RSValueTrait that is implemented by mocks and the final FFI implementation
  • Adds unit tests with mock type of RSValue

Referenced PRs

Previous PRs:

Upcoming PRs:

Archived PRs:

@DarthB DarthB force-pushed the rp-rssortingvector branch 2 times, most recently from 75fb169 to 50e444c Compare June 13, 2025 14:28
@DarthB DarthB force-pushed the rp-rssortingvector branch 2 times, most recently from b15859c to a9b46e6 Compare June 13, 2025 14:59
@DarthB DarthB changed the title Rp rssortingvector MOD-9985 - Rust Implementation of RPSortingVector Jun 13, 2025
@DarthB DarthB force-pushed the rp-rssortingvector branch 2 times, most recently from 5d7c5d6 to 1e7e21d Compare June 13, 2025 15:48
@DarthB DarthB changed the title MOD-9985 - Rust Implementation of RPSortingVector MOD-9985 - Rust Implementation of RSSortingVector Jun 16, 2025
@DarthB DarthB force-pushed the rp-rssortingvector branch 11 times, most recently from 08f5375 to 5f7722b Compare June 18, 2025 09:33
@DarthB DarthB force-pushed the rp-rssortingvector branch 2 times, most recently from fbfddf3 to 784887d Compare June 25, 2025 14:28
@DarthB DarthB force-pushed the rp-rssortingvector branch 4 times, most recently from 401002e to 12e1ec8 Compare June 30, 2025 10:43
@DarthB DarthB force-pushed the rp-rssortingvector branch from 4501bb2 to 8814717 Compare July 3, 2025 12:52
Comment on lines +182 to +184
unimplemented!(
"We cannot yet use `NormalizedString` here, as the RSValue string allocations still happen\
in the C layer and the workaround for linking C code for allocations is not ready."
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unimplemented!(
"We cannot yet use `NormalizedString` here, as the RSValue string allocations still happen\
in the C layer and the workaround for linking C code for allocations is not ready."
unimplemented!(
"We cannot yet allocate RSValues in Rust. See MOD-10347 for details."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +188 to +198
pub fn try_insert_string_for_tests<S: AsRef<str>>(
&mut self,
_idx: usize,
_str: S,
) -> Result<(), IndexOutOfBounds> {
self.in_bounds(_idx)?;
let casemapper = CaseMapper::new();
let normalized = casemapper.fold_string(_str.as_ref()).into_owned();
self.values[_idx] = T::create_string(normalized);
Ok(())
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid mixing test helpers with production code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to RSValue and its C-side string allocations, this is a temporary fix. Nonetheless, I eliminated this second method.

386aec0

@DarthB DarthB force-pushed the rp-rssortingvector branch from 8c2a92e to 460a463 Compare July 7, 2025 09:27
@DarthB DarthB force-pushed the rp-rssortingvector branch from 460a463 to 3f9e3d8 Compare July 8, 2025 06:46
@raz-mon raz-mon requested a review from Copilot July 8, 2025 11:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a Rust-based RSSortingVector implementation with string normalization support, defines an RSValueTrait abstraction for value handling, and integrates C header updates and unit tests.

  • Introduces RSSortingVector<T> in Rust with methods for inserting numbers, strings (with ICU4X case folding), references, and nulls
  • Defines RSValueTrait to abstract over RSValue creation and inspection for both mocks and FFI
  • Updates src/sortable.h with normalizeStr prototype, extends the FFI build, and adds comprehensive unit tests

Reviewed Changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/sortable.h Added documentation and prototype for normalizeStr
src/redisearch_rs/value/src/lib.rs Defined the RSValueTrait trait
src/redisearch_rs/value/Cargo.toml Configured the new value crate in the workspace
src/redisearch_rs/sorting_vector/src/lib.rs Implemented RSSortingVector and its APIs
src/redisearch_rs/sorting_vector/tests/sorting_vector.rs Added unit tests covering creation, insertion, memory sizing, and normalization
src/redisearch_rs/sorting_vector/Cargo.toml Configured the sorting_vector crate dependencies
src/redisearch_rs/ffi/build.rs Included sortable.h and value.h in the bindgen build
src/redisearch_rs/Cargo.toml Registered sorting_vector and value crates in the workspace
Comments suppressed due to low confidence (3)

src/redisearch_rs/sorting_vector/src/lib.rs:79

  • The doc reference Error::OutOfBounds does not match the actual error type IndexOutOfBounds. Update the link to [IndexOutOfBounds].
    /// Returns `Ok(())` if the index is in bounds, [`Error::OutOfBounds`] otherwise.

src/redisearch_rs/sorting_vector/src/lib.rs:115

  • [nitpick] Parameter name str shadows the built-in str type. Consider renaming it (e.g., input or value) for clarity.
        str: S,

src/redisearch_rs/sorting_vector/tests/sorting_vector.rs:187

  • [nitpick] Variable name str shadows the built-in str type. Consider renaming (e.g., input_str or original).
    let str = "Straße";

Copy link
Copy Markdown
Collaborator

@raz-mon raz-mon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM basically
A couple of questions:

  • I guess it would be good to have as full an API as possible at this point, such that we can test the most and add less additions later on when the RSValue is supported. That would basically require an extended mock for the RSValue - do you think that's worthwhile, or prefer to have bigger additions to the API and tests later on?
  • Some comments relate to the previous code. While that is comfortable for the review and the transition, we should at some point remove them. Probably the best time would be prior to merging, so that we don't forget it like that.

sz += T::mem_size();
}

// the original behavior would by-pass references in the middle of the chain
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will the comments about the previous implementations be removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
if T::is_ptr_type() {
// count the size of the struct if not null, like in C
sz += T::mem_size();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this double-counting for the second case above?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DarthB
Copy link
Copy Markdown
Contributor Author

DarthB commented Jul 9, 2025

  • I guess it would be good to have as full an API as possible at this point, such that we can test the most and add less additions later on when the RSValue is supported. That would basically require an extended mock for the RSValue - do you think that's worthwhile, or prefer to have bigger additions to the API and tests later on?

I checked the RSValue API and propose the following:

  1. add increment and decrement to the trait in this PR (we will need it soon for RLookupRow)
  2. Have a follow-up PR for the methods that are needed in RLookup

We plan to port the RSValue type in MOD-10347 and attempt to minimize the workload associated with that trait workaround.

  • Some comments relate to the previous code. While that is comfortable for the review and the transition, we should at some point remove them. Probably the best time would be prior to merging, so we don't forget it.

I would like to address this size calculation when we port RSValue - MOD-10347.

@DarthB DarthB removed the size:XL label Jul 9, 2025
Copy link
Copy Markdown
Collaborator

@raz-mon raz-mon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Note the rdbLoad function as well, that is not implemented here

@DarthB DarthB added this pull request to the merge queue Jul 10, 2025
Merged via the queue into master with commit 3bb7bee Jul 10, 2025
16 of 17 checks passed
@DarthB DarthB deleted the rp-rssortingvector branch July 10, 2025 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants