Skip to content

chore: rust code cleanup for FFI - #1127

Open
ayushjain17 wants to merge 1 commit into
mainfrom
ffi/changes
Open

chore: rust code cleanup for FFI#1127
ayushjain17 wants to merge 1 commit into
mainfrom
ffi/changes

Conversation

@ayushjain17

@ayushjain17 ayushjain17 commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Change log

Rust side changes in superposition_core needed for FFI languages

Summary by CodeRabbit

  • New Features

    • Added filtered configuration parsing for JSON and TOML using dimensions and prefix inclusion or exclusion.
    • Added provider cache operations for filtering configurations and experiments and retrieving applicable variants.
    • Added support for partially applying experiment filters.
  • Breaking Changes

    • Removed the separate JSON and TOML parsing APIs from the Kotlin and Python bindings. Use the unified filtered configuration parsing API instead.

Copilot AI lite review requested due to automatic review settings August 12, 2026 18:50
@ayushjain17
ayushjain17 requested a review from a team as a code owner August 12, 2026 18:50
@semanticdiff-com

semanticdiff-com Bot commented Aug 12, 2026

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3aeb675c-2bea-4a45-bfd4-d7874fda24df

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

The core crate now provides filtered JSON/TOML configuration parsing and provider-cache FFI operations. Separate JSON/TOML parser exports were removed from Rust, Kotlin, and Python bindings.

Changes

Filtered configuration and provider-cache FFI

Layer / File(s) Summary
Shared filtered configuration parsing
crates/superposition_core/src/format.rs, crates/superposition_core/src/ffi.rs, crates/superposition_core/src/lib.rs
The core parser selects JSON or TOML input and applies dimension and prefix filters.
Shared provider-cache operations
crates/superposition_core/src/experiment.rs, crates/superposition_core/src/ffi.rs
ProviderCache delegates filtering and variant lookup to shared inner methods. ExperimentConfig now derives serialization traits.
Legacy FFI entrypoints and exports
crates/superposition_core/src/ffi_legacy.rs, crates/superposition_core/src/lib.rs
Legacy FFI functions add cache filtering, applicable-variant lookup, and unified filtered file parsing with nullable filter inputs and JSON results.
Generated binding API removal
clients/java/bindings/src/main/kotlin/uniffi/superposition_client/superposition_client.kt, clients/python/bindings/superposition_bindings/superposition_client.py
Kotlin and Python bindings remove JSON/TOML parser declarations, checksum checks, implementations, and public exports.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant LegacyFFI
  participant ProviderCache
  participant ConfigParser
  Caller->>LegacyFFI: submit filtered config or cache request
  LegacyFFI->>ConfigParser: parse file with filters
  LegacyFFI->>ProviderCache: filter cache or resolve variants
  ConfigParser-->>LegacyFFI: return filtered Config
  ProviderCache-->>LegacyFFI: return filtered result
  LegacyFFI-->>Caller: return JSON or error
Loading

Possibly related PRs

Suggested reviewers: sauraww, datron

Poem

I hop through filters, neat and bright,
JSON and TOML share one flight.
Cache variants line up in rows,
Old parser paths now close.
Bindings shed their unused load—
A tidy burrow, code-approved!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the Rust FFI cleanup and related binding changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ffi/changes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

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 refactors superposition_core’s Rust-side FFI surface to reduce duplicated logic across UniFFI and the legacy C ABI, while adding legacy C ABI entry points to filter cached configs/experiments and compute applicable variants.

Changes:

  • Centralized parse+filter behavior into format::parse_config_file_with_filters and updated UniFFI/C-ABI adapters to call it.
  • Added shared non-FFI ProviderCache::*_inner methods and exposed new legacy C ABI functions for cache filtering and variant lookup.
  • Removed legacy UniFFI ffi_parse_json_config / ffi_parse_toml_config and updated generated Python/Java bindings accordingly.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/superposition_core/src/lib.rs Updates public re-exports to reflect the new shared parse/filter API and legacy C-ABI exports.
crates/superposition_core/src/format.rs Introduces shared parse_config_file_with_filters used by both UniFFI and C-ABI layers.
crates/superposition_core/src/ffi.rs Removes duplicated parsing logic and factors cache operations into shared *_inner methods.
crates/superposition_core/src/ffi_legacy.rs Adds new C-ABI functions for cache filtering/variants and replaces per-format parse entry points with a unified parse+filter function.
crates/superposition_core/src/experiment.rs Adds Serialize/Deserialize derives needed for JSON serialization in C-ABI returns.
clients/python/bindings/superposition_bindings/superposition_client.py Removes bindings/checksums for deleted UniFFI parse functions.
clients/java/bindings/src/main/kotlin/uniffi/superposition_client/superposition_client.kt Removes bindings/checksums for deleted UniFFI parse functions.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +978 to 990
let file_content = match c_str_to_string(file_content) {
Ok(s) => s,
Err(e) => {
copy_string(ebuf, format!("Invalid UTF-8 in toml_content: {}", e));
copy_string(ebuf, format!("Invalid UTF-8 in file_content: {}", e));
return ptr::null_mut();
}
};

// Parse TOML
let parsed = match TomlFormat::parse_config(&toml_str) {
Ok(p) => p,
let format = match c_str_to_string(format) {
Ok(s) => s,
Err(e) => {
copy_string(ebuf, e.to_string());
copy_string(ebuf, format!("Invalid UTF-8 in format: {}", e));
return ptr::null_mut();
}

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/superposition_core/src/lib.rs`:
- Around line 24-32: Remove or migrate all references to core_parse_toml_config
and core_parse_json_config in the Haskell FFI, JavaScript native resolver,
related Python tests, and documentation before deleting their exported symbols
from the core bindings. Use the supported parse_config_file_with_filters and
format-based API where migration is appropriate, and keep tests and docs aligned
with the resulting public entrypoints.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bfb007b0-e103-4229-bba9-3c961f167667

📥 Commits

Reviewing files that changed from the base of the PR and between ccda04b and 9b15fe8.

📒 Files selected for processing (7)
  • clients/java/bindings/src/main/kotlin/uniffi/superposition_client/superposition_client.kt
  • clients/python/bindings/superposition_bindings/superposition_client.py
  • crates/superposition_core/src/experiment.rs
  • crates/superposition_core/src/ffi.rs
  • crates/superposition_core/src/ffi_legacy.rs
  • crates/superposition_core/src/format.rs
  • crates/superposition_core/src/lib.rs
💤 Files with no reviewable changes (2)
  • clients/python/bindings/superposition_bindings/superposition_client.py
  • clients/java/bindings/src/main/kotlin/uniffi/superposition_client/superposition_client.kt

Comment thread crates/superposition_core/src/lib.rs Outdated
Comment on lines +24 to +32
core_parse_config_file_with_filters, core_provider_cache_filter_config,
core_provider_cache_filter_experiment, core_provider_cache_get_applicable_variants,
};

// Re-export format module and types
pub use format::{json::JsonFormat, toml::TomlFormat, ConfigFormat, FormatError};
pub use format::{
json::JsonFormat, parse_config_file_with_filters, toml::TomlFormat, ConfigFormat,
FormatError,
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Find stale references to the removed JSON/TOML parser entrypoints.
rg -n --iglob '!**/target/**' \
  'core_parse_toml_config|core_parse_json_config|ffi_parse_toml_config|ffi_parse_json_config' \
  . | head -100

Repository: juspay/superposition

Length of output: 3451


Remove stale parser references from client bindings and tests.

The Haskell FFI and JavaScript native resolver still reference core_parse_toml_config and core_parse_json_config. Remove or migrate these references before removing the exported symbols. Update the related Python tests and documentation if these entrypoints are no longer supported.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/superposition_core/src/lib.rs` around lines 24 - 32, Remove or migrate
all references to core_parse_toml_config and core_parse_json_config in the
Haskell FFI, JavaScript native resolver, related Python tests, and documentation
before deleting their exported symbols from the core bindings. Use the supported
parse_config_file_with_filters and format-based API where migration is
appropriate, and keep tests and docs aligned with the resulting public
entrypoints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants