[GHC] #9128: Possible bug in strictness analyzer when where clause declared NOINLINE

#9128: Possible bug in strictness analyzer when where clause declared NOINLINE -----------------------------------------+--------------------------------- Reporter: aalevy | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Keywords: strictness bytestring | Operating System: Architecture: Unknown/Multiple | Unknown/Multiple Difficulty: Unknown | Type of failure: Runtime Blocked By: | crash Related Tickets: | Test Case: | Blocking: -----------------------------------------+--------------------------------- I've encountered the following error message using a relatively straight forward library that wraps postgresql-simple in certain edge cases: {{{ *** Exception: Oops! Entered absent arg a_sYDl{v} [lid] bytestring-0.10.4.0:Data.ByteString.Internal.ByteString{tc r5T} }}} This happens on an invocation of a function, `dbSelect` under certain compilation conditions: {{{ dbSelect :: (Model a) => Connection -> DBSelect a -> IO [a] {-# INLINE #-} dbSelect conn dbs = map lookupRow <$> query_ conn q where {-# NOINLINE #-} q = renderDBSelect dbs }}} A DBSelect is just a data-structure with different `Query` (wrapper around strict bytestring) fields for clauses in a SQL select query. `renderDBSelect` generates a single `Query` value from the DBSelect (by way of contructing a Blaze.Builder as an intermediate step). When compiled with no optimizations, this works fine, no issues. With -O1, I get the error above. The errors goes away, if I compile with -fno- strictness or remove the NOINLINE *or* INLINE pragmas. We've worked around this for now in the library by removgin the NOINLINE pragmas, but tracking this down it seems like the strictness analyzer might be falsly assuming `q` is never actually evaluated. For reference, this is a commit that still exhibits the bug: https://github.com/alevy/postgresql- orm/tree/93075d56ae5ffeb8f80ecc8c01436713c2656a6b I've also attached a small test application that excercises the bug. Because of how the library sets up a scratch database, the test application requires postgres and pg_ctl to be available in the path. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9128 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9128: Possible bug in strictness analyzer when where clause declared NOINLINE ---------------------------------+----------------------------------------- Reporter: aalevy | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: strictness bytestring Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: Runtime | Blocked By: crash | Related Tickets: Test Case: | Blocking: | ---------------------------------+----------------------------------------- Comment (by simonpj): Can you give clear instructions for how to reproduce, starting from a fresh GHC 7.8.2. Doubtless some libraries to install? Then get some specific (non Hackage) version of postgres SQL, or something. Assume I am stupid and you won't go far wrong. Thanks, Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9128#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9128: Possible bug in strictness analyzer when where clause declared NOINLINE ---------------------------------+----------------------------------------- Reporter: aalevy | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: strictness bytestring Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: Runtime | Blocked By: crash | Related Tickets: Test Case: | Blocking: | ---------------------------------+----------------------------------------- Comment (by aalevy): Yes, sorry. From a fresh install with ghc-7.8.2 and cabal (1.20 in my case, but since it's just for installing dependencies, and I don't think default optimization levels have changed recently, I suspect it doesn't matter): 0. Prerequisites: postgresql (I'm using 9.3, but probably doesn't matter) with tools (specifically pg_ctl). Tools, for example, are not installed by default on the postgresql version that comes with OS X -- you have to install from homebrew I think. pg_ctl comes with postgresql on most distros of linux though. Unfortunately, I don't know about windows and don't have an install available to test with. 1. Grab the unpatched version of the postgresql-orm from github: {{{ $ git clone https://github.com/alevy/postgresql-orm.git $ cd postgresql-orm $ git checkout 93075d56ae5ffeb8f80ecc8c01436713c2656a6b }}} 2. Install library dependencies (inside a cabal sandbox if you care about not polluting your global environment): {{{ $ cabal sandbox init $ cabal install --only-dependencies }}} 3. Copy test.hs into the project directory 4. Compile with O1: {{{ $ ghc -O1 test.hs -package-db ./.cabal-sandbox/x86_64-linux- ghc-7.8.2-packages.conf.d }}} 5. Run: {{{ $ ./test test: Oops! Entered absent arg a_sYDl{v} [lid] bytestring-0.10.4.0:Data.ByteString.Internal.ByteString{tc r5T} }}} All the machines I've tested this on are running Arch Linux, with ghc-7.8.2 Are there any steps I haven't thought to include? Thanks! -amit -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9128#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9128: Possible bug in strictness analyzer when where clause declared NOINLINE ---------------------------------+----------------------------------------- Reporter: aalevy | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: strictness bytestring Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: Runtime | Blocked By: crash | Related Tickets: Test Case: | Blocking: | ---------------------------------+----------------------------------------- Comment (by aalevy): OK, I can reproduce it without a dependency on the database (which should make it easier to repro for others...) Same instructions as before, except no need to install/setup the postgresql database server, and use the new attached (test2.hs) file instead: 1. Grab the unpatched version of the postgresql-orm from github: {{{ $ git clone https://github.com/alevy/postgresql-orm.git $ cd postgresql-orm $ git checkout 93075d56ae5ffeb8f80ecc8c01436713c2656a6b }}} 2. Install library dependencies (inside a cabal sandbox if you care about not polluting your global environment): {{{ $ cabal sandbox init $ cabal install --only-dependencies }}} 3. Copy test2.hs into the project directory 4. Compile with O1: {{{ $ ghc -O1 test2.hs -package-db ./.cabal-sandbox/x86_64-linux- ghc-7.8.2-packages.conf.d }}} 5. Run: {{{ $ ./test test: Oops! Entered absent arg a_sYDl{v} [lid] bytestring-0.10.4.0:Data.ByteString.Internal.ByteString{tc r5T} }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9128#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9128: Possible bug in strictness analyzer when where clause declared NOINLINE ---------------------------------+----------------------------------------- Reporter: aalevy | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: strictness bytestring Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime | Difficulty: Unknown crash | Blocked By: Test Case: | Related Tickets: Blocking: | ---------------------------------+----------------------------------------- Changes (by aalevy): * os: Unknown/Multiple => Linux * architecture: Unknown/Multiple => x86_64 (amd64) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9128#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9128: Possible bug in strictness analyzer when where clause declared NOINLINE ---------------------------------+----------------------------------------- Reporter: aalevy | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: strictness bytestring Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime | Difficulty: Unknown crash | Blocked By: Test Case: | Related Tickets: Blocking: | ---------------------------------+----------------------------------------- Comment (by rwbarton): Someone on #haskell reported this: http://lpaste.net/105005 which looks like it might be the same bug, but sadly they didn't include enough details to reproduce it (and my 5-minute attempt to do so by guessing the rest of the program was unsuccessful). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9128#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9128: Possible bug in strictness analyzer when where clause declared NOINLINE ---------------------------------+----------------------------------------- Reporter: aalevy | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: strictness bytestring Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime | Difficulty: Unknown crash | Blocked By: Test Case: | Related Tickets: Blocking: | ---------------------------------+----------------------------------------- Comment (by aalevy): @rwbarton, know who it was? It does look related. I would like to try and get info from them to help me track this down. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9128#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9128: Possible bug in strictness analyzer when where clause declared NOINLINE ---------------------------------+----------------------------------------- Reporter: aalevy | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: strictness bytestring Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime | Difficulty: Unknown crash | Blocked By: Test Case: | Related Tickets: Blocking: | ---------------------------------+----------------------------------------- Comment (by rwbarton): Replying to [comment:6 aalevy]:
@rwbarton, know who it was? It does look related. I would like to try and get info from them to help me track this down. freenode Web user `ticktockman` (http://ircbrowse.net/browse/haskell?id=18255857×tamp=1401773327#t1401773327). Good luck :)
-- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9128#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9128: Possible bug in strictness analyzer when where clause declared NOINLINE ---------------------------------+----------------------------------------- Reporter: aalevy | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: strictness bytestring Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: Runtime | Difficulty: Unknown crash | Blocked By: Test Case: | Related Tickets: Blocking: | ---------------------------------+----------------------------------------- Comment (by simonpj): I would love a smaller test case. I'm currently stalled thus {{{ cabal install --with-ghc=/home/simonpj/5builds/HEAD-2/inplace/bin/ghc- stage2 Resolving dependencies... [1 of 1] Compiling Main ( /tmp/postgresql-libpq-0.9.0.1-63567 /postgresql-libpq-0.9.0.1/dist/setup/setup.hs, /tmp/postgresql- libpq-0.9.0.1-63567/postgresql-libpq-0.9.0.1/dist/setup/Main.o ) Linking /tmp/postgresql-libpq-0.9.0.1-63567/postgresql- libpq-0.9.0.1/dist/setup/setup ... Configuring postgresql-libpq-0.9.0.1... setup: The program 'pg_config' is required but it could not be found. Failed to install postgresql-libpq-0.9.0.1 cabal: Error: some packages failed to install: postgresql-libpq-0.9.0.1 failed during the configure step. The exception was: ExitFailure 1 postgresql-orm-0.3.0 depends on postgresql-libpq-0.9.0.1 which failed to install. postgresql-simple-0.4.2.2 depends on postgresql-libpq-0.9.0.1 which failed to install. }}} I gather that `pg_config` is part of !PostgreSQL, which I am reluctant to install on my (shared) Linux box. (I have no clue how to even begin.) But perhaps it is not really necessary? At the moment this looks like a somewhat serious bug (in the demand analyser) which I have no way to reproduce. Thanks Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9128#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9128: Possible bug in strictness analyzer when where clause declared NOINLINE
---------------------------------+-----------------------------------------
Reporter: aalevy | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.8.2
Resolution: | Keywords: strictness bytestring
Operating System: Linux | Architecture: x86_64 (amd64)
Type of failure: Runtime | Difficulty: Unknown
crash | Blocked By:
Test Case: | Related Tickets:
Blocking: |
---------------------------------+-----------------------------------------
Comment (by Simon Peyton Jones

#9128: Possible bug in strictness analyzer when where clause declared NOINLINE -------------------------------------+------------------------------------- Reporter: aalevy | Owner: Type: bug | Status: merge Priority: normal | Milestone: 7.8.3 Component: Compiler | Version: 7.8.2 Resolution: | Keywords: strictness Operating System: Linux | bytestring Type of failure: Runtime crash | Architecture: x86_64 (amd64) Test Case: | Difficulty: Unknown simplCore/should_run/T9128 | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------- Changes (by simonpj): * status: new => merge * testcase: => simplCore/should_run/T9128 * milestone: => 7.8.3 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9128#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9128: Possible bug in strictness analyzer when where clause declared NOINLINE -------------------------------------+------------------------------------- Reporter: aalevy | Owner: Type: bug | Status: closed Priority: normal | Milestone: 7.8.3 Component: Compiler | Version: 7.8.2 Resolution: fixed | Keywords: strictness Operating System: Linux | bytestring Type of failure: Runtime crash | Architecture: x86_64 (amd64) Test Case: | Difficulty: Unknown simplCore/should_run/T9128 | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------- Changes (by thoughtpolice): * status: merge => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9128#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC