Skip to content

Fix build after GHC known-keys patch (10.1) - #244

Open
alt-romes wants to merge 1 commit into
haskell:masterfrom
alt-romes:wip/romes/known-keys
Open

Fix build after GHC known-keys patch (10.1)#244
alt-romes wants to merge 1 commit into
haskell:masterfrom
alt-romes:wip/romes/known-keys

Conversation

@alt-romes

Copy link
Copy Markdown

Prepares binary for the about-to-land GHC MR: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/15899

@alt-romes

alt-romes commented Jul 15, 2026

Copy link
Copy Markdown
Author

CI keeps failing in my fork on job ghc-i386 seemingly because of a GHCup failure

@konsumlamm konsumlamm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Has there been a CLC proposal for the changes to base? I don't really like that the behaviour depends on the used GHC version, but I guess there is no clean way around that.

Comment thread src/Data/Binary/Class.hs
Comment on lines +1028 to +1035
#if __GLASGOW_HASKELL__ >= 1001
put KindRepType = putWord8 4
put KindRepConstraint = putWord8 5
put (KindRepTypeLit sort r) = putWord8 6 >> put sort >> put r
#else
put (KindRepTYPE r) = putWord8 4 >> put r
put (KindRepTypeLit sort r) = putWord8 5 >> put sort >> put r
#endif

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What does Binary guarantee in the way of stability of the representation? It seems unfortunate that a serialised KindRep may fail to deserialise if you change the GHC version.

I think this patch could avoid that in most cases, though, by choosing the serialisation scheme to be backwards compatible (see below).

(I'm not sure what KindRepConstraint corresponds to, and if someone had serialised KindRepTYPE r for a strange runtime rep it might be impossible to deserialise in the new version, but I think the common case will be KindRepTYPE (BoxedRep Lifted) and we could make sure that has the same serialisation?)

Suggested change
#if __GLASGOW_HASKELL__ >= 1001
put KindRepType = putWord8 4
put KindRepConstraint = putWord8 5
put (KindRepTypeLit sort r) = putWord8 6 >> put sort >> put r
#else
put (KindRepTYPE r) = putWord8 4 >> put r
put (KindRepTypeLit sort r) = putWord8 5 >> put sort >> put r
#endif
#if __GLASGOW_HASKELL__ >= 1001
put KindRepType = putWord8 4 >> putWord8 3 -- was (BoxedRep Lifted)
put KindRepConstraint = putWord8 4 >> putWord8 _ -- not sure what this should be?
#else
put (KindRepTYPE r) = putWord8 4 >> put r
#endif
put (KindRepTypeLit sort r) = putWord8 5 >> put sort >> put r

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

KindRepConstraint corresponds to KindRepApp $tcCONSTRAINT [...] where $tcCONSTRAINT is the ty con automatically generated when compiling the module defining CONSTRAINT

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Okay, so the same thing should in principle work? We just need to adjust the serialised version of KindRepConstraint to match that? (Though I suppose there is a round-trip failure wherein KindRepConstraint would be indistinguishable from KindRepApp $tcCONSTRAINT [...]...)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

but this would already be the case if you previously desugared something as KindRepApp $tcTYPE [...] rather than as KindRepTYPE [...]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What does Binary guarantee in the way of stability of the representation? It seems unfortunate that a serialised KindRep may fail to deserialise if you change the GHC version.

There are currently no stability guarantees I'm aware of. The Binary TypeRep instance unfortunately also has this problem. At the end of the day, I doubt that anyone (except maybe GHC) actually uses these instances though.

I think this patch could avoid that in most cases, though, by choosing the serialisation scheme to be backwards compatible (see below).

That would be ideal.

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