Re: Optimisation and unsafePerformIO

2002-10-30 Thread David Sabel

- Original Message - 
From: "Albert Lai" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, October 30, 2002 7:35 AM
Subject: Re: Optimisation and unsafePerformIO


> "David Sabel" <[EMAIL PROTECTED]> writes:
> 
> > {-# NOINLINE b #-}
> > 
> > b x  = if even x then unsafePerformIO getChar else bot
> > 
> > bot = bot
> > 
> > main = do
> >  putChar (b 4)
> >  putChar (b 6)
> 
> I am not a compiler implementer (or lawyer, for that matter :)
> But I propose this guess.  First, both even 4 and even 6 get
> constant-folded to True; so b 4 and b 6 both become unsafePerformIO
> getChar.  Then there is a common subexpression elimination.

No! I used the option -fno-cse, what means that common supexpression
elimination is turned off.

> ___
> Glasgow-haskell-users mailing list
> [EMAIL PROTECTED]
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



Re: Optimisation and unsafePerformIO

2002-10-29 Thread Albert Lai
"David Sabel" <[EMAIL PROTECTED]> writes:

> {-# NOINLINE b #-}
> 
> b x  = if even x then unsafePerformIO getChar else bot
> 
> bot = bot
> 
> main = do
>  putChar (b 4)
>  putChar (b 6)

I am not a compiler implementer (or lawyer, for that matter :)
But I propose this guess.  First, both even 4 and even 6 get
constant-folded to True; so b 4 and b 6 both become unsafePerformIO
getChar.  Then there is a common subexpression elimination.
___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



Re: Optimisation and unsafePerformIO

2002-10-28 Thread David Sabel
Of course, I used unsafePerformIO in an unsafe way!
I'm thinking about a way to make unsafePerformIO safe.
Therefore the compiler can't do any transformation the ghc does and I want
to locate these transformations.


- Original Message -
From: "Simon Marlow" <[EMAIL PROTECTED]>
To: "David Sabel" <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Monday, October 28, 2002 10:41 AM
Subject: RE: Optimisation and unsafePerformIO


> Consider the following program:
>
> -
> {-# NOINLINE b #-}
>
> b x  = if even x then unsafePerformIO getChar else bot
>
> bot = bot
>
> main = do
>  putChar (b 4)
>  putChar (b 6)
>
> -
>
> when you compile the programm with the options: -O0
> and execute the program you get:
> > test
> ab  (That's the input)
> ab  (That's the ouput)
>
> when you compile the programm with the options: -O1 -fno-cse
> you get:
> > test
> ab
> aa

You are using unsafePerformIO in an unsafe way.  The meaning of your
program depends on whether the compiler implements full laziness or not,
which is a decision left entirely up to the compiler implementor.  If
you want to write portable code, don't use unsafePerformIO in this way.

What exactly is it you're trying to achieve?  Perhaps we can suggest a
better solution.

Cheers,
Simon

___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



RE: Optimisation and unsafePerformIO

2002-10-28 Thread Simon Marlow
> Consider the following program:
> 
> -
> {-# NOINLINE b #-}
> 
> b x  = if even x then unsafePerformIO getChar else bot
> 
> bot = bot
> 
> main = do
>  putChar (b 4)
>  putChar (b 6)
> 
> -
> 
> when you compile the programm with the options: -O0
> and execute the program you get:
> > test
> ab  (That's the input)
> ab  (That's the ouput)
> 
> when you compile the programm with the options: -O1 -fno-cse
> you get:
> > test
> ab
> aa

You are using unsafePerformIO in an unsafe way.  The meaning of your
program depends on whether the compiler implements full laziness or not,
which is a decision left entirely up to the compiler implementor.  If
you want to write portable code, don't use unsafePerformIO in this way.

What exactly is it you're trying to achieve?  Perhaps we can suggest a
better solution.

Cheers,
Simon
___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



Optimisation and unsafePerformIO

2002-10-27 Thread David Sabel
Consider the following program:

-
{-# NOINLINE b #-}

b x  = if even x then unsafePerformIO getChar else bot

bot = bot

main = do
 putChar (b 4)
 putChar (b 6)

-

when you compile the programm with the options: -O0
and execute the program you get:
> test
ab  (That's the input)
ab  (That's the ouput)

when you compile the programm with the options: -O1 -fno-cse
you get:
> test
ab
aa

my question is now: which transformation/optimisation is responsible for
that, and is it
possible to switch off this transformation?

David Sabel


___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users