[GHC] #14994: ghc api: `load LoadAllTargets` is not idempotent

#14994: ghc api: `load LoadAllTargets` is not idempotent -------------------------------------+------------------------------------- Reporter: int-e | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHC API | Version: 8.4.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- While trying to adapt `hint` for ghc 8.4.1, I've encountered the following phenomenon where an extra `load LoadAllTargets` line causes errors. {{{#!hs -- warning: the code below creates files A.hs and B.hs in the current working directory import System.Directory import Control.Monad.IO.Class import GHCi.RemoteTypes import GHC.Paths -- cf. the ghc-paths package import Unsafe.Coerce main = do writeFile "A.hs" "module Ahidden(a) where { a :: Int; a = 42 }" let mod_nameA = mkModuleName "Ahidden" mod_targetA = Target (TargetFile "A.hs" Nothing) False Nothing runGhc (Just libdir) $ do -- setup df0 <- getSessionDynFlags (df1, _, _) <- parseDynamicFlags df0 [] setSessionDynFlags df1{ ghcMode = CompManager, hscTarget = HscInterpreted, ghcLink = LinkInMemory, verbosity = 0 } -- context : *X setTargets [mod_targetA] load LoadAllTargets load LoadAllTargets -- this line causes the next line to fail setContext [IIModule mod_nameA] -- error: -- ...: Could not find module ‘Ahidden’ -- Use -v to see a list of the files searched for. runIOExpr "print a :: IO ()" runIOExpr e = do HValue h <- compileExpr e liftIO (unsafeCoerce h :: IO ()) }}} This code works with ghc 8.2. The new behavior probably originates in 1893ba12fe1fa2ade35a62c336594afcd569736e, which adds flushing of the finder cache (main/Finder.hs) for every dependency analysis; my guess is that this is where the connection between the module name `Ahidden` and the file `A.hs` used be tracked. http://lpaste.net/364298 is a less artificial example of the same behavior. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14994 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14994: ghc api: `load LoadAllTargets` is not idempotent -------------------------------------+------------------------------------- Reporter: int-e | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHC API | Version: 8.4.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by int-e): Ping? I'd like to know whether this is considered to be a bug. (The question arises because the GHC API has no stability guarantees, and apperently the current behavior is enough for ghci to work. On the other hand, specifying and loading targets by filename incrementally can be quite useful, and it used to work.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14994#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14994: ghc api: `load LoadAllTargets` is not idempotent -------------------------------------+------------------------------------- Reporter: int-e | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.6.1 Component: GHC API | Version: 8.4.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * cc: Jaffacake (added) * priority: normal => high * milestone: => 8.6.1 Comment: This sounds like a bug to me. I too would expect `load` to be idempotent. CCing Jaffacake. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14994#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14994: ghc api: `load LoadAllTargets` is not idempotent -------------------------------------+------------------------------------- Reporter: int-e | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.6.1 Component: GHC API | Version: 8.4.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by int-index): I tried to tackle this and couldn't reproduce — I've run the compiled binary and it prints `42`. Also, I've had to add `import GHC` to compile. With a freshly built compiler, here are the steps I took. Installed `ghc-paths`: {{{ [nix-shell:~/Projects/ghc2]$ cabal install --with- compiler=`pwd`/inplace/bin/ghc-stage2 --package- db=`pwd`/inplace/lib/package.conf.d ghc-paths --allow-newer Resolving dependencies... Configuring ghc-paths-0.1.0.9... Building ghc-paths-0.1.0.9... Installed ghc-paths-0.1.0.9 }}} Tried to build: {{{ [nix-shell:~/Projects/ghc2]$ inplace/bin/ghc-stage2 T14994.hs [1 of 1] Compiling Main ( T14994.hs, T14994.o ) T14994.hs:19:13: error: Not in scope: ‘ghcMode’ | 19 | ghcMode = CompManager, | ^^^^^^^ T14994.hs:20:13: error: Not in scope: ‘hscTarget’ | 20 | hscTarget = HscInterpreted, | ^^^^^^^^^ T14994.hs:21:13: error: Not in scope: ‘ghcLink’ | 21 | ghcLink = LinkInMemory, | ^^^^^^^ T14994.hs:22:13: error: Not in scope: ‘verbosity’ | 22 | verbosity = 0 | ^^^^^^^^^ }}} Added `import GHC`, tried to build: {{{ [nix-shell:~/Projects/ghc2]$ inplace/bin/ghc-stage2 T14994.hs [1 of 1] Compiling Main ( T14994.hs, T14994.o ) T14994.hs:6:1: error: Could not find module ‘GHC’ It is a member of the hidden package ‘ghc-8.5’. You can run ‘:set -package ghc’ to expose it. (Note: this unloads all the modules in the current scope.) Use -v to see a list of the files searched for. }}} Modified the build command by adding `-package ghc`: {{{ [nix-shell:~/Projects/ghc2]$ inplace/bin/ghc-stage2 T14994.hs -package ghc [1 of 1] Compiling Main ( T14994.hs, T14994.o ) Linking T14994 ... }}} Running: {{{ [nix-shell:~/Projects/ghc2]$ ./T14994 42 }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14994#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14994: ghc api: `load LoadAllTargets` is not idempotent -------------------------------------+------------------------------------- Reporter: int-e | Owner: (none) Type: bug | Status: closed Priority: high | Milestone: 8.8.1 Component: GHC API | Version: 8.4.1 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by int-e): * status: new => closed * resolution: => invalid Comment: I'm sorry, but I cannot reproduce this as described either. This is embarrassing, because I really spent a lot of time on tracking this down. But I did patch the compiler at the time, so it's possible that I ended up breaking it and never testing my findings with a pristine version. I'll have to retrace my steps. I'll hopefully find time for that after the next weekend. In the meantime I'm marking this as invalid. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14994#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC