<div dir="ltr">I've uploaded <a href="https://phabricator.haskell.org/D125">https://phabricator.haskell.org/D125</a> to give an idea of what such a change might look like. I'm not quite done with the change (it's quite a chore) but the commit gives and idea of what such a change might look like.<div>

<br></div><div>I'm still not convinced that making ByteOff a Word is the right thing, there seems to be several cases where it's used to represent a negative offset.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">

On Thu, Aug 7, 2014 at 3:53 PM, Johan Tibell <span dir="ltr"><<a href="mailto:johan.tibell@gmail.com" target="_blank">johan.tibell@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr">I guess this example, from mk_switch in StgCmmUtils, is the same<div><br></div><div><div>    return (mkSwitch (cmmOffset dflags tag_expr (- real_lo_tag)) arms)</div></div><div><br></div><div>?</div><div><br>


</div><div>(This is clearly a negative offset and I don't know the implications of the Cmm code we output if we switch to ByteOff = Word)</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br>

<div class="gmail_quote">On Thu, Aug 7, 2014 at 3:49 PM, Edward Z. Yang <span dir="ltr"><<a href="mailto:ezyang@mit.edu" target="_blank">ezyang@mit.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Yes, in particular if the offset is zero.  Morally, however, we're<br>
just doing this to clear the tag bit.<br>
<br>
Edward<br>
<br>
Excerpts from Johan Tibell's message of 2014-08-07 14:45:43 +0100:<br>
<div>> I'm hacking on this now. I'm not 100% sure that ByteOff isn't used for<br>
> negative values though, see for example<br>
><br>
> mkTaggedObjectLoad<br>
>   :: DynFlags -> LocalReg -> LocalReg -> ByteOff -> DynTag -> CmmAGraph<br>
> -- (loadTaggedObjectField reg base off tag) generates assignment<br>
> --      reg = bitsK[ base + off - tag ]<br>
> -- where K is fixed by 'reg'<br>
> mkTaggedObjectLoad dflags reg base offset tag<br>
>   = mkAssign (CmmLocal reg)<br>
>              (CmmLoad (cmmOffsetB dflags<br>
>                                   (CmmReg (CmmLocal base))<br>
>                                   (offset - tag))<br>
>                       (localRegType reg))<br>
><br>
> from StgCmmUtils.<br>
><br>
> Wouldn't it be possible that the offset in cmmOffsetB (which is of type<br>
> ByteOff) could be negative?<br>
><br>
><br>
><br>
> On Thu, Aug 7, 2014 at 1:49 PM, Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>><br>
> wrote:<br>
><br>
> >  I’m all for it!<br>
> ><br>
> ><br>
> ><br>
> > I believe that ByteOff/WordOff are always 0 or positive.   At least, they<br>
> > were when I introduced them!<br>
> ><br>
> ><br>
> ><br>
> > SImon<br>
> ><br>
> ><br>
> ><br>
</div>> > *From:* ghc-devs [mailto:<a href="mailto:ghc-devs-bounces@haskell.org" target="_blank">ghc-devs-bounces@haskell.org</a>] *On Behalf Of *Johan<br>
> > Tibell<br>
> > *Sent:* 07 August 2014 12:21<br>
> > *To:* Simon Marlow<br>
> > *Cc:* <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
> > *Subject:* Re: Improving the Int/Word story inside GHC<br>
<div><div>> ><br>
> ><br>
> ><br>
> > Simon M, is the intention of ByteOff and WordOff that they should be able<br>
> > to represent negative quantities as well? If so we might need to split it<br>
> > into ByteOff (still an Int) and ByteIndex (a Word) to have a type for<br>
> > indexing into arrays.<br>
> ><br>
> ><br>
> ><br>
> > On Thu, Aug 7, 2014 at 1:16 PM, Edward Z. Yang <<a href="mailto:ezyang@mit.edu" target="_blank">ezyang@mit.edu</a>> wrote:<br>
> ><br>
> >  If it's strictly just in the codegen (and not affecting user code),<br>
> > seems fine to me.<br>
> ><br>
> > Edward<br>
> ><br>
> > Excerpts from Johan Tibell's message of 2014-08-07 12:10:37 +0100:<br>
> ><br>
> > > Inside GHC we mostly use Int instead of Word, even when we want to<br>
> > > represent non-negative values, such as sizes of things or indices into<br>
> > > things. This is now causing some grief in<br>
> > > <a href="https://ghc.haskell.org/trac/ghc/ticket/9416" target="_blank">https://ghc.haskell.org/trac/ghc/ticket/9416</a>, where an allocation<br>
> > boundary<br>
> > > case test fails with a segfault because a n < m Int comparison overflows.<br>
> > ><br>
> > > I tried to fix the issue by changing the type of maxInlineAllocSize,<br>
> > which<br>
> > > is used on one side of the above comparison, to Word. However, that<br>
> > > unravels a bunch of other issues, such as wordsToBytes, ByteOff, etc are<br>
> > > all Int-valued quantities.<br>
> > ><br>
> > > I could perhaps work around these problems by judicious use of<br>
> > fromIntegral<br>
> > > in StgCmmPrim, but I'm a bit unhappy about it because it 1) makes the<br>
> > code<br>
> > > uglier and 2) needs to be done in quite a few places.<br>
> > ><br>
> > > How much work would it be to try to switch the codegen to use Word for<br>
> > most<br>
> > > of these quantities instead?<br>
> > ><br>
> > > -- Johan<br>
> ><br>
> ><br>
> ><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>