Keep hashCode consistent with equals for Equatable bridged types #293
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
marcprux
Summary
A bridged struct or class that is
Equatablebut notHashablegets a value-basedequals()(throughSwift_isequal) and the defaulthashCode():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 theequals/hashCodecontract:HashMap/HashSetlookups miss,distinct()/toSet()keep duplicates, and anything else that buckets by hash before callingequalsbehaves 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
Hashableconformance on the Swift side there is nothing value-based to hash, so the only hash consistent with a value-basedequalsis a constant. When a type has a bridgedequalsbut nohashCode, the generated code is now: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
Hashableare unaffected and keepSwift_hashvalue. Types without a bridgedequalskeep the identity-style hash, which is consistent with their identityequals.Tests
BridgeToKotlinTests.testStructEquatableNotHashablecovering the generated Kotlin and Swift.swift test --filter SkipSyntaxTests: 868/868.skip testagainst 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