Skip to content

valid doesn't seem to work as expected with -O0 #459

Closed
@sjakobi

Description

@sjakobi

I ran into this issue while working on #458. I'm using the sjakobi/valid-O0 branch to investigate.

To reproduce:

$ cabal test --test-show-details=direct --test-options ' --quickcheck-tests 4 -p Lazy.alterF.valid --quickcheck-max-size 100 --quickcheck-verbose --quickcheck-replay=836177' -w ghc-9.2
All
  Properties
    Data.HashMap.Lazy
      alterF
        valid: FAIL
          Passed:
          <fun>
          K {hash = 1, _x = C}
          fromList []
          [] == []
          
          Failed:
          <fun>
          K {hash = 9, _x = A}
          fromList [(K {hash = -724960, _x = D},2),(K {hash = 1, _x = D},12),(K {hash = 8, _x = A},7),(K {hash = 2305843009213693960, _x = C},9),(K {hash = 264, _x = C},10),(K {hash = 9, _x = A},1),(K {hash = 1961, _x = C},10),(K {hash = 1482, _x = B},6),(K {hash = -22, _x = B},25),(K {hash = 1111, _x = A},26)]
          [Invalid (INV6_misplaced_hash 0) (SubHashPath {partialHash = 9, lengthInBits = 10}),Invalid (INV6_misplaced_hash 0) (SubHashPath {partialHash = 9, lengthInBits = 10}),Invalid (INV6_misplaced_hash 0) (SubHashPath {partialHash = 9, lengthInBits = 10}),Valid,Invalid (INV6_misplaced_hash 0) (SubHashPath {partialHash = 9, lengthInBits = 10}),Invalid (INV6_misplaced_hash 0) (SubHashPath {partialHash = 9, lengthInBits = 10})] /= [Valid,Valid,Valid,Valid,Valid,Valid]

<lots of shrinking>

          *** Failed! Falsified (after 2 tests and 23 shrinks):
          {_->[Just 1]}
          K {hash = 8, _x = A}
          fromList [(K {hash = 0, _x = A},1),(K {hash = 8, _x = A},1)]
          [Invalid (INV6_misplaced_hash 0) (SubHashPath {partialHash = 8, lengthInBits = 5})] /= [Valid]
          Use --quickcheck-replay=836177 to reproduce.

The code used by alterF here is actually buggy (fixed in 1e8ca8c and 418aa71) so the test failure is expected.

However if I run the same command and add -O0, we apparently get the same test case, but valid reports the resulting HashMaps to be Valid:

$ cabal test --test-show-details=direct --test-options ' --quickcheck-tests 4 -p Lazy.alterF.valid --quickcheck-max-size 100 --quickcheck-verbose --quickcheck-replay=836177' -w ghc-9.2 -O0
All
  Properties
    Data.HashMap.Lazy
      alterF
        valid: OK
          Passed:
          <fun>
          K {hash = 1, _x = C}
          fromList []
          [] == []
          
          Passed:
          <fun>
          K {hash = 9, _x = A}
          fromList [(K {hash = -724960, _x = D},2),(K {hash = 1, _x = D},12),(K {hash = 8, _x = A},7),(K {hash = 2305843009213693960, _x = C},9),(K {hash = 264, _x = C},10),(K {hash = 9, _x = A},1),(K {hash = 1961, _x = C},10),(K {hash = 1482, _x = B},6),(K {hash = -22, _x = B},25),(K {hash = 1111, _x = A},26)]
          [Valid,Valid,Valid,Valid,Valid,Valid] == [Valid,Valid,Valid,Valid,Valid,Valid]

<two more tests>

I've tried to increase the number of tests and the size of the test cases but I still can't get the testsuite to fail with -O0.

I have tried to reproduce the shrunk failure case in GHCi but that's reported as Valid too.

EDIT: I'm getting the same behaviour with GHC 8.2.2, so it doesn't seem to be a recent regression in GHC.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions