← Back to Pull requests

jextract: deduplicate protocol requirements before code generation #916

Closed
Hokila closed this pull request without merging on Oct 15, 2026 02:41 UTC
View on GitHub
Hokila Hokila commented on Sep 15, 2026 08:17 UTC
Author

Summary

  • Deduplicate protocol requirements before code generation, so default implementations are not treated as separate callable requirements.

  • Compare protocol requirements using a normalized callable signature that ignores implementation-only differences such as local parameter names, default arguments, and narrower throwing effects.

  • Apply the deduplicated requirements consistently to Swift JNI thunks, Java bindings, and Java callback wrappers.

  • Preserve distinct Swift overloads by keeping argument labels and API kind as part of requirement identity.

  • Add regression tests covering protocol default implementations, differing parameter names, overloads, and non-throwing default implementations satisfying throwing requirements.
  • Fixes #891

    Testing

  • swift test --filter JNIProtocolTests

  • swift test --filter JExtractSwiftTests

  • xcrun swift-format lint --configuration .swift-format on changed Swift files
  • Diff: 272 lines (+262 / -10) across 6 files Reviewer: ktoso Review duration: 42864m
    All Vouch review confidence checks passed
    Residual risk 0.07 = Change Risk (0.44) × (1 − Review Confidence (0.84)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.44 · 272 lines diff across 6 files
    0.44
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.73 · 5 substantive comment(s)
    0.73
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    84%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.336
    Real PR Conversation Timeline
    9 items
    Hokila Hokila commented on Oct 01, 2026 03:45 UTC
    Author

    @ktoso Gentle ping on this one when you have a chance. The CI checks are green, and this addresses #891. Please let me know if you'd like any changes. Thanks!

    ktoso ktoso commented on Oct 02, 2026 00:33 UTC
    Contributor

    This seems to be fixing the symptom and not the problem itself? We should insttead fix how requirements are collected maybe?

    ktoso ktoso commented on code on Oct 02, 2026 00:34 UTC
    Code Review
    Tests/JExtractSwiftTests/JNI/JNIProtocolTests.swift:1
    @@ -82,6 +82,18 @@ struct JNIProtocolTests {
           public func makeChild() -> any ChildProtocol
         """
     
    +  let protocolDefaultImplementationSource = """
    +      public protocol Test {
    +        public func action()

    this isn't valid swift tbh, can't have the public here

    ktoso ktoso commented on code on Oct 02, 2026 00:35 UTC
    Code Review
    Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift:1
    @@ -389,6 +389,7 @@ extension JNISwift2JavaGenerator {
       /// function (including requirements inherited from refined protocols).
       private func printExistentialBoxDispatchThunks(_ printer: inout SwiftPrinter, _ type: ExtractedNominalType) {
         let boxParentName = SwiftQualifiedTypeName(type.swiftNominal.javaExistentialBoxName)
    +    var emittedCDeclSymbols: Set<String> = []

    This seems a bit hacky, like fixing the symptom rathe rthan maybe identify them differently to begin with?

    Hokila Hokila commented on code on Oct 02, 2026 07:14 UTC
    Code Review
    Tests/JExtractSwiftTests/JNI/JNIProtocolTests.swift:1
    @@ -82,6 +82,18 @@ struct JNIProtocolTests {
           public func makeChild() -> any ChildProtocol
         """
     
    +  let protocolDefaultImplementationSource = """
    +      public protocol Test {
    +        public func action()

    fixed, sorry for this bug

    Hokila Hokila commented on code on Oct 02, 2026 07:15 UTC
    Code Review
    Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift:1
    @@ -389,6 +389,7 @@ extension JNISwift2JavaGenerator {
       /// function (including requirements inherited from refined protocols).
       private func printExistentialBoxDispatchThunks(_ printer: inout SwiftPrinter, _ type: ExtractedNominalType) {
         let boxParentName = SwiftQualifiedTypeName(type.swiftNominal.javaExistentialBoxName)
    +    var emittedCDeclSymbols: Set<String> = []

    Moved the deduplication upstream to uniqueProtocolRequirements, so both Swift thunks and Java bindings use the deduplicated protocol requirements.

    I also added signature normalization and regression tests to cover cases like different parameter names, overloads, and a non-throwing default implementation satisfying a throwing requirement.

    Hokila Hokila commented on Oct 02, 2026 07:38 UTC
    Author

    Update PR title and description for current implementation.

    Hokila Hokila commented on Oct 15, 2026 02:41 UTC
    Author

    I think this PR is too big, close this one and rewrite in #934

    Reviewers
    Assignees
    Hokila Hokila
    Labels
    risk: low confidence: 84.2% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 43.9% (MEDIUM) · Higher = larger blast radius
    43.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 84.2% · Lower = rushed or shallow review
    84.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 7.0% · Safe to merge
    7.0%