Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inspection-testing-0.5.0.3/0.6 fails with GHC-9.12 #82

Open
phadej opened this issue Jan 4, 2025 · 11 comments
Open

inspection-testing-0.5.0.3/0.6 fails with GHC-9.12 #82

phadej opened this issue Jan 4, 2025 · 11 comments

Comments

@phadej
Copy link
Contributor

phadej commented Jan 4, 2025

<no location info>: error:
    panic! (the 'impossible' happened)
  GHC version 9.12.1:
	lookupIdSubst

But it's metadata explicltly says it works: ghc <9.13. Please fix either inspection-testing-0.5 or metadata.

@phadej
Copy link
Contributor Author

phadej commented Jan 4, 2025

Actually I see this error with inspection-testing-0.6 too. See well-typed/optics#512 for reproducer.

@phadej phadej changed the title inspection-testing-0.5.0.3 fails with GHC-9.12 inspection-testing-0.5.0.3/0.6 fails with GHC-9.12 Jan 4, 2025
@nomeata
Copy link
Owner

nomeata commented Jan 4, 2025

Guess our test suite is incomplete here? @erikd you did the bump over at #80, do you feel like investigating?

@phadej
Copy link
Contributor Author

phadej commented Jan 4, 2025

In particular, there seems to be only on tests which causes the panic:

  , testCase "iover (imapped <% imapped) = iover (imapped % mapped)" $
    -- GHC 9.* applies a worker-wrapper transformation to the RHS.
    ghcGE90failure $(inspectTest $ 'lhs09 === 'rhs09)

in Optics.Tests.Core.

@phadej
Copy link
Contributor Author

phadej commented Jan 5, 2025

For the record, I was pointed to https://gitlab.haskell.org/ghc/ghc/-/issues/25468 but applying it fix to GHC-9.12.1-release didn't make the issue go away. (EDIT: looking at GHC issue tracker lookupIdSubst related issues are not uncommon).

It still might be a GHC issue, but I leave it to you to report upstream, as I don't know what inspection-testing is doing.

@phadej
Copy link
Contributor Author

phadej commented Jan 5, 2025

Another note: With -O0 the tests do compile, so it does look like an issue in GHC. That however doesn't help me, as there is no point to inspect -O0 code.

@erikd
Copy link
Contributor

erikd commented Jan 5, 2025

Guess our test suite is incomplete here? @erikd you did the bump over at #80, do you feel like investigating?

Yes, seems test suite is incomplete. I will see if I can extract the part of well-typed/optics#512 to add to the tests here.

@erikd
Copy link
Contributor

erikd commented Jan 6, 2025

I have reproduced the issue locally by cloning https://github.com/well-typed/optics/ and checking out the ghc-9.12 branch.

Reducing the file optics/tests/Optics/Tests/Core.hs to:

{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fplugin=Test.Inspection.Plugin -dsuppress-all #-}
module Optics.Tests.Core (coreTests) where

import Test.Tasty
import Test.Tasty.HUnit
import Test.Inspection

import Optics
import Optics.Tests.Utils

coreTests :: TestTree
coreTests = testGroup "Core"
  [ testCase "iover (imapped <% imapped) = iover (imapped % mapped)" $
    -- GHC 9.* applies a worker-wrapper transformation to the RHS.
    ghcGE90failure $(inspectTest $ 'lhs09 === 'rhs09)
  ]

-- Sometimes we need to eta expand, as without it pretty much equivalent code is
-- produced, but somewhat rearranged. Expanding allows us to get rid of these
-- differences to satisfy the check. However, when we do that we also need to
-- check whether the form that is not eta-expanded optimizes away internal
-- representation correctly.

lhs09, rhs09
  :: (FunctorWithIndex i t, FunctorWithIndex j s)
  => (i -> a -> b)
  -> t (s a)
  -> t (s b)
lhs09 = iover (imapped <% imapped)
rhs09 = iover (imapped % mapped)

is sufficient to trigger the GHC bug.

@erikd
Copy link
Contributor

erikd commented Jan 6, 2025

Raised a GHC issue: https://gitlab.haskell.org/ghc/ghc/-/issues/25631

Now trying to extract the code that triggers this bug for inclusion in the test suite.

@erikd
Copy link
Contributor

erikd commented Jan 6, 2025

When I cargo culted minimal parts of inpection-testing into the file optics/tests/Optics/Tests/Core.hs the GHC panic was not triggered. 😭

@erikd
Copy link
Contributor

erikd commented Jan 7, 2025

SPJ' latest comment: https://gitlab.haskell.org/ghc/ghc/-/issues/25631#note_602995

I had a look at the code but could make very little sense of it. @nomeata ?

@Mikolaj
Copy link
Contributor

Mikolaj commented Mar 1, 2025

FYI, I've just used inspection-testing with a couple weeks old GHC HEAD with great success and no crashes. But I haven't attempted reproducing your problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants