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

Rebasing generic work #394

Merged
merged 19 commits into from
Mar 16, 2022
Merged

Rebasing generic work #394

merged 19 commits into from
Mar 16, 2022

Conversation

treeowl
Copy link
Collaborator

@treeowl treeowl commented Feb 23, 2022

Rebase in progress of #316.

@treeowl treeowl marked this pull request as draft February 23, 2022 04:55
@treeowl treeowl marked this pull request as ready for review February 24, 2022 00:36
@treeowl
Copy link
Collaborator Author

treeowl commented Feb 24, 2022

I don't know how to set up ormolu for formatting, and I don't really have time to futz with that right now. Can someone help me out?

@treeowl
Copy link
Collaborator Author

treeowl commented Feb 24, 2022

@aspiwack aside from the formatting thing, I think this is pretty much ready. It doesn't remove all the orphans, but that can be done in another PR or two.

@tbagrel1
Copy link
Member

I don't know how to set up ormolu for formatting, and I don't really have time to futz with that right now. Can someone help me out?

You should be able to format with ./format.sh at the root of the repo. It uses stack to fetch, build and exec ormolu on the codebase.

@aspiwack
Copy link
Member

If you have Nix installed, you can $ nix-shell --run "./format,sh". Alternatively, if you have Stack installed, you can ./format.sh.

I pushed a formatting commit.

@tbagrel1 This is a pretty big patch, please give it a review, I'll do the same myself.

Copy link
Member

@tbagrel1 tbagrel1 left a comment

Choose a reason for hiding this comment

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

Just a bit of nitpicking. Thank you really much for this impressive work!

src/Control/Functor/Linear/Internal/Class.hs Outdated Show resolved Hide resolved
src/Control/Functor/Linear/Internal/Class.hs Show resolved Hide resolved
src/Data/Functor/Linear/Internal/Functor.hs Outdated Show resolved Hide resolved
src/Data/Unrestricted/Linear/Internal/Dupable.hs Outdated Show resolved Hide resolved
src/Data/Unrestricted/Linear/Internal/Dupable.hs Outdated Show resolved Hide resolved
src/Data/Unrestricted/Linear/Internal/Movable.hs Outdated Show resolved Hide resolved
Copy link
Member

@aspiwack aspiwack left a comment

Choose a reason for hiding this comment

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

(I've reviewed only about half way through, but I won't have time to resume for a while, so posting what I have)

linear-base.cabal Outdated Show resolved Hide resolved
src/Control/Functor/Linear/Internal/Class.hs Show resolved Hide resolved
src/Data/Functor/Linear/Internal/Functor.hs Outdated Show resolved Hide resolved
src/Data/Functor/Linear/Internal/Functor.hs Outdated Show resolved Hide resolved
@tbagrel1
Copy link
Member

@aspiwack Do you remember the motivations behind the difference of organisation between Data.Functor.Linear.xxx modules and Control.Functor.Linear.xxx modules?

@treeowl
Copy link
Collaborator Author

treeowl commented Feb 24, 2022

@aspiwack , you seem to be fighting a long term trend to prefer explicit and qualified imports to hiding in most cases. Why is that? The former are more robust in the face of additions to the imported modules.

@aspiwack
Copy link
Member

@aspiwack , you seem to be fighting a long term trend to prefer explicit and qualified imports to hiding in most cases. Why is that? The former are more robust in the face of additions to the imported modules.

They are more robust, but in practice they cost more of my time. My inclination is to use qualified import as much as is reasonable (which will be easier when the Local Module proposal comes to fruition). But I prefer figuring out the occasional error, than preemptively making import list management something I have to care about on a daily basis.

@aspiwack
Copy link
Member

@aspiwack Do you remember the motivations behind the difference of organisation between Data.Functor.Linear.xxx modules and Control.Functor.Linear.xxx modules?

I think @Divesh-Otwani found it easier to document modules when they were split into smaller chunks for me. I don't care much either way as long as we have a reasonably small list of modules to import in the user-facing land.

@treeowl
Copy link
Collaborator Author

treeowl commented Feb 24, 2022

Note: when this is merged, it would be good to give @sjoerdvisscher credit for the substantial work he did on it before I showed up. As I recall, his most interesting contribution was generic derivation of control functors. I'm not sure how best to do that in the context of git with such a wild rebase.

@treeowl
Copy link
Collaborator Author

treeowl commented Feb 24, 2022

@aspiwack ormolu chokes doing something or other with dependencies (constraints and hedgehog) that have CPP in their module export lists when I use the stack version. The nix thing is still compiling the world.

@treeowl
Copy link
Collaborator Author

treeowl commented Feb 25, 2022

The nix formatting approach fails for me too.

@tbagrel1
Copy link
Member

@aspiwack ormolu chokes doing something or other with dependencies (constraints and hedgehog) that have CPP in their module export lists when I use the stack version. The nix thing is still compiling the world.

I formatted it. I got no issues with ormolu (but I already had it installed through format.sh a long time ago, so maybe there is something which prevents ormolu installation via stack now?).

@tbagrel1
Copy link
Member

Closes #316 .

@aspiwack
Copy link
Member

aspiwack commented Mar 7, 2022

Note: when this is merged, it would be good to give @sjoerdvisscher credit for the substantial work he did on it before I showed up. As I recall, his most interesting contribution was generic derivation of control functors. I'm not sure how best to do that in the context of git with such a wild rebase.

I believe that if you add the line

Co-authored-by: Sjoerd Visscher <firstname.name@tweag.io>

To the relevant commits' messages, then Sjoerd will appear – at least in Github – as a coauthor of the commits.

@aspiwack
Copy link
Member

aspiwack commented Mar 7, 2022

I think it's specifically at the end of the commit message. Github's documentation is here.

Copy link
Member

@aspiwack aspiwack left a comment

Choose a reason for hiding this comment

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

There are only a few points to address to get this merged. @treeowl can you do that this week? If so we can include it in the next release.

I really like this. Thanks to both of you and @sjoerdvisscher for the great work that came into this.

Comment on lines +76 to +74
lcoerce :: forall a b. Coercible a b => a %1 -> b
lcoerce = coerce ((\x -> x) :: a %1 -> a)
Copy link
Member

Choose a reason for hiding this comment

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

Very nice 🙂

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Glad you like it ;-)

linear-base.cabal Outdated Show resolved Hide resolved
src/Data/Unrestricted/Linear/Internal/Dupable.hs Outdated Show resolved Hide resolved
src/Control/Functor/Linear/Internal/Class.hs Show resolved Hide resolved
Comment on lines 67 to 70
-- @deriving via 'Generically'@. Note that at present this mechanism
-- can have performance problems for recursive parameterized types.
-- Specifically, the methods will not specialize to underlying 'Dupable'
-- instances.
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand the performance problem that you are pointing at?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@aspiwack, the underlying Dupable dictionary ends up being a (static) argument to a recursive function that doesn't get an unfolding. So the underlying duplication function will never be inlined, no matter how small it is. Probably not the biggest problem for Dupable; probably a bigger problem for Traversable, where traverse won't specialize to a particular Applicative, let alone a particular function to traverse with. See https://gitlab.haskell.org/ghc/ghc/-/issues/21131

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've linked to the GHC issue from the docs.

src/Prelude/Linear/Unsatisfiable.hs Outdated Show resolved Hide resolved
@aspiwack
Copy link
Member

Thanks @tbagrel1 for taking care of the small issues. @treeowl do you have time to address the couple of request for extra comments? In either case, I plan to merge this tomorrow, and then we make a release :slightly_smiling_face: .

sjoerdvisscher and others added 14 commits March 16, 2022 00:53
Co-authored-by: David Feuer <David.Feuer@gmail.com>
To avoid orphans, put the generic deriving machinery
with the `Traversable` class.
- `Consumable`, `Dupable` and `Movable` uniformly implemented for tuples up to
n=5
- Fix some names/imports according to the project conventions
@treeowl
Copy link
Collaborator Author

treeowl commented Mar 16, 2022

I think everything's sorted now.

@treeowl
Copy link
Collaborator Author

treeowl commented Mar 16, 2022

(Unless I've broken some ormolu junk again, in which case I imagine you can fix it.)

@aspiwack
Copy link
Member

Thanks!

I'm guessing the dance around unsatisfiable is necessary to make it representation-polymorphic. I don't have much of a grasp of why (or why the previous implementation worked). I'd be glad if you gave a few words about it in the thread.

@treeowl
Copy link
Collaborator Author

treeowl commented Mar 16, 2022

Thanks!

I'm guessing the dance around unsatisfiable is necessary to make it representation-polymorphic. I don't have much of a grasp of why (or why the previous implementation worked). I'd be glad if you gave a few words about it in the thread.

Yes, partly to make it representation polymorphic to match what the GHC built-in version will do as closely as we can. The previous implementation had

unsatisfiable' :: Bottom => a

This was used at type

unsatisfiable' :: Bottom  => (##) -> q

where q is the actual desired result type.


What's the rest of the dance for? The "obvious" thing is to give unsatisfiable an Unsatisfiable e constraint. But this would not be ergonomical at all, and would not match the "magical" behavior of the future built-in version. Why? Because each invocation of unsatisfiable would then have to specify the type error, completely uselessly. By using Bottom, we avoid caring, at the call site, why we couldn't possibly have gotten there.

@tbagrel1 tbagrel1 merged commit 0841c91 into tweag:master Mar 16, 2022
@treeowl
Copy link
Collaborator Author

treeowl commented Oct 11, 2022 via email

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.

None yet

4 participants