Skip to content

Commit 75d94e6

Browse files
Merge pull request #427 from HugoPeters1024/GHC-55666
document GHC-55666
2 parents b85a812 + 41d47c7 commit 75d94e6

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{-# LANGUAGE MagicHash #-}
2+
3+
module Bang_on_unlifted_type where
4+
5+
import GHC.Base (Int#)
6+
7+
data T = MkT Int#
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{-# LANGUAGE MagicHash #-}
2+
3+
module Bang_on_unlifted_type where
4+
5+
import GHC.Base (Int#)
6+
7+
data T = MkT !Int#
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: Bang (!) on unlifted type
3+
---
4+
5+
```
6+
src/MyLib.hs:16:5: warning: [GHC-55666] [-Wredundant-strictness-flags]
7+
* Strictness flag has no effect on unlifted type `Int#'
8+
* In the definition of data constructor `MkT'
9+
In the data type declaration for `T'
10+
|
11+
| = MkT !Int#
12+
| ^^^^^^^
13+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: Strictness annotation on unlifted type
3+
summary: Using a strictness annotation (bang) on an unlifted type is redudant as unlifted values are strict by definition
4+
severity: warning
5+
flag: -Wredundant-strictness-flags
6+
introduced: GHC 9.6.1
7+
---
8+
9+
A strictness annotation (also called a bang: `!`) can be used to denote that a value should not be evaluated lazily.
10+
In some cases this can lead to faster code because fewer heap allocations are required.
11+
Here it is used to mark a that a field in a datatype should not be evaluated lazily.
12+
13+
However, values of unlifted types like `Int#` are strict by definition because they represent an actual value,
14+
not a pointer to a potentially unevaluated value (thunk).
15+
16+
Therefore, adding strictness annotations to unlifted types or fields of such types is redundant.
17+
They should be omitted to avoid confusion.

0 commit comments

Comments
 (0)