You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: proposals/0000-ghc-module-naming.rst
+81-22Lines changed: 81 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,26 +7,35 @@ Background and motivation
7
7
The accepted `Proposal #51: GHC base libraries <https://github.com/haskellfoundation/tech-proposals/blob/main/proposals/accepted/051-ghc-base-libraries.rst>`_
8
8
defines the following libraries:
9
9
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.
12
12
* 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.
13
15
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
* 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.
18
21
19
22
* It is user-facing (user are encouraged to depend on it), but its API is less stable than ``base``.
20
23
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.
* Define functions and data types used internally by GHC to support the API of ``base`` and ``ghc-experimental``.
22
30
23
31
* These libraries come with no stability guarantees: they may change at short notice.
24
32
25
33
In addition we already have:
26
34
27
35
* ``ghc``: this library exposes GHC as a library, through the (currently ill-defined) GHC API.
28
36
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.
30
39
31
40
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
32
41
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``.
44
53
Proposal 1
45
54
-----------
46
55
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.
48
57
49
58
That principle leads immediately to the question: what should those names be? Hence proposal 2.
50
59
51
60
Proposal 2
52
61
-----------
53
62
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.
57
66
58
67
So example we might have
59
68
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
+
63
112
64
113
Proposal 3
65
114
-----------
@@ -80,16 +129,26 @@ rather carefully.
80
129
Proposal 4
81
130
------------
82
131
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.
84
146
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.*``.
88
147
89
148
90
149
Timescale
91
150
==========
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
93
152
release in early 2024. It would be good to establish naming conventions for modules well before this date.
94
153
95
154
Example lifecycle
@@ -118,7 +177,7 @@ Alternatives
118
177
* 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``.
119
178
* It loses the explicit cue, in the source code, given by ``import Experimental.Data.Tuple``.
120
179
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
122
181
123
182
* There are two sorts of GHC-specific-ness to consider:
124
183
@@ -127,14 +186,14 @@ Alternatives
127
186
128
187
It is worth distinguishing these: it's confusing if both start with ``GHC.``.
129
188
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``.
131
190
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.
133
192
134
193
* We could use a suffix ``*.Internals`` or ``*.Experimental`` instead of a prefix. But
135
194
136
195
* 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.
0 commit comments