Skip to content

Commit 8f6f1c9

Browse files
authored
Merge pull request #33 from input-output-hk/coot/records-and-threadid
Added record name to ctx & ThreadId instance
2 parents 0065368 + 262f604 commit 8f6f1c9

File tree

5 files changed

+53
-4
lines changed

5 files changed

+53
-4
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,22 @@ jobs:
3636
- run: cabal test $CONFIG
3737
- run: cabal haddock $CONFIG
3838
- run: cabal sdist
39+
40+
check-changelogs:
41+
name: Check changelogs
42+
runs-on: ubuntu-latest
43+
defaults:
44+
run:
45+
shell: bash
46+
47+
steps:
48+
- name: Install dependencies
49+
run: sudo apt install -y fd-find
50+
51+
- uses: actions/checkout@v3
52+
53+
- name: git fetch
54+
run: git fetch origin master:master
55+
56+
- name: Check changelogs
57+
run: ./scripts/check-changelogs.sh

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Revision history for nothunks
22

3+
## next version
4+
5+
* `NoThunks ThreadId` instance
6+
37
## 0.1.4 -- 2023-03-27
48

59
* Made cabal flags manual.

scripts/check-changelogs.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
FD="$(which fdfind 2>/dev/null || which fd 2>/dev/null)"
4+
5+
set -eo pipefail
6+
7+
function check_project () {
8+
project=$1
9+
n=$()
10+
if [[ -n $(git diff --name-only origin/master..HEAD -- $project) ]];then
11+
if [[ -z $(git diff --name-only origin/master..HEAD -- $project/CHANGELOG.md) ]]; then
12+
echo "$project was modified but its CHANGELOG was not updated"
13+
exit 1
14+
fi
15+
fi
16+
}
17+
18+
for cbl in $($FD -e 'cabal'); do
19+
check_project $(dirname $cbl)
20+
done
21+

src/NoThunks/Class.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import GHC.Exts.Heap
4343
import GHC.Generics
4444
import GHC.Records
4545
import GHC.TypeLits
46+
import GHC.Conc.Sync (ThreadId (..))
4647

4748
-- For instances
4849

@@ -427,10 +428,12 @@ instance GWNoThunks a V1 where
427428
-------------------------------------------------------------------------------}
428429

429430
-- | If @fieldName@ is allowed to contain thunks, skip it.
430-
instance GWRecordField f (Elem fieldName a)
431+
instance ( GWRecordField f (Elem fieldName a)
432+
, KnownSymbol fieldName
433+
)
431434
=> GWNoThunks a (S1 ('MetaSel ('Just fieldName) su ss ds) f) where
432435
gwNoThunks _ ctxt (M1 fp) =
433-
gwRecordField (Proxy @(Elem fieldName a)) ctxt fp
436+
gwRecordField (Proxy @(Elem fieldName a)) (symbolVal @fieldName Proxy : ctxt) fp
434437

435438
class GWRecordField f (b :: Bool) where
436439
gwRecordField :: proxy b -> Context -> f x -> IO (Maybe ThunkInfo)
@@ -640,6 +643,8 @@ instance NoThunks a => NoThunks (NonEmpty a)
640643

641644
instance (NoThunks a, NoThunks b) => NoThunks (Either a b)
642645

646+
deriving via InspectHeap ThreadId instance NoThunks ThreadId
647+
643648
{-------------------------------------------------------------------------------
644649
Spine-strict container types
645650

test/Test/NoThunks/Class.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,13 @@ instance FromModel (AllowThunksIn '["field1"] Record) where
333333

334334
modelIsNF ctxt = \case
335335
RecordThunk _ -> NotWHNF ctxt'
336-
RecordDefined a b -> constrNF [modelIsNF ctxt' a, modelIsNF ctxt' b]
336+
RecordDefined a b -> constrNF [modelIsNF ("field1" : ctxt') a, modelIsNF ("field2" : ctxt') b]
337337
where
338338
ctxt' = "Record" : ctxt
339339

340340
modelUnexpected ctxt = \case
341341
RecordThunk _ -> Just ctxt'
342-
RecordDefined _ y -> modelUnexpected ctxt' y
342+
RecordDefined _ y -> modelUnexpected ("field2" : ctxt') y
343343
where
344344
ctxt' = "Record" : ctxt
345345

0 commit comments

Comments
 (0)