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

Index out of range when the observed function throws an error #5

Closed
igrep opened this issue Mar 26, 2017 · 2 comments · Fixed by #6

Comments

@igrep
Copy link
Contributor

commented Mar 26, 2017

Problem

Index out of range error thrown by eventsToCDS's array function call when the observed function pattern-matches on a value whose type is Generic-derived-Observable instance throws an error.

Minimum program to reproduce

#!/usr/bin/env stack
{-# LANGUAGE DeriveGeneric #-}
-- stack --resolver lts-8.4 runghc --package hood

import           Debug.Hood.Observe
import           GHC.Generics


data Hoge =
  Hoge
    { hoge1 :: Int
    , hoge2 :: String
    } deriving Generic

instance Observable Hoge


main :: IO ()
main = runO $ print $ f undefined


f :: Hoge -> Bool
f = observe "f" f'
f' :: Hoge -> Bool
f' h@(Hoge _h1 _h2) = error "ERROR"

And here's the output:

[Escaping Exception in Code : Prelude.undefined
CallStack (from HasCallStack):
  error, called at libraries\base\GHC\Err.hs:79:14 in base:GHC.Err
  undefined, called at hood-error-case.hs:19:25 in main:Main]

hood-error-case.exe: Ix{Int}.index: Index (12) out of range ((0,11))
@igrep

This comment has been minimized.

Copy link
Contributor Author

commented Mar 26, 2017

According to my debug code, the Index (12) out of range ((0,11)) error happens because one of the generated node ids is skipped (maybe by the exception) without getting counted as an event by sendEvent.

I'm going to investigate its more detailed cause and fix it.
Do you have any idea on the cause or the solution?

@andygill

This comment has been minimized.

Copy link
Member

commented Mar 26, 2017

Thanks for finding this, and the test case. I think that we need to catch exceptions when we are ignoring them.

igrep added a commit to igrep/hood that referenced this issue Apr 9, 2017
igrep added a commit to igrep/hood that referenced this issue Apr 9, 2017
…rows an Exception

Fix ku-fpg#5 by incrementing the node id **only when the function is executed without exception**

Notes on Thread-Safety
====

This change would make hood less thread-safe because it doesn't lock `uniqSem` when reading anymore.
But IMO hood needs much more changes to be truly thread-safe
(for example, save the event stream and node id counter in thread-local variable)
So I think lowering the thread-safety by this change isn't be a big problem.
@andygill andygill closed this in #6 Apr 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.