Skip to content

Commit 6ccd02b

Browse files
jappeaceKleidukos
andauthored
Add blogpost on understanding breakage (#26)
* Add blogpost on udnerstadning breakage 🚢🚢🚢 * add jappie * fix the headers * Update content/investigating-lang-ext-semantics/index.md Co-authored-by: Hécate <Kleidukos@users.noreply.github.com> * Update content/investigating-lang-ext-semantics/index.md Co-authored-by: Hécate <Kleidukos@users.noreply.github.com> * Update content/investigating-lang-ext-semantics/index.md Co-authored-by: Hécate <Kleidukos@users.noreply.github.com> * Update content/investigating-lang-ext-semantics/index.md Co-authored-by: Hécate <Kleidukos@users.noreply.github.com> * Update content/investigating-lang-ext-semantics/index.md Co-authored-by: Hécate <Kleidukos@users.noreply.github.com> * Update content/investigating-lang-ext-semantics/index.md Co-authored-by: Hécate <Kleidukos@users.noreply.github.com> * fix diff syntax * add notes on head.hackage * Fix markdown rendere * spacing * Go over again * Fixup some minor errors. nice and thight * fix table 2 * Update content/investigating-lang-ext-semantics/index.md Co-authored-by: Hécate <Kleidukos@users.noreply.github.com> * Update content/investigating-lang-ext-semantics/index.md Co-authored-by: Hécate <Kleidukos@users.noreply.github.com> * Update content/investigating-lang-ext-semantics/index.md Co-authored-by: Hécate <Kleidukos@users.noreply.github.com> * Update content/investigating-lang-ext-semantics/index.md Co-authored-by: Hécate <Kleidukos@users.noreply.github.com> * Update content/investigating-lang-ext-semantics/index.md Co-authored-by: Hécate <Kleidukos@users.noreply.github.com> --------- Co-authored-by: Hécate <Kleidukos@users.noreply.github.com>
1 parent f8a9075 commit 6ccd02b

File tree

1 file changed

+212
-0
lines changed
  • content/investigating-lang-ext-semantics

1 file changed

+212
-0
lines changed
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
+++
2+
title = "Analyzing language extension semantics"
3+
date = 2025-11-26
4+
[taxonomies]
5+
authors = ["Jappie Klooster"]
6+
categories = ["Haskell Foundation"]
7+
tags = ["Community", "Stability"]
8+
+++
9+
10+
Hi I'm [Jappie](https://jappie.me) and I volunteer for the [Haskell Foundation Stability Working Group](https://blog.haskell.org/stability-working-group/).
11+
Recently we analyzed the [head.hackage](https://gitlab.haskell.org/ghc/head.hackage) patches to understand
12+
why code breaks on new GHC releases.
13+
"head.hackage" is a repository of patches for Hackage.
14+
GHC engineers use these to test out new GHC builds on a wide range of
15+
Hackage packages without having to upstream[^upstream] a patch, which can take time.
16+
Instead, they can put the patch in "head.hackage"
17+
and immediately test it on a wide range of packages.
18+
Surprisingly, most breakage wasn’t caused by
19+
[Template Haskell](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/template_haskell.html),
20+
it came from deeper semantic changes in language extensions.
21+
The meaning of (some) language extensions changed between GHC releases.
22+
This post walks through the main categories of breakage,
23+
why they happened, and what they tell us about long-term stability.
24+
If you care about a smoother upgrade path for Haskell users,
25+
we invite you to participate in the [Haskell Foundation Stability Working Group](https://blog.haskell.org/stability-working-group/).
26+
27+
[^upstream]: Upstreaming is the process of sending a patch to the “maintainers” of an open-source project. The maintainers will then make the patch ‘official’ by merging it. In principle, the process is simple, but in practice, the burden of proof (especially for larger projects) is on the person who submitted the patch. They have to convince the maintainers that the patch is useful, which takes time in the form of communication
28+
29+
Extending our initial [investigation](https://jappie.me/analyzing-haskell-stability.html),
30+
We're also interested in understanding *why* breakage occurs.
31+
So we've recently done further analysis on [head.hackage](https://ghc.gitlab.haskell.org/head.hackage/),
32+
and learned surprisingly enough that the root cause
33+
of a lot of breakage isn't Template Haskell,
34+
but seems to be from language extension semantics[^meaning].
35+
We're doing this investigation to understand better where efforts
36+
should be focused in improving stability.
37+
38+
[^meaning]: The precise meaning of features enabled by language extensions. I guess parser changes also count.
39+
40+
This gave us the following table:
41+
42+
| Name | Cause | Had warnings? |
43+
|-------------------------------------|----------------------------------------------|---------------|
44+
| Cabal-2.4.1.0.patch | simplified subsumption | no |
45+
| Cabal-3.0.2.0.patch | simplified subsumption | no |
46+
| Cabal-3.2.1.0.patch | simplified subsumption | no |
47+
| data-r-tree-0.6.0.patch | parser change (see 1) | no |
48+
| drinkery-0.4.patch | simplified subsumption | no |
49+
| ghc-lib-parser-9.8.1.20231121.patch | rename forall identifiers (2) | yes |
50+
| hgeometry-ipe-0.13.patch | Instances moved due to splice enforcement | no |
51+
| singletons-3.0.2.patch | add TypeAbstractions as a language extension | yes |
52+
| singletons-base-3.1.1.patch | add TypeAbstractions as a language extension | yes |
53+
| vector-space-0.16.patch | Star is type (4) | yes |
54+
55+
`th-compat-0.1.4.patch` was miscounted so I left that out.
56+
Simplified subsumption appears a lot but 3 are for Cabal,
57+
so it's only 2 real occurrences.
58+
I'd expect that to appear a lot however,
59+
because it was one of *the* motivating changes for a [stability working group](https://blog.haskell.org/stability-working-group/).
60+
61+
## Simplified subsumption
62+
For the blissfully ignorant reader simplified subsumption causes you
63+
to do this under certain existential conditions:
64+
```diff
65+
--- a/Distribution/Simple/Utils.hs
66+
+++ b/Distribution/Simple/Utils.hs
67+
@@ -1338,7 +1338,7 @@ withTempFileEx opts tmpDir template action =
68+
(\(name, handle) -> do hClose handle
69+
unless (optKeepTempFiles opts) $
70+
handleDoesNotExist () . removeFile $ name)
71+
- (withLexicalCallStack (uncurry action))
72+
+ (withLexicalCallStack (\x -> uncurry action x))
73+
74+
```
75+
You have to insert a lambda, which apparently has some performance impact.
76+
This had a big impact on [Yesod stacks](https://www.yesodweb.com/book),
77+
whose code generation helpfully created
78+
the database alias in the template:
79+
```haskell
80+
type DB a = forall (m :: Type -> Type).
81+
(MonadUnliftIO m) => ReaderT SqlBackend m a
82+
```
83+
84+
Normally this is quite convenient,
85+
however with the simplified subsumption change,
86+
any code that interacts with the database now has to insert those lambdas.
87+
As you can imagine this would in many places for a commercial code base.
88+
Causing a lot of compile errors for industrial users.
89+
Instead of inserting lambdas, you can also delete those existential aliases to solve the problem.
90+
Or you can enable the language extension: [DeepSubsumption](https://downloads.haskell.org/~ghc/9.12.2/docs/users_guide/exts/rank_polymorphism.html#extension-DeepSubsumption).
91+
Which restores the original behavior.
92+
93+
## Moving of instances due to Template Haskell
94+
This change forces you to put the instances above the splice where
95+
they are being used in the same module.
96+
A dear colleague decided to generate instances in Template Haskell.
97+
That was quite the puzzle!
98+
I asked the GHC devs why they did this,
99+
and it turns out this was a soundness issue in the typechecker.
100+
Here, soundness means the type system can't be tricked into allowing invalid programs.
101+
So the community is better off, despite this causing a fair bit of work.
102+
103+
```diff
104+
--- a/src/Ipe/Content.hs
105+
+++ b/src/Ipe/Content.hs
106+
@@ -288,6 +288,14 @@
107+
108+
+instance Fractional r => IsTransformable (IpeObject r) where
109+
+ transformBy t (IpeGroup i) = IpeGroup $ i&core %~ transformBy t
110+
+ ...
111+
makePrisms ''IpeObject
112+
113+
@@ -303,14 +311,6 @@
114+
115+
-instance Fractional r => IsTransformable (IpeObject r) where
116+
- transformBy t (IpeGroup i) = IpeGroup $ i&core %~ transformBy t
117+
- ...
118+
```
119+
120+
## (1) Parser change
121+
122+
The parser is the component of the compiler that transforms text
123+
into a memory structure the compiler can work with.
124+
This structure is called an abstract syntax tree.
125+
126+
```diff
127+
- Node4 {getMBB :: {-# UNPACK #-} ! MBB, getC1 :: ! (RTree a), getC2 :: ! (RTree a), getC3 :: ! (RTree a), getC4 :: ! (RTree a) }
128+
- | Node3 {getMBB :: {-# UNPACK #-} ! MBB, getC1 :: ! (RTree a), getC2 :: ! (RTree a), getC3 :: ! (RTree a) }
129+
- | Node2 {getMBB :: {-# UNPACK #-} ! MBB, getC1 :: ! (RTree a), getC2 :: ! (RTree a) }
130+
+ Node4 {getMBB :: {-# UNPACK #-} !MBB, getC1 :: !(RTree a), getC2 :: !(RTree a), getC3 :: !(RTree a), getC4 :: !(RTree a) }
131+
+ | Node3 {getMBB :: {-# UNPACK #-} !MBB, getC1 :: !(RTree a), getC2 :: !(RTree a), getC3 :: !(RTree a) }
132+
+ | Node2 {getMBB :: {-# UNPACK #-} !MBB, getC1 :: !(RTree a), getC2 :: !(RTree a) }
133+
| Node {getMBB :: MBB, getChildren' :: [RTree a] }
134+
- | Leaf {getMBB :: {-# UNPACK #-} ! MBB, getElem :: a}
135+
+ | Leaf {getMBB :: {-# UNPACK #-} !MBB, getElem :: a}
136+
| Empty
137+
138+
```
139+
140+
This is a change from all the way back in 2020, where the *core* language changed by
141+
disallowing `!` before parens.
142+
Here the bang `!` indicates strict fields.
143+
Technically this doesn't fit into the category
144+
because the core language isn't a language extension.
145+
But semantics did change!
146+
Actually I don't think we expected to find something like this at all.
147+
I'm not sure how relevant this is to discuss further because it appears
148+
quite rare for someone to do this.
149+
You can enable [StrictData](https://downloads.haskell.org/ghc/latest/docs/users_guide/exts/strict.html#extension-StrictData)
150+
in your Cabal file and delete all those bangs!
151+
152+
## (2) Rename forall identifiers
153+
This changes the forall identifier into a keyword at term level.
154+
It already was at the type level.
155+
The issue is discussed [here](https://gitlab.haskell.org/ghc/ghc/-/issues/23719)
156+
157+
```diff
158+
hintExplicitForall :: Located Token -> P ()
159+
hintExplicitForall tok = do
160+
- forall <- getBit ExplicitForallBit
161+
+ forAll <- getBit ExplicitForallBit
162+
rulePrag <- getBit InRulePragBit
163+
- unless (forall || rulePrag) $ addError $ mkPlainErrorMsgEnvelope (getLoc tok) $
164+
+ unless (forAll || rulePrag) $ addError $ mkPlainErrorMsgEnvelope (getLoc tok) $
165+
(PsErrExplicitForall (isUnicode tok))
166+
```
167+
168+
## (3) TypeAbstractions
169+
170+
From what I understand from the [manual](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/type_abstractions.html#type-abstractions)
171+
is that part of the syntax for type abstractions landed in GHC 9.2,
172+
however 9.8 and onwards requires you to enable this language extension.
173+
This appeared because certain new functionality was introduced behind an
174+
old language extension flag, according to [this proposal](https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0448-type-variable-scoping.rst#4type-arguments-in-constructor-patterns). It says we don't want to introduce new functionality behind established extensions,
175+
so that's why we require TypeAbstractions now,
176+
where previously ScopedTypeVariables and TypeApplications were enough.
177+
178+
This extension enables you to bind type variables in pattern matches.
179+
I don't know why this happened like this, but it happened in 2023:
180+
181+
```diff
182+
+-- Invisible type binders in type declarations, such as
183+
+--
184+
+-- type family Sing @k
185+
+--
186+
+-- require the TypeAbstractions extension.
187+
+#if __GLASGOW_HASKELL__ >= 909
188+
+{-# LANGUAGE TypeAbstractions #-}
189+
+#endif
190+
+
191+
```
192+
193+
## (4) Star is type
194+
This change was announced via a warning.
195+
It tells users to write `Type` instead of `*` for kinds representing types.
196+
A kind is essentially the type of a type,
197+
and as a concept is used for type-level programming type safety.
198+
199+
```diff
200+
- type Basis v :: *
201+
+ type Basis v :: Type
202+
```
203+
204+
## Conclusion
205+
206+
Often these breakages are annoying and frustrating.
207+
But if we look deeper, we find that each of them has
208+
a little story
209+
and good reasons for being introduced.
210+
If you find this all as interesting as I do,
211+
please consider joining some of the stability
212+
working group meetings!

0 commit comments

Comments
 (0)