[Git][ghc/ghc][wip/marge_bot_batch_merge_job] 4 commits: Relax instances for Functor combinators; put superclass on Class1 to make non-breaking

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Wed Aug 10 05:21:35 UTC 2022



Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC


Commits:
4b5a4e99 by John Ericson at 2022-08-10T01:21:16-04:00
Relax instances for Functor combinators; put superclass on Class1 to make non-breaking

The first change makes the `Eq`, `Ord`, `Show`, and `Read` instances for
`Sum`, `Product`, and `Compose` match those for `:+:`, `:*:`, and `:.:`.
These have the proper flexible contexts that are exactly what the
instance needs:

For example, instead of
```haskell
instance (Eq1 f, Eq1 g, Eq a) => Eq (Compose f g a) where
  (==) = eq1
```
we do
```haskell
deriving instance Eq (f (g a)) => Eq (Compose f g a)
```

But, that change alone is rather breaking, because until now `Eq (f a)`
and `Eq1 f` (and respectively the other classes and their `*1`
equivalents too) are *incomparable* constraints. This has always been an
annoyance of working with the `*1` classes, and now it would rear it's
head one last time as an pesky migration.

Instead, we give the `*1` classes superclasses, like so:
```haskell
(forall a. Eq a => Eq (f a)) => Eq1 f
```
along with some laws that canonicity is preserved, like:
```haskell
liftEq (==) = (==)
```

and likewise for `*2` classes:
```haskell
(forall a. Eq a => Eq1 (f a)) => Eq2 f
```
and laws:
```haskell
liftEq2 (==) = liftEq1
```

The `*1` classes also have default methods using the `*2` classes where
possible.

What this means, as explained in the docs, is that `*1` classes really
are generations of the regular classes, indicating that the methods can
be split into a canonical lifting combined with a canonical inner, with
the super class "witnessing" the laws[1] in a fashion.

Circling back to the pragmatics of migrating, note that the superclass
means evidence for the old `Sum`, `Product`, and `Compose` instances is
(more than) sufficient, so breakage is less likely --- as long no
instances are "missing", existing polymorphic code will continue to
work.

Breakage can occur when a datatype implements the `*1` class but not the
corresponding regular class, but this is almost certainly an oversight.
For example, containers made that mistake for `Tree` and `Ord`, which I
fixed in https://github.com/haskell/containers/pull/761, but fixing the
issue by adding `Ord1` was extremely *un*controversial.

`Generically1` was also missing `Eq`, `Ord`, `Read,` and `Show`
instances. It is unlikely this would have been caught without
implementing this change.

-----

[1]: In fact, someday, when the laws are part of the language and not
only documentation, we might be able to drop the superclass field of the
dictionary by using the laws to recover the superclass in an
instance-agnostic manner, e.g. with a *non*-overloaded function with
type:

```haskell
DictEq1 f -> DictEq a -> DictEq (f a)
```

But I don't wish to get into optomizations now, just demonstrate the
close relationship between the law and the superclass.

Bump haddock submodule because of test output changing.

- - - - -
a32663b3 by Douglas Wilson at 2022-08-10T01:21:20-04:00
testsuite: 21651 add test for closeFdWith + setNumCapabilities

This bug does not affect windows, which does not use the
base module GHC.Event.Thread.

- - - - -
cd6068ee by Douglas Wilson at 2022-08-10T01:21:20-04:00
base: Fix races in IOManager (setNumCapabilities,closeFdWith)

Fix for #21651

Fixes three bugs:

- writes to eventManager should be atomic. It is accessed concurrently by ioManagerCapabilitiesChanged and closeFdWith.
- The race in closeFdWith described in the ticket.
- A race in getSystemEventManager where it accesses the 'IOArray' in
  'eventManager' before 'ioManagerCapabilitiesChanged' has written to
  'eventManager', causing an Array Index exception. The fix here is to
  'yield' and retry.

- - - - -
051628b4 by Trevis Elser at 2022-08-10T01:21:24-04:00
Updates language extension documentation

Adding a 'Status' field with a few values:
- Deprecated
- Experimental
- InternalUseOnly
- Noting if included in 'GHC2021', 'Haskell2010' or 'Haskell98'

Those values are pulled from the existing descriptions or elsewhere in
the documentation.

While at it, include the :implied by: where appropriate, to provide
more detail.

Fixes #21475

- - - - -


30 changed files:

- docs/users_guide/bugs.rst
- docs/users_guide/exts/binary_literals.rst
- docs/users_guide/exts/constrained_class_methods.rst
- docs/users_guide/exts/constraint_kind.rst
- docs/users_guide/exts/datatype_contexts.rst
- docs/users_guide/exts/deriving_extra.rst
- docs/users_guide/exts/duplicate_record_fields.rst
- docs/users_guide/exts/empty_case.rst
- docs/users_guide/exts/empty_data_deriving.rst
- docs/users_guide/exts/existential_quantification.rst
- docs/users_guide/exts/explicit_forall.rst
- docs/users_guide/exts/explicit_namespaces.rst
- docs/users_guide/exts/ffi.rst
- docs/users_guide/exts/field_selectors.rst
- docs/users_guide/exts/flexible_contexts.rst
- docs/users_guide/exts/functional_dependencies.rst
- docs/users_guide/exts/gadt_syntax.rst
- docs/users_guide/exts/generics.rst
- docs/users_guide/exts/hex_float_literals.rst
- docs/users_guide/exts/import_qualified_post.rst
- docs/users_guide/exts/instances.rst
- docs/users_guide/exts/kind_signatures.rst
- docs/users_guide/exts/let_generalisation.rst
- docs/users_guide/exts/linear_types.rst
- docs/users_guide/exts/multi_param_type_classes.rst
- docs/users_guide/exts/newtype_deriving.rst
- docs/users_guide/exts/nk_patterns.rst
- docs/users_guide/exts/nullary_type_classes.rst
- docs/users_guide/exts/nullary_types.rst
- docs/users_guide/exts/numeric_underscores.rst


The diff was not included because it is too large.


View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a7c7ae9a406bb2b87f9aa5566ccfe5fe371cfb08...051628b4589e0c5e8bae78aaa7698201a5f1071d

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a7c7ae9a406bb2b87f9aa5566ccfe5fe371cfb08...051628b4589e0c5e8bae78aaa7698201a5f1071d
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20220810/d34710a3/attachment-0001.html>


More information about the ghc-commits mailing list