Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refcount: define macro-constraint HasCallStackIfDebug #495

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src-control/Control/RefCount.hs
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ class RefCounted obj where
getRefCounter :: obj -> RefCounter (FinaliserM obj)

#ifdef NO_IGNORE_ASSERTS
#define HAS_CALL_STACK => HasCallStack
#define HasCallStackIfDebug HasCallStack
#else
#define HAS_CALL_STACK
#define HasCallStackIfDebug ()
#endif
Comment on lines 202 to 206
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the all-caps macros because it makes it clear that it is not actual haskell syntax

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you feel that with the all-caps name, this is an improvement?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is, of course, the risk that this is highly dependent on what is arguably a GHC bug.


-- GHC says specialising is too complicated! But it's ok, each of these can
Expand All @@ -219,7 +219,7 @@ class RefCounted obj where
--
newRef ::
(RefCounted obj, FinaliserM obj ~ m, PrimMonad m)
HAS_CALL_STACK
=> HasCallStackIfDebug
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason that this does not throw a warning?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the looks of it, GHC combines successive constraint arrows, so by the time it reaches the warning subsystem, (A, B) => () => x has turned into (A, B) => x by concatenation, whereas it does no other normalisation, so (A, B, ()) => x remains unchanged.

=> m ()
-> (RefCounter m -> obj)
-> m (Ref obj)
Expand All @@ -234,7 +234,7 @@ newRef finaliser mkObject = do
--
releaseRef ::
(RefCounted obj, FinaliserM obj ~ m, PrimMonad m, MonadMask m)
HAS_CALL_STACK
=> HasCallStackIfDebug
=> Ref obj
-> m ()
releaseRef ref@Ref{refobj} = do
Expand Down Expand Up @@ -268,7 +268,7 @@ deRef ref@Ref{refobj} =
withRef ::
forall m obj a.
PrimMonad m
HAS_CALL_STACK
=> HasCallStackIfDebug
=> Ref obj
-> (obj -> m a)
-> m a
Expand All @@ -280,7 +280,7 @@ withRef ref@Ref{refobj} f = do
--
dupRef ::
(RefCounted obj, FinaliserM obj ~ m, PrimMonad m)
HAS_CALL_STACK
=> HasCallStackIfDebug
=> Ref obj
-> m (Ref obj)
dupRef ref@Ref{refobj} = do
Expand Down Expand Up @@ -313,7 +313,7 @@ mkWeakRefFromRaw obj = WeakRef obj
--
deRefWeak ::
(RefCounted obj, FinaliserM obj ~ m, PrimMonad m)
HAS_CALL_STACK
=> HasCallStackIfDebug
=> WeakRef obj
-> m (Maybe (Ref obj))
deRefWeak (WeakRef obj) = do
Expand Down
Loading