Mark pure function

This commit is contained in:
George Thomas 2026-02-19 15:56:55 +00:00
parent 5907a064a7
commit 5019af701f
7 changed files with 25 additions and 16 deletions

View File

@ -41,5 +41,5 @@ helloStruct = Raw.hello_struct . convertT
helloShape :: Shape -> IO () helloShape :: Shape -> IO ()
helloShape = Raw.hello_shape . convertShape helloShape = Raw.hello_shape . convertShape
add :: Int64 -> Int64 -> IO Int64 add :: Int64 -> Int64 -> Int64
add = Raw.add add = Raw.add

View File

@ -9,4 +9,4 @@ main = do
helloStruct T{a = False, b = maxBound} helloStruct T{a = False, b = maxBound}
helloShape $ Circle 3.14 helloShape $ Circle 3.14
helloShape $ Rectangle 10.0 5.0 helloShape $ Rectangle 10.0 5.0
putStrLn . ("3 + 4 = " <>) . show =<< add 3 4 putStrLn $ "3 + 4 = " <> show (add 3 4)

View File

@ -125,7 +125,7 @@ hs_bindgen_bbabdbe61cd1eeb2 =
{-# NOINLINE add #-} {-# NOINLINE add #-}
{-| __C declaration:__ @add@ {-| __C declaration:__ @add@
__defined at:__ @garnet_rs.h 38:9@ __defined at:__ @garnet_rs.h 38:32@
__exported by:__ @garnet_rs.h@ __exported by:__ @garnet_rs.h@
-} -}

View File

@ -126,19 +126,23 @@ hello_shape =
foreign import ccall safe "hs_bindgen_1c0c71fa74c428a9" hs_bindgen_1c0c71fa74c428a9_base :: foreign import ccall safe "hs_bindgen_1c0c71fa74c428a9" hs_bindgen_1c0c71fa74c428a9_base ::
GHC.Int.Int64 GHC.Int.Int64
-> GHC.Int.Int64 -> GHC.Int.Int64
-> IO GHC.Int.Int64 -> GHC.Int.Int64
-- __unique:__ @com_garnet_GarnetRs_Safe_add@ -- __unique:__ @com_garnet_GarnetRs_Safe_add@
hs_bindgen_1c0c71fa74c428a9 :: hs_bindgen_1c0c71fa74c428a9 ::
HsBindgen.Runtime.LibC.Int64 HsBindgen.Runtime.LibC.Int64
-> HsBindgen.Runtime.LibC.Int64 -> HsBindgen.Runtime.LibC.Int64
-> IO HsBindgen.Runtime.LibC.Int64 -> HsBindgen.Runtime.LibC.Int64
hs_bindgen_1c0c71fa74c428a9 = hs_bindgen_1c0c71fa74c428a9 =
HsBindgen.Runtime.Internal.HasFFIType.fromFFIType hs_bindgen_1c0c71fa74c428a9_base HsBindgen.Runtime.Internal.HasFFIType.fromFFIType hs_bindgen_1c0c71fa74c428a9_base
{-| __C declaration:__ @add@ {-|
__defined at:__ @garnet_rs.h 38:9@ Marked @__attribute((const))__@
__C declaration:__ @add@
__defined at:__ @garnet_rs.h 38:32@
__exported by:__ @garnet_rs.h@ __exported by:__ @garnet_rs.h@
-} -}
@ -147,5 +151,5 @@ add ::
-- ^ __C declaration:__ @a@ -- ^ __C declaration:__ @a@
-> HsBindgen.Runtime.LibC.Int64 -> HsBindgen.Runtime.LibC.Int64
-- ^ __C declaration:__ @b@ -- ^ __C declaration:__ @b@
-> IO HsBindgen.Runtime.LibC.Int64 -> HsBindgen.Runtime.LibC.Int64
add = hs_bindgen_1c0c71fa74c428a9 add = hs_bindgen_1c0c71fa74c428a9

View File

@ -126,19 +126,23 @@ hello_shape =
foreign import ccall unsafe "hs_bindgen_20eb651f0a8faf48" hs_bindgen_20eb651f0a8faf48_base :: foreign import ccall unsafe "hs_bindgen_20eb651f0a8faf48" hs_bindgen_20eb651f0a8faf48_base ::
GHC.Int.Int64 GHC.Int.Int64
-> GHC.Int.Int64 -> GHC.Int.Int64
-> IO GHC.Int.Int64 -> GHC.Int.Int64
-- __unique:__ @com_garnet_GarnetRs_Unsafe_add@ -- __unique:__ @com_garnet_GarnetRs_Unsafe_add@
hs_bindgen_20eb651f0a8faf48 :: hs_bindgen_20eb651f0a8faf48 ::
HsBindgen.Runtime.LibC.Int64 HsBindgen.Runtime.LibC.Int64
-> HsBindgen.Runtime.LibC.Int64 -> HsBindgen.Runtime.LibC.Int64
-> IO HsBindgen.Runtime.LibC.Int64 -> HsBindgen.Runtime.LibC.Int64
hs_bindgen_20eb651f0a8faf48 = hs_bindgen_20eb651f0a8faf48 =
HsBindgen.Runtime.Internal.HasFFIType.fromFFIType hs_bindgen_20eb651f0a8faf48_base HsBindgen.Runtime.Internal.HasFFIType.fromFFIType hs_bindgen_20eb651f0a8faf48_base
{-| __C declaration:__ @add@ {-|
__defined at:__ @garnet_rs.h 38:9@ Marked @__attribute((const))__@
__C declaration:__ @add@
__defined at:__ @garnet_rs.h 38:32@
__exported by:__ @garnet_rs.h@ __exported by:__ @garnet_rs.h@
-} -}
@ -147,5 +151,5 @@ add ::
-- ^ __C declaration:__ @a@ -- ^ __C declaration:__ @a@
-> HsBindgen.Runtime.LibC.Int64 -> HsBindgen.Runtime.LibC.Int64
-- ^ __C declaration:__ @b@ -- ^ __C declaration:__ @b@
-> IO HsBindgen.Runtime.LibC.Int64 -> HsBindgen.Runtime.LibC.Int64
add = hs_bindgen_20eb651f0a8faf48 add = hs_bindgen_20eb651f0a8faf48

View File

@ -35,4 +35,4 @@ void hello_struct(struct T t);
void hello_shape(struct Shape s); void hello_shape(struct Shape s);
int64_t add(int64_t a, int64_t b); __attribute__((const)) int64_t add(int64_t a, int64_t b);

View File

@ -34,6 +34,7 @@ extern "C" fn hello_shape(s: Shape) -> () {
say_hello(&format!("{:?}", s)) say_hello(&format!("{:?}", s))
} }
/// cbindgen:prefix=__attribute__((const))
#[unsafe(no_mangle)] #[unsafe(no_mangle)]
extern "C" fn add(a: i64, b: i64) -> i64 { extern "C" fn add(a: i64, b: i64) -> i64 {
a + b a + b