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

Segmentation fault on OS X #3

Closed
lapplislazuli opened this issue May 7, 2021 · 10 comments
Closed

Segmentation fault on OS X #3

lapplislazuli opened this issue May 7, 2021 · 10 comments
Labels
Bug Something isn't working

Comments

@lapplislazuli
Copy link
Collaborator

Trying to run it on my macbook gives me the following:

(base) TUD500590:HenProg lapplis$ cabal run henprog -- tests/BrokenModule.hs
Resolving dependencies...
Up to date
TARGET:
  `broken` in tests/BrokenModule.hs
SCOPE:
  import Prelude hiding (id, ($), ($!), asTypeOf)
TARGET TYPE:
  [Int] -> Int
MUST SATISFY:
  prop'_isSum broken xs = broken xs == sum xs
IN CONTEXT:
  prop_isSum :: [Int] -> Bool
  broken :: [Int] -> Int
  add :: Int -> Int -> Int
  main :: IO ()
  prop_isSum xs = broken xs == sum xs
  broken = foldl (-) 0
  add = (+)
  main = print "Unrelated main function"
PARAMETERS:
  MAX HOLES: 2
  MAX DEPTH: 1
PROGRAM TO REPAIR: 
let
  broken :: [Int] -> Int
  broken = foldl (-) 0
in broken
REPAIRING...
Segmentation fault: 11
~/HenProg lapplis$ cabal run henprog -- tests/BrokenGCD.hs
Up to date
TARGET:
  `gcd'` in tests/BrokenGCD.hs
SCOPE:
  import Prelude hiding (id, ($), ($!), asTypeOf)
TARGET TYPE:
  Int -> Int -> Int
MUST SATISFY:
  prop'_1 gcd' = gcd' 0 55 == 55
  prop'_2 gcd' = gcd' 1071 1029 == 21
  prop'_3 gcd' a b = gcd' (abs a) (abs b) == gcd (abs a) (abs b)
IN CONTEXT:
  add :: Int -> Int -> Int
  zero :: Int
  one :: Int
  gcd' :: Int -> Int -> Int
  main :: IO ()
  add = (+)
  zero = 0
  one = 1
  prop_1 = gcd' 0 55 == 55
  prop_2 = gcd' 1071 1029 == 21
  prop_3 a b = gcd' (abs a) (abs b) == gcd (abs a) (abs b)
  gcd' 0 b = gcd' 0 b
gcd' a b | b == 0 = a
gcd' a b = if (a > b) then gcd' (a - b) b else gcd' a (b - a)
  main = print "Unrelated main function"
PARAMETERS:
  MAX HOLES: 2
  MAX DEPTH: 1
PROGRAM TO REPAIR: 
let
  gcd' :: Int -> Int -> Int
  gcd' 0 b = gcd' 0 b
  gcd' a b | b == 0 = a
  gcd' a b = if (a > b) then gcd' (a - b) b else gcd' a (b - a)
in gcd'
REPAIRING...
Segmentation fault: 11

I get the same issue with the BrokenModule.hs.

I installed QuickCheck Manually beforehand doing cabal install --lib QuickCheck.

Altering the command to cabal run henprog -- tests/BrokenModule.hs -fdebug or cabal run henprog -- -fdebug tests/BrokenModule.hs does not produce additional output.

GHC: 8.10.1
Cabal: 3.2.0.0
MacOS: Big Sur 13.1.1

@lapplislazuli lapplislazuli added the Bug Something isn't working label May 7, 2021
@Tritlo
Copy link
Owner

Tritlo commented May 7, 2021 via email

@lapplislazuli
Copy link
Collaborator Author

Here is the Debug Log
HenProgDebug.log

My guts tell me it's somewhere with the Caching.

@Tritlo
Copy link
Owner

Tritlo commented May 18, 2021

@lapplislazuli that file just contains "Up to date"... maybe you only redirected the error output? I need the stdout as well.

@lapplislazuli
Copy link
Collaborator Author

That's funny actually, sorry. Seems that when I pipe it > henprog.log it just puts the cabal output there.

here is the actual output:

 cabal run henprog -- tests/BrokenModule.hs --log=debug

Leads to:

Up to date
TARGET:
  `broken` in tests/BrokenModule.hs
SCOPE:
  import Prelude hiding (id, ($), ($!), asTypeOf)
TARGET TYPE:
  [Int] -> Int
MUST SATISFY:
  prop'_isSum broken xs = broken xs == sum xs
IN CONTEXT:
  prop_isSum :: [Int] -> Bool
  broken :: [Int] -> Int
  add :: Int -> Int -> Int
  main :: IO ()
  prop_isSum xs = broken xs == sum xs
  broken = foldl (-) 0
  add = (+)
  main = print "Unrelated main function"
PARAMETERS:
  MAX HOLES: 2
  MAX DEPTH: 1
PROGRAM TO REPAIR: 
let
  broken :: [Int] -> Int
  broken = foldl (-) 0
in broken
REPAIRING...
AUDIT: 79ms
DEBUG:   (let
     broken :: [Int] -> Int
     broken = foldl (-) 0
   in broken) ::
    [Int] -> Int
DEBUG: [(<no location info>, _<no location info>),
 (<no location info>, _<no location info> :: [Int] -> Int),
 (<no location info>, (_<no location info>) :: [Int] -> Int),
 (tests/BrokenModule.hs:8:10-20,
    (let
       broken :: [Int] -> Int
       broken = _8_10_21
     in broken) ::
      [Int] -> Int),
 (tests/BrokenModule.hs:8:10-18,
    (let
       broken :: [Int] -> Int
       broken = _8_10_19 0
     in broken) ::
      [Int] -> Int),
 (tests/BrokenModule.hs:8:10-14,
    (let
       broken :: [Int] -> Int
       broken = _foldl8_10_15 (-) 0
     in broken) ::
      [Int] -> Int),
 (tests/BrokenModule.hs:8:16-18,
    (let
       broken :: [Int] -> Int
       broken = foldl _-8_16_19 0
     in broken) ::
      [Int] -> Int),
 (tests/BrokenModule.hs:8:20,
    (let
       broken :: [Int] -> Int
       broken = foldl (-) _8_20_21
     in broken) ::
      [Int] -> Int),
 (<no location info>,
    (let
       broken :: [Int] -> Int
       broken = foldl (-) 0
     in _broken<no location info>) ::
      [Int] -> Int)]
Segmentation fault: 11

@Tritlo
Copy link
Owner

Tritlo commented May 18, 2021

Hmm, maybe. Could you try and add some logStr "HERE" to track down where exactly it happens? It's a bit hard for me to figure out, since I can't run it on a Mac.

@lapplislazuli
Copy link
Collaborator Author

These are the last parts it touches before the segfault.

https://github.com/Tritlo/HenProg/blob/2ad47d80aa7f7576325d6e5cbf6a1f6372f2e334/src/Synth/Eval.hs#L153-L187

I tried to get more info by adding
let p = unsafePerformIO $ logStr DEBUG "Ping" but I can't see them, is that an error on my side? How can I get more info from in there?

@Tritlo
Copy link
Owner

Tritlo commented May 21, 2021 via email

@Tritlo Tritlo changed the title Segmentation Fault Segmentation fault on OS X May 21, 2021
@lapplislazuli
Copy link
Collaborator Author

Ok so I had another look at it, and the InitGhcCtxt' is run 3 times (fully succesfull, atleast every marks are run) and then it fails further upstream. It also persists in the improved-genetic-parts branch, so I'll be looking there for it.

the trace goes

main -> genetic search -> initialpopulation -> repairattempt -> Either ( failingProps) or (collectStats)

In collect stats, it does weird stuff

"instrumented" CollectStats

collectStats :: (MonadIO m, HasCallStack) => m a -> m a
collectStats a = do
  liftIO $ putStrLn "1"
  (t, r) <- time a
  liftIO $ putStrLn "2"
  let ((_, GHS.SrcLoc {..}) : _) = getCallStack callStack
  liftIO $ putStrLn "3"
  liftIO $ modifyIORef statsRef (Map.insertWith (+) (srcLocFile, srcLocStartLine) t)
  liftIO $ putStrLn "4"
  withFrozenCallStack $ liftIO $ logStr AUDIT (showTime t)
  liftIO $ putStrLn "5"
  return r

output

[... as above...]
REPAIRING...
1
2
3
4
5
1
1
Segmentation fault: 11

Another place is

-- | Returns the props that fail for the given program
failingProps :: CompileConfig -> EProblem -> IO [EProp]
failingProps _ EProb {e_props = []} = return []
-- Our method for checking which props fail is restricted to maximum 8 at a time,
-- so if we have more than that, we check the first 8 and then the rest, and
-- so on.
failingProps cc rp@EProb {e_props = ps} | length ps > 8 = do
  putStrLn "A1"
  let (ps1, ps2) = splitAt 8 ps
  putStrLn "B1"
  p1 <- failingProps cc rp {e_props = ps1}
  putStrLn "C1"
  p2 <- failingProps cc rp {e_props = ps2}
  putStrLn "D1"
  return (p1 ++ p2)
failingProps cc ep@EProb {..} = do

  putStrLn "A2"
  let cc' = (cc {hole_lvl = 0, importStmts = checkImports ++ importStmts cc})
      check = buildSuccessCheck ep
  putStrLn "B2"
  [compiled_check] <- compileParsedChecks cc' [check]

  putStrLn "C2"
  ran <- runCheck compiled_check
  putStrLn "D2"
  case ran of
    -- Some of the props are failing:
    Left p -> return $ map fst $ filter (\(p, c) -> not c) $ zip e_props p
    -- None of the props are failing:
    Right True -> return []
    -- One of the props is causing an error/infinite loop, so we need
    -- to check each individually
    Right False ->
      case e_props of
        -- If there's only one failing prop left, that's the one causing
        -- the loop
        [prop] -> return [prop]
        -- Otherwise, we split the props into two sets, and check each
        -- split individually.
        xs -> do
          let fp :: [EProp] -> IO [EProp]
              fp ps = failingProps cc ep {e_props = ps}
              ps1, ps2 :: [EProp]
              (ps1, ps2) = splitAt (length e_props `div` 2) e_props
          concat <$> mapM fp [ps1, ps2]

Which leads to (with the one above)

[... as above...]
REPAIRING...
1
2
3
4
5
1
1
A2
B2
Segmentation fault: 11

@lapplislazuli
Copy link
Collaborator Author

lapplislazuli commented Jun 25, 2021

Oh wow, my google fu is strong today.
I just ran

cabal configure --enable-optimization --enable-executable-dynamic 

in project root after reading this bug haskell/haskell-language-server#469 .
It works now, finding solutions and being nice.

let's close this after adding something about it in the Readme.

lapplislazuli added a commit that referenced this issue Jun 25, 2021
…ode from main. Added a log-output for terminating due to time.
@lapplislazuli
Copy link
Collaborator Author

We made a remark in the README and in the Relase - should be good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants