Storable and constant memory

Roman Leshchinskiy rl at cse.unsw.edu.au
Fri Apr 23 04:04:00 EDT 2010


On 23/04/2010, at 17:27, Simon Peyton-Jones wrote:

> Bother.   It seems like a good improvement to SpecConstr anyway.

Actually, aren't ok-for-speculation terms let-bound? Is there ever a (case e of ...) where e is unboxed and ok-for-speculation?

> But it's disappointing that it doesn't hit this case.  In fact it seems that it should.  It's not ok to discard a 'touch' but it's fine to move it around.  Maybe what we want is primOpIsCheap?  Which is currently defined to be the same as primOpOkForSpeculation, but perhaps it should not be.
 
I'm not sure if it's that simple. You want SpecConstr (and the rule matcher?) to somehow go from this:

foo v x = ... foo v (Just (case readIntOffAddr# p# i# realWorld# of { (# s#, n# #) ->
                           case touch# fp s# of { _ -> I# n# }})) ...

to this:

foo v x = ... case readIntOffAddr# p# i# realWorld# of { (# s#,  n# #) ->
              case touch# fp s# of { _ -> 
               foo v (Just (I# n# }})) ...

But if touch# has side effects, then it isn't safe to do so because foo might never evaluate it in the original version. In this particular case, neither touch# nor readIntOffAddr# really have side effects even though they say they do so it's ok to evaluate them speculatively. It is also ok to drop them both but it is not ok to drop touch# without dropping the read. In a different mail, I suggested combining touching and reading into one operation. That would also work here as that operation could be ok-for-speculation.

BTW, at the moment readIntOffAddr# is also marked as has-side-effects. I'm not sure if that is really necessary.

Roman

> | -----Original Message-----
> | From: Roman Leshchinskiy [mailto:rl at cse.unsw.edu.au]
> | Sent: 23 April 2010 07:55
> | To: Simon Peyton-Jones
> | Cc: Haskell Libraries
> | Subject: Re: Storable and constant memory
> | 
> | Simon,
> | 
> | On 23/04/2010, at 16:49, Simon Peyton-Jones wrote:
> | 
> | > | foo v x = ... case readIntOffAddr# p# i# realWorld# of { (# s#,  n# #) ->
> | > |               case touch# fp s# of { _ ->
> | >                foo v (Just (I# n# }})) ...
> | >
> | > I'll implement that fix.  It should catch cases like this where the primops
> | involves are
> | > 	- ok-for-speculation
> | > 	- have just one result (ie only one case alternative
> | 
> | I don't think touch# is ok-for-speculation.
> | 
> | primop TouchOp "touch#" GenPrimOp
> |    o -> State# RealWorld -> State# RealWorld
> |    with
> |    has_side_effects = True
> | 
> | Note the has_side_effects part. In fact, wouldn't it be eliminated altogether
> | in this case if it was ok-for-speculation?
> | 
> | Roman
> | 
> | 



More information about the Libraries mailing list