fpco / ide-backend

ide-backend drives the GHC API to build, query, and run your code
120 stars 17 forks source link

ide-backend-common build failure #272

Closed cocreature closed 9 years ago

cocreature commented 9 years ago

When trying to compile ide-backend-common (which is pulled in as a dependency) I get the following error:

Configuring ide-backend-common-0.9.0...
Building ide-backend-common-0.9.0...
Preprocessing library ide-backend-common-0.9.0...
[18 of 24] Compiling IdeSession.Types.Public ( IdeSession/Types/Public.hs, dist/dist-sandbox-11a90ed7/build/IdeSession/Types/Public.o )

IdeSession/Types/Public.hs:36:1: Warning:
    The import of ‘Control.Applicative’ is redundant
      except perhaps to import instances from ‘Control.Applicative’
    To import instances alone, use: import Control.Applicative()
[19 of 24] Compiling IdeSession.GHC.Requests ( IdeSession/GHC/Requests.hs, dist/dist-sandbox-11a90ed7/build/IdeSession/GHC/Requests.o )

IdeSession/GHC/Requests.hs:15:1: Warning:
    The import of ‘Control.Applicative’ is redundant
      except perhaps to import instances from ‘Control.Applicative’
    To import instances alone, use: import Control.Applicative()
[20 of 24] Compiling IdeSession.Types.Private ( IdeSession/Types/Private.hs, dist/dist-sandbox-11a90ed7/build/IdeSession/Types/Private.o )

IdeSession/Types/Private.hs:40:1: Warning:
    The import of ‘Control.Applicative’ is redundant
      except perhaps to import instances from ‘Control.Applicative’
    To import instances alone, use: import Control.Applicative()
[21 of 24] Compiling IdeSession.Types.Translation ( IdeSession/Types/Translation.hs, dist/dist-sandbox-11a90ed7/build/IdeSession/Types/Translation.o )

IdeSession/Types/Translation.hs:81:19:
    Could not deduce (XShared a0 ~ XShared a)
    from the context (Show a, ExplicitSharing a)
      bound by the type signature for
                 showNormalized :: (Show a, ExplicitSharing a) =>
                                   Private.ExplicitSharingCache -> XShared a -> String
      at IdeSession/Types/Translation.hs:(81,19)-(82,69)
    NB: ‘XShared’ is a type function, and may not be injective
    The type variable ‘a0’ is ambiguous
    Expected type: Private.ExplicitSharingCache -> XShared a -> String
      Actual type: Private.ExplicitSharingCache -> XShared a0 -> String
    In the ambiguity check for the type signature for ‘showNormalized’:
      showNormalized :: forall a.
                        (Show a, ExplicitSharing a) =>
                        Private.ExplicitSharingCache -> XShared a -> String
    To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
    In the type signature for ‘showNormalized’:
      showNormalized :: forall a. (Show a, ExplicitSharing a) =>
                        Private.ExplicitSharingCache -> XShared a -> String
cabal: Error: some packages failed to install:
ide-backend-common-0.9.0 failed during the building phase. The exception was:
ExitFailure 1

I tried building from git with the same error (I don't think at this point git differs from hackage). I'm using ghc 7.10.1.

snoyberg commented 9 years ago

@edsko Any thoughts on this error? It looks legitimate to me, I'm surprised the code compiles on 7.8 actually.

cocreature commented 9 years ago

It looks like it can be fixed by adding a Proxy a parameter so that it is no longer ambigous. After doing that ide-backend-common builds fine for me, however ide-backend fails with a (probably) related error

IdeSession/Query.hs:363:57:
    Couldn't match expected type ‘XShared a1’
                with actual type ‘Private.SpanInfo’
    The type variable ‘a1’ is ambiguous
    Relevant bindings include
      idInfo' :: a1 (bound at IdeSession/Query.hs:363:11)
    In the second argument of ‘removeExplicitSharing’, namely ‘idInfo’
    In the expression: removeExplicitSharing computedCache idInfo

IdeSession/Query.hs:383:52:
    Couldn't match expected type ‘XShared a0’
                with actual type ‘Private.ModuleId’
    The type variable ‘a0’ is ambiguous
    Relevant bindings include
      mod' :: a0 (bound at IdeSession/Query.hs:383:9)
    In the second argument of ‘removeExplicitSharing’, namely ‘mod’
    In the expression: removeExplicitSharing computedCache mod

After adding another Proxy in removeExplicitSharing and changing every call to pass in the Proxy and giving explicit type annotations to the proxy argument at the two error locations, I actually got it to compile. Note: I know very little about type families, so this is probably a terrible solution :) (cabal test seems to be happy)

edsko commented 9 years ago

I'll take a look at this shortly.

edsko commented 9 years ago

We're currently thinking at Well-Typed HQ that this is a regression in the ghc typechecker.. Stay tuned :)

edsko commented 9 years ago

Ok, so I've reported this as a regression in ghc (https://ghc.haskell.org/trac/ghc/ticket/10226). Meanwhile, yes, I think adding some proxies will circumvent the problem. Adding the proxy argument makes the whole MShared type family redundant, but that doesn't really matter I guess. So if you managed to make this work by adding some proxies, that's fine.