arximboldi / immer

Postmodern immutable and persistent data structures for C++ — value semantics at scale
https://sinusoid.es/immer
Boost Software License 1.0
2.5k stars 182 forks source link

GDB Pretty printing support #97

Open dwightguth opened 5 years ago

dwightguth commented 5 years ago

I work for a startup that is developing an interpreter for a functional programming language, and we recently decided to start using this library as the implementation of our map, list, and set types in our language. At roughly the same time, I have been working on improving the support for our programming language, which compiles down to native code, in GDB.

One thing that was particularly useful was to be able to use gdb's print command to print the elements of a map, list, or set. I originally tried to make this work by invoking functions inside the inferior process, but it turns out gdb segfaults when you invoke code from within a custom pretty printer. As a result, it proved necessary to reimplement the logic of rrbtree_iterator and champ_iterator in python using GDB's python API.

The code I wrote works great, although it is not fully production ready for inclusion back into the library in the sense that it is still specialized in several places to the specific template parameters we use for our data types in our programming language, but I wanted to bring your attention to the code since it could potentially be used to drastically improve the experience of debugging other programs that make use of these collections.

Here is the source code.

arximboldi commented 5 years ago

That is super cool! If you flesh it out into sth that you think could live in the main repo, feel free to make a PR. There is an extra and tools folders where something like this could live.

arximboldi commented 5 years ago

Also, quite curious about this functional language. I hope Immer helps!

dwightguth commented 5 years ago

Unfortunately it's unlikely that I'll have a chance to flesh this out the rest of the way anytime soon because the main thing that is left is to make this code properly parametric in the template parameters, and that's not something that is required for the use case that I'm dealing with because the template parameters are always the same in our code. I would have to spend some time on it as a hobby, and I have other hobby projects at the moment that would provide more utility to me.

I'm happy to answer questions about this code if it would help you finish the work yourself though, if you're interested in trying to do it.

The functional language is called K by the way and the code that uses immer is here if you want to take a look. The library has turned out to be a great choice and it is significantly faster than our old implementation, which was based on a similar rust library. We would significantly benefit from map and set transients, since we use garbage collection and have to do a fair number of batch changes, but it's still quite good performance. And I really like how simple and clear the immer implementation is.

arximboldi commented 5 years ago

I understand. I will leave the issue open, so your implementation is easier to find for people that are looking for one.

And yeah... the lack of transients for maps and set really bothers me too, it is the main lack in the library at the moment (maybe ordered collections would be quite desirable too for certain use cases). I hope to find time to do it at some point. Some of my consulting clients are the library, so maybe at at some point someone pays me to do it :)

arximboldi commented 5 years ago

And that K language looks interesting, I am glad the immer integration was smooth. Are there docs somewhere describing the language itself?

dwightguth commented 5 years ago

Documentation is still very much a work in progress. There is some slightly outdated "documentation by example" found here: https://github.com/kframework/k/tree/master/k-distribution/tutorial

And some up-to-date but incomplete documentation here: https://github.com/kframework/k/blob/master/pending-documentation.md

But nothing definitive like a complete reference manual yet.

dhly-etc commented 1 year ago

@dwightguth Sorry to pester you on this three and a half years later, but would you be okay with me opening a PR for this with a slightly modified version of your gist? (The gist doesn't have clear licensing info, so I didn't want to assume. 😅)

dwightguth commented 1 year ago

Go ahead! I went ahead and added a BSD 3-clause license file to the gist, but I'd also be happy to sign a CLA if you'd prefer.

dhly-etc commented 1 year ago

Thanks for the quick response, @dwightguth! I'm wondering if it would simplify things from a legal perspective if the gist used the same license (Boost Source License 1.0) as the main immer library. That way we go from original author -> intermediary author -> library distribution under the same terms and don't have to worry about including the BSD license in the final version.

dwightguth commented 1 year ago

Sure. I went ahead and dual-licensed the code under that license as well. That means you're free to use the code under the terms of either license. You are not subject to both licenses at the same time lol.

dhly-etc commented 1 year ago

Perfect, thanks! I'll try and get a PR for this up in the next few working days.