David Eichmann pushed to branch wip/dcoutts/foreign-label-source-refactoring at Glasgow Haskell Compiler / GHC
Commits:
-
b8a8d6a5
by David Eichmann at 2026-05-01T09:21:55+01:00
2 changed files:
Changes:
| 1 | +section: cmm
|
|
| 2 | +synopsis: Foreign imports of Cmm code may now specify source package
|
|
| 3 | +issues: #27162
|
|
| 4 | +mrs: !15905
|
|
| 5 | +description: {
|
|
| 6 | + With the `GHCForeignImportPrim` extension, Cmm symbols can be imported via the
|
|
| 7 | + `prim` calling convention, but there was previously no way to specify the
|
|
| 8 | + source package where the Cmm symbol is defined. With this change, the source
|
|
| 9 | + package may be specified before the symbol name, separated by a space. For
|
|
| 10 | + example, a Cmm symbol `addOne` from package `somePackage` can be imported as
|
|
| 11 | + follows:
|
|
| 12 | + |
|
| 13 | + foreign import prim "somePackage addOne" addOne :: Int# -> Int#
|
|
| 14 | + |
|
| 15 | + Once dynamic linking on windows is implemented, it will require specifying the
|
|
| 16 | + source package for Cmm imports unless the source package is the current
|
|
| 17 | + package. Failure to do so will result in linker errors. Non windows targets
|
|
| 18 | + and static linking on windows are unaffected.
|
|
| 19 | +} |
| ... | ... | @@ -294,6 +294,10 @@ Primitive imports |
| 294 | 294 | |
| 295 | 295 | :status: InternalUseOnly
|
| 296 | 296 | |
| 297 | +This feature is not intended for use outside of the core libraries that
|
|
| 298 | +come with GHC. For more details see the
|
|
| 299 | +:ghc-wiki:`GHC developer wiki <commentary/prim-ops>`.
|
|
| 300 | + |
|
| 297 | 301 | With :extension:`GHCForeignImportPrim`, GHC extends the FFI with an additional
|
| 298 | 302 | calling convention ``prim``, e.g.: ::
|
| 299 | 303 | |
| ... | ... | @@ -306,9 +310,15 @@ or ``Any :: UnliftedType`` (which can be arranged by way of |
| 306 | 310 | ``unsafeCoerce#``) and the result type is allowed to be an unboxed tuple
|
| 307 | 311 | or the types ``Any :: Type`` or ``Any :: UnliftedType``.
|
| 308 | 312 | |
| 309 | -This feature is not intended for use outside of the core libraries that
|
|
| 310 | -come with GHC. For more details see the
|
|
| 311 | -:ghc-wiki:`GHC developer wiki <commentary/prim-ops>`.
|
|
| 313 | +The source package may be specified before the symbol name, separated by a
|
|
| 314 | +space. For example, to import ``addOne`` from ``somePackage``: ::
|
|
| 315 | + |
|
| 316 | + foreign import prim "somePackage addOne" addOne :: Int# -> Int#
|
|
| 317 | + |
|
| 318 | +When dynamic linking on windows, source package must be correctly specified.
|
|
| 319 | +If the source package is omitted then it is assumed to be the current package.
|
|
| 320 | +An incorrect source package will result in linker errors when dynamic linking
|
|
| 321 | +on windows. Static linking and non-windows targets are unaffected.
|
|
| 312 | 322 | |
| 313 | 323 | .. _ffi-interruptible:
|
| 314 | 324 |