Re: Static values language extension proposal
indeed! Thanks erik! On the paralllel list, edkso shares with us a single commit that adds all the requested features as a user land lib https://github.com/haskell-distributed/distributed-static/commit/d2bd2ebca5a96ea5df621770e98bfb7a3b745bc7 @tweag folks, please do not write personal attacks on the issue tracker, if you find yourself frustrated, I probably am too! please keep a positive constructive tone in all future communications. On Tue, Jan 28, 2014 at 9:20 PM, Erik de Castro Lopo mle...@mega-nerd.comwrote: Mathieu Boespflug wrote: [Sorry for the multiple reposts - couldn't quite figure out which email address doesn't get refused by the list..] Hi Carter, thank you for the good points you raise. I'll try and address each of them as best I can below. 0) I think you could actually implement this proposal as a userland library, at least as you've described it. Have you tried doing so? Indeed, this could be done without touching the compiler at all. We had this response really early on in this discussion. Quite honestly I think that should have been the end of the discussion. The existing GHC release already have a huge workload getting releases out the door and adding to that workload without adding manpower and resources would be a bad idea. You really should try doing this as a library outside of GHC and if GHC needs a few small additional features, they can be added. The `static e` form could as well be a piece of Template Haskell, but making it a proper extension means that the compiler can enforce more invariants and be a bit more helpful to the user. Once it works outside GHC and has proven useful, then it might be worthwhile add small specific, easily testable/maintainable features to GHC to support what goes on on your library. Erik -- -- Erik de Castro Lopo http://www.mega-nerd.com/ ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Static values language extension proposal
For interested fellows, discussion also continues in [1] and [2]. Best, Facundo [1] https://ghc.haskell.org/trac/ghc/ticket/7015 [2] https://groups.google.com/d/topic/parallel-haskell/b-x7VmjlEOw/discussion On Thu, Jan 30, 2014 at 4:47 PM, Carter Schonwald carter.schonw...@gmail.com wrote: indeed! Thanks erik! On the paralllel list, edkso shares with us a single commit that adds all the requested features as a user land lib https://github.com/haskell-distributed/distributed-static/commit/d2bd2ebca5a96ea5df621770e98bfb7a3b745bc7 @tweag folks, please do not write personal attacks on the issue tracker, if you find yourself frustrated, I probably am too! please keep a positive constructive tone in all future communications. On Tue, Jan 28, 2014 at 9:20 PM, Erik de Castro Lopo mle...@mega-nerd.com wrote: Mathieu Boespflug wrote: [Sorry for the multiple reposts - couldn't quite figure out which email address doesn't get refused by the list..] Hi Carter, thank you for the good points you raise. I'll try and address each of them as best I can below. 0) I think you could actually implement this proposal as a userland library, at least as you've described it. Have you tried doing so? Indeed, this could be done without touching the compiler at all. We had this response really early on in this discussion. Quite honestly I think that should have been the end of the discussion. The existing GHC release already have a huge workload getting releases out the door and adding to that workload without adding manpower and resources would be a bad idea. You really should try doing this as a library outside of GHC and if GHC needs a few small additional features, they can be added. The `static e` form could as well be a piece of Template Haskell, but making it a proper extension means that the compiler can enforce more invariants and be a bit more helpful to the user. Once it works outside GHC and has proven useful, then it might be worthwhile add small specific, easily testable/maintainable features to GHC to support what goes on on your library. Erik -- -- Erik de Castro Lopo http://www.mega-nerd.com/ ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Static values language extension proposal
On 01/28/2014 06:03 PM, Carter Schonwald wrote: Theres actually a missing piece of information in this thread: what are the example computations that are being sent? My understanding is that erlang has not way to send file handles, shared variables, Tvars, Mvars, memory mapped binary files, GPU code / memory pointers , and other fun unportable things between nodes, and I don't really expect / see how we can hope to sanely do that in haskell! [...]exactly the same binary, running on a cluster of homogeneous machines with the exact same hardware, with a modern linux distro [...] Nathan Howell was actually doing some experimentation with one strategy for this special case here https://github.com/alphaHeavy/vacuum-tube as a deeply rts twiddling bit of hackery so you could in fact serialize arbitrary closures between homogeneous machines running the exact same code (and with address randomization disabled too i think) When mentioning Nathan's approach (based on foreign primops), let me point to a more complete, RTS-backed implementation; work done by myself and itself based on a long-standing runtime support for a parallel Haskell on distributed memory systems. The latest instance of this rts-based serialisation was reported in the Haskell-implementors' workshop 2013 ( www.haskell.org/wikiupload/2/28/HIW2013PackingAPI.pdf ); code is on github (https://github.com/jberthold/rts-serialisation) Some technical remarks: -Nathan's prim.op approach is awesome, but it is not easy to get its interplay with garbage collection right. It is on my list to take a look at this code again and see how far we can push the envelope. -About address randomisation: The RTS-based serialisation uses relative locations from a known offset to handle it. A more concerning detail is that CAFs must be reverted rather than discarded during GC (currently they are just retained, not satisfactory for long-running code). -About sending arbitrary closures: indeed it does not make any sense to transfer MVars and IORefs (file handles, StablePtrs, etc). My approach is to solve this dynamically by exception handling. I can imagine that there is a sensible combination of RTS support with a suitable type class framework (Static, for one), but lazy evaluation, especially lazy I/O, complicates matters. / Jost Berthold ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Static values language extension proposal
Hi Carter, On Tue, Jan 28, 2014 at 6:03 PM, Carter Schonwald carter.schonw...@gmail.com wrote: Theres actually a missing piece of information in this thread: what are the example computations that are being sent? Quite simply, the same as those considered in the original Cloud Haskell paper, that already advocates the extension that Facundo's first email merely fleshed out a tiny bit. Here's the link once again: Towards Haskell in the Cloud, Jeff Epstein, Andrew P. Black, and Simon Peyton-Jones (2011). http://research.microsoft.com/en-us/um/people/simonpj/papers/parallel/remote.pdf We are emphatically not considering arbitrary closures as you say below, anymore than the original paper does. As such... My understanding is that erlang has not way to send file handles, shared variables, Tvars, Mvars, memory mapped binary files, GPU code / memory pointers , and other fun unportable things between nodes, and I don't really expect / see how we can hope to sanely do that in haskell! ... the above is completely impossible. The original paper explains why this is so (see Sections 2.3 and 5.1). Here's the gist: 1. you can only send remotely serializable values, i.e. that have an instance of class Serializable. 2. none of the above have a Serializable instance, and are hence not send-able. When it comes to sending closures capturing any of the above types of values, the reasoning goes like this: 3. a closure in the sense of CH is a pair of a static value and an environment, 4. a closure can only be sent if it is serializable, 5. a closure is serializable only if its its environment can be serialized, 5. its environment can be serialized only if all free variables of the closure can, 6. none of the above have a Serializable instance, 7. hence any closure capturing file handles, MVars, memory pointers, etc cannot be sent. point in fact, even when restricted to exactly the same binary, running on a cluster of homogeneous machines with the exact same hardware, with a modern linux distro you hit some gnarly problems doing this for arbitrary closures! Its for a very simple (and fun) reason: address randomization! Which is why neither we nor the original paper considered using addresses as labels for static values. We use linker labels, which are stable. on the GHC API front, http://www.haskell.org/ghc/docs/latest/html/libraries/ghc-7.6.3/DynamicLoading.html along with (and more appropriately http://www.haskell.org/ghc/docs/latest/html/libraries/ghc-7.6.3/ObjLink.html ) should actually give enough basic tooling to make this possible as a userland library, mind you unload was recently fixed up in HEAD by Simon Marlow to support the dynamic code loading / unloading use case he has in facebook. Point being the GHC 7.8 version of the ObjLink api should actually give enough support tooling to prototype this idea in user land, and that plus better support for writing direct haskell code and getting out both a local computation and an AST we can serialize would probably be a good set of primitives for making this feasible in user land. I For the third time: we can of course use any linker API that the system or the compiler happens to provide, so long as it allows resolving linker symbols to Haskell values. The (small) extension under consideration does not replace or add to any existing linker API. It just transparently floats closed expressions to the top-level, makes sure linker symbols will exist at runtime (they currently don't always do), and does some basic sanity checks so the user doesn't lose his. I listed problems labeled 1a), 1b) and 2) in my previous email. You still haven't showed us how to address those in pure TH userland. In Fact, because in general not every computation will be properly serializable, you need not even bother with tracking an explicit symbol table on each side, just try to load it at a given type and if it fails it wasn't there! The point being, linkers are a thing, ghc exposes an API for linking, have you tried that api? http://www.haskell.org/ghc/docs/latest/html/libraries/ghc-7.6.3/ObjLink.html Yes we have. But I don't see how using it or not using it makes any difference to the user interface of the proposed compiler extension. It's an implementation detail with tradeoffs that Facundo could explain in detail in GHC ticket #8711 if you hadn't rudely closed it as a duplicate of some future and unspecified work of yours. Best, Mathieu ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Static values language extension proposal
Hi Eric, On Wed, Jan 29, 2014 at 3:20 AM, Erik de Castro Lopo mle...@mega-nerd.com wrote: Mathieu Boespflug wrote: thank you for the good points you raise. I'll try and address each of them as best I can below. 0) I think you could actually implement this proposal as a userland library, at least as you've described it. Have you tried doing so? Indeed, this could be done without touching the compiler at all. We had this response really early on in this discussion. Quite honestly I think that should have been the end of the discussion. The response you quote above comes in context, which includes the sentence you also quote below. In another email, the problems we face with a pure TH implementation are labeled as 1a), 1b), 2). We'd be very happy if you could show us how to solve those problems using TH alone in a way that does not impact user friendliness and static checking of invariants in any way. The existing GHC release already have a huge workload getting releases out the door and adding to that workload without adding manpower and resources would be a bad idea. You really should try doing this as a library outside of GHC and if GHC needs a few small additional features, they can be added. The `static e` form could as well be a piece of Template Haskell, but making it a proper extension means that the compiler can enforce more invariants and be a bit more helpful to the user. Once it works outside GHC and has proven useful, then it might be worthwhile add small specific, easily testable/maintainable features to GHC to support what goes on on your library. I for one very much agree with all the principles state above. But the wider context of the discussion is that we already have such a TH userland solution today, implemented in packages distributed-static and distributed-process. We already have several users, including in the industry (to my knowledge Parallel Scientific for over a year, Tweag I/O for a couple of months, probably others...). The proposal to go ahead and implement an idea that was first presented in the original Cloud Haskell paper was borne out of frustration with the existing approach based on remote tables, which are very error prone in practice, and the operational experience that I, Facundo, Tim and others have had showing that making the semantics of distributed computation depend on *all* modules across several packages being compiled with the right incantation of compiler flags without any kind of static checking is a problem, especially for beginners. Is there something in the proposed extension that leads you to believe that is neither small nor specific, or that it would not be easily testable, or maintainable? If so, we could amend it accordingly. Best, Mathieu ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Static values language extension proposal
Hello, I'd just like to say I haven't gone over every discussion in this thread and had time to digest it all - I thought I would just highlight a minor technicality. On Fri, Jan 24, 2014 at 11:19 AM, Facundo Domínguez facundo.doming...@tweag.io wrote: Looking up static references `unstatic` is implemented as a function which finds a top-level value from the `GlobalName`, otherwise it raises an exception. It crucially relies on leveraging the system’s dynamic linker, so out-of-the-box only works with dynamically linked binaries (but see below). `unstatic` proceeds as follows: * Determines the name of the shared library from the package name and the package version. * Determines the symbol of the value by Z-Encoding the package name, the module name and the value name. * Uses the system’s dynamic linker interface to obtain the address of the symbol. * Converts the symbol to a haskell value with `GHC.Prim.addrToAny#` In principle, only symbols in shared libraries can be found. However, the dynamic linker is able to find symbols in modules that are linked statically if GHC is fed with the option -optl-Wl,--export-dynamic. A future enhancement could be to have GHC warn the user when modules using the extension are linked statically and this option is not used during linking. GHC only defines symbols for exported definitions in modules. So unstatic won’t be able to find the private bindings of a module. For this sake, the implementation of static should in addition ensure that the bindings it gets will appear in the symbol table when they are not exported by their defining modules. Regarding -optl-Wl,--export-dynamic for static builds, and all that jazz - if I am understanding you right, note that Windows is a bit particular here, because there is a hard limit on the number of symbols allowed in a DLL. That means forcefully exporting *everything* could quickly get you to the symbol limit with the dynamic linker with large-ish applications (one exported function or data type may result in a handful of exported symbols created.) If you want to see the pain this has caused GHC itself, please see GHC bug #5987[1], which makes dynamic support on windows difficult - it's currently disabled now anyway. Furthermore, dynamic DLLs on Windows are a bit tricky anyway as the loader is fundamentally different from your typical ld.so (which there are ways around[2], but a bit nasty as you have to hack the COFF file.) Windows unfortunately isn't in an easy position here, but it's improving and it would be unfortunate to neglect it. This restriction does not exist with the static linker inside the RTS, so my suggestion, I guess, is that I'm inclined to want this to work for *both* static/dynamic configurations out of the box without hackery, if at all possible, which would be great for Windows users especially until the dynamic story is back up to scratch. [1] https://ghc.haskell.org/trac/ghc/ticket/5987 [2] http://blog.omega-prime.co.uk/?p=138 As the application depends on shared libraries, now a tool to collect these libraries would be required so they can be distributed together with the executable binary when deploying a Cloud Haskell application in a cluster. We won’t delve further into this problem. And for any people interested in this - on Linux, a tool like patchelf[3] would help immensely for moving executables+their dependencies around in a 'bundle' style way. [3] http://nixos.org/patchelf.html -- Regards, Austin Seipp, Haskell Consultant Well-Typed LLP, http://www.well-typed.com/ ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Static values language extension proposal
Hi Austin, this is very useful information, thanks. So it seems that the rts linker is here to stay for a while longer still, at least because there is no good alternative on Windows as of yet. If I understand you correctly, on Windows dynamic linking is not an option in part because of the number-of-exported-symbols limit, and when linking statically one hits the same limit if stuff like -optl-Wl,--export-dynamic is used. So at least on Windows, the only way out is the rts linker. Supporting both linkers is certainly an option. If I remember correctly, the issue Facundo found with the rts linker is that to use it for looking up symbol addresses, you apparently need to have an object file loaded twice, effectively (once statically linked at build time, the second time through the rts linker at runtime for doing the lookups). Maybe there's a way around that, or that could be added? In any case for platforms with no alternative, like Windows, I guess double loading is a tolerable price to pay. Best, Mathieu On Wed, Jan 29, 2014 at 12:11 PM, Austin Seipp aus...@well-typed.com wrote: Hello, I'd just like to say I haven't gone over every discussion in this thread and had time to digest it all - I thought I would just highlight a minor technicality. On Fri, Jan 24, 2014 at 11:19 AM, Facundo Domínguez facundo.doming...@tweag.io wrote: Looking up static references `unstatic` is implemented as a function which finds a top-level value from the `GlobalName`, otherwise it raises an exception. It crucially relies on leveraging the system's dynamic linker, so out-of-the-box only works with dynamically linked binaries (but see below). `unstatic` proceeds as follows: * Determines the name of the shared library from the package name and the package version. * Determines the symbol of the value by Z-Encoding the package name, the module name and the value name. * Uses the system's dynamic linker interface to obtain the address of the symbol. * Converts the symbol to a haskell value with `GHC.Prim.addrToAny#` In principle, only symbols in shared libraries can be found. However, the dynamic linker is able to find symbols in modules that are linked statically if GHC is fed with the option -optl-Wl,--export-dynamic. A future enhancement could be to have GHC warn the user when modules using the extension are linked statically and this option is not used during linking. GHC only defines symbols for exported definitions in modules. So unstatic won't be able to find the private bindings of a module. For this sake, the implementation of static should in addition ensure that the bindings it gets will appear in the symbol table when they are not exported by their defining modules. Regarding -optl-Wl,--export-dynamic for static builds, and all that jazz - if I am understanding you right, note that Windows is a bit particular here, because there is a hard limit on the number of symbols allowed in a DLL. That means forcefully exporting *everything* could quickly get you to the symbol limit with the dynamic linker with large-ish applications (one exported function or data type may result in a handful of exported symbols created.) If you want to see the pain this has caused GHC itself, please see GHC bug #5987[1], which makes dynamic support on windows difficult - it's currently disabled now anyway. Furthermore, dynamic DLLs on Windows are a bit tricky anyway as the loader is fundamentally different from your typical ld.so (which there are ways around[2], but a bit nasty as you have to hack the COFF file.) Windows unfortunately isn't in an easy position here, but it's improving and it would be unfortunate to neglect it. This restriction does not exist with the static linker inside the RTS, so my suggestion, I guess, is that I'm inclined to want this to work for *both* static/dynamic configurations out of the box without hackery, if at all possible, which would be great for Windows users especially until the dynamic story is back up to scratch. [1] https://ghc.haskell.org/trac/ghc/ticket/5987 [2] http://blog.omega-prime.co.uk/?p=138 As the application depends on shared libraries, now a tool to collect these libraries would be required so they can be distributed together with the executable binary when deploying a Cloud Haskell application in a cluster. We won't delve further into this problem. And for any people interested in this - on Linux, a tool like patchelf[3] would help immensely for moving executables+their dependencies around in a 'bundle' style way. [3] http://nixos.org/patchelf.html -- Regards, Austin Seipp, Haskell Consultant Well-Typed LLP, http://www.well-typed.com/ -- Mathieu Boespflug Founder at http://tweag.io. ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Static values language extension proposal
To address the concerns about static linking and portability, there is also the alternative of of using the RTS linker in those platforms that need it. In many aspects, neither linker makes a big difference to us. We are going with the system's dynamic linker mainly because GHC team has expressed the desire to get rid of the RTS linker. Using the RTS linker would require addressing some additional technical issues, none of which appear to be show-stoppers. It would be just more work. Best, Facundo On Mon, Jan 27, 2014 at 2:20 PM, Tim Watson watson.timo...@gmail.com wrote: Hi Brandon, On 26 Jan 2014, at 19:01, Brandon Allbery wrote: On Sun, Jan 26, 2014 at 1:43 PM, Tim Watson watson.timo...@gmail.com wrote: In Erlang, I can rpc/send *any* term and evaluate it on another node. That includes functions of course. Whether or not we want to be quite that general is another matter, but that is the comparison I've been making. Note that Erlang gets away with this through being a virtual machine architecture; BEAM is about as write-once-run-anywhere as it gets, and the platform specifics are abstracted by the BEAM VM interpreter. You just aren't going to accomplish this with a native compiled language, without encoding as a virtual machine yourself (that is, the AST-based mechanisms). Yeah, I do realise this. Of course we're not trying to reproduce the BEAM really, but what we /do/ want is to be able to do is exchange messages between nodes that are not running the same executable. The proposal does appear to address this requirement, at least to some extent. There may be complementary (or better) approaches. I believe Carter is going to provide some additional details viz his work in this area at some point. Anything that reduces the amount of Template Haskell required to work with Cloud Haskell is a good thing (tm) IMO. Not that I mind using TH, but the programming model is currently quite awkward from the caller's perspective, since you've got to (a) create a Static/Closure out of potentially complex chunks of code, which often involves creating numerous top level wrapper APIs and (b) fiddle around with the remote-table (both in the code that defines remote-able thunks *and* in the code that starts a node wishing to operate on them. Also note that this problem isn't limited to sending code around the network. Just sending arbitrary *data* between nodes is currently discouraged (though not disallowed) because the receiving program *might* not understand the types you're sending it. This is very restrictive and the proposal does, at the very least, allow us to safely serialise, send and receive types that both programs know about by virtue of having been linked to the same library/libraries. But yes - there are certainly constraints and edge cases aplenty here. I'm not entirely sure whether or not we'd need to potentially change the (binary) encoding of raw messages in distributed-process, for example, in response to this change. Currently we serialise a pointer (i.e., the pointer to the fingerprint for the type that's being sent), and I can imagine that not working properly across different nodes running on different architectures etc. Perhaps you should consider fleshing out ghc's current bytecode support to be a full VM? After discussing this with Simon M, we concluded there was little point in doing so. The GHC RTS is practically a VM anyway, and there's probably not that much value to be gained by shipping bytecode around. Besides, as you put it, the AST-based mechanisms allow for this anyway (albeit with some coding required on the part of the application developer) and Carter (and others) assure me that the mechanisms required to do this kind of thing already exist. We just need to find the right way to take advantage of them. Or perhaps an interesting alternative would be a BEAM backend for ghc. I've talked to a couple of people that want to try this. I'm intrigued, but have other things to focus on. :) Cheers, Tim ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Static values language extension proposal
Hi Carter, Tim, On Sat, Jan 25, 2014 at 7:12 PM, Carter Schonwald carter.schonw...@gmail.com wrote: anyways 1) you should (once 7.8 is out) evaluate how far you can push your ideas wrt dynamic loading as a user land library. If you can't make it work as a library and can demonstrate why (or how even though it works its not quite satisfactory), thats signals something! Signals what? On Sun, Jan 26, 2014 at 7:43 PM, Tim Watson watson.timo...@gmail.com wrote: Is that something you'll consider looking at Matthieu? We would prefer to do it that way, to be honest. As explained in my previous email, we identified two problems with this approach: 1) User friendliness. It's important for us that Cloud Haskell be pretty much as user friendly and easy to use as Erlang is. a) I don't know that it's possible from Template Haskell to detect and warn the user when dependent modules have not been compiled into dynamic object code or into static code with the right flags. b) It's very convenient in practice to be able to send not just `f` if `f` is a global identifier, but in general `e` where `e` is any closed expression mentioning only global names. That can easily be done by having the compiler float the expression `e` to the top-level and give it a global name. I don't see how to do that in TH in a user friendly way. 2) A technical issue: you ought to be able to send unexported functions across the wire, just as you can pass unexported functions as arguments to higher-order functions. Yet GHC does not create linker symbols for unexported identifiers, so our approach would break down. Worse, I don't think that it's even possible to detect in TH whether an identifier is exported or not, in order to warn the user. One could imagine a compiler flag to force the creation of linker symbols for all toplevel bindings, exported or unexported. But that seems wasteful, and potentially not very user friendly. If the above can be solved, all the better! If not: we don't always want to touch the compiler, but when we do, ideally it should be in an unintrusive way. I contend our proposal fits that criterion. And our cursory implementation efforts seem to confirm that so far. But I really think insisting that the linker symbol names denote the datum agreement in a distributed system is punting on what should be handled at the application level. Simon Marlow put some improvements into GHC to help improve doing dynamic code (un)loading, stress test that! We could use either the system linker or rts linker. Not sure that it makes any difference at the application level. 2) I've a work in progress on specing out a proper (and sound :) ) static values type extension for ghc, that will be usable perhaps in your your case (though by dint of being sound, will preclude some of the things you think you want). I look forward to hearing more about that. How is the existing proposal not (type?) sound? BUT, any type system changes need to actually provide safety. To be clear, this proposal doesn't touch the type checker in any way. As for *how* to send an AST fragment, edward kmett and other have some pretty nice typed AST models that are easy to adapt and extend for an application specific use case. Bound http://hackage.haskell.org/package/bound is one nice one. heres a really really good school of haskell exposition https://www.fpcomplete.com/user/edwardk/bound These are nice encodings for AST's. But they don't address how to minimize the amount of code to ship around the cluster. If you have no agreement about what functions are commonly available, then the AST needs to include the code for the function you are sending, + any functions it depends, + any of their dependencies, and so on transitively. Tim, perhaps the following also answers some of your questions. This is where the current proposal comes in: if you choose to ship around AST's, you can minimize their size by having them mention shared linker symbol names. Mind, that's already possible today, by means of the global RemoteTable, but it's building that remote table safely, conveniently, in a modular way, and with static checking that no symbols from any of the modules that were linked at build time were missed, that is difficult. By avoiding a RemoteTable entirely, we avoid having to solve that difficult problem. :) Best, -- Mathieu Boespflug Founder at http://tweag.io. ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Static values language extension proposal
Hi Mathieu, On 28 Jan 2014, at 12:53, Mathieu Boespflug wrote: We would prefer to do it that way, to be honest. As explained in my previous email, we identified two problems with this approach: 1) User friendliness. It's important for us that Cloud Haskell be pretty much as user friendly and easy to use as Erlang is. Exactly! a) I don't know that it's possible from Template Haskell to detect and warn the user when dependent modules have not been compiled into dynamic object code or into static code with the right flags. I don't think that it is, from what I've seen, though I'm by no means an expert. b) It's very convenient in practice to be able to send not just `f` if `f` is a global identifier, but in general `e` where `e` is any closed expression mentioning only global names. That can easily be done by having the compiler float the expression `e` to the top-level and give it a global name. I don't see how to do that in TH in a user friendly way. Agreed. 2) A technical issue: you ought to be able to send unexported functions across the wire, just as you can pass unexported functions as arguments to higher-order functions. Yet GHC does not create linker symbols for unexported identifiers, so our approach would break down. Worse, I don't think that it's even possible to detect in TH whether an identifier is exported or not, in order to warn the user. One could imagine a compiler flag to force the creation of linker symbols for all toplevel bindings, exported or unexported. But that seems wasteful, and potentially not very user friendly. Interesting. If the above can be solved, all the better! If not: we don't always want to touch the compiler, but when we do, ideally it should be in an unintrusive way. I contend our proposal fits that criterion. And our cursory implementation efforts seem to confirm that so far. Good! But I really think insisting that the linker symbol names denote the datum agreement in a distributed system is punting on what should be handled at the application level. Simon Marlow put some improvements into GHC to help improve doing dynamic code (un)loading, stress test that! We could use either the system linker or rts linker. Not sure that it makes any difference at the application level. No indeed. 2) I've a work in progress on specing out a proper (and sound :) ) static values type extension for ghc, that will be usable perhaps in your your case (though by dint of being sound, will preclude some of the things you think you want). I look forward to hearing more about that. +1 How is the existing proposal not (type?) sound? I'd like to hear more about the concerns too. As for *how* to send an AST fragment, edward kmett and other have some pretty nice typed AST models that are easy to adapt and extend for an application specific use case. Bound http://hackage.haskell.org/package/bound is one nice one. heres a really really good school of haskell exposition https://www.fpcomplete.com/user/edwardk/bound These are nice encodings for AST's. But they don't address how to minimize the amount of code to ship around the cluster. If you have no agreement about what functions are commonly available, then the AST needs to include the code for the function you are sending, + any functions it depends, + any of their dependencies, and so on transitively. That was precisely my concern with the idea of shipping *something* AST-like around. It's a lot of overhead for every application you want to develop, or a *massive* overhead to cover all bases. Tim, perhaps the following also answers some of your questions. This is where the current proposal comes in: if you choose to ship around AST's, you can minimize their size by having them mention shared linker symbol names. Indeed, that does seem to simplify things. Mind, that's already possible today, by means of the global RemoteTable, but it's building that remote table safely, conveniently, in a modular way, and with static checking that no symbols from any of the modules that were linked at build time were missed, that is difficult. Yep. It's awkward and when you get it wrong, you're either fighting with TH-obscured compiler errors or worse, the damn thing just doesn't work (because you can't decode properly on the remote node and things just crash, or worse still, just hang on waiting for the *correct* input types, which never arrive because they're not known to the RTS). By avoiding a RemoteTable entirely, we avoid having to solve that difficult problem. :) Not having a RemoteTable sounds like a plus to me. Cheers, Tim ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Static values language extension proposal
Theres actually a missing piece of information in this thread: what are the example computations that are being sent? My understanding is that erlang has not way to send file handles, shared variables, Tvars, Mvars, memory mapped binary files, GPU code / memory pointers , and other fun unportable things between nodes, and I don't really expect / see how we can hope to sanely do that in haskell! point in fact, even when restricted to exactly the same binary, running on a cluster of homogeneous machines with the exact same hardware, with a modern linux distro you hit some gnarly problems doing this for arbitrary closures! Its for a very simple (and fun) reason: address randomization! Nathan Howell was actually doing some experimentation with one strategy for this special case here https://github.com/alphaHeavy/vacuum-tube as a deeply rts twiddling bit of hackery so you could in fact serialize arbitrary closures between homogeneous machines running the exact same code (and with address randomization disabled too i think) on the GHC API front, http://www.haskell.org/ghc/docs/latest/html/libraries/ghc-7.6.3/DynamicLoading.htmlalong with (and more appropriately http://www.haskell.org/ghc/docs/latest/html/libraries/ghc-7.6.3/ObjLink.html) should actually give enough basic tooling to make this possible as a userland library, mind you unload was recently fixed up in HEAD by Simon Marlow to support the dynamic code loading / unloading use case he has in facebook. Point being the GHC 7.8 version of the ObjLink api should actually give enough support tooling to prototype this idea in user land, and that plus better support for writing direct haskell code and getting out both a local computation and an AST we can serialize would probably be a good set of primitives for making this feasible in user land. I The meat of my point is 1) yes I want this too but also 2) one thing I really have come to appreciate about how GHC is engineered is a lot of work is done to provide the right primitives so that really really great tools can be built in user land. I think That the goal of this proposal can be accomplished quite nicely with the ObjLink module, unless i'm not understanding something. In Fact, because in general not every computation will be properly serializable, you need not even bother with tracking an explicit symbol table on each side, just try to load it at a given type and if it fails it wasn't there! The point being, linkers are a thing, ghc exposes an API for linking, have you tried that api? http://www.haskell.org/ghc/docs/latest/html/libraries/ghc-7.6.3/ObjLink.html On Tue, Jan 28, 2014 at 10:21 AM, Brandon Allbery allber...@gmail.comwrote: On Tue, Jan 28, 2014 at 7:53 AM, Mathieu Boespflug m...@tweag.io wrote: On Sat, Jan 25, 2014 at 7:12 PM, Carter Schonwald carter.schonw...@gmail.com wrote: 1) you should (once 7.8 is out) evaluate how far you can push your ideas wrt dynamic loading as a user land library. If you can't make it work as a library and can demonstrate why (or how even though it works its not quite satisfactory), thats signals something! Signals what? That there is a shortcoming in ghc and/or the rts that needs to be addressed. -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Static values language extension proposal
Hello Carter, Thanks for the links. IIUC the ObjLink module contains an interface to the RTS linker. The points raised by Mathieu in his last email as (1a), (1b) and (2) still hold. Here's a use case for (2): module Communicate(run) import Control.Distributed.Process f :: Int - Int f = id runSend :: Process () runSend = send someone (static f) runExpect :: Int - Process Int runExpect n = fmap (($ n) . unstatic) expect If any program tries to use runExpect, it would fail at runtime because it would fail to find `f`, because `f` is not exported and therefore a symbol for it would not appear in object files. The solution that modifies the compiler is superior to all workarounds we could think of to workaround this problem with a library. Any suggestions? Best, Facundo On Tue, Jan 28, 2014 at 3:03 PM, Carter Schonwald carter.schonw...@gmail.com wrote: Theres actually a missing piece of information in this thread: what are the example computations that are being sent? My understanding is that erlang has not way to send file handles, shared variables, Tvars, Mvars, memory mapped binary files, GPU code / memory pointers , and other fun unportable things between nodes, and I don't really expect / see how we can hope to sanely do that in haskell! point in fact, even when restricted to exactly the same binary, running on a cluster of homogeneous machines with the exact same hardware, with a modern linux distro you hit some gnarly problems doing this for arbitrary closures! Its for a very simple (and fun) reason: address randomization! Nathan Howell was actually doing some experimentation with one strategy for this special case here https://github.com/alphaHeavy/vacuum-tube as a deeply rts twiddling bit of hackery so you could in fact serialize arbitrary closures between homogeneous machines running the exact same code (and with address randomization disabled too i think) on the GHC API front, http://www.haskell.org/ghc/docs/latest/html/libraries/ghc-7.6.3/DynamicLoading.html along with (and more appropriately http://www.haskell.org/ghc/docs/latest/html/libraries/ghc-7.6.3/ObjLink.html ) should actually give enough basic tooling to make this possible as a userland library, mind you unload was recently fixed up in HEAD by Simon Marlow to support the dynamic code loading / unloading use case he has in facebook. Point being the GHC 7.8 version of the ObjLink api should actually give enough support tooling to prototype this idea in user land, and that plus better support for writing direct haskell code and getting out both a local computation and an AST we can serialize would probably be a good set of primitives for making this feasible in user land. I The meat of my point is 1) yes I want this too but also 2) one thing I really have come to appreciate about how GHC is engineered is a lot of work is done to provide the right primitives so that really really great tools can be built in user land. I think That the goal of this proposal can be accomplished quite nicely with the ObjLink module, unless i'm not understanding something. In Fact, because in general not every computation will be properly serializable, you need not even bother with tracking an explicit symbol table on each side, just try to load it at a given type and if it fails it wasn't there! The point being, linkers are a thing, ghc exposes an API for linking, have you tried that api? http://www.haskell.org/ghc/docs/latest/html/libraries/ghc-7.6.3/ObjLink.html On Tue, Jan 28, 2014 at 10:21 AM, Brandon Allbery allber...@gmail.com wrote: On Tue, Jan 28, 2014 at 7:53 AM, Mathieu Boespflug m...@tweag.io wrote: On Sat, Jan 25, 2014 at 7:12 PM, Carter Schonwald carter.schonw...@gmail.com wrote: 1) you should (once 7.8 is out) evaluate how far you can push your ideas wrt dynamic loading as a user land library. If you can't make it work as a library and can demonstrate why (or how even though it works its not quite satisfactory), thats signals something! Signals what? That there is a shortcoming in ghc and/or the rts that needs to be addressed. -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Static values language extension proposal
Escuse me, the module export list was meant to be module Communicate(runExpect, runSend) where Facundo On Tue, Jan 28, 2014 at 5:13 PM, Facundo Domínguez facundo.doming...@tweag.io wrote: Hello Carter, Thanks for the links. IIUC the ObjLink module contains an interface to the RTS linker. The points raised by Mathieu in his last email as (1a), (1b) and (2) still hold. Here's a use case for (2): module Communicate(run) import Control.Distributed.Process f :: Int - Int f = id runSend :: Process () runSend = send someone (static f) runExpect :: Int - Process Int runExpect n = fmap (($ n) . unstatic) expect If any program tries to use runExpect, it would fail at runtime because it would fail to find `f`, because `f` is not exported and therefore a symbol for it would not appear in object files. The solution that modifies the compiler is superior to all workarounds we could think of to workaround this problem with a library. Any suggestions? Best, Facundo On Tue, Jan 28, 2014 at 3:03 PM, Carter Schonwald carter.schonw...@gmail.com wrote: Theres actually a missing piece of information in this thread: what are the example computations that are being sent? My understanding is that erlang has not way to send file handles, shared variables, Tvars, Mvars, memory mapped binary files, GPU code / memory pointers , and other fun unportable things between nodes, and I don't really expect / see how we can hope to sanely do that in haskell! point in fact, even when restricted to exactly the same binary, running on a cluster of homogeneous machines with the exact same hardware, with a modern linux distro you hit some gnarly problems doing this for arbitrary closures! Its for a very simple (and fun) reason: address randomization! Nathan Howell was actually doing some experimentation with one strategy for this special case here https://github.com/alphaHeavy/vacuum-tube as a deeply rts twiddling bit of hackery so you could in fact serialize arbitrary closures between homogeneous machines running the exact same code (and with address randomization disabled too i think) on the GHC API front, http://www.haskell.org/ghc/docs/latest/html/libraries/ghc-7.6.3/DynamicLoading.html along with (and more appropriately http://www.haskell.org/ghc/docs/latest/html/libraries/ghc-7.6.3/ObjLink.html ) should actually give enough basic tooling to make this possible as a userland library, mind you unload was recently fixed up in HEAD by Simon Marlow to support the dynamic code loading / unloading use case he has in facebook. Point being the GHC 7.8 version of the ObjLink api should actually give enough support tooling to prototype this idea in user land, and that plus better support for writing direct haskell code and getting out both a local computation and an AST we can serialize would probably be a good set of primitives for making this feasible in user land. I The meat of my point is 1) yes I want this too but also 2) one thing I really have come to appreciate about how GHC is engineered is a lot of work is done to provide the right primitives so that really really great tools can be built in user land. I think That the goal of this proposal can be accomplished quite nicely with the ObjLink module, unless i'm not understanding something. In Fact, because in general not every computation will be properly serializable, you need not even bother with tracking an explicit symbol table on each side, just try to load it at a given type and if it fails it wasn't there! The point being, linkers are a thing, ghc exposes an API for linking, have you tried that api? http://www.haskell.org/ghc/docs/latest/html/libraries/ghc-7.6.3/ObjLink.html On Tue, Jan 28, 2014 at 10:21 AM, Brandon Allbery allber...@gmail.com wrote: On Tue, Jan 28, 2014 at 7:53 AM, Mathieu Boespflug m...@tweag.io wrote: On Sat, Jan 25, 2014 at 7:12 PM, Carter Schonwald carter.schonw...@gmail.com wrote: 1) you should (once 7.8 is out) evaluate how far you can push your ideas wrt dynamic loading as a user land library. If you can't make it work as a library and can demonstrate why (or how even though it works its not quite satisfactory), thats signals something! Signals what? That there is a shortcoming in ghc and/or the rts that needs to be addressed. -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Static values language extension proposal
Mathieu Boespflug wrote: [Sorry for the multiple reposts - couldn't quite figure out which email address doesn't get refused by the list..] Hi Carter, thank you for the good points you raise. I'll try and address each of them as best I can below. 0) I think you could actually implement this proposal as a userland library, at least as you've described it. Have you tried doing so? Indeed, this could be done without touching the compiler at all. We had this response really early on in this discussion. Quite honestly I think that should have been the end of the discussion. The existing GHC release already have a huge workload getting releases out the door and adding to that workload without adding manpower and resources would be a bad idea. You really should try doing this as a library outside of GHC and if GHC needs a few small additional features, they can be added. The `static e` form could as well be a piece of Template Haskell, but making it a proper extension means that the compiler can enforce more invariants and be a bit more helpful to the user. Once it works outside GHC and has proven useful, then it might be worthwhile add small specific, easily testable/maintainable features to GHC to support what goes on on your library. Erik -- -- Erik de Castro Lopo http://www.mega-nerd.com/ ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Static values language extension proposal
Hi Brandon, On 26 Jan 2014, at 19:01, Brandon Allbery wrote: On Sun, Jan 26, 2014 at 1:43 PM, Tim Watson watson.timo...@gmail.com wrote: In Erlang, I can rpc/send *any* term and evaluate it on another node. That includes functions of course. Whether or not we want to be quite that general is another matter, but that is the comparison I've been making. Note that Erlang gets away with this through being a virtual machine architecture; BEAM is about as write-once-run-anywhere as it gets, and the platform specifics are abstracted by the BEAM VM interpreter. You just aren't going to accomplish this with a native compiled language, without encoding as a virtual machine yourself (that is, the AST-based mechanisms). Yeah, I do realise this. Of course we're not trying to reproduce the BEAM really, but what we /do/ want is to be able to do is exchange messages between nodes that are not running the same executable. The proposal does appear to address this requirement, at least to some extent. There may be complementary (or better) approaches. I believe Carter is going to provide some additional details viz his work in this area at some point. Anything that reduces the amount of Template Haskell required to work with Cloud Haskell is a good thing (tm) IMO. Not that I mind using TH, but the programming model is currently quite awkward from the caller's perspective, since you've got to (a) create a Static/Closure out of potentially complex chunks of code, which often involves creating numerous top level wrapper APIs and (b) fiddle around with the remote-table (both in the code that defines remote-able thunks *and* in the code that starts a node wishing to operate on them. Also note that this problem isn't limited to sending code around the network. Just sending arbitrary *data* between nodes is currently discouraged (though not disallowed) because the receiving program *might* not understand the types you're sending it. This is very restrictive and the proposal does, at the very least, allow us to safely serialise, send and receive types that both programs know about by virtue of having been linked to the same library/libraries. But yes - there are certainly constraints and edge cases aplenty here. I'm not entirely sure whether or not we'd need to potentially change the (binary) encoding of raw messages in distributed-process, for example, in response to this change. Currently we serialise a pointer (i.e., the pointer to the fingerprint for the type that's being sent), and I can imagine that not working properly across different nodes running on different architectures etc. Perhaps you should consider fleshing out ghc's current bytecode support to be a full VM? After discussing this with Simon M, we concluded there was little point in doing so. The GHC RTS is practically a VM anyway, and there's probably not that much value to be gained by shipping bytecode around. Besides, as you put it, the AST-based mechanisms allow for this anyway (albeit with some coding required on the part of the application developer) and Carter (and others) assure me that the mechanisms required to do this kind of thing already exist. We just need to find the right way to take advantage of them. Or perhaps an interesting alternative would be a BEAM backend for ghc. I've talked to a couple of people that want to try this. I'm intrigued, but have other things to focus on. :) Cheers, Tim___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Static values language extension proposal
On 25 Jan 2014, at 18:12, Carter Schonwald wrote: 1) you should (once 7.8 is out) evaluate how far you can push your ideas wrt dynamic loading as a user land library. If you can't make it work as a library and can demonstrate why (or how even though it works its not quite satisfactory), thats signals something! Is that something you'll consider looking at Matthieu? Theres quite a few industrial haskell shops that provide products / services where internally they do runtime dynamic loading of user provided object files, so i'm sure that the core GHC support is there if you actually dig into the apis! And they do this in a distributed systems context, sans CH. We have a pull request from Edsko that melds hs-plugins support with static, as per the original proposal's notes, so this seems like a corollary issue to me. 2) I've a work in progress on specing out a proper (and sound :) ) static values type extension for ghc, that will be usable perhaps in your your case (though by dint of being sound, will preclude some of the things you think you want). BUT, any type system changes need to actually provide safety. My motivation for having a notion of static values comes from a desire to add compiler support for certain numerical computing operations that require compiler support to be usable in haskell. BUT, much of the same work Timescales? There are commercial users of Cloud Haskell clamouring for improvements to the way we handle this situation, and I'm keen to combine getting broader community agreements about the right thing to do with facilitating our users real needs. If there are other options pertaining to static support, I'd like to know more! @tim: what on earth does sending arbitrary code mean? I feel like the more precise thing everyone here wants is for a given application / infrastructure deployment, I would to be able to send my application specific computations over the network, using cloud haskell, and be sure that both sides think its the same code. With Cloud Haskell in its current guise, I can Closure up pretty any thunk I like and spawn it on a remote node. If the node's are both running the same executable, we're fine. If they're not, we're potentially in trouble. In Erlang, I can rpc/send *any* term and evaluate it on another node. That includes functions of course. Whether or not we want to be quite that general is another matter, but that is the comparison I've been making. As for *how* to send an AST fragment, edward kmett and other have some pretty nice typed AST models that are easy to adapt and extend for an application specific use case. Bound http://hackage.haskell.org/package/bound is one nice one. heres a really really good school of haskell exposition https://www.fpcomplete.com/user/edwardk/bound And theres a generalization that supports strong typing that i've copied from an hpaste https://gist.github.com/cartazio/5727196, where its notable that the AST data type is called Remote :), I think thats a hint its meant to be a haskell manipulable way of constructing a typed DSL you can serialize using a finally tagless style api approach (ie have a set of type class instances / operations that you use to run the computation and/or construct the AST you can send over the wire) These are all lovely, but aren't we talking about either (a) putting together an AST to represent whatever valid Haskell program someone wants to send, or (b) forcing every application developer to write an AST to cover all their remote computations. Both of those sound like a lot more work than the proposal below. They may be the right approach from some domains, but there is a fair bit of developer overhead involved from what I can see. On Fri, Jan 24, 2014 at 3:19 PM, Mathieu Boespflug 0xbadc...@gmail.com wrote: The `static e` form could as well be a piece of Template Haskell, but making it a proper extension means that the compiler can enforce more invariants and be a bit more helpful to the user. In particular, detecting situations where symbolic references cannot be generated because e.g. the imported packages were not compiled as dynamic linked libraries. Or seamlessly supporting calling `static f` on an idenfier `f` that is not exported by the module. All of which sound like a usability improvement to me. I very much subscribe to the idea of defining small DSL's for exchanging code between nodes. And this proposal is compatible with that idea. One thing that might not have been so clear in the original email is that we are proposing here to introduce just *one such DSL*. It's just that it's a trivial one whose grammar only contains linker symbol names. That triviality is a rather important point as well, because... As it happens, distributed-static today already supports two such DSL's: a DSL of labels, which are arbitrary string names for functions, and a small language
Re: Static values language extension proposal
On Sun, Jan 26, 2014 at 1:43 PM, Tim Watson watson.timo...@gmail.comwrote: In Erlang, I can rpc/send *any* term and evaluate it on another node. That includes functions of course. Whether or not we want to be quite that general is another matter, but that is the comparison I've been making. Note that Erlang gets away with this through being a virtual machine architecture; BEAM is about as write-once-run-anywhere as it gets, and the platform specifics are abstracted by the BEAM VM interpreter. You just aren't going to accomplish this with a native compiled language, without encoding as a virtual machine yourself (that is, the AST-based mechanisms). Perhaps you should consider fleshing out ghc's current bytecode support to be a full VM? Or perhaps an interesting alternative would be a BEAM backend for ghc. -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Static values language extension proposal
anyways 1) you should (once 7.8 is out) evaluate how far you can push your ideas wrt dynamic loading as a user land library. If you can't make it work as a library and can demonstrate why (or how even though it works its not quite satisfactory), thats signals something! But I really think insisting that the linker symbol names denote the datum agreement in a distributed system is punting on what should be handled at the application level. Simon Marlow put some improvements into GHC to help improve doing dynamic code (un)loading, stress test that! Theres quite a few industrial haskell shops that provide products / services where internally they do runtime dynamic loading of user provided object files, so i'm sure that the core GHC support is there if you actually dig into the apis! And they do this in a distributed systems context, sans CH. 2) I've a work in progress on specing out a proper (and sound :) ) static values type extension for ghc, that will be usable perhaps in your your case (though by dint of being sound, will preclude some of the things you think you want). BUT, any type system changes need to actually provide safety. My motivation for having a notion of static values comes from a desire to add compiler support for certain numerical computing operations that require compiler support to be usable in haskell. BUT, much of the same work @tim: what on earth does sending arbitrary code mean? I feel like the more precise thing everyone here wants is for a given application / infrastructure deployment, I would to be able to send my application specific computations over the network, using cloud haskell, and be sure that both sides think its the same code. As for *how* to send an AST fragment, edward kmett and other have some pretty nice typed AST models that are easy to adapt and extend for an application specific use case. Bound http://hackage.haskell.org/package/bound is one nice one. heres a really really good school of haskell exposition https://www.fpcomplete.com/user/edwardk/bound And theres a generalization that supports strong typing that i've copied from an hpaste https://gist.github.com/cartazio/5727196, where its notable that the AST data type is called Remote :), I think thats a hint its meant to be a haskell manipulable way of constructing a typed DSL you can serialize using a finally tagless style api approach (ie have a set of type class instances / operations that you use to run the computation and/or construct the AST you can send over the wire) On Fri, Jan 24, 2014 at 3:19 PM, Mathieu Boespflug 0xbadc...@gmail.comwrote: [Sorry for the multiple reposts - couldn't quite figure out which email address doesn't get refused by the list..] Hi Carter, thank you for the good points you raise. I'll try and address each of them as best I can below. 0) I think you could actually implement this proposal as a userland library, at least as you've described it. Have you tried doing so? Indeed, this could be done without touching the compiler at all. We thought long and hard about a path that would ultimately make an extension either unnecessary, or at any rate very small. At this point, the only thing that we are proposing to add to the compiler is the syntactic form static e. Contrary to the presentation in the paper, the 'unstatic' function can be implemented entirely as library code and does not need to be a primop. Moreover, we do not need to piece together any kind of global remote table at compile time or link time, because we're piggy backing on that already constructed by the system linker. The `static e` form could as well be a piece of Template Haskell, but making it a proper extension means that the compiler can enforce more invariants and be a bit more helpful to the user. In particular, detecting situations where symbolic references cannot be generated because e.g. the imported packages were not compiled as dynamic linked libraries. Or seamlessly supporting calling `static f` on an idenfier `f` that is not exported by the module. 1) what does this accomplish that can not be accomplished by having various nodes agree on a DSL, and sending ASTs to each other? 1a) in fact, I'd argue (and some others agree, and i'll admit my opinions have been shaped by those more expert than me) that the sending a wee AST you can interpret on the other side is much SAFER than sending a function symbol thats hard coded hopefully into both programs in a way that it means the same thing. I very much subscribe to the idea of defining small DSL's for exchanging code between nodes. And this proposal is compatible with that idea. One thing that might not have been so clear in the original email is that we are proposing here to introduce just *one such DSL*. It's just that it's a trivial one whose grammar only contains linker symbol names. As it happens, distributed-static today already supports two such DSL's: a DSL of labels,
Re: Static values language extension proposal
Hey Facundo, thanks for sharing this proposal. several questions: 0) I think you could actually implement this proposal as a userland library, at least as you've described it. Have you tried doing so? 1) what does this accomplish that can not be accomplished by having various nodes agree on a DSL, and sending ASTs to each other? 1a) in fact, I'd argue (and some others agree, and i'll admit my opinions have been shaped by those more expert than me) that the sending a wee AST you can interpret on the other side is much SAFER than sending a function symbol thats hard coded hopefully into both programs in a way that it means the same thing. I've had many educational conversations with 2) how does it provide more type safety than the current TH based approach? (I've seen Tim and others hit very very gnarly bugs in cloud haskell based upon the magic static values approach). 3) this proposal requires changes to linking etc that would really make it useful only on systems and deployments that only have Template Haskell AND Dynamic linking. (and also rules out any context where it'd be nice to deploy a static app or say, use CH in ios! ) to repeat: have you considered defining an AST type + interpreter for the computations you want to send around, and doing that? I think its a much simpler, safer, easier, flexible and PORTABLE approach, though one current CH doesn't do (though the folks working on CH seem to be receptive to switching to such a strategy if someone validates it) cheers -Carter On Fri, Jan 24, 2014 at 12:19 PM, Facundo Domínguez facundo.doming...@tweag.io wrote: Hello, With the support of Tweag I/O, Mathieu and I have been assembling a design proposal for the language extension for Static values that will take Cloud Haskell a big step forward in usability. Please, find the proposal inlined below. We are looking forward to discuss its feasibility and features with the community. Best, Facundo -- In these notes we discuss a design of the language extension proposed in [1] for Cloud Haskell. That is, support from the compiler to produce labels that can be used to identify Haskell top-level bindings across processes in a network. Static values = Following [1], the extension consists of a new syntactic form `static e`, along with a type constructor `StaticRef` and a function unstatic :: StaticRef a - a The idea is that values of type `StaticRef a` uniquely identify a value that can be referred to by a global name rather than serialized over the network between processes that are instances of a single binary, because all such processes share the same top-level bindings. Generating static references We start by introducing global names. A `GlobalName` is a symbol bound in the top-level environment. It is much like global names in Template Haskell, but `GlobalNames` always refer to terms, and they include a package version. data GlobalName = GlobalName PkgName PkgVersion ModName OccName `GlobalNames` can be used as references to static values. newtype StaticRef a = StaticRef GlobalName `StaticRef a` is to `GlobalName` what `Ptr a` is to `Addr#`: a wrapper with a phantom type parameter that keeps track of the type of the value that is referenced. The special form static e is an expression of type `StaticRef a` where `e :: a` is a closed expression (meaning any free variables in `e` are bound in the top-level environment). If `e` is an identifier, `static e` just refers to it. Otherwise, the compiler needs to introduce a new top-level binding with a fresh name and the expression used as right-hand side, and the static reference would point to this top-level binding instead. Looking up static references `unstatic` is implemented as a function which finds a top-level value from the `GlobalName`, otherwise it raises an exception. It crucially relies on leveraging the system’s dynamic linker, so out-of-the-box only works with dynamically linked binaries (but see below). `unstatic` proceeds as follows: * Determines the name of the shared library from the package name and the package version. * Determines the symbol of the value by Z-Encoding the package name, the module name and the value name. * Uses the system’s dynamic linker interface to obtain the address of the symbol. * Converts the symbol to a haskell value with `GHC.Prim.addrToAny#` In principle, only symbols in shared libraries can be found. However, the dynamic linker is able to find symbols in modules that are linked statically if GHC is fed with the option -optl-Wl,--export-dynamic. A future enhancement could be to have GHC warn the user when modules using the extension are linked statically and this option is not used during linking. GHC only defines symbols for exported definitions in modules. So unstatic won’t be able to find the private bindings of a module. For this
Re: Static values language extension proposal
I don't have time to weigh in on this proposal right now, but I have several comments... On 24 Jan 2014, at 17:19, Facundo Domínguez wrote: Rationale === We want the language extension to meet the following requirements: 1. It must be a practical alternative to the remoteTable functions in the distributed-static package. Agreed - this is vital! 2. It must not change the build scheme used for Haskell programs. A collection of .o files produced from Haskell source code should still be possible to link with the system linking tools. Also vital. 3. It must not restrict all communicating processes using the extension to be launched from the same binary. I personally think this is very valuable. About the need for using different binaries == While using distributed-process we found some use cases for supporting communicating closures between multiple binaries. One of these use cases involved a distributed application and a monitoring tool. The monitoring tool would need to link in some graphics libraries to display information on the screen, none of which were required by the monitored application. Conversely, the monitored application would link in some modules that the monitoring application didn’t need. Crucially, both applications are fairly loosely coupled, even if they both need to exchange static values about bindings in some modules they shared. Indeed - this is an almost canonical use-case, as are administrative (e.g., remote management) tools. As the application depends on shared libraries, now a tool to collect these libraries would be required so they can be distributed together with the executable binary when deploying a Cloud Haskell application in a cluster. We won’t delve further into this problem. Great idea. Another possible line of work is extending this approach so a process can pull shared objects from a remote peer, when this remote peer sends a static value that is defined in a shared object not available to the process. This would go a long way towards answering our questions about 'hot code upgrade' and be useful in many other areas too. ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Static values language extension proposal
On 24 Jan 2014, at 17:59, Carter Schonwald wrote: 0) I think you could actually implement this proposal as a userland library, at least as you've described it. Have you tried doing so? I didn't pick up on that at all - how would we be able to do that? 1) what does this accomplish that can not be accomplished by having various nodes agree on a DSL, and sending ASTs to each other? 1a) in fact, I'd argue (and some others agree, and i'll admit my opinions have been shaped by those more expert than me) that the sending a wee AST you can interpret on the other side is much SAFER than sending a function symbol thats hard coded hopefully into both programs in a way that it means the same thing. I've had many educational conversations with I've still not seen a convincing example of how to do this though. It would help if someone explained what this would look like, running over two (or more) separate binaries and still shipping code. It's just that, afaict, that AST wouldn't be so wee once it had to represent any arbitrary expression. One could, of course, just ship source (or some intermediate representation), but that would also require compiler infrastructure to be installed on the target. 2) how does it provide more type safety than the current TH based approach? (I've seen Tim and others hit very very gnarly bugs in cloud haskell based upon the magic static values approach). This is definitely true, but I see it as a problem related to our use of TH rather than our current use of closures and 'Static' per se. Having said that, it can be toe-curlingly difficult to work with closure/static sometimes, so *anything* that makes this easier sounds good to me. to repeat: have you considered defining an AST type + interpreter for the computations you want to send around, and doing that? I think its a much simpler, safer, easier, flexible and PORTABLE approach, though one current CH doesn't do (though the folks working on CH seem to be receptive to switching to such a strategy if someone validates it) I/we are, I think, amenable to doing whatever makes the most sense. This could include doing more than one thing, when it comes to dealing with 'statics'. Personally I think the proposal sounds interesting, though as I mentioned in my previously mail, I haven't had time to sit down and look at it in detail yet. Cheers, Tim ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Static values language extension proposal
On Fri, Jan 24, 2014 at 12:19 PM, Facundo Domínguez facundo.doming...@tweag.io wrote: In principle, only symbols in shared libraries can be found. However, the dynamic linker is able to find symbols in modules that are linked statically if GHC is fed with the option -optl-Wl,--export-dynamic. A This strikes me as highly platform specific to the Linux and possibly FreeBSD implementations of ELF; it likely will not work with Solaris ELF, which handles dynamic symbols differently (or at least used to), and will not work with non-ELF platforms (OS X, Windows) and probably won't work with a non-GNU ld such as is used on Solaris and OS X. -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Static values language extension proposal
[Sorry for the multiple reposts - couldn't quite figure out which email address doesn't get refused by the list..] Hi Carter, thank you for the good points you raise. I'll try and address each of them as best I can below. 0) I think you could actually implement this proposal as a userland library, at least as you've described it. Have you tried doing so? Indeed, this could be done without touching the compiler at all. We thought long and hard about a path that would ultimately make an extension either unnecessary, or at any rate very small. At this point, the only thing that we are proposing to add to the compiler is the syntactic form static e. Contrary to the presentation in the paper, the 'unstatic' function can be implemented entirely as library code and does not need to be a primop. Moreover, we do not need to piece together any kind of global remote table at compile time or link time, because we're piggy backing on that already constructed by the system linker. The `static e` form could as well be a piece of Template Haskell, but making it a proper extension means that the compiler can enforce more invariants and be a bit more helpful to the user. In particular, detecting situations where symbolic references cannot be generated because e.g. the imported packages were not compiled as dynamic linked libraries. Or seamlessly supporting calling `static f` on an idenfier `f` that is not exported by the module. 1) what does this accomplish that can not be accomplished by having various nodes agree on a DSL, and sending ASTs to each other? 1a) in fact, I'd argue (and some others agree, and i'll admit my opinions have been shaped by those more expert than me) that the sending a wee AST you can interpret on the other side is much SAFER than sending a function symbol thats hard coded hopefully into both programs in a way that it means the same thing. I very much subscribe to the idea of defining small DSL's for exchanging code between nodes. And this proposal is compatible with that idea. One thing that might not have been so clear in the original email is that we are proposing here to introduce just *one such DSL*. It's just that it's a trivial one whose grammar only contains linker symbol names. As it happens, distributed-static today already supports two such DSL's: a DSL of labels, which are arbitrary string names for functions, and a small language for composing Static values together. There is a patch lying around by Edsko proposing to add a third DSL: one that allows nodes to trade arbitrary Haskell strings that are then eval'ed on the other end by the 'plugins' package. As Facundo explains at the end of his email, the notion of a static value ought to be a more general one than was first envisioned in the paper: a static value is any closed denotation, denoted in any of a choice of multiple small languages, some of which ship standard with distributed-static. The user can define his own DSL for shipping code around. This is why we propose to make Static into a class. Each DSL is generated by one datatype. Each such datatype has a Static instance. If you would like to ship an AST around the cluster, you can make the datatype for that AST an instance of Static, with 'unstatic' being defined as an interpreter for your AST. Concretely: data HsExpr = ... instance Static HsExpr where unstatic e = Hs.interpret e I've had many educational conversations with ... ? 2) how does it provide more type safety than the current TH based approach? (I've seen Tim and others hit very very gnarly bugs in cloud haskell based upon the magic static values approach). The type safety of the current TH approach is reasonable I think. One potential problem comes from managing dynamically typed values in the remote table, which must be coerced to the right type and use the right decoders if you don't use TH. With the approach we propose, there is no remote table, so I guess this should help eliminate a source of bugs. 3) this proposal requires changes to linking etc that would really make it useful only on systems and deployments that only have Template Haskell AND Dynamic linking. (and also rules out any context where it'd be nice to deploy a static app or say, use CH in ios! ) I don't know about iOS. And it's very likely that there are contexts in which this extension doesn't work. But as I said above, you are always free to define your own DSL's that cover the particular use case that you have in mind. The nice thing with this particular DSL is that it requires little to no TH to generate label names, which can always be a source of bugs, especially when you forget to include them in the global remote table (which is something that TH doesn't and can't help you with). Furthermore, it was my understanding that GHC is heading towards a world of dynamic linkable by default, and it is by now something that is supported on most platforms by GHC. See e.g.
Re: Static library to redefine entrypoint
On Fri, 2009-04-24 at 12:56 +0200, Philip K.F. Hölzenspies wrote: Dear GHCers, I am trying to write a wrapper library for lab work to give to students. My problem is, that the libraries I use require initialization that I really want to hide from our students. The wrapper I'm writing is compiled to a static library and installed with cabal, so students can just ghc --make or ghci their sources. Here comes the problem: I want to define main and let students just define labMain as an entry point to their program. How can I have my library use labMain without a definition? Keep in mind that I want to give them a cabalized library that they can just link to, so I can't give them a template file that they fill and compile together with my code. Is it at all possible to have external functions and letting the linker sort stuff out? When I've set practicals like this I've just provided them with a 3 line Main module that imports functions exported by the module(s) that the students write. Eg I have them fill in Draw.lhs but tell them to compile the thing using ghc --make Main.hs. I never found that this confused any of them (indeed some were interested in looking at the code). Duncan ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Static library to redefine entrypoint
Why not just tell them to import your library and do something like main = withSomeInit labMain where withSomeInit is the function you provide? This approach is present in some other libs that require initialization. Best regards Christopher Skrzętnicki On Fri, Apr 24, 2009 at 12:56, Philip K.F. p.k.f.holzensp...@utwente.nlwrote: Dear GHCers, I am trying to write a wrapper library for lab work to give to students. My problem is, that the libraries I use require initialization that I really want to hide from our students. The wrapper I'm writing is compiled to a static library and installed with cabal, so students can just ghc --make or ghci their sources. Here comes the problem: I want to define main and let students just define labMain as an entry point to their program. How can I have my library use labMain without a definition? Keep in mind that I want to give them a cabalized library that they can just link to, so I can't give them a template file that they fill and compile together with my code. Is it at all possible to have external functions and letting the linker sort stuff out? Regards, Philip ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Static library to redefine entrypoint
On Fri, 2009-04-24 at 13:06 +0200, Krzysztof Skrzętnicki wrote: Why not just tell them to import your library and do something like main = withSomeInit labMain where withSomeInit is the function you provide? This approach is present in some other libs that require initialization. Dear Christopher, I know there are alternatives and I know some people use them. A particular problem I have now, though, is SDL. On OS X, the SDL library defines an alternative entry-point to the application, called SDL_main, where the libSDL.a provides a main (insert long story about Cocoa frameworks and Objective-C linking here). I don't particularly like this method, but it's the world I have to work with. Also, many alternatives to SDL don't play nice with GHCi, which is particularly useful for lab teaching. If I can somehow introduce my own new entry point, I could also wrap GHCi in something else quite easily (I know I could wrap GHCi as it is, but it would be even nicer if I could just link to the binary). I figured this level of detail would distract form the question, though and I would run the risk that people would try to solve my SDL linking woes, which is not the point of the question. Regards, Philip ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static linking
Hello, Further on my static linking woes: debian ~$ ghc --version The Glorious Glasgow Haskell Compilation System, version 6.8.2 -debian ~$ cat T.hs main :: IO () main = putStrLn Hello world -debian ~$ ghc -optl-static -static --make T.hs Linking T ... /usr/lib/gcc/i486-linux-gnu/4.2.3/../../../../lib/ librt.a(timer_create.o): In function `timer_create': (.text+0x107): undefined reference to `pthread_once' ... references to missing pthread symbols Does anyone have static linking working for GHC 6.8.2 and can inform me of the magic incantation? Get the latest development version from darcs, perhaps? BTW when I said move to the end, I meant move to the end of -l flags. cheers peter On 27/05/2008, at 10:37 AM, Peter Gammie wrote: Hello, I am having a bit of trouble static linking my program using GHC 6.8.2. In brief: rt uses pthread, but -lrt is the final thing on the command line passed to the linker, and so the pthread symbols are not resolved. Manually moving -lpthread to the end of the collect2 command line does the trick. The question is how to do this using ghc. This is on Debian, using the 6.8.2-5 from unstable. I can provide the command lines if that is helpful. Note the same setup worked fine under GHC 6.6.1. cheers peter ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static linking
Peter Gammie wrote: Hello, Further on my static linking woes: debian ~$ ghc --version The Glorious Glasgow Haskell Compilation System, version 6.8.2 -debian ~$ cat T.hs main :: IO () main = putStrLn Hello world -debian ~$ ghc -optl-static -static --make T.hs Linking T ... /usr/lib/gcc/i486-linux-gnu/4.2.3/../../../../lib/librt.a(timer_create.o): In function `timer_create': (.text+0x107): undefined reference to `pthread_once' ... references to missing pthread symbols Does anyone have static linking working for GHC 6.8.2 and can inform me of the magic incantation? Get the latest development version from darcs, perhaps? BTW when I said move to the end, I meant move to the end of -l flags. We may need to tweak the order of the libraries in rts/package.conf.in (this is where -lrt comes from). The question is, do we need a configure test? Cheers, Simon cheers peter On 27/05/2008, at 10:37 AM, Peter Gammie wrote: Hello, I am having a bit of trouble static linking my program using GHC 6.8.2. In brief: rt uses pthread, but -lrt is the final thing on the command line passed to the linker, and so the pthread symbols are not resolved. Manually moving -lpthread to the end of the collect2 command line does the trick. The question is how to do this using ghc. This is on Debian, using the 6.8.2-5 from unstable. I can provide the command lines if that is helpful. Note the same setup worked fine under GHC 6.6.1. cheers peter ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static constants -- ideas?
jason.dusek: I have an awkward programming problem -- I need to take a dictionary, parse it, build a bunch of intermediate lists and then make maps and tries out of the list. A programming problem because it's taken me a fair amount of effort to pull together the parser and list generator -- and awkward because a 69000 item list, [(String, [(String, String)])], does not compile under GHC (stack overflow). (It's not likely to compile under anything else, either!) Here's an example of the approach Bryan outlined, which does seem to work for files as large as gcc can handle: * generate your big Haskell Map * serialise it with Data.Binary, and Codec.Compression.GZip to a file * compile the data into a C const array, and link that into Haskell * decode it on startup, ressurecting the Haskell data. The C source looks like: const uint8_t beowulf[] = { 31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 124, 189, 75, 150, 46, 54, 93, 193, 96, 144, 241, 168, 172, 238, 214, 0, ... http://code.haskell.org/~dons/code/compiled-constants/cbits/constants.c which is the gzip, Data.Binary encoded version of a Map ByteString Int. Then the Haskell code need only access this array as a Ptr Word8, wrap that as a Bytestring, then run Data.Binary over the result to rebuild the Map. As you can see here: http://code.haskell.org/~dons/code/compiled-constants/Constants.hs I've put a couple of examples of how to access C-side serialised Haskell values in a package here: http://code.haskell.org/~dons/code/compiled-constants/ Cheers, Don ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static constants -- ideas?
Jason Dusek [EMAIL PROTECTED]: Bryan O'Sullivan [EMAIL PROTECTED] wrote: The trick I usually use in cases like this is to compile the data as C code and link against it, then access it from Haskell via a Ptr. For my particular application, I really need to ship a single static binary that has it all -- data as well as algorithms -- so I'm going with the FFI. It's too bad that I end up working in the IO monad much of the time. I hope we'll have massive static constants someday soon! unsafePerformIO should be safe on constants, right? It has worked for me, at least. Jay ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static constants -- ideas?
On Sat, Mar 1, 2008 at 12:24 PM, Jay Scott [EMAIL PROTECTED] wrote: Jason Dusek [EMAIL PROTECTED]: unsafePerformIO should be safe on constants, right? It has worked for me, at least. Unfortunately, reading in the list does not allow me to ship a single binary. It's not file reading, though, that forces me in to the IO Monad -- it's pointer dereferencing. -- _jsn ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static constants -- ideas?
Simon Peyton-Jones [EMAIL PROTECTED] wrote: It's not quite as stupid as it sounds...have another go when you see that #2002 is fixed. Thanks for pointing me to that -- in the meantime, I'd still rather write C and Haskell than plain C++! -- _jsn ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static constants -- ideas?
jay: Don Stewart [EMAIL PROTECTED]: jay: Don Stewart [EMAIL PROTECTED]: jay: I also have constants that are too large to compile. I am resigned to loading them from data files--other solutions seem even worse. ... Data.Binary eases the irritation somewhat. Did you try bytestring literals (and maybe parsing them in-memory with Data.Binary)? I finally squeezed enough time to try it, and it didn't work for me. -- ghc Overflow.hs [1 of 1] Compiling Overflow ( Overflow.hs, Overflow.o ) Enable optimisations! Compile with ghc -O2. You need this to avoid having a very slow pack call at runtime. Overflow.hs:8:10:stack overflow: use +RTS -Ksize to increase it -- where Overflow.hs is in the vicinity of 40M and looks like -- {-# LANGUAGE OverloadedStrings #-} module Overflow where import qualified Data.ByteString.Lazy as S bigData :: S.ByteString bigData = \0\0\0\0\0\5\67\195\0\0\0\0... -- I didn't compress it, because Codec.Compression.GZip didn't compile for me. It looked like a library change since 6.6 broke it. Probably you don't have the zlib.h header? Or make sure you have the latest version of zlib from hackage -- it does work. Is there a handy string escaping function in the libraries somewhere? It only took a minute to write one, and I spent longer than that looking, so maybe it's the wrong question Surely it's in there somewhere, and I'm just 2 dum 2 c. The show function? ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static constants -- ideas?
Don Stewart [EMAIL PROTECTED]: jay: Don Stewart [EMAIL PROTECTED]: jay: I also have constants that are too large to compile. I am resigned to loading them from data files--other solutions seem even worse. ... Data.Binary eases the irritation somewhat. Did you try bytestring literals (and maybe parsing them in-memory with Data.Binary)? I finally squeezed enough time to try it, and it didn't work for me. -- ghc Overflow.hs [1 of 1] Compiling Overflow ( Overflow.hs, Overflow.o ) Overflow.hs:8:10:stack overflow: use +RTS -Ksize to increase it -- where Overflow.hs is in the vicinity of 40M and looks like -- {-# LANGUAGE OverloadedStrings #-} module Overflow where import qualified Data.ByteString.Lazy as S bigData :: S.ByteString bigData = \0\0\0\0\0\5\67\195\0\0\0\0... -- I didn't compress it, because Codec.Compression.GZip didn't compile for me. It looked like a library change since 6.6 broke it. Is there a handy string escaping function in the libraries somewhere? It only took a minute to write one, and I spent longer than that looking, so maybe it's the wrong question Surely it's in there somewhere, and I'm just 2 dum 2 c. Jay ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static constants -- ideas?
Don Stewart [EMAIL PROTECTED]: jay: Don Stewart [EMAIL PROTECTED]: jay: I also have constants that are too large to compile. I am resigned to loading them from data files--other solutions seem even worse. ... Data.Binary eases the irritation somewhat. Did you try bytestring literals (and maybe parsing them in-memory with Data.Binary)? That didn't occur to me, since neither of my large constants includes strings I think you're suggesting that each constant could appear in the source as a long bytestring and be deserialized into the data structure. If that works, it should improve the startup time, but it's still not as nice as simply compiling it straight up. I'll try it. Here's an example, which stores a Data.Map in a gzip-compressed bytestring literal (a C string literal in the compiled code). The Map is reconstructed on startup. {-# LANGUAGE OverloadedStrings #-} import Data.Binary import qualified Data.Map as M import qualified Data.ByteString.Char8 as S import Data.ByteString.Lazy import Codec.Compression.GZip -- -- this is a gzip compressed literal bytestring, storing a binary- encoded Data.Map -- mytable = \US\139\b\NUL\NUL\NUL\NUL\NUL\NUL\ETXEN\219\SO\194 \f\197\224 \188\196\CAN\227\US\224\171~\NAKc\GS4ce\161`\178\191\215(\176\190\180\167 \231\210\n\241\171\203\191\ti\157\217\149\249 \ENQ\214\9\202\162\179a \132X\233\ESC=\231\215\164\SYN\157\DC2D\226*\146\174o\t\167\DLE\209\i_ \240\193\129\199W\250nC\CAN\212\CAN\162J\160\141C\178\133\216;[EMAIL PROTECTED] \203\209x\205\140\166\RS\163\237]9f\170\143\ACK\163g\223\STX\184\7\rH \222\FSW\130\7D\197\NUL\164\0U\193\186\t\186o\228\180~\NUL\a6\249\137# \SOH\NUL\NUL main = print = M.lookup ghc m where -- build the table from the bytestring: m :: M.Map String (Maybe String) m = decode . decompress . fromChunks . return $ mytable Running it: $ ./A Just dinosaur! :) Important to use a bytestring, since that gets compiled to a C string literal (and not messed with by the simplifier). -- Don ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static constants -- ideas?
Don Stewart [EMAIL PROTECTED]: jay: Don Stewart [EMAIL PROTECTED]: jay: Don Stewart [EMAIL PROTECTED]: jay: I also have constants that are too large to compile. I am resigned to loading them from data files--other solutions seem even worse. ... Data.Binary eases the irritation somewhat. Did you try bytestring literals (and maybe parsing them in-memory with Data.Binary)? I finally squeezed enough time to try it, and it didn't work for me. -- ghc Overflow.hs [1 of 1] Compiling Overflow ( Overflow.hs, Overflow.o ) Enable optimisations! Compile with ghc -O2. You need this to avoid having a very slow pack call at runtime. Yes, I tried basic variations like that. The result is the same with -O1 or with -O2, and with Data.ByteString or Data.ByteString.Lazy . I'm just 2 dum 2 c. The show function? Ha ha! Jay ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static constants -- ideas?
jay: Don Stewart [EMAIL PROTECTED]: jay: Don Stewart [EMAIL PROTECTED]: jay: Don Stewart [EMAIL PROTECTED]: jay: I also have constants that are too large to compile. I am resigned to loading them from data files--other solutions seem even worse. ... Data.Binary eases the irritation somewhat. Did you try bytestring literals (and maybe parsing them in-memory with Data.Binary)? I finally squeezed enough time to try it, and it didn't work for me. -- ghc Overflow.hs [1 of 1] Compiling Overflow ( Overflow.hs, Overflow.o ) Enable optimisations! Compile with ghc -O2. You need this to avoid having a very slow pack call at runtime. Yes, I tried basic variations like that. The result is the same with -O1 or with -O2, and with Data.ByteString or Data.ByteString.Lazy . Ok, hmm, that really shouldn't be the case. Do you have the example available somewhere? It's just a 40M inline bytestring? -- Don ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static constants -- ideas?
Bryan O'Sullivan [EMAIL PROTECTED] wrote: The trick I usually use in cases like this is to compile the data as C code and link against it, then access it from Haskell via a Ptr. For my particular application, I really need to ship a single static binary that has it all -- data as well as algorithms -- so I'm going with the FFI. It's too bad that I end up working in the IO monad much of the time. I hope we'll have massive static constants someday soon! -- _jsn ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static constants -- ideas?
Is it _possible_ to use Template Haskell to take the name of the external binary file and produce such a bytestring literal? ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
RE: static constants -- ideas?
| On another note, I am extremely curious about the difference | between statically compiling a list and building it at | runtime. I find it hard to wrap my head around the fact that I | can build the list at runtime in a short time, but can not | compile it without eating all of my machine's RAM. It's not quite as stupid as it sounds. The run-time version is like an *interpreter*: you write an interpreter (a parser in fact) that interprets the byte-strings you read from disk, and builds in-heap data. The compile time version is, well, a compiler, and generates statically-allocated data. This may be a lot bigger than the interpreter, of course, and it all has to be stuffed through all the compiler phases. That should certainly be possible, but it's just something that GHC is not well optimised for. We are actively working on the more egregious manifestations thought: see http://hackage.haskell.org/trac/ghc/ticket/2002. Anyway, have another go when you see that #2002 is fixed. Simon ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static constants -- ideas?
jason.dusek: I have an awkward programming problem -- I need to take a dictionary, parse it, build a bunch of intermediate lists and then make maps and tries out of the list. A programming problem because it's taken me a fair amount of effort to pull together the parser and list generator -- and awkward because a 69000 item list, [(String, [(String, String)])], does not compile under GHC (stack overflow). (It's not likely to compile under anything else, either!) Members of #haskell have urged me to load the offending material from a file; indeed, it only takes ten seconds to parse the dictionary and build the lists, sort them and dump them back out again -- but it offends my sensibilities. I don't want to wait ten seconds to load my dictionary every time. I could use the FFI, then I can make the trie and lists all in C. That'd work great. My list likely uses too much RAM now, anyways. I'm considering one other option though -- I wonder if I can build large constants in GHC Core? If anybody has tried it -- or found some other way to make big huge constants in Haskell -- I would sure like to know about it. You can build large constant bytestrings, fwiw. They turn into an Addr#, and GHC will leave them alone. See, e.g. this regex testsuite, which has *lots* of bytestring (overloaded) literals, http://code.haskell.org/~dons/code/pcre-light/tests/Unit.hs Using the OverloadedStrings pragma. This is approximately the same approach as Alex (the lexer generator) takes with its lexing tables stored in an unboxed string literal. -- Don ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static constants -- ideas?
Don Stewart [EMAIL PROTECTED] wrote: You can build large constant bytestrings, fwiw. They turn into an Addr#, and GHC will leave them alone. Well, for my particular problem -- I guess I could align all the elements of the lists, and then build the trie and maps from the ByteStrings at startup. -- _jsn ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static constants -- ideas?
jason.dusek: Don Stewart [EMAIL PROTECTED] wrote: You can build large constant bytestrings, fwiw. They turn into an Addr#, and GHC will leave them alone. Well, for my particular problem -- I guess I could align all the elements of the lists, and then build the trie and maps from the ByteStrings at startup. You could pull them out with Data.Binary too, making it a little faster constructing. -- Don ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static constants -- ideas?
Jason Dusek [EMAIL PROTECTED]: I have an awkward programming problem -- I need to take a dictionary, parse it, build a bunch of intermediate lists and then make maps and tries out of the list. A programming problem because it's taken me a fair amount of effort to pull together the parser and list generator -- and awkward because a 69000 item list, [(String, [(String, String)])], does not compile under GHC (stack overflow). I also have constants that are too large to compile. I am resigned to loading them from data files--other solutions seem even worse. With data files: - The program starts up more slowly. - The code is more complex. - There may be some hassles with laziness. - Distributing the executable is not as simple. Data.Binary eases the irritation somewhat. Jay ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static constants -- ideas?
jay: Jason Dusek [EMAIL PROTECTED]: I have an awkward programming problem -- I need to take a dictionary, parse it, build a bunch of intermediate lists and then make maps and tries out of the list. A programming problem because it's taken me a fair amount of effort to pull together the parser and list generator -- and awkward because a 69000 item list, [(String, [(String, String)])], does not compile under GHC (stack overflow). I also have constants that are too large to compile. I am resigned to loading them from data files--other solutions seem even worse. With data files: - The program starts up more slowly. - The code is more complex. - There may be some hassles with laziness. - Distributing the executable is not as simple. Data.Binary eases the irritation somewhat. Did you try bytestring literals (and maybe parsing them in-memory with Data.Binary)? -- Don ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static constants -- ideas?
Don Stewart [EMAIL PROTECTED]: jay: I also have constants that are too large to compile. I am resigned to loading them from data files--other solutions seem even worse. ... Data.Binary eases the irritation somewhat. Did you try bytestring literals (and maybe parsing them in-memory with Data.Binary)? That didn't occur to me, since neither of my large constants includes strings I think you're suggesting that each constant could appear in the source as a long bytestring and be deserialized into the data structure. If that works, it should improve the startup time, but it's still not as nice as simply compiling it straight up. I'll try it. Jay ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static constants -- ideas?
Jay Scott wrote: That didn't occur to me, since neither of my large constants includes strings The trick I usually use in cases like this is to compile the data as C code and link against it, then access it from Haskell via a Ptr. b ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static constants -- ideas?
jay: Don Stewart [EMAIL PROTECTED]: jay: I also have constants that are too large to compile. I am resigned to loading them from data files--other solutions seem even worse. ... Data.Binary eases the irritation somewhat. Did you try bytestring literals (and maybe parsing them in-memory with Data.Binary)? That didn't occur to me, since neither of my large constants includes strings I think you're suggesting that each constant could appear in the source as a long bytestring and be deserialized into the data structure. If that works, it should improve the startup time, but it's still not as nice as simply compiling it straight up. I'll try it. Here's an example, which stores a Data.Map in a gzip-compressed bytestring literal (a C string literal in the compiled code). The Map is reconstructed on startup. {-# LANGUAGE OverloadedStrings #-} import Data.Binary import qualified Data.Map as M import qualified Data.ByteString.Char8 as S import Data.ByteString.Lazy import Codec.Compression.GZip -- -- this is a gzip compressed literal bytestring, storing a binary-encoded Data.Map -- mytable = \US\139\b\NUL\NUL\NUL\NUL\NUL\NUL\ETXEN\219\SO\194 \f\197\224\188\196\CAN\227\US\224\171~\NAKc\GS4ce\161`\178\191\215(\176\190\180\167\231\210\n\241\171\203\191\ti\157\217\149\249 \ENQ\214\9\202\162\179a\132X\233\ESC=\231\215\164\SYN\157\DC2D\226*\146\174o\t\167\DLE\209\i_\240\193\129\199W\250nC\CAN\212\CAN\162J\160\141C\178\133\216;[EMAIL PROTECTED]7\rH\222\FSW\130\7D\197\NUL\164\0U\193\186\t\186o\228\180~\NUL\a6\249\137#\SOH\NUL\NUL main = print = M.lookup ghc m where -- build the table from the bytestring: m :: M.Map String (Maybe String) m = decode . decompress . fromChunks . return $ mytable Running it: $ ./A Just dinosaur! :) Important to use a bytestring, since that gets compiled to a C string literal (and not messed with by the simplifier). -- Don ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static linking with ghc
On Sat, Mar 26, 2005 at 03:11:43PM +0100, Patrick Scheibe wrote: Is it possible to tell ghc to take all stuff out of the .so libs and compile my source to a all-including executable? I know that ghc just calls the linker which is doing this part. The --static flag for the linker just says: take the static library if possible for linking But I don't have a static version of these libs and I don't want to recompile all libraries. I often build my applications with ghc -optl-static, which works for me most of the time, but: - You need to have static (.a) versions of libraries, which you don't have - At least on linux the NSS (name service switch) libraries are linked in dynamically even in statically linked programs. If you have incompatible nss libraries, your programs may crash. The workaround is to compile glibc with --enable-static-nss - There are some licensing issues with GMP Best regards Tomasz ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: -static
On Tue, Mar 09, 2004 at 01:04:59AM +0100, Wolfgang Thaller wrote: So I assume this is on powerpc-linux? Yup, sorry (and the others are all Linux too). Thanks Ian ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: -static
On 09.03.2004, at 15:53, Ian Lynagh wrote: On Tue, Mar 09, 2004 at 01:04:59AM +0100, Wolfgang Thaller wrote: So I assume this is on powerpc-linux? Yup, sorry (and the others are all Linux too). Ah yes, that -static flag was lurking there from the old AIX port. It's definitely OK to remove it. I've just done so in the CVS HEAD. According to the source, alpha, hppa and mips also pass the -static flag to the linker. I've done nothing about that yet, as I have no idea why they do so. Cheers, Wolfgang ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
RE: -static
In ghc/compiler/main/DriverFlags.hs machdepCCOpts includes a -static flag for some arches. Is this really necessary? I can't see any comments as to why, nor any real answers from a quick google. I can't remember why either. It causes this when compiling darcs on these arches: /usr/lib/ghc-6.2/libHSunix.a(User.o)(.text+0x2a2c): In function `s6T9_ret': : warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking which I assume would lead to too strict dependencies on glibc being necessary. What platform? Does everything work if you remove the -static? Cheers, Simon ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
RE: -static
On Mon, Mar 08, 2004 at 11:07:07AM -, Simon Marlow wrote: It causes this when compiling darcs on these arches: /usr/lib/ghc-6.2/libHSunix.a(User.o)(.text+0x2a2c): In function `s6T9_ret': : warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking which I assume would lead to too strict dependencies on glibc being necessary. What platform? Does everything work if you remove the -static? alpha, powerpc and hppa so far. I expect the same will happen for mips and mipsel. If, on powerpc, I run the final link command without -static (that's the only place it should make a difference, right?) then it links without warnings and looks to be working fine. I haven't looked at the others yet. Wolfgang: can -static be removed on powerpc as far as you know? Cheers, Simon ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: -static
On Mon, Mar 08, 2004 at 03:25:06PM +, Ian Lynagh wrote: On Mon, Mar 08, 2004 at 11:07:07AM -, Simon Marlow wrote: What platform? Does everything work if you remove the -static? alpha, powerpc and hppa so far. I expect the same will happen for mips and mipsel. If, on powerpc, I run the final link command without -static (that's the only place it should make a difference, right?) then it links without warnings and looks to be working fine. I haven't looked at the others yet. Same on alpha and hppa. I unfortunately don't have access to mips/mipsel at the moment. Thanks Ian ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: -static
What platform? Does everything work if you remove the -static? alpha, powerpc and hppa so far. I expect the same will happen for mips and mipsel. If, on powerpc, I run the final link command without -static (that's the only place it should make a difference, right?) then it links without warnings and looks to be working fine. I haven't looked at the others yet. Wolfgang: can -static be removed on powerpc as far as you know? On powerpc-darwin, GHC has always passed -dynamic to the linker (otherwise, nothing would work at all). So I assume this is on powerpc-linux? If so, I don't see why the PPC should be any different from Intel in this respect. I cant test it now, but maybe I'll get around to having a short look at it tomorrow. Cheers, Wolfgang ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: static linking on cygnus
the appended message. Any idea what I do wrong? E:/ghc/ghc-4.08/lib/libHSstd_cbits.a(openFile.o)(.text+0x17f):ghc4632.c: undefined reference to `__imp__iob' E:/ghc/ghc-4.08/lib/libHSrts.a(StgMiscClosures.o)(.text+0x392):ghc29658.c: undefined reference to `__imp__iob' E:/ghc/ghc-4.08/lib/libHSrts.a(StgMiscClosures.o)(.text+0x3ba):ghc29658.c: undefined reference to `__imp__iob' E:/ghc/ghc-4.08/lib/libHSrts.a(StgMiscClosures.o)(.text+0x3e2):ghc29658.c: undefined reference to `__imp__iob' E:/ghc/ghc-4.08/lib/libHSrts.a(StgMiscClosures.o)(.text+0x40a):ghc29658.c: undefined reference to `__imp__iob' E:/ghc/ghc-4.08/lib/libHSrts.a(StgMiscClosures.o)(.text+0x432):ghc29658.c: more undefined references to `__imp__iob' follow What's your version of Cygwin? It looks as though you're using Cygwin 1.1, and the static libraries aren't compatible. You can use the new version of GHC, 4.08.1, with Cygwin 1.1. -- http://sc3d.org/rrt/ | maxim, n. wisdom for fools
Re: static linking on cygnus
thanks for the help. yes I used the latest cygwin and with yesterday evening I installed GHC, 4.08.1 and static linking is no problem with that Sven Eric Date: Wed, 6 Sep 2000 11:52:02 +0100 (BST) From: Reuben Thomas [EMAIL PROTECTED] Sender: [EMAIL PROTECTED] [.] What's your version of Cygwin? It looks as though you're using Cygwin 1.1, and the static libraries aren't compatible. You can use the new version of GHC, 4.08.1, with Cygwin 1.1. -- http://sc3d.org/rrt/ | maxim, n. wisdom for fools __ Sven Eric Panitz Uhlandstr. 12 Software AG [EMAIL PROTECTED] D-64297 Darmstadt (+49)6151-92-1426 __ half of what I say is meaningless