← Back to Pull requests

Keep hashCode consistent with equals for Equatable bridged types #293

Closed
unknown closed this pull request without merging on Oct 11, 2026 18:48 UTC
View on GitHub
unknown unknown commented on Oct 07, 2026 10:32 UTC
Author

Summary

A bridged struct or class that is Equatable but not Hashable gets a value-based equals() (through Swift_isequal) and the default hashCode():

override fun hashCode(): Int = Swift_peer.hashCode()

Every read of a bridged value creates a new Kotlin peer around a new SwiftValueTypeBox, so two equal values almost always hash differently. That breaks the equals/hashCode contract: HashMap/HashSet lookups miss, distinct()/toSet() keep duplicates, and anything else that buckets by hash before calling equals behaves as if the values were different.

It is common in practice: in the Polymarket app, 160 generated Kotlin files have this combination (for example a plain public struct AssetPriceOutcomeTitle: Equatable, Sendable).

Fix

With no Hashable conformance on the Swift side there is nothing value-based to hash, so the only hash consistent with a value-based equals is a constant. When a type has a bridged equals but no hashCode, the generated code is now:

override fun hashCode(): Int = "S".hashCode()

The trade-off: these types land in a single bucket in hash containers, so lookups degrade to linear scans of that bucket, where today they are fast but wrong. Types that are Hashable are unaffected and keep Swift_hashvalue. Types without a bridged equals keep the identity-style hash, which is consistent with their identity equals.

Tests

  • New BridgeToKotlinTests.testStructEquatableNotHashable covering the generated Kotlin and Swift.

  • swift test --filter SkipSyntaxTests: 868/868.

  • skip-bridge skip test against this skipstone (SKIPLOCAL): 151/151.
  • Independent of skiptools/skipstone#292 (pointer-based equals); the two touch different functions and can land in either order.

    🤖 Generated with Claude Code

    Diff: 232 lines (+174 / -58) across 2 files Reviewer: marcprux Review duration: 6255m
    All Vouch review confidence checks passed
    Residual risk 0.15 = Change Risk (0.37) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 232 lines diff across 2 files
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    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.326
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #293"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 37.1% (MEDIUM) · Higher = larger blast radius
    37.1%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 14.6% · Safe to merge
    14.6%