haskell-distributed / haskell-distributed/distributed-process

[DP-67] remotable TH fails on type synonyms

Open
#226 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Haskell
Stars
751
Forks
99
Avg merge
45m
Merged PRs (30d)
2

Description

[Imported from JIRA. Reported by Niklas Hambuechen @mail@nh2.me) as DP-67 on 2013-02-12 18:12:08]
Assume I write a function

f :: (ProcessId, ProcessId) -> Process ()

remotable ['f] works fine.

Then I make

type WorkStealingSlaveProcess a = (ProcessId, ProcessId) -> Process a
slave :: WorkStealingSlaveProcess ()

Now remotable ['f] fails, it says (my f is called slave here):

SimpleLocalnet.hs:1:1: Splicing declarations
    remotable ['slave]
  ======>
    SimpleLocalnet.hs:37:1-18
    slave__static :: Static (WorkStealingSlaveProcess ())
    slave__static = Control.Distributed.Static.staticLabel "Main.slave"
    __remoteTable :: RemoteTable -> RemoteTable
    __remoteTable
      = Control.Distributed.Static.registerStatic
          "Main.slave" (Data.Rank1Dynamic.toDynamic slave)
SimpleLocalnet.hs:56:22-37: Splicing expression
    mkClosure 'slave
  ======>
    ((closure
        (slave__static
         `Control.Distributed.Static.staticCompose`
           (staticDecode slave__sdict)))
     . Data.Binary.encode)

SimpleLocalnet.hs:56:22:
    Not in scope: `slave__sdict'
    In the result of the splice:
      $(mkClosure 'slave)
    To see what the splice expanded to, use -ddump-splices
    In the expression: $(mkClosure 'slave)
    In an equation for `slaveProcess':
        slaveProcess = $(mkClosure 'slave)

It simply doesn't generate the f__sdict function, which is because my type doesn't contain an arrow = see the following code from distributed-process (http://hackage.haskell.org/packages/archive/distributed-process/0.2.1.4/doc/html/src/Control-Distributed-Process-Internal-Closure-TH.html#remotable):

generateDefs :: Name -> Q ([Dec], [Q Exp])
generateDefs n = do
    proc <- [t| Process |]
    mType <- getType n
    case mType of
      Just (origName, typ) -> do
        let (typVars, typ') = case typ of ForallT vars [] mono -> (vars, mono)
                                          _                    -> ([], typ)

        -- The main "static" entry                                  
        (static, register) <- makeStatic origName typVars typ' 

        -- If n :: T1 -> T2, static serializable dictionary for T1 
        -- TODO: we should check if arg is an instance of Serializable, but we cannot
        -- http://hackage.haskell.org/trac/ghc/ticket/7066
        (sdict, registerSDict) <- case (typVars, typ') of
          ([], ArrowT `AppT` arg `AppT` _res) -> 
            makeDict (sdictName origName) arg
          _ -> 
            return ([], [])

We are in the second case because there is no ArrowT inside - it is hidden inside my type declaration.

Probably the solution is to "unfold" type aliases first.

If not, there should at least be a warning about this, instead of just returning [].

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Control.Distributed.Process.Internal.Closure.TH.html at generateDefs, especially the ArrowT pattern that decides whether to generate the serializable dictionary. Reproduce the type-synonym case from the issue with remotable and mkClosure, then verify that aliases are handled or that an explicit warning replaces the missing sdict failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.