Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,866
    • Issues 4,866
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 455
    • Merge requests 455
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #21363
Closed
Open
Created Apr 08, 2022 by Gergő Érdi@cactusContributor

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 OccNames (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 IfaceExprs.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking