Skip to content

Conversation

@sjakobi
Copy link
Member

@sjakobi sjakobi commented Nov 27, 2025

No description provided.

disjointSubtrees _s _a Empty = True
disjointSubtrees s a (Leaf hB (L kB _)) =
lookupCont (\_ -> True) (\_ _ -> False) hB kB s a
disjointSubtrees s a b@Collision{} = disjointSubtrees s b a
Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately GHC fails to specialize this and we end up with stuff like

disjoint_$s$wdisjointSubtrees @a @b @Int bx bx1 ww $fEqInt wild

or

disjoint_$s$wdisjointSubtrees @a @b @String bx bx1 ww $fEqList_$s$fEqList1 wild

Copy link
Member Author

@sjakobi sjakobi Nov 27, 2025

Choose a reason for hiding this comment

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

I misunderstood.

This function seems to be the result of case liberation (EDIT: it's not, it's due to -fspec-constr):

disjoint_$s$wdisjointSubtrees [Occ=LoopBreaker]
  :: forall b a k.
     Word#
     -> SmallArray# (Leaf k a) -> Int# -> Eq k => HashMap k b -> Bool

and I suspect the specialization failure is related to the Eq dict being tucked in the middle of the other parameters instead of being first.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can replicate the issue with -O1 -fspec-constr.

Copy link
Member Author

Choose a reason for hiding this comment

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

-- Note that as of GHC 9.12, SpecConstr creates a specialized worker for
-- handling the Collision vs. {BitmapIndexed,Full} and vice-versa cases,
-- but this worker fails to be properly specialized for different key
-- types. See https://gitlab.haskell.org/ghc/ghc/-/issues/26615.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we perform constructor specialization manually to work around this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't mind if you or someone else wants to work on this, but I won't.

@sjakobi sjakobi marked this pull request as ready for review December 4, 2025 23:33
@sjakobi sjakobi merged commit 3fa0102 into master Dec 5, 2025
10 checks passed
@sjakobi sjakobi deleted the sjakobi/disjoint branch December 5, 2025 06:16
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