Skip to content

Conversation

@newhoggy
Copy link
Member

@newhoggy newhoggy commented Dec 27, 2025

Description

This PR modernizes the import structure by migrating from GHC internal modules (GHC.Prim, GHC.Word) to their standard library equivalents (GHC.Exts, Data.Word). This change improves compatibility, reduces dependency on GHC internals, and removes the explicit ghc-prim package dependency while maintaining full functionality across all build configurations.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test coverage improvement

Changes Made

Import Modernization

  • Replaced GHC.Word with Data.Word in both src/Data/Bits/Pdep/Prim.hs and src/Data/Bits/Pext/Prim.hs for standard Word type imports
  • Replaced GHC.Prim with GHC.Exts in BMI2-enabled code paths (src/Data/Bits/Pext/Prim.hs)
  • GHC.Exts re-exports the necessary primitives from both GHC.Prim and GHC.Word, providing a cleaner unified interface

Dependency Cleanup

  • Removed ghc-prim dependency from bits-extra.cabal:
    • Removed from library build-depends
    • Removed from test-suite build-depends
    • Removed from benchmark build-depends
    • Removed common ghc-prim section entirely

Build Configuration Simplification

  • Simplified conditional compilation flag in cabal file from if (flag(bmi2)) && (impl(ghc >= 8.4.1)) to if flag(bmi2)
  • Removed GHC version constraint as BMI2 functionality is now accessed through the standard GHC.Exts module available in all supported GHC versions

Testing

  • All existing tests pass
  • New tests added for new functionality (N/A - refactoring only)
  • Manual testing performed

Additional Notes

Motivation: This refactoring reduces the direct dependency on GHC's internal primitive modules, making the codebase more maintainable and less susceptible to changes in GHC's internal structure. The GHC.Exts module provides a stable interface for accessing GHC extensions and primitives that's part of the base library.

Compatibility: The changes maintain full backward compatibility as GHC.Exts re-exports all necessary types and functions from GHC.Prim and GHC.Word. The functionality remains identical while the import structure is cleaner and more idiomatic.

Impact: This is a pure refactoring with no functional changes—all primitive operations and Word types remain available through the new import paths. The removal of ghc-prim as an explicit dependency simplifies the package's dependency tree.

@newhoggy newhoggy marked this pull request as ready for review December 27, 2025 02:59
@newhoggy newhoggy changed the title refactor: consolidate GHC imports and fix non-BMI2 build compatibility refactor: Avoid ghc-prim dependency Dec 27, 2025
Modernize import structure by switching from GHC internal modules to
their standard library equivalents. This change improves compatibility
and reduces dependency on GHC internals.

Changes made:
- Replace GHC.Word with Data.Word in Pdep/Pext modules
- Replace GHC.Prim with GHC.Exts for BMI2-enabled builds
- Remove ghc-prim dependency from cabal file (library, tests, benchmarks)
- Simplify conditional compilation flag check (remove GHC version constraint)

The BMI2 conditional now applies to all GHC versions with the flag enabled,
relying on the standard library's GHC.Exts module instead of the lower-level
GHC.Prim for primitive operations.
@newhoggy newhoggy changed the title refactor: Avoid ghc-prim dependency refactor: Migrate from GHC.Prim/GHC.Word to standard imports Dec 27, 2025
@newhoggy newhoggy merged commit dc34700 into main Dec 27, 2025
10 checks passed
@newhoggy newhoggy deleted the konsumlamm-main branch December 27, 2025 05:53
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

Successfully merging this pull request may close these issues.

3 participants