Skip to content

Resolve trait impl's in submodules and avoid Java keyword collisions#56

Merged
skeet70 merged 5 commits intoIronCoreLabs:mainfrom
criccomini:fix-histo-bug
Apr 6, 2026
Merged

Resolve trait impl's in submodules and avoid Java keyword collisions#56
skeet70 merged 5 commits intoIronCoreLabs:mainfrom
criccomini:fix-histo-bug

Conversation

@criccomini
Copy link
Copy Markdown
Contributor

This is two PRs combined in one. I got on a roll debugging. They're small enough that I feel it's OK. If you prefer two distinct PRs, LMK. The two issues uncovered ar:

  1. I was seeing some errors with a struct+fn we had called Histogram::record:
pub trait Histogram: Send + Sync {
    /// Records `value` in the histogram.
    fn record(&self, value: f64);
}

This was failing to compile.

  1. Callbacks inside submodules were not getting properly resolved.

You can review each commit in this PR individually. See the detailed commit descriptions for each if you want more info.

Java trait implementation rendering was assuming that a trait type's full module_path could always be resolved directly via ComponentInterface::find_component_interface. That is not true for local callback interfaces defined in a submodule of the current crate, such as slatedb_uniffi::metrics::MetricsRecorder.

In that case the metadata still belongs to the current component interface, but trait_interface_name looked up the full module path and failed with: "no interface with module_path: slatedb_uniffi::metrics". This broke Java code generation for local object trait impls and forced downstream crates to keep callback traits at the crate root as a workaround.

Fix the lookup by resolving the component interface from the trait type's crate name first. If the crate name matches the current component interface, use the current interface directly. Otherwise keep the existing external-interface lookup behavior, falling back from the full module path to the crate name.

Add a regression test covering a local object that implements a callback interface declared in test::metrics. The test verifies both the filter result and the generated Java class declaration so the original failure mode is exercised directly.
Generate callback helper implementation classes with a class-style name derived from the trait method plus a Callback suffix instead of reusing the method identifier directly.

This prevents invalid nested types such as "record" from being emitted when a callback method name collides with a Java keyword, while keeping the user-facing callback method name unchanged. Add a regression test for a "record" callback interface method.
@criccomini criccomini requested a review from a team as a code owner April 4, 2026 01:55
@criccomini criccomini requested review from giarc3 and removed request for a team April 4, 2026 01:55
@criccomini criccomini changed the title Resolve trait imp's in submodules and avoid Java keyword collisions Resolve trait impl's in submodules and avoid Java keyword collisions Apr 4, 2026
@criccomini
Copy link
Copy Markdown
Contributor Author

cc @skeet70

@skeet70
Copy link
Copy Markdown
Member

skeet70 commented Apr 6, 2026

Thanks! I had run into the submodule issue myself and fixed it the same way Kotlin had, though I haven't released it yet. I'll look to see if your regression test covers anything mine doesn't. I'll pull the Java keyword fix in too.

In my upstream library I noticed a regression in a very specific case (all other tests/benches on both projects show at least moderate gains), so I'm digging into that. I'll release these other bugfixes before that though since it's taking a while to track down.

@criccomini
Copy link
Copy Markdown
Contributor Author

Awesome, thanks! Happy to take your fixes :) Feel free to close this PR if/when needed.

Copy link
Copy Markdown
Member

@skeet70 skeet70 left a comment

Choose a reason for hiding this comment

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

Thanks! This turned out to be better than the fix I had!

@skeet70 skeet70 merged commit 4140852 into IronCoreLabs:main Apr 6, 2026
11 of 12 checks passed
@criccomini criccomini deleted the fix-histo-bug branch April 6, 2026 18:22
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.

3 participants