Skip to content

Commit

Permalink
Add stubs for FFI functions
Browse files Browse the repository at this point in the history
Without these stubs HLS wouldn't be able to provide completion in any
module that directly or indirectly includes any of the
'Data.Array.Accelerate.Pattern.*' modules.

haskell/haskell-language-server#365
  • Loading branch information
robbert-vdh committed Feb 21, 2021
1 parent b23f41f commit 6c39c35
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Data/Array/Accelerate/Debug/Internal/Flags.hs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ clearFlags = mapM_ clearFlag
-- notEnabled = error $ unlines [ "Data.Array.Accelerate: Debugging options are disabled."
-- , "Reinstall package 'accelerate' with '-fdebug' to enable them." ]

-- FIXME: HLS requires stubs because it does not process the
-- 'addForeignFilePath' calls when evaluating Template Haskell
--
-- https://github.com/haskell/haskell-language-server/issues/365
#ifndef __GHCIDE__

-- Import the underlying flag variables. These are defined in the file
-- cbits/flags.h as a bitfield and initialised at program initialisation.
--
Expand All @@ -174,6 +180,19 @@ foreign import ccall "&__cmd_line_flags" __cmd_line_flags :: Ptr Word32
foreign import ccall "&__unfolding_use_threshold" unfolding_use_threshold :: Value -- the magic cut-off figure for inlining
foreign import ccall "&__max_simplifier_iterations" max_simplifier_iterations :: Value -- maximum number of scalar simplification passes

#else

__cmd_line_flags :: Ptr Word32
__cmd_line_flags = undefined

unfolding_use_threshold :: Value
unfolding_use_threshold = undefined

max_simplifier_iterations :: Value
max_simplifier_iterations = undefined

#endif

-- These @-f<blah>@ flags can be reversed with @-fno-<blah>@
--
seq_sharing = Flag 0 -- recover sharing of sequence expressions
Expand Down
26 changes: 26 additions & 0 deletions src/Data/Atomic.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE NoImplicitPrelude #-}
Expand Down Expand Up @@ -49,6 +50,12 @@ newtype Atomic = Atomic ( Ptr Int64 )
-- write a v
-- return a

-- FIXME: HLS requires stubs because it does not process the
-- 'addForeignFilePath' calls when evaluating Template Haskell
--
-- https://github.com/haskell/haskell-language-server/issues/365
#ifndef __GHCIDE__

-- | Get the current value.
--
foreign import ccall unsafe "atomic_read_64" read :: Atomic -> IO Int64
Expand All @@ -69,6 +76,25 @@ foreign import ccall unsafe "atomic_fetch_and_and_64" and :: Atomic -> Int64 ->
--
foreign import ccall unsafe "atomic_fetch_and_sub_64" subtract :: Atomic -> Int64 -> IO Int64

#else

read :: Atomic -> IO Int64
read = undefined

write :: Atomic -> Int64 -> IO ()
write = undefined

add :: Atomic -> Int64 -> IO Int64
add = undefined

and :: Atomic -> Int64 -> IO Int64
and = undefined

subtract :: Atomic -> Int64 -> IO Int64
subtract = undefined

#endif

-- SEE: [linking to .c files]
--
runQ $ do
Expand Down

0 comments on commit 6c39c35

Please sign in to comment.