[GHC] #8628: dynCompileExpr breaks repeated runDecls of the same name

#8628: dynCompileExpr breaks repeated runDecls of the same name ------------------------------------+------------------------------------- Reporter: agibiansky | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHC API | Version: 7.6.3 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- Using `dynCompileExpr` with `runDecls` from `InteractiveEval` seems to be incredibly problematic when evaluating declarations for the same name. For instance, consider the following code: {{{ runDecls "data X = Y Int" gtry $ runStmt "print (Y 3)" RunToCompletion :: GhcMonad m => m (Either SomeException RunResult) runDecls "data X = Y Int deriving Show" runStmt "print (Y 8)" RunToCompletion }}} As expected, this prints `Y 8` once (the first one fails because `X` is not an instance of `Show`). However, if we insert an arbitrary `dynCompileExpr`, things begin to break: {{{ runDecls "data X = Y Int" gtry $ runStmt "print (Y 3)" RunToCompletion :: GhcMonad m => m (Either SomeException RunResult) runDecls "data X = Y Int deriving Show" _ <- dynCompileExpr "'x'" runStmt "print (Y 8)" RunToCompletion }}} We then get: {{{ No instance for (GHC.Show.Show :Interactive.X) arising from a use of `System.IO.print' Possible fix: add an instance declaration for (GHC.Show.Show :Interactive.X) }}} Which is clearly incorrect - we haven't done anything to change the data declaration. I'm not sure what's going on, but I've tried to investigate into the source of `dynCompileExpr`. It loads `Data.Dynamic` via a `setContext` and then unloads it, and that may be the issue. If we do the following (very similar to the `dynCompileExpr` source), things work fine: {{{ runDecls "data X = Y Int" gtry $ runStmt "print (Y 3)" RunToCompletion :: GhcMonad m => m (Either SomeException RunResult) runDecls "data X = Y Int deriving Show" let stmt = "let __expr = 'x'" Just (ids, hval, fixenv) <- withSession $ \hsc_env -> liftIO $ hscStmt hsc_env stmt vals <- liftIO (unsafeCoerce hval :: IO [Char]) liftIO $ print vals -- thish prints "x", as expected runStmt "print (Y 8)" RunToCompletion }}} I have not tested with GHC API other than 7.6.3, and could not find a bug that was similar to this. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8628 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8628: dynCompileExpr breaks repeated runDecls of the same name
-------------------------------------+------------------------------------
Reporter: agibiansky | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: GHC API | Version: 7.6.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: Unknown/Multiple
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+------------------------------------
Comment (by Simon Peyton Jones

#8628: dynCompileExpr breaks repeated runDecls of the same name
-------------------------------------+------------------------------------
Reporter: agibiansky | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: GHC API | Version: 7.6.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: Unknown/Multiple
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+------------------------------------
Comment (by Simon Peyton Jones

#8628: dynCompileExpr breaks repeated runDecls of the same name -------------------------------------+------------------------------------ Reporter: agibiansky | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: GHC API | Version: 7.6.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: ghc-api/T8628 | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by simonpj): * status: new => closed * testcase: => ghc-api/T8628 * resolution: => fixed Comment: Good example. Fixed! Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8628#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8628: dynCompileExpr breaks repeated runDecls of the same name -------------------------------------+------------------------------------ Reporter: agibiansky | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: GHC API | Version: 7.6.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: ghc-api/T8628 | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by agibiansky): Simon, The same thing happens with `setContext` instead of `dynCompileExpr`. Does the fix correct that issue as well? (And do you know how I might work around this in the meantime? Is there something else I can use instead of `setContext`, or modify the `setContext` source somehow, to make it work?) Andrew -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8628#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8628: dynCompileExpr breaks repeated runDecls of the same name -------------------------------------+------------------------------------ Reporter: agibiansky | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: GHC API | Version: 7.6.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: ghc-api/T8628 | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by simonpj): I think so, but we won't know for sure until we try it. Maybe you can try? I don't know what a good workaround might be. I'm expecting a release candidate for 7.8 any day now, so you can use that. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8628#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8628: dynCompileExpr breaks repeated runDecls of the same name -------------------------------------+------------------------------------ Reporter: agibiansky | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: GHC API | Version: 7.6.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: ghc-api/T8628 | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by agibiansky): Alright, thanks. Looking at the source it seems like the same issue, as it uses `icPlusGblRdrEnv`. I'll try it on 7.8 RC when it's out, I guess. Thanks! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8628#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC