[GHC] #14596: Remove uses of unsafeGlobalDynFlags for state hack

#14596: Remove uses of unsafeGlobalDynFlags for state hack -------------------------------------+------------------------------------- Reporter: bgamari | Owner: (none) Type: task | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.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: -------------------------------------+------------------------------------- Currently there are a variety of uses of the terrible `unsafeGlobalDynFlags` scattered about the compiler to implement `-fno- state-hack`. This global state makes parallel compilation unreliable and complicates API usage. Remove these uses. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14596 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14596: Remove uses of unsafeGlobalDynFlags for state hack -------------------------------------+------------------------------------- Reporter: bgamari | Owner: (none) Type: task | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.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): Phab:D4265 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * cc: DemiMarie (added) * differential: => Phab:D4265 Comment: DemiMarie has a patch (Phab:D4265) implementing this. Unfortunately it's quite invasive. On the call Simon proposed an alternate way forward: rather than making the decision of whether to apply the state hack during simplification, instead push the decision up to the typechecker. The `State#` tycon would carry whether or not it should be considered for the state hack. Simonpj will likely pop up here and fill in more details later. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14596#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14596: Remove uses of unsafeGlobalDynFlags for state hack -------------------------------------+------------------------------------- Reporter: bgamari | Owner: (none) Type: task | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.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): Phab:D4265 Wiki Page: | -------------------------------------+------------------------------------- Comment (by dobenour): It seems like the logical place to put this is as a flag in `TyCon`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14596#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14596: Remove uses of unsafeGlobalDynFlags for state hack -------------------------------------+------------------------------------- Reporter: bgamari | Owner: (none) Type: task | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.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): Phab:D4265 Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj):
It seems like the logical place to put this is as a flag in TyCon.
Yes... * The flag is only needed in `PrimTyCon` * And only used for `statePrimTyCon` (see `Id.isStateHackType`) The trouble is, if `statePrimTyCon` is dependent on `DynFlags`, it can't be top-level defines (as it is now). Does that matter? Turns out that `statePrimTyCon` is used * In `MkId.runRWId`. I think I can elimiante this top-level Id altogether * In `TysPrim.mkStatePrimTy`... * ...which in turn is used in `PrelRules.seqRule`. That is easy to elminate; I'll submit a patch shortly. * ...and `TysPrim.realWorldStatePrimTy` and `MkId.realWorldPrimId`. This is a bit harder; it they are used in: * a bunch of cases in `DsCCall`, but there is a monad to hand there, so that's easy to fix. * a couple of places in `eqType realWorldStatePrimTy`, but that doesn't need the tycon, only the unique * in `CorePrep` and `ByteCodeGen` where we are inlining `runRWId`. I'm sure these would be do-able because we have an argument of type `State#` so the relevant `TyCon` is in there. In short, I think this could be done with minimal plumbing. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14596#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14596: Remove uses of unsafeGlobalDynFlags for state hack
-------------------------------------+-------------------------------------
Reporter: bgamari | Owner: (none)
Type: task | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.2.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): Phab:D4265
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Simon Peyton Jones

#14596: Remove uses of unsafeGlobalDynFlags for state hack
-------------------------------------+-------------------------------------
Reporter: bgamari | Owner: (none)
Type: task | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.2.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): Phab:D4265
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Simon Peyton Jones
participants (1)
-
GHC