[GHC] #8083: setNumCapabilities broken in HEAD

#8083: setNumCapabilities broken in HEAD --------------------------+------------------------------------------------ Reporter: parcs | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: | Version: 7.7 Runtime System | Operating System: Unknown/Multiple Keywords: | Type of failure: Incorrect result at runtime Architecture: | Test Case: Unknown/Multiple | Blocking: Difficulty: | Unknown | Blocked By: | Related Tickets: | --------------------------+------------------------------------------------ {{{ #!haskell import GHC.Conc import Control.Monad main :: IO () main = do n <- getNumCapabilities when (n == 1) $ setNumCapabilities 2 print () }}} One would expect this program to print () just once, but when compiled with -O or -O2 it prints () repeatedly and indefinitely! This doesn't happen on GHC 7.6.2 or 7.4.1, only on HEAD. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8083 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8083: setNumCapabilities broken in HEAD ------------------------------------------------+-------------------------- Reporter: parcs | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result at runtime | Unknown/Multiple Test Case: | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Comment (by parcs): Even simpler test case: {{{ #!haskell import GHC.Conc import Control.Monad main :: IO () main = do n <- getNumCapabilities when (n == 1) $ setNumCapabilities 2 }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8083#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8083: setNumCapabilities broken in HEAD ------------------------------------------------+-------------------------- Reporter: parcs | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result at runtime | Unknown/Multiple Test Case: | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Comment (by parcs): After further investigation this doesn't appear to be intrinsic to setNumCapabilities; rather, it looks like a bug in the codegen related to safe foreign ccalls. Another test case: {{{ #!haskell import GHC.Conc import Foreign.C foreign import ccall safe blah :: IO () main :: IO () main = do n <- getNumCapabilities case n of 1 -> blah _ -> return () }}} {{{ #!c void blah () { } }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8083#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8083: setNumCapabilities broken in HEAD ------------------------------------------------+-------------------------- Reporter: parcs | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result at runtime | Unknown/Multiple Test Case: | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Changes (by simonmar): * cc: simonmar (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8083#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8083: setNumCapabilities broken in HEAD
------------------------------------------------+--------------------------
Reporter: parcs | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Runtime System | Version: 7.7
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Incorrect result at runtime | Unknown/Multiple
Test Case: T8083 | Difficulty:
Blocking: | Unknown
| Blocked By:
| Related Tickets:
------------------------------------------------+--------------------------
Changes (by igloo):
* testcase: => T8083
Comment:
We get this:
{{{
==================== Post control-flow optimisations ====================
{offset
c18y:
if (Sp - <highSp> < SpLim) goto c18D; else goto c18E;
c18D:
R1 = Main.main1_closure;
call (stg_gc_fun)(R1) args: 8, res: 0, upd: 8;
c18E:
_s188::I64 = %MO_SS_Conv_W32_W64(I32[n]);
_s188::I64 = _s188::I64;
_s189::I64 = _s188::I64;
if (_s189::I64 != 1) goto c18w; else goto c18x;
c18w:
R1 = GHC.Tuple.()_closure+1;
call (P64[(old + 8)])(R1) args: 8, res: 0, upd: 8;
c18x:
_c18B::I64 = blah;
I64[(young<c18C> + 8)] = c18C;
foreign call "ccall" arg hints: [] result hints: []
(_c18B::I64)(...) returns to c18C args: ([]) ress: ([])upd: 8;
c18C:
R1 = GHC.Tuple.()_closure+1;
call (P64[(old + 8)])(R1) args: 8, res: 0, upd: 8;
}
}}}
note that `c18w` and `c18C` look identical. They then get commoned up:
{{{
==================== Post common block elimination ====================
{offset
c18y:
if (Sp - <highSp> < SpLim) goto c18D; else goto c18E;
c18D:
R1 = Main.main1_closure;
call (stg_gc_fun)(R1) args: 8, res: 0, upd: 8;
c18E:
_s188::I64 = %MO_SS_Conv_W32_W64(I32[n]);
_s188::I64 = _s188::I64;
_s189::I64 = _s188::I64;
if (_s189::I64 != 1) goto c18w; else goto c18x;
c18x:
_c18B::I64 = blah;
I64[(young<c18w> + 8)] = c18w;
foreign call "ccall" arg hints: [] result hints: []
(_c18B::I64)(...) returns to c18w args: ([]) ress: ([])upd: 8;
c18w:
R1 = GHC.Tuple.()_closure+1;
call (P64[(old + 8)])(R1) args: 8, res: 0, upd: 8;
}
}}}
The problem is that the code ends up looking like this:
{{{
# at this point rbp =

#8083: setNumCapabilities broken in HEAD ------------------------------------------------+-------------------------- Reporter: parcs | Owner: Type: bug | Status: new Priority: high | Milestone: 7.8.1 Component: Runtime System | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result at runtime | Unknown/Multiple Test Case: T8083 | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Changes (by igloo): * priority: normal => high * milestone: => 7.8.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8083#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8083: setNumCapabilities broken in HEAD
------------------------------------------------+--------------------------
Reporter: parcs | Owner:
Type: bug | Status: new
Priority: high | Milestone: 7.8.1
Component: Runtime System | Version: 7.7
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Incorrect result at runtime | Unknown/Multiple
Test Case: T8083 | Difficulty:
Blocking: | Unknown
| Blocked By:
| Related Tickets:
------------------------------------------------+--------------------------
Comment (by ian@…):
commit be89c675339982cb53a5e32d6d282410c9c50f7c
{{{
Author: Ian Lynagh

#8083: setNumCapabilities broken in HEAD ------------------------------------------------+-------------------------- Reporter: parcs | Owner: Type: bug | Status: new Priority: high | Milestone: 7.8.1 Component: Runtime System | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result at runtime | Unknown/Multiple Test Case: T8083 | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Changes (by jstolarek): * cc: jan.stolarek@… (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8083#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8083: setNumCapabilities broken in HEAD ------------------------------------------------+-------------------------- Reporter: parcs | Owner: Type: bug | Status: new Priority: highest | Milestone: 7.8.1 Component: Runtime System | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result at runtime | Unknown/Multiple Test Case: T8083 | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Changes (by simonmar): * priority: high => highest Comment: Thanks Ian, probably a bug in `CmmLayoutStack`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8083#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8083: setNumCapabilities broken in HEAD ------------------------------------------------+-------------------------- Reporter: parcs | Owner: Type: bug | simonmar Priority: highest | Status: new Component: Runtime System | Milestone: 7.8.1 Resolution: | Version: 7.7 Operating System: Unknown/Multiple | Keywords: Type of failure: Incorrect result at runtime | Architecture: Test Case: T8083 | Unknown/Multiple Blocking: | Difficulty: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Changes (by simonmar): * owner: => simonmar Comment: I have a fix, just waiting for validate breakage to be fixed. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8083#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8083: setNumCapabilities broken in HEAD
------------------------------------------------+--------------------------
Reporter: parcs | Owner:
Type: bug | simonmar
Priority: highest | Status: new
Component: Runtime System | Milestone: 7.8.1
Resolution: | Version: 7.7
Operating System: Unknown/Multiple | Keywords:
Type of failure: Incorrect result at runtime | Architecture:
Test Case: T8083 | Unknown/Multiple
Blocking: | Difficulty:
| Unknown
| Blocked By:
| Related Tickets:
------------------------------------------------+--------------------------
Comment (by marlowsd@…):
commit c23488590cd65fa584ddd648cdbab2fa13f5656b
{{{
Author: Simon Marlow

#8083: setNumCapabilities broken in HEAD ------------------------------------------------+-------------------------- Reporter: parcs | Owner: Type: bug | simonmar Priority: highest | Status: closed Component: Runtime System | Milestone: 7.8.1 Resolution: fixed | Version: 7.7 Operating System: Unknown/Multiple | Keywords: Type of failure: Incorrect result at runtime | Architecture: Test Case: T8083 | Unknown/Multiple Blocking: | Difficulty: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Changes (by simonmar): * status: new => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8083#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC