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 Object use an opaque Textmap interface #865

Closed
wants to merge 1 commit into from

Conversation

Boarders
Copy link
Contributor

No description provided.

@Boarders
Copy link
Contributor Author

I still didn't add the Lifted instance as I do not know Template Haskell well enough to know what to do. Please let me know what else needs to change? I can add documentation for TextMap.

@Boarders Boarders force-pushed the textmap branch 2 times, most recently from ec32861 to 463b365 Compare September 13, 2021 00:50
src/Data/Aeson/TextMap.hs Outdated Show resolved Hide resolved
@Boarders
Copy link
Contributor Author

Do you think there is any value in also making this abstract in terms of the Text type so that could be switched out or save that for later?

@phadej
Copy link
Collaborator

phadej commented Sep 13, 2021

Let's do with concrete Text for now. One step at the time.

@phadej
Copy link
Collaborator

phadej commented Sep 13, 2021

FWIW, feel free to squash my commit once things starts to look ok.

src/Data/Aeson/TextMap.hs Outdated Show resolved Hide resolved
@Boarders Boarders force-pushed the textmap branch 9 times, most recently from 93bb3a1 to 9738cb5 Compare September 13, 2021 03:29
@Boarders
Copy link
Contributor Author

Apologies if this led to a bunch of CI spam.

@Boarders Boarders force-pushed the textmap branch 5 times, most recently from 5dfae44 to c4d793b Compare September 13, 2021 04:35
Copy link
Collaborator

@phadej phadej left a comment

Choose a reason for hiding this comment

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

Starting to look great!

src/Data/Aeson/TH.hs Outdated Show resolved Hide resolved
src/Data/Aeson/TextMap.hs Outdated Show resolved Hide resolved
src/Data/Aeson/TextMap.hs Show resolved Hide resolved
liftToJSON g _ = Object . fmap g

-- liftToEncoding :: forall a. (a -> Encoding) -> ([a] -> Encoding) -> TM.HashMap k a -> Encoding
liftToEncoding g _ = case toJSONKey of
Copy link
Collaborator

Choose a reason for hiding this comment

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

the same issue as previously with liftToJSON.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You'll have to let me know if what I wrote is the expected behaviour.

@Boarders
Copy link
Contributor Author

@phadej any ideas what to do with the panic on GHC 8.0.2 - I don't have access to a local copy and failed to quickly build it.

@phadej
Copy link
Collaborator

phadej commented Sep 13, 2021

ignore it for now, i guess what it suggests will do the trick, but it's easier to test locally (i'll do)

EDIT: i want also to check what it is simplifying there, doesn't feel right it hits the limit

@phadej
Copy link
Collaborator

phadej commented Sep 13, 2021

Ah, Parser.Internal already has

#if __GLASGOW_HASKELL__ <= 710 && __GLASGOW_HASKELL__ >= 706
-- Work around a compiler bug
{-# OPTIONS_GHC -fsimpl-tick-factor=300 #-}
#endif

bump that to 400, let's see if that's enough :)

Co-authored-by: Callan McGill <callan.mcgill@gmail.com>
@Boarders
Copy link
Contributor Author

Thank you for the guidance @phadej. Looks like we got it to green.

@Boarders Boarders changed the title [WIP] Make Object use an opaque Textmap interface Make Object use an opaque Textmap interface Sep 13, 2021

-- | Convert a 'TextMap' to a 'HashMap'.
toHashMap :: TextMap v -> HashMap Text v
toHashMap = unTextMap

Choose a reason for hiding this comment

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

Why no inline here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't add inline anywhere, I think, in general, it is best practice to add inline when a benchmark actually proves it is worthwhile and not before, but I am open to changing it if others agree.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm thinking how get rid (or at least discourage the usage) of this function. We don't want to have HashMap intermediates, if they are not necessary i.e. we are literally parsing into HashMap / serializing from HashMap...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me investigate if these functions are really needed. For the instances for HashMap itself we can probably use a fold which will be more representative of an abstract interface.

Copy link
Collaborator

@phadej phadej Sep 14, 2021

Choose a reason for hiding this comment

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

They are fine for now. Probably the "pain" will clearer when there is alternative implementation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

To clarify: we would like to avoid rebuilding a *Map when the representation is the same. nice to have.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There might be some way to not expose it as part of the interface but add a re-write rule for this representation or something like that.

@phadej
Copy link
Collaborator

phadej commented Sep 14, 2021

I renamed TextMap into KeyMap in #866 and merged. Thanks @Boarders

@phadej phadej closed this Sep 15, 2021
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.

4 participants