Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make extensibleState primarily keyed by TypeRep instead of type names #326

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

liskin
Copy link
Member

@liskin liskin commented Sep 2, 2021

Description

We've been using the String we get out of show . typeOf as key in extensibleState, but that has a somewhat serious bug: it shows unqualified type names, so if two modules use the same type name, their extensible states will be stored in one place and get overwritten all the time.

To fix this, the extensibleState map is now primarily keyed by the TypeRep themselves, with fallback to String for not yet deserialized data. XMonad.Core now exports showExtType which serializes type names qualified, and this is used in writeStateToFile.

A simpler fix would be to just change the serialization of type names in XMonad.Util.ExtensibleState, but I'm afraid that might slows things down: Most types used here will start with "XMonad.", and that's a lot of useless linked-list pointer jumping.

Fixes: xmonad/xmonad-contrib#94
Related: xmonad/xmonad-contrib#600


I must admit I don't really like the code, especially the xmonad-contrib part. There's the assumption that a Right key maps to a Right value, and Left key to Left value, but enforcing that in the types probably means adding a another field to the XState.

Checklist

  • I've read CONTRIBUTING.md

  • I've confirmed these changes don't belong in xmonad-contrib instead

  • I updated the CHANGES.md file

We've been using the String we get out of `show . typeOf` as key in
`extensibleState`, but that has a somewhat serious bug: it shows
unqualified type names, so if two modules use the same type name, their
extensible states will be stored in one place and get overwritten all
the time.

To fix this, the `extensibleState` map is now primarily keyed by the
TypeRep themselves, with fallback to String for not yet deserialized
data. XMonad.Core now exports `showExtType` which serializes type names
qualified, and this is used in `writeStateToFile`.

A simpler fix would be to just change the serialization of type names in
`XMonad.Util.ExtensibleState`, but I'm afraid that might slows things
down: Most types used here will start with "XMonad.", and that's a lot
of useless linked-list pointer jumping.

Fixes: xmonad/xmonad-contrib#94
Related: xmonad/xmonad-contrib#600
@slotThe
Copy link
Member

slotThe commented Sep 3, 2021

A simpler fix would be to just change the serialization of type names in XMonad.Util.ExtensibleState, but I'm afraid that might slows things down: Most types used here will start with "XMonad.", and that's a lot of useless linked-list pointer jumping.

As a great man once told me: have you benchmarked this? We still use String all over the place, so I can't imagine that a linked list of length 7 has that much of a performance impact

@liskin
Copy link
Member Author

liskin commented Sep 3, 2021

I didn't, true. It just feels wrong, and a couple other people suggested using Fingerprint in the past, so I went ahead and tried implementing it. It may indeed be negligible in the grand scheme of things (although that would suggest other things are also terribly inefficient). I'll try to benchmark this somehow in the coming days.

@liskin liskin added this to the v0.18 milestone Oct 18, 2021
@liskin liskin modified the milestones: v0.18.0, v0.17.1 Mar 11, 2022
@liskin liskin self-assigned this Mar 11, 2022
@geekosaur
Copy link
Contributor

Turns out Fingerprint (and therefore the internal representation of TypeRep) is not stable across compiles, much less GHC versions, so we would need to use the String anyway unless you deal with this during serialization and deserialization. I'd just go ahead and use the String, possibly with "XMonad." prefix removed (although this is a problem if we're passed a type that isn't defined by xmonad).

Copy link
Contributor

@geekosaur geekosaur left a comment

Choose a reason for hiding this comment

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

LGTM

@liskin liskin modified the milestones: v0.18.0, v0.19.0 Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To Merge
Development

Successfully merging this pull request may close these issues.

ExtensibleState map keys are not unique
3 participants