Experimentally run ST in a fake world
Needs RevisionPublic

Authored by dfeuer on Mar 23 2017, 2:34 AM.

Details

Reviewers
hvr
bgamari
austin
Summary

Currently, ST actions are instantiated at s = RealWorld when
run. We'd really like to treat ST and IO somewhat differently
for demand analysis, which means we need to have a way to distinguish
them. The most conservative option seems to be to use a different
State# token type.

This commit experimentally (and with a big hammer) adds a new
FakeWorld primitive type, a fakeWorld# :: State# FakeWorld
primitive token, and a runFW# (run in a fake world) token.
It then uses runFW# to implement runST. Let's see what happens.

Diff Detail

Repository
rGHC Glasgow Haskell Compiler
Branch
AlternateUniverse
Lint
Lint WarningsExcuse: Linty
SeverityLocationCodeMessage
Warningcompiler/basicTypes/MkId.hs:1119TXT3Line Too Long
Warningcompiler/basicTypes/MkId.hs:1129TXT3Line Too Long
Warningcompiler/basicTypes/MkId.hs:1574TXT3Line Too Long
Warningcompiler/coreSyn/CorePrep.hs:822TXT3Line Too Long
Warningcompiler/coreSyn/CoreUnfold.hs:523TXT3Line Too Long
Warningcompiler/prelude/TysPrim.hs:177TXT3Line Too Long
Warningcompiler/prelude/TysPrim.hs:195TXT3Line Too Long
Unit
No Unit Test Coverage
Build Status
Buildable 15288
Build 25529: [GHC] Linux/amd64: Patch building
Build 25528: [GHC] OSX/amd64: Continuous Integration
Build 25527: [GHC] Windows/amd64: Continuous Integration
Build 25526: arc lint + arc unit
dfeuer created this revision.Mar 23 2017, 2:34 AM
dfeuer updated this revision to Diff 11850.Mar 23 2017, 3:11 AM
  • Change runST definition
dfeuer updated this revision to Diff 11851.Mar 23 2017, 8:37 AM
  • Change runST definition
bgamari requested changes to this revision.Mar 29 2017, 4:24 PM

What needs to happen to finish this up, @dfeuer?

compiler/basicTypes/MkId.hs
1285

It really seems like this should share code with runRWId.

compiler/prelude/primops.txt.pp
2319

It seems like ST should be mentioned here.

This revision now requires changes to proceed.Mar 29 2017, 4:24 PM

Is this still pertinent?

compiler/coreSyn/CorePrep.hs
823

Is this an exact copy of the above code (except for fakeWorldPrimId)? How about a local refactoring?

Is this still pertinent?

Perhaps, but it requires a tad more work since Core Prep currently doesn't do any substitution in types (which we must do to instantiate State#'s argument) . I think we want to preserve this property, so we would likely need to do something like adding a substitution in the runFW# case in cpeApp.

compiler/coreSyn/CorePrep.hs
823

I agree. @dfeuer, in my local branch where I debugged this I refactored this to,

-- Given an expression @runRW# arg arg1 .. argN@, construct
-- @arg realWorld# arg1 .. argN@, beta reducing if possible.
apply_realWorld :: CorePrepEnv -> CoreExpr -> [ArgInfo] -> Int -> UniqSM (Floats, CpeRhs)
apply_realWorld env arg args depth =
  pprTrace "apply_reawlWorld" (ppr arg $$ ppr args $$ ppr env) $
  case arg of
    Lam s body  ->
      let env'  = extendCorePrepEnv env s realWorldPrimId
      in cpe_app env' body args (depth - 1)
    _           ->
      let args' = CpeApp (Var realWorldPrimId) : args
      in cpe_app env  arg  args' depth

With the appropriate rewrites of the cases in cpe_app.

dfeuer updated this revision to Diff 12138.Apr 15 2017, 3:22 PM
dfeuer edited edge metadata.
  • Change runST definition
  • Tighten up; comment up

What about a testcase?

.arc-linters/check-cpp.py
76

It looks like your base commit is incorrect.

compiler/prelude/TysPrim.hs
177

This line should really be split up at some point. I'll take care of this after merging this.

docs/users_guide/8.2.1-notes.rst
115

Base commit again.

bgamari requested changes to this revision.Apr 17 2017, 10:23 AM
This revision now requires changes to proceed.Apr 17 2017, 10:23 AM

I realize this is kind of inconvenient to change, but I would be happier if we just called this thing stWorld#, runST#, etc. rather than having to remember the trivia that fakeWorld# is used for ST.

austin resigned from this revision.Nov 9 2017, 11:36 AM