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 Documentation: foreign imports of Cmm code may now specify source package - - - - - 2 changed files: - + changelog.d/foreign-import-prim-with-package.md - docs/users_guide/exts/ffi.rst Changes: ===================================== changelog.d/foreign-import-prim-with-package.md ===================================== @@ -0,0 +1,19 @@ +section: cmm +synopsis: Foreign imports of Cmm code may now specify source package +issues: #27162 +mrs: !15905 +description: { + With the `GHCForeignImportPrim` extension, Cmm symbols can be imported via the + `prim` calling convention, but there was previously no way to specify the + source package where the Cmm symbol is defined. With this change, the source + package may be specified before the symbol name, separated by a space. For + example, a Cmm symbol `addOne` from package `somePackage` can be imported as + follows: + + foreign import prim "somePackage addOne" addOne :: Int# -> Int# + + Once dynamic linking on windows is implemented, it will require specifying the + source package for Cmm imports unless the source package is the current + package. Failure to do so will result in linker errors. Non windows targets + and static linking on windows are unaffected. +} ===================================== docs/users_guide/exts/ffi.rst ===================================== @@ -294,6 +294,10 @@ Primitive imports :status: InternalUseOnly +This feature is not intended for use outside of the core libraries that +come with GHC. For more details see the +:ghc-wiki:`GHC developer wiki <commentary/prim-ops>`. + With :extension:`GHCForeignImportPrim`, GHC extends the FFI with an additional calling convention ``prim``, e.g.: :: @@ -306,9 +310,15 @@ or ``Any :: UnliftedType`` (which can be arranged by way of ``unsafeCoerce#``) and the result type is allowed to be an unboxed tuple or the types ``Any :: Type`` or ``Any :: UnliftedType``. -This feature is not intended for use outside of the core libraries that -come with GHC. For more details see the -:ghc-wiki:`GHC developer wiki <commentary/prim-ops>`. +The source package may be specified before the symbol name, separated by a +space. For example, to import ``addOne`` from ``somePackage``: :: + + foreign import prim "somePackage addOne" addOne :: Int# -> Int# + +When dynamic linking on windows, source package must be correctly specified. +If the source package is omitted then it is assumed to be the current package. +An incorrect source package will result in linker errors when dynamic linking +on windows. Static linking and non-windows targets are unaffected. .. _ffi-interruptible: View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b8a8d6a52240cb956f731a283e991641... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b8a8d6a52240cb956f731a283e991641... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
David Eichmann (@DavidEichmann)