Tidy doesn't remove shadowing from typeclass method accessors
@simonpj requested that I file this as a bug (https://mail.haskell.org/pipermail/ghc-devs/2022-April/020640.html)
Given the following input source:
module A where
class C a where
foo :: a -> Int
bar :: a -> Bool
The output of the Tidy phase contains definitions of foo
and bar
where there is shadowing of the variable v
. This is fatal in the case of foo
, where the v
would like to refer to the v
one lambda outer:
$ ghc -ddump-simpl -fforce-recomp -dno-typeable-binds /tmp/A.hs
==================== Tidy Core ====================
Result size of Tidy Core
= {terms: 14, types: 32, coercions: 0, joins: 0/0}
-- RHS size: {terms: 6, types: 10, coercions: 0, joins: 0/0}
foo :: forall a. C a => a -> Int
[GblId[ClassOp],
Arity=1,
Caf=NoCafRefs,
Str=<S(SL),U(U,A)>,
RULES: Built in rule for foo: "Class op foo"]
foo
= \ (@ a_agd) (v_B1 :: C a_agd) ->
case v_B1 of v_B1 { A.C:C v_B2 v_B3 -> v_B2 }
-- RHS size: {terms: 6, types: 10, coercions: 0, joins: 0/0}
bar :: forall a. C a => a -> Bool
[GblId[ClassOp],
Arity=1,
Caf=NoCafRefs,
Str=<S(LS),U(A,U)>,
RULES: Built in rule for bar: "Class op bar"]
bar
= \ (@ a_agd) (v_B1 :: C a_agd) ->
case v_B1 of v_B1 { A.C:C v_B2 v_B3 -> v_B3 }
So if we project the definition of foo
to just the OccName
s (which is what toIfaceExpr
does), we have:
foo = \ @a v -> case v of v { C v v -> v }
Simon also writes:
That looks very odd. If that gets serialised into a .hi file it won't work at all.
But note that these definition do NOT get serialised into .hi
files by GHC, since they don't occur in unfoldings. This is only causing a problem to me, GHC-as-a-library user, when trying to save all bindings as IfaceExpr
s.