[Haskell-cafe] Timing out a pure evaluation of an expression I did not write myself

Erik Hesselink hesselink at gmail.com
Thu Nov 29 10:15:49 UTC 2018


Hi Ryan,

I'm not quite sure of your use case, but lambdabot/mueval do something like
this I think. From a brief look at the source [1] it seems they compute in
a separate thread, then in another thread, wait until the timeout then kill
the computation thread. Would something like that work for you?

Erik

[1]
https://github.com/gwern/mueval/blob/09b6a7aa5a25c4115442ea2e6ae0c2db557007f8/Mueval/Parallel.hs

On Thu, 29 Nov 2018 at 03:41, Ryan Reich <ryan.reich at gmail.com> wrote:

> I expected something like that. I'm all the way back in ghc-8.2.2, but I
> think what this really shows is that the flag is unreliable and
> version-dependent. Unfortunately there doesn't seem to be a precise
> specification of where yield points should appear, and therefore, where
> they might be not-omitted.
>
> On Wed, Nov 28, 2018, 17:10 Viktor Dukhovni <ietf-dane at dukhovni.org wrote:
>
>> On Wed, Nov 28, 2018 at 09:39:01AM -0800, Ryan Reich wrote:
>>
>> > Thanks for the suggestion, which Arjen made also.  Unfortunately, it
>> does
>> > not appear to help.  See this simple program:
>> >
>> > -- Loop.hs
>> > import Control.Exception
>> > import System.Timeout
>> >
>> > main :: IO (Maybe Integer)
>> > main = timeout 100000 $ evaluate $ last $ repeat 0
>> > -- end
>> >
>> > With either GHC invocation "stack exec ghc Loop[ -- -fno-omit-yields]",
>> > running ./Loop fails to terminate (it should do so in 0.1s).
>> >
>> > Based only on the very terse description of that flag in the User's
>> Guide,
>> > and its name, I think the problem is simply that GHC doesn't normally
>> > *generate* yields in that loop, so there's nothing not to omit.
>>
>> It times out for me with GHC 8.4.4 on FreeBSD 11.2, and "ghc -O
>> -fno-omit-yields"
>> and does  not time out with "ghc -O":
>>
>>     $ cat /tmp/foo.hs
>>     import Control.Exception
>>     import System.Timeout
>>
>>     main :: IO (Maybe Integer)
>>     main = timeout 1000000 $ evaluate $ last $ repeat 0
>>
>>     $ ghc -O -fno-omit-yields /tmp/foo.hs
>>     [1 of 1] Compiling Main             ( /tmp/foo.hs, /tmp/foo.o )
>> [Optimisation flags changed]
>>     Linking /tmp/foo ...
>>
>>     $ time /tmp/foo
>>
>>     real    0m1.033s
>>     user    0m1.025s
>>     sys     0m0.008s
>>
>>     $ rm /tmp/foo
>>     $ ghc -O /tmp/foo.hs
>>     [1 of 1] Compiling Main             ( /tmp/foo.hs, /tmp/foo.o )
>> [Optimisation flags changed]
>>     Linking /tmp/foo ...
>>
>>     $ time /tmp/foo
>>     ^C^C
>>
>>     real    0m5.864s
>>     user    0m5.857s
>>     sys     0m0.000s
>>
>> On MacOS X with GHC 7.10.3, it does not time out either way.  Perhaps
>> some versions of GHC don't make the timeout possible.
>>
>> --
>>         Viktor.
>> _______________________________________________
>> Haskell-Cafe mailing list
>> To (un)subscribe, modify options or view archives go to:
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>> Only members subscribed via the mailman list are allowed to post.
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20181129/0679f513/attachment.html>


More information about the Haskell-Cafe mailing list