Skip to content

Represents ModuleNames as a single Text#3843

Merged
kritzcreek merged 2 commits intopurescript:masterfrom
kritzcreek:modulename-as-single-text
Apr 21, 2020
Merged

Represents ModuleNames as a single Text#3843
kritzcreek merged 2 commits intopurescript:masterfrom
kritzcreek:modulename-as-single-text

Conversation

@kritzcreek
Copy link
Copy Markdown
Member

@kritzcreek kritzcreek commented Apr 12, 2020

The hierarchy newtype ModuleName = ModuleName [ProperName] suggests doesn't actually exist except for the Prim. namespace.

The compiler compares module names for equality and ordering all over the place though, so we should pick a representation suitable for that. This improves my extern loading benchmarks by another 10%.

Most of that will be the more compact encoding, that I could get with a handwritten instance as well, but I wanted to suggest this representation for a while now. What do you think?

The hierarchy `[ProperName]` suggests doesn't actually exist except
for the `Prim.` namespace. The compiler compares module names for
equality and ordering all over the place though, so we should pick a
representation suitable for that.
$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''Ident)
$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''ModuleName)

instance ToJSON ModuleName where
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm continuing to encode module names as arrays of strings in JSON to not break the compatibility tests. I'm assuming changing this would break Pursuit. Would Pursuit be fine if my handwritten instance accepted both a single string as well as an array of them?

@natefaubion
Copy link
Copy Markdown
Contributor

I think we just need to be aware of how changes like this will affect CoreFn, which is a stable API.

@hdgarrood
Copy link
Copy Markdown
Contributor

hdgarrood commented Apr 13, 2020

Pursuit would probably be fine if we changed the format; we've made changes to JSON instances in a backwards-compatible way for Pursuit before, i.e. changing the format we generate but keeping old versions of parsers around and attempting the older parser if the new parser fails to parse. The only issue I'm aware of with that is that we need to update Pursuit quickly after a new release when we do that because older compilers won't be able to parse the new JSON of course. That should be easier now that more people can deploy to the Pursuit server, though.

However, I think changing the JSON format is more of an issue for corefn, as @natefaubion points out. Do you think we would gain a lot from changing the JSON encoding to use a single string? At the moment this doesn't seem worth breaking people's corefn parsers to me; I think I would prefer to retain all of the same JSON instances (i.e. convert to/from a list of strings during encoding/decoding) and keep this change strictly internal.

@kritzcreek
Copy link
Copy Markdown
Member Author

Thanks for pointing out that CoreFn shouldn't change for something like this. I've changed the en/decoders to match our previous representation.

@kritzcreek kritzcreek marked this pull request as ready for review April 13, 2020 08:16
@kritzcreek
Copy link
Copy Markdown
Member Author

Thanks for the review! Let's hope I don't cause too many conflicts in open PRs...

@kritzcreek kritzcreek merged commit 9c2e6ce into purescript:master Apr 21, 2020
@kritzcreek kritzcreek deleted the modulename-as-single-text branch April 21, 2020 18:58
kl0tl added a commit to kl0tl/zephyr that referenced this pull request May 9, 2020
kl0tl added a commit to kl0tl/zephyr that referenced this pull request May 9, 2020
@hdgarrood hdgarrood mentioned this pull request May 23, 2020
hdgarrood pushed a commit that referenced this pull request May 23, 2020
* Represents ModuleNames as a single Text

The hierarchy `[ProperName]` suggests doesn't actually exist except
for the `Prim.` namespace. The compiler compares module names for
equality and ordering all over the place though, so we should pick a
representation suitable for that.

* preserve CoreFn encoding
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