<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Aug 21, 2015 at 9:49 AM, Ryan Yates <span dir="ltr"><<a href="mailto:fryguybob@gmail.com" target="_blank">fryguybob@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Edward,<br>
<br>
I've been working on removing indirection in STM and I added a heap<br>
object like SmallArray, but with a mix of words and pointers (as well<br>
as a header with metadata for STM).  It appears to work well now, but<br>
it is missing the type information.  All the pointers have the same<br>
type which works fine for your Upper.  In my case I use it to<br>
represent a red-black tree node [1].<br></blockquote><div> </div><div>This would be perfect for my purposes.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Also all the structures I make are fixed size and it would be nice if<br>
the compiler could treat that fix size like a constant in code<br>
generation.  </blockquote><div><br></div><div><div>To make the fixed sized thing work without an extra couple of size parameters in the arguments, you'd want to be able to build an info table for each generated size. That sounds messy.</div></div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I don't know what the right design is or what would be<br>
needed, but it seems simple enough to give the right typing<br>
information to something like this and basically get a mutable struct.<br>
I'm talking about this work at HIW and really hope to find someone<br>
interested in extending this expressiveness to let us write something<br>
that looks clear in Haskell, but gives the heap representation that we<br>
really need for performance.  </blockquote><div><br></div><div><div>I'll be there. Let's talk.</div></div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From the RTS perspective I think there are any obstacles.<br></blockquote><div><br></div><div>FWIW- I was able to get some code put together that let me scribble unlifted SmallMutableArray#s directly into other SmallMutableArray#s, which nicely "just works" as long as you fix up all the fields that are supposed to be arrays before you ever dare use them.</div><div><br></div>







<font face="monospace, monospace">writeSmallMutableArraySmallArray# :: SmallMutableArray# s Any -> Int# -> SmallMutableArray# s Any -> State# s -> State# s<br>writeSmallMutableArraySmallArray# m i a s = unsafeCoerce# writeSmallArray# m i a s<br>{-# INLINE writeSmallMutableArraySmallArray# #-}<br><br>readSmallMutableArraySmallArray# :: SmallMutableArray# s Any -> Int# -> State# s -> (# State# s, SmallMutableArray# s Any #)<br>readSmallMutableArraySmallArray# m i s = unsafeCoerce# readSmallArray# m i s<br>{-# INLINE readSmallMutableArraySmallArray# #-}</font><p class="p3">With some support for typed 'Field's I can write code now that looks like:</p><font face="monospace, monospace">order :: PrimMonad m => Upper (PrimState m) -> Int -> Order (PrimState m) -> Order (PrimState m) -> m (Order (PrimState m))<br>order p a l r = st $ do<br>  this <- primitive $ \s -> case unsafeCoerce# newSmallArray# 4# a s of </font></div><div class="gmail_quote"><font face="monospace, monospace">    (# s', b #) -> (# s', Order b #)<br>  set parent this p<br>  set next this l<br>  set prev this r<br>  return this</font></div><div class="gmail_quote"><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_quote"><font face="arial, helvetica, sans-serif">and in there basically build my own little strict, mutable, universe and with some careful monitoring of the core make sure that the little Order wrappers as the fringes get removed.</font></div><div class="gmail_quote"><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_quote"><font face="arial, helvetica, sans-serif">Here I'm using one of the slots as a pointer to a boxed Int for testing, rather than as a pointer to a MutableByteArray that holds the Int.</font><br><br><div>-Edward</div></div></div></div>