Opened 8 years ago

Closed 8 years ago

#5625 closed bug (fixed)

Code using seq has wrong strictness when unoptimised (too lazy)

Reported by: michal.palka Owned by: simonpj
Priority: high Milestone: 7.4.1
Component: Compiler Version: 7.3
Keywords: seq strictness strict lazy Cc: michal.palka@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect result at runtime Test Case: simplCore/should_run/T5625
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

The code code should crash with Prelude.undefined. When compiled with -O it behaves correctly, however with no optimisation (-O0) it prints [0] instead. Reading the Core suggests that the expression gets translated into print (id [0]) when compiled with -O0. It was tested with GHC 7.3.20111022.

main = do
  let a = \x -> seq undefined (+1)
  print $ (a `seq` a [] `seq` id) [0]

Change History (4)

comment:1 Changed 8 years ago by michal.palka

It seems that it's possible to simplify it further if a is exported. Thanks to Nick Smallbone for suggesting this one.

module Main (a, main) where

a = \x -> seq undefined (+1)

main = do
  print $ (a [] `seq` id) [0]

comment:2 Changed 8 years ago by igloo

Milestone: 7.4.1
Owner: set to simonpj
Priority: normalhigh

comment:3 Changed 8 years ago by simonpj@…

commit a522c3b25eea1fe40edae7052335acce75e8a1c3

Author: Simon Peyton Jones <simonpj@microsoft.com>
Date:   Fri Nov 11 20:08:42 2011 +0000

    Tighten up the definition of arityType a bit further,
    to make Trac #5625 work.  The main change is that
    we eta-expand (case x of p -> \y. blah) only if the
    case-expression is in the context of a \x.  That is still
    technically unsound, but it makes a big difference to
    performance; and the change narrows the unsound cases
    a lot.

 compiler/coreSyn/CoreArity.lhs |  140 +++++++++++++++++++++++-----------------
 1 files changed, 80 insertions(+), 60 deletions(-)

comment:4 Changed 8 years ago by simonpj

Resolution: fixed
Status: newclosed
Test Case: simplCore/should_run/T5625

Great! Test added.

Note: See TracTickets for help on using tickets.