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

incompatible with record fields that are actually duplicated -- "symbol already defined" #9

Open
peterwicksstringfield opened this issue Oct 8, 2022 · 2 comments

Comments

@peterwicksstringfield
Copy link
Contributor

barbies-th works fine with DuplicateRecordFields enabled (thanks to the name unmangling patches); but it can't handle record fields that are actually duplicated. Possibly this is an accepted limitation, but it would be nice to document it I think. The error message is not very friendly:

... Assembler messages: ... Error: symbol `testlibzm0zi1zi0zi0zminplace_Lib_qux_info' is already defined ... testlibzm0zi1zi0zi0zminplace_Lib_qux_info

@Elvecent reported this as well, at the bottom of the thread in #3.

GHC 8.10.7
barbies == 2.0.3.1
barbies-th == 0.1.10

Example:

{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DuplicateRecordFields #-}

module Lib where

import Barbies.TH (declareBareB)

declareBareB
  [d|
    data Foo = Foo
      { qux :: Integer
      }
    |]

declareBareB
  [d|
    data Bar = Bar
      { qux :: Integer
      }
    |]
cabal-version:   3.4
name:            testlib
version:         0.1.0.0
build-type:      Simple

common warnings
    ghc-options: -Wall

library
    import:           warnings
    exposed-modules:  Lib
    build-depends:
        base ^>=4.14.3.0,
        barbies == 2.0.3.1,
        barbies-th == 0.1.10
    hs-source-dirs:   src
    default-language: Haskell2010
peter@gtower:~/2022october8_reproduce_barbies_error$ cabal build
Build profile: -w ghc-8.10.7 -O1
In order, the following will be built (use -v for more details):
 - testlib-0.1.0.0 (lib) (first run)
Preprocessing library for testlib-0.1.0.0..
Building library for testlib-0.1.0.0..
[1 of 1] Compiling Lib              ( src/Lib.hs, /home/peter/2022october8_reproduce_barbies_error/dist-newstyle/build/x86_64-linux/ghc-8.10.7/testlib-0.1.0.0/build/Lib.o, /home/peter/2022october8_reproduce_barbies_error/dist-newstyle/build/x86_64-linux/ghc-8.10.7/testlib-0.1.0.0/build/Lib.dyn_o )
/tmp/ghc80775_0/ghc_2.s: Assembler messages:

/tmp/ghc80775_0/ghc_2.s:1298:0: error:
     Error: symbol `testlibzm0zi1zi0zi0zminplace_Lib_qux_info' is already defined
     |
1298 | testlibzm0zi1zi0zi0zminplace_Lib_qux_info:
     | ^

/tmp/ghc80775_0/ghc_2.s:1329:0: error:
     Error: symbol `testlibzm0zi1zi0zi0zminplace_Lib_qux_closure' is already defined
     |
1329 | testlibzm0zi1zi0zi0zminplace_Lib_qux_closure:
     | ^
`gcc' failed in phase `Assembler'. (Exit code: 1)

I tried to minimize the testcase further by expanding the splices and minimizing the generated code, but I was unable to achieve further minimization. I expanded one splice using the code-action offered by HLS. I found that the generated code is referencing a symbol called (Unit :: (Type -> Constraint) -> Type -> Constraint). I stubbed out such a type like this:

{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE UndecidableSuperClasses #-}
import Data.Kind (Constraint, Type)
class c t => Unit (c :: Type -> Constraint) (t :: Type) where
  {- empty body -}

When I added that bit, the generated code started compiling. That is, without the "symbol already defined" error.

Thanks for the library, seems cool.

@fumieval
Copy link
Owner

Thank you for reporting this, I was able to reproduce this on GHC 9.2.4 too. That's a shame... This looks like a GHC bug because such error messages are most likely not intended to be shown to users.

@fumieval
Copy link
Owner

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

2 participants