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

Disable 1-field simplification by default #1321

Merged
merged 4 commits into from
Sep 19, 2019
Merged

Conversation

Gabriella439
Copy link
Collaborator

This builds on top of #1315 to minimize disruption by disabling the
breaking change by default and instead requiring the user to opt in
by setting a new collapseSingletonRecords option to True.

The additional tests added to verify this also caught a bug in the
Interpret instance for functions, which this change also fixes.

This builds on top of #1315 to minimize disruption by disabling the
breaking change by default and instead requiring the user to opt in
by setting a new `collapseSingletonRecords` option to `True`.

The additional tests added to verify this also caught a bug in the
`Interpret` instance for functions, which this change also fixes.
Copy link
Collaborator

@sjakobi sjakobi left a comment

Choose a reason for hiding this comment

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

A few comments – take them with a grain of salt though: After all I don't use these bindings myself.

I would be interested in @rprije's and @patrickmn's opinion though!

dhall/src/Dhall.hs Outdated Show resolved Hide resolved
dhall/tests/Dhall/Test/Dhall.hs Show resolved Hide resolved
| R1 { a :: () }
| R2 { x :: Double }
| R3 { a :: (), b :: () }
| R4 { x :: Double, y :: Double }
Copy link
Collaborator

Choose a reason for hiding this comment

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

BTW I don't see any tests for simple record types like data D = D { a :: Bool, … } and newtypes – I assume they would be translated to records and also be influenced by the collapseSingletonRecords setting?!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you see my comment above, @Gabriel439?

I'm mostly wondering whether these types are marshalled differently with the new default setting.

dhall/src/Dhall.hs Outdated Show resolved Hide resolved
... based on feedback from @sjakobi

This change the option to a three-valued option:

* `Bare`    - 1-field constructor does not include a nested record
* `Wrapped` - 1-field constructor always includes a nested record
* `Smart`   - Named fields that don't begin with `_` include a nested record

The default is `Wrapped` (for backwards compatibility), but users will
probably want to eventually switch to `Smart`
Copy link
Collaborator

@sjakobi sjakobi left a comment

Choose a reason for hiding this comment

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

Cheers, the Smart option seems very useful! 👍


> < Foo : { x : Double } | Bar : { _1 : Double } > -- Wrapped

> < Foo : { x : Double } | Bar : Double > -- Smart
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

dhall/src/Dhall.hs Show resolved Hide resolved
| R1 { a :: () }
| R2 { x :: Double }
| R3 { a :: (), b :: () }
| R4 { x :: Double, y :: Double }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you see my comment above, @Gabriel439?

I'm mostly wondering whether these types are marshalled differently with the new default setting.

Copy link

@rprije rprije left a comment

Choose a reason for hiding this comment

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

I only briefly looked over the code, but the approach looks great to me. Continuing with Wrapped for backwards compatibility for now while aiming to switch toward Smart seems like a good approach. Users might appreciate some explicit warning before that switch happens. On the other hand, maybe just mentioning it in the release notes is enough; I expect Dhall's user base knows to be pretty tolerant of backwards-incompatible changes at this point.

Thanks for making this change happen; Smart definitely looks like the sort of behaviour users are most likely to expect.

instance (Selector s, Interpret a) => GenericInterpret (M1 S s (K1 i a)) where
genericAutoWith options@InterpretOptions{..} = do
let n :: M1 S s (K1 i a) r
n = undefined
Copy link

Choose a reason for hiding this comment

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

I'm a little concerned about all these undefineds. Would Proxy be a safer alternative?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@rprije: The undefineds are necessary. It's a limitation of the GHC generics API, since it doesn't support a Proxy-based selName.

@Gabriella439
Copy link
Collaborator Author

@sjakobi: After this change, all fields will be marshalled the same as they were in version 1.26.0 (i.e. Wrapped by default)

@mergify mergify bot merged commit 54241f8 into master Sep 19, 2019
@mergify mergify bot deleted the gabriel/collapse_option branch September 19, 2019 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants