Skip to content

Commit 7198482

Browse files
committed
Updates following Stability group discussion
1 parent acef007 commit 7198482

File tree

1 file changed

+81
-22
lines changed

1 file changed

+81
-22
lines changed

proposals/0000-ghc-module-naming.rst

Lines changed: 81 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,35 @@ Background and motivation
77
The accepted `Proposal #51: GHC base libraries <https://github.com/haskellfoundation/tech-proposals/blob/main/proposals/accepted/051-ghc-base-libraries.rst>`_
88
defines the following libraries:
99

10-
* ``base``: the foundational library on which the rest of the ecosystem is based.
11-
10+
* ``base``:
11+
* The foundational library on which the rest of the Haskell ecosystem is based.
1212
* Its API is carefully curated by the `Core Libraries Committee <https://github.com/haskell/core-libraries-committee>`_, and is kept rather stable.
13+
* Depends on ``ghc-internal`` (and ``ghc-prim`` etc), but *not* on ``ghc-experimental``.
14+
* Major version bumps are at the Core Libraries Committee's discretion.
1315

14-
* ``ghc-experimental``: the home of experimental extensions to GHC, usually ones proposed by the
16+
* ``ghc-experimental``:
17+
* The home of experimental extensions to GHC, usually ones proposed by the
1518
`GHC Steering Committee <https://github.com/ghc-proposals/ghc-proposals/>`_.
1619

17-
* Functions and types in here are usually candidates for later transfer into ``base``. But not necessarily: if a collection of functions is not adopted widely enough, it may not be proposed for a move to `base`.
20+
* Functions and types in here are usually candidates for later transfer into ``base``. But not necessarily: if a collection of functions is not adopted widely enough, it may not be proposed for a move to `base`. Or it could move to another library entirely.
1821

1922
* It is user-facing (user are encouraged to depend on it), but its API is less stable than ``base``.
2023

21-
* ``ghc-prim, ghc-internals`` (and perhaps others): define functions and data types used internally by GHC to support the API of ``base`` and ``ghc-experimental``.
24+
* Depends on ``base``.
25+
26+
* Likely to have a major version bump with each GHC release.
27+
28+
* ``ghc-prim, ghc-internal`` (and perhaps others; it's an internal GHC implementation decision):
29+
* Define functions and data types used internally by GHC to support the API of ``base`` and ``ghc-experimental``.
2230

2331
* These libraries come with no stability guarantees: they may change at short notice.
2432

2533
In addition we already have:
2634

2735
* ``ghc``: this library exposes GHC as a library, through the (currently ill-defined) GHC API.
2836

29-
All these libraries follow the Haskell Package Versioning Policy (PVP).
37+
All these libraries follow the Haskell Package Versioning Policy (PVP). The reader is encouraged
38+
to consult `Proposal #51: GHC base libraries <https://github.com/haskellfoundation/tech-proposals/blob/main/proposals/accepted/051-ghc-base-libraries.rst>`_ for more background and rationale for this library structure.
3039

3140
The question arises of *what module names should be used*. For example, suppose that all three exposed a module called ``Data.Tuple``. In principle that would be fine -- GHC allows you
3241
to use the package name in the ``import`` statement, to disambiguate. But it's *extremely* confusing. This proposal articulates a set of conventions to
@@ -44,22 +53,62 @@ any changes to ``ghc`` or to ``cabal``.
4453
Proposal 1
4554
-----------
4655

47-
* Modules in ``base``, ``ghc-experimental``, ``ghc-prim``, ``ghc-internals`` etc should all have distinct names.
56+
* Modules in ``base``, ``ghc-experimental``, ``ghc-prim``, ``ghc-internal`` etc should all have distinct names.
4857

4958
That principle leads immediately to the question: what should those names be? Hence proposal 2.
5059

5160
Proposal 2
5261
-----------
5362

54-
* Modules in GHC's internal libraries (``ghc-prim``, ``ghc-internals`` etc) should be of form ``GHC.*``.
55-
* Modules in ``ghc-experimental`` should be of form ``Experimental.*``.
56-
* Modules in ``base`` should not have either of these prefixes.
63+
* Modules in GHC's internal libraries (``ghc-prim``, ``ghc-internal`` etc) should be of form ``GHC.Internal*``.
64+
* Modules in ``ghc-experimental`` should be of form ``*.Experimental``.
65+
* Modules in ``base`` should not have either of these forms.
5766

5867
So example we might have
5968

60-
* ``GHC.Tuple`` in ``ghc-internals``,
61-
* ``Experimental.Tuple`` or ``Experimental.Data.Tuple`` in ``ghc-experimental``
62-
* ``Data.Tuple`` in ``base``
69+
* ``GHC.Internal.Bits`` in ``ghc-internal``,
70+
* ``Data.Bits.Experimental`` in ``ghc-experimental``
71+
* ``Data.Bits``, and currently also ``GHC.Bits``, in ``base``
72+
73+
Why ``GHC.Internal.*`` for modules in ``ghc-internal``? Would ``GHC.*`` not be enough? Here's why:
74+
* ``base`` already has ``GHC.Bits``, and Proposal 1 stops us re-using the same module name in ``ghc-internal``.
75+
If we were starting from a blank sheet of paper we might have no ``GHC.*`` modules in ``base``, but there
76+
curently 138 such modules and it seems unlikely that we will ever remove all, or even most, of them from
77+
``base``.
78+
79+
* The prefix ``GHC.Internal`` serves as an additional clue to the importing module that this API is not stable.
80+
81+
Note that among the GHC implementation packages (``ghc-prim``, ``ghc-internal``, ``ghc-bignum`` etc) there
82+
is no expectation that the module name signals which package the module is in. It's just an internal
83+
implementation matter.
84+
85+
Using a prefix for ``ghc-internal`` and a suffix for ``ghc-experimental`` may seem inconsistent,
86+
but it was a clear consensus from the discussion about the proposal:
87+
* ``Data.Tuple.Experimental``, for example, is an companion/extension of ``Data.Tuple``; some exports may move from one to the other. Many developers sort their imports alphabetically. Making this a suffix means all ``Data.Tuple``-related imports are next to each other. For example, one might prefer this::
88+
89+
import Control.Applicative
90+
import Control.Applicative.Experimental
91+
import Control.Arrow
92+
import Data.Tuple
93+
import Foreign.C
94+
import Foreign.C.Experimental
95+
96+
to this::
97+
98+
import Control.Applicative
99+
import Control.Arrow
100+
import Experimental.Control.Applicative
101+
import Experimental.Foreign.C
102+
import Data.Tuple
103+
import Foreign.C
104+
105+
This pattern, of a module in ``ghc-experimental`` that is closely related to one in ``base`` seems likely to be common.
106+
107+
* On the other hand, GHC-internal modules are often unrelated to the naming scheme of ``base``.
108+
Here a prefix feels more appropriate. Moreover this ``GHC.*`` convention is already widely
109+
used, in both ``base`` and ``ghc-prim``, as well as the modules that implement GHC itself, so
110+
using a prefix aligns with current practice.
111+
63112

64113
Proposal 3
65114
-----------
@@ -80,16 +129,26 @@ rather carefully.
80129
Proposal 4
81130
------------
82131

83-
* The public API of package ``ghc`` (GHC as a library) should have modules of form ``GhcAPI.*``.
132+
All of the modules in package ``ghc`` currently start with ``GHC.*`` which
133+
(currently correctly) signals that they are part of GHC's internals.
134+
135+
As part of the GHC API redesign (a HF project in its own right, currently stalled) it would be very helpful
136+
to identify a (multi-module) stable API for package ``ghc``. In that way, users of package ``ghc``
137+
could know whether
138+
they are using a curated, relatively-stable API function, or reaching deep into GHC's guts and using
139+
a random fuction whose name or type, or very existence, might change without warning. Hence:
140+
141+
* The public API of package ``ghc`` (GHC as a library) should have modules whose names clearly distinguish them
142+
from internal modules.
143+
144+
For example, the public API could have modules of form ``GhcAPI.*``, or ``GHC.API.*``, or something else.
145+
The specifica are a matter for the future GHC API working group.
84146

85-
All of the modules in package ``ghc`` currently start with ``GHC.*`` which correctly signals that they are part of GHC's internals.
86-
As part of the GHC API redesign (a HF project in its own right, currently stalled) it would be very helpfult
87-
to modules with stable APIs, and a new prefix, such as ``GhcAPI.*``.
88147

89148

90149
Timescale
91150
==========
92-
The first release of GHC with `ghc-experimental` and `ghc-internals` will be GHC 9.10, which expect to
151+
The first release of GHC with `ghc-experimental` and `ghc-internal` will be GHC 9.10, which expect to
93152
release in early 2024. It would be good to establish naming conventions for modules well before this date.
94153

95154
Example lifecycle
@@ -118,7 +177,7 @@ Alternatives
118177
* In the meantime there are two modules both called ``Data.Tuple``. This is bad. Which one does ``import Data.Tuple`` import? (Look at the Cabal file, perhaps?) How can I import both? (Package-qualified imports perhaps.) So it will really only help in the case of a brand-new module, not already in ``base``.
119178
* It loses the explicit cue, in the source code, given by ``import Experimental.Data.Tuple``.
120179

121-
* We could use ``GHC.*`` for modules in ``ghc-experimental``, and maybe ``GHC.Internals.*`` for module in ``ghc-internals``. But
180+
* We could use ``GHC.*`` for modules in ``ghc-experimental``, and maybe ``GHC.Internals.*`` for module in ``ghc-internal``. But
122181

123182
* There are two sorts of GHC-specific-ness to consider:
124183

@@ -127,14 +186,14 @@ Alternatives
127186

128187
It is worth distinguishing these: it's confusing if both start with ``GHC.``.
129188

130-
* It would be a huge upheaval (with impact on users) to rename hundreds of modules in ``ghc-internals``.
189+
* It would be a huge upheaval (with impact on users) to rename hundreds of modules in ``ghc-internal``.
131190

132-
* We could use ``GHC.Experimental.*`` for modules in ``ghc-experimental``. But that seems a bit backwards: ``GHC.Tuple`` (in ``ghc-internals``) would superficially appear more stable (less experimental) than ``GHC.Experimental.Tuple`` in ``ghc-experimental``; but the reverse is the case.
191+
* We could use ``GHC.Experimental.*`` for modules in ``ghc-experimental``. But that seems a bit backwards: ``GHC.Tuple`` (in ``ghc-internal``) would superficially appear more stable (less experimental) than ``GHC.Experimental.Tuple`` in ``ghc-experimental``; but the reverse is the case.
133192

134193
* We could use a suffix ``*.Internals`` or ``*.Experimental`` instead of a prefix. But
135194

136195
* This sort of naming is often used to distinguish modules *within* a package, not *between* packages.
137-
* In the case of ``ghc-internals`` it would still suffer from the cost of renaming hundreds of modules.
196+
* In the case of ``ghc-internal`` it would still suffer from the cost of renaming hundreds of modules.
138197

139198
* Concerning Proposal 4, we could instead use
140199

0 commit comments

Comments
 (0)