Skip to content

ghc-lib-parser causes segfaults when used together with the ghc library on ghc-9.10 #620

Open

Description

@AndreasPK

The FastString table built into GHC changed recently.

Since this table is shared by all versions of the GHC source code via an RTS symbol this causes segfaults when ghc-lib-parser-9.12 and ghc-9.10 are used together since they use different memory layouts for this table.

The fix for this is either to change GHC.Data.FastString such that the sharedCAF mechanism is not used. However that means FastStrings created by ghc-lib-parser and ghc are never allowed to be mixed.

The other alternative is to use CPP to adjust the memory layout of the faststring table depending on the GHC version used.

This is the change in question: https://gitlab.haskell.org/ghc/ghc/-/commit/f2cc1107790d42fee1a11d5b16bc282d31ea6f78


The simplest option of course would be to mark ghc-lib-parser-9.12 unbuildable on ghc-9.10, but perhaps also a bit of a shame.

Activity

  1. AndreasPK commented on Dec 2, 2025

    @AndreasPK
    Author

    Related HLS bug where this was discovered: haskell/haskell-language-server#4674

  2. shayne-fletcher commented on Dec 7, 2025

    @shayne-fletcher
    Contributor

    The other alternative is to use CPP to adjust the memory layout of the faststring table depending on the GHC version used.

    what would that cpp look like and where would it go? FastString.hs? we can have ghc-lib generate it. care to offer a patch?

  3. vaibhavsagar commented on Dec 19, 2025

    @vaibhavsagar

    I don't know where to put this as a PR, but I'm guessing a patch would look something like this:

    diff --git a/compiler/GHC/Data/FastString.hs b/compiler/GHC/Data/FastString.hs
    index 017a8d3926a..c72a24cf16b 100644
    --- a/compiler/GHC/Data/FastString.hs
    +++ b/compiler/GHC/Data/FastString.hs
    @@ -310,6 +310,7 @@ data FastStringTable = FastStringTable
       {-# UNPACK #-} !FastMutInt
       -- ^ The unique ID counter shared with all buckets
       --
    +#if MIN_VERSION_ghc(9,12,0)
       -- We unpack the 'FastMutInt' counter as it is always consumed strictly.
       {-# NOUNPACK #-} !FastMutInt
       -- ^ Number of computed z-encodings for all buckets.
    @@ -318,6 +319,9 @@ data FastStringTable = FastStringTable
       -- in 'mkFastStringWith' and needs to be boxed any way.
       -- If this is unpacked, then we box this single 'FastMutInt' once for each
       -- allocated FastString.
    +#else
    +  {-# UNPACK #-} !FastMutInt -- number of computed z-encodings for all buckets
    +#endif
       (Array# (IORef FastStringTableSegment)) -- ^  concurrent segments
    
     data FastStringTableSegment = FastStringTableSegment
  4. shayne-fletcher commented on Dec 21, 2025

    @shayne-fletcher
    Contributor
  5. dylant-da commented on Dec 22, 2025

    @dylant-da
    Contributor

    Seen this just now - I'll take a look tomorrow to see what I can understand of the issue and the proposed fix.

  6. AndreasPK commented on Dec 22, 2025

    @AndreasPK
    Author

    What @vaibhavsagar posted seems right to me.

  7. hasufell commented on Jan 6, 2026

    @hasufell

    What is the status of fixing this?

  8. dylant-da commented on Jan 12, 2026

    @dylant-da
    Contributor

    Apologies, this fell off my radar - taking a look at incorporating this change later today.

  9. dylant-da commented on Jan 13, 2026

    @dylant-da
    Contributor

    Gonna need a bit longer to make the time for this.

  10. vaibhavsagar commented on Jul 6, 2026

    @vaibhavsagar

    Were you able to make any progress on this?

  11. ysangkok commented on Sep 12, 2026

    @ysangkok

    @dylant-da Are you still planning to address this?

  12. ysangkok commented on Oct 20, 2026

    @ysangkok

    @paulbrauner-da Are you looking for new maintainers for this library?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions