Fix optimization-dependent invalid Map decoding - #1190
Open
PaleRoses wants to merge 1 commit into
Open
Conversation
Lysxia
reviewed
Aug 29, 2026
| if maybe True (currentKey <) nextKey | ||
| then Just (Just currentKey) | ||
| else Nothing | ||
| {-# INLINE mapKeyO #-} |
Collaborator
There was a problem hiding this comment.
I don't think this is the right place for this kind of optimization.
- It's orthogonal to fixing the main issue at hand.
- When the keys are not ordered you end up paying the cost of applying
fktwice to each key, which might be expensive if it's doing nontrivial parsing. I'm also not sure this optimization is worthwhile sincemapKeysWithalready takes care of running in linear time if the mapping is monotonic.
| fromJSONKey = fmap MyText' fromJSONKey | ||
| fromJSONKeyList = error "not used" | ||
|
|
||
| newtype ReverseText = ReverseText Text |
Lysxia
reviewed
Aug 29, 2026
| assertDecodedCollidingMap :: Assertion | ||
| assertDecodedCollidingMap = decodedMap @?= Just (Map.singleton (FoldedText "a") "upper") | ||
| where | ||
| decodedMap = decode "{\"A\":\"upper\",\"a\":\"lower\"}" :: Maybe (Map FoldedText Text) |
Collaborator
There was a problem hiding this comment.
This test relies on KeyMap being ordered. That's why it sometimes fails the flag ordered-keymap disabled.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1169.
Remove the unsound
"FromJSONKeyCoerce: fmap coerce"RULE.mapKeyOreuses the source tree only when mapped keys stay strictly ordered; otherwise it rebuilds the map.Tests cover reversed ordering and collisions. The full suite passes at
-O0and-O2. All 32 Map benchmarks pass the 5% regression check; affected cases are 29–41% faster.