Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why remote tables and StaticLabels are still used in CloudHaskell?

I'm reading the source code of distributed-process and related packages. In distributed-static we have the definition of StaticLabel:

data StaticLabel =
    StaticLabel String
  | StaticApply !StaticLabel !StaticLabel
  | StaticPtr SDynamic
  deriving (Eq, Ord, Typeable, Show)

Which is then used to define Static as a newtype wrapper around StaticLabel with a phantom variable attached for type safety:

newtype Static a = Static StaticLabel
  deriving (Eq, Ord, Typeable, Show)

I have no questions about StaticApply, it just lumps together two static values. However, StaticLabel and StaticPtr seem to achieve the same goal in different ways.

If we go with StaticLabel we just have/transimt a String label which then can be used to lookup a Dynamic value from RemoteTable:

newtype RemoteTable = RemoteTable (Map String Dynamic)

Where Dynamic is (defined in rank1dynamic):

data Dynamic = Dynamic TypeRep GHC.Any

Which is almost the same as SDynamic contained in StaticPtr:

data SDynamic = SDynamic TypeRep (StaticPtr GHC.Any)

The difference being, with Dynamic we have GHC.Any without indirection, with SDynamic we must lookup the value. The result is the same: we receive that Any value which we can unsafeCoerce if the target TypeRep is instanceOf of the TypeRep we store in SDynamic or Dynamic.

Management of remote tables, although automated to some extent via TH, is still kind of annoying, so why not use just StaticPtrs? Does StaticLabel exist only for backward compatibility with older GHCs or am I missing something?

like image 505
Mark Karpov Avatar asked Nov 07 '22 12:11

Mark Karpov


1 Answers

One of the main reasons for doing that is that we had to have backwards compatibility and support 3 major versions of GHC. It was also not obvious if we want to jump in the static-pointers solution straight away. As for example their "stability" weaker. Basically the only guarantee is that for the same version of compiler, libraries and the same source-code - static-pointers will be compiled to the same value. Actually distributed-process was defined with that in mind, but some people want to have more stable pointers and static labels gives that as you can define your own rules for the label and have the same label even across the different executables.

If guarantees of the static pointers is enough for you, then there is distributed-closure package, that provides a static-pointers based functions referencing. With this package you don't need to use remotetable at all and leave that only for the distributed-process internals and backward compatibility.

like image 86
qnikst Avatar answered Nov 15 '22 08:11

qnikst