IntRep etc

Ömer Sinan Ağacan omer at
Wed Sep 4 13:29:16 UTC 2019

Hi all,

 > !1381/#16893: inline unsafeCoerce# in CorePrep

The problem with !1381 is that it reveals a coercion accepted by CoreLint but
rejected by an assertion later in the compilation. The coercion casts an Int# to
Int64#, which is fine on a 64-bit system. One way to fix this is by fixing
#17026, but as explained in the issue it's too much work and it'll either
require huge amount of work (if we implement some kind of Type/TyCon caching) or
make everything slower (if we make top-level intPrimTy/intPrimTyCon which are
currently constants, functions).

 > #17041: coercion safety in STG Lint

This basically asks for a type checker that works on PrimReps instead of Types.
I was too busy with #9718/!1304 and #17088 so couldn't make progress here.
Perhaps I can work on this at MuniHac.

 > !1552: tidy up linting on unsafe coercions

I'll address your comments and test this more. My main concern (and the reason
why I added "DO NOT MERGE") was that I wasn't 100% sure that this change is
sound (though I don't remember what I was concerned about specifically). I'll
try to test this more on my desktop (where I can more efficiently make release
builds and test) when I'm back home.

 > #16964: definition of Int#

The part related to GHC internals is moved to #17026. Regarding definition of
Int#, I'm not sure what to do about this,

 > #17026: definition of IntRep

Simon argues that if we keep Int and Int# distinct types (rather than synonyms
to Int32/Int64 and Int32#/Int64# depending on platform word size, this is
discussed in #16964) then we should keep RuntimeReps for them distinct too.
I think this is mostly fine but a problem with this that blocked !1381 is IntRep
and Int64Rep are not equal (according to the Eq instance) on a 64-bit system so
a simple code that checks whether two types are represented the same fails.

If we keep IntRep/WordRep then I think we should remove the Eq instance of
PrimRep and and provide a `primRepEq :: PlatformWordSize -> PrimRep -> PrimRep
-> Eq` for checking whether types are represented the same on the target
platform (or maybe name it `primRepCoercible`).

So in summary; I think I'll make progress in this order:

- Read the changes in !1552, test it more.
     - If merged then !1381 will be unblocked, merge it.
- Remove Eq instance of PrimRep, implement primRepEq (or primRepCoercible) that
   takes target platform size as argument. Use this in coercion checks.
     - This also unblocks !1381, merge it
- Implement type checker in StgLint that works on PrimReps (instead of on
   actual types).

I'm not sure about how to proceed in #16964. I'm inclined to just document the
status quo more accurately, but apparently there's also a MR that's supposed to
improve/fix it (!1102), though I'm having trouble seeing how it is even related.


On 3.09.2019 00:45, Simon Peyton Jones wrote:
> Omer, Ben
> There’s a little cluster of tickets that it’d be really good to nail.
>   * !1381/#16893: inline unsafeCoerce# in CorePrep
>   * #17041: coercion safety in STG Lint
>   * !1552: tidy up linting on unsafe coercions
>   * #16964: definition of Int#
>   * #17026: definition of IntRep
> They are all somehow tied up together.  Can we kill them off together, soon?  I 
> have left comments...
> Simon

More information about the ghc-devs mailing list