futhark-manifest 1.0.0.1 → 1.1.0.0
raw patch · 4 files changed
+111/−21 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Futhark.Manifest: RecordField :: Text -> TypeName -> CFuncName -> RecordField
+ Futhark.Manifest: RecordOps :: [RecordField] -> CFuncName -> RecordOps
+ Futhark.Manifest: [recordFieldName] :: RecordField -> Text
+ Futhark.Manifest: [recordFieldProject] :: RecordField -> CFuncName
+ Futhark.Manifest: [recordFieldType] :: RecordField -> TypeName
+ Futhark.Manifest: [recordFields] :: RecordOps -> [RecordField]
+ Futhark.Manifest: [recordNew] :: RecordOps -> CFuncName
+ Futhark.Manifest: data RecordField
+ Futhark.Manifest: data RecordOps
+ Futhark.Manifest: instance Data.Aeson.Types.FromJSON.FromJSON Futhark.Manifest.RecordField
+ Futhark.Manifest: instance Data.Aeson.Types.FromJSON.FromJSON Futhark.Manifest.RecordOps
+ Futhark.Manifest: instance Data.Aeson.Types.ToJSON.ToJSON Futhark.Manifest.RecordField
+ Futhark.Manifest: instance Data.Aeson.Types.ToJSON.ToJSON Futhark.Manifest.RecordOps
+ Futhark.Manifest: instance GHC.Classes.Eq Futhark.Manifest.RecordField
+ Futhark.Manifest: instance GHC.Classes.Eq Futhark.Manifest.RecordOps
+ Futhark.Manifest: instance GHC.Classes.Ord Futhark.Manifest.RecordField
+ Futhark.Manifest: instance GHC.Classes.Ord Futhark.Manifest.RecordOps
+ Futhark.Manifest: instance GHC.Show.Show Futhark.Manifest.RecordField
+ Futhark.Manifest: instance GHC.Show.Show Futhark.Manifest.RecordOps
+ Futhark.Manifest: type CFuncName = Text
+ Futhark.Manifest: type CTypeName = Text
+ Futhark.Manifest: type TypeName = Text
- Futhark.Manifest: ArrayOps :: Text -> Text -> Text -> Text -> ArrayOps
+ Futhark.Manifest: ArrayOps :: CFuncName -> CFuncName -> CFuncName -> CFuncName -> ArrayOps
- Futhark.Manifest: EntryPoint :: Text -> [Output] -> [Input] -> EntryPoint
+ Futhark.Manifest: EntryPoint :: CFuncName -> [Output] -> [Input] -> EntryPoint
- Futhark.Manifest: Input :: Text -> Text -> Bool -> Input
+ Futhark.Manifest: Input :: Text -> TypeName -> Bool -> Input
- Futhark.Manifest: Manifest :: Map Text EntryPoint -> Map Text Type -> Text -> Text -> Manifest
+ Futhark.Manifest: Manifest :: Map Text EntryPoint -> Map TypeName Type -> Text -> Text -> Manifest
- Futhark.Manifest: OpaqueOps :: Text -> Text -> Text -> OpaqueOps
+ Futhark.Manifest: OpaqueOps :: CFuncName -> CFuncName -> CFuncName -> OpaqueOps
- Futhark.Manifest: Output :: Text -> Bool -> Output
+ Futhark.Manifest: Output :: TypeName -> Bool -> Output
- Futhark.Manifest: TypeArray :: Text -> Text -> Int -> ArrayOps -> Type
+ Futhark.Manifest: TypeArray :: CTypeName -> TypeName -> Int -> ArrayOps -> Type
- Futhark.Manifest: TypeOpaque :: Text -> OpaqueOps -> Type
+ Futhark.Manifest: TypeOpaque :: CTypeName -> OpaqueOps -> Maybe RecordOps -> Type
- Futhark.Manifest: [arrayFree] :: ArrayOps -> Text
+ Futhark.Manifest: [arrayFree] :: ArrayOps -> CFuncName
- Futhark.Manifest: [arrayNew] :: ArrayOps -> Text
+ Futhark.Manifest: [arrayNew] :: ArrayOps -> CFuncName
- Futhark.Manifest: [arrayShape] :: ArrayOps -> Text
+ Futhark.Manifest: [arrayShape] :: ArrayOps -> CFuncName
- Futhark.Manifest: [arrayValues] :: ArrayOps -> Text
+ Futhark.Manifest: [arrayValues] :: ArrayOps -> CFuncName
- Futhark.Manifest: [entryPointCFun] :: EntryPoint -> Text
+ Futhark.Manifest: [entryPointCFun] :: EntryPoint -> CFuncName
- Futhark.Manifest: [inputType] :: Input -> Text
+ Futhark.Manifest: [inputType] :: Input -> TypeName
- Futhark.Manifest: [manifestTypes] :: Manifest -> Map Text Type
+ Futhark.Manifest: [manifestTypes] :: Manifest -> Map TypeName Type
- Futhark.Manifest: [opaqueFree] :: OpaqueOps -> Text
+ Futhark.Manifest: [opaqueFree] :: OpaqueOps -> CFuncName
- Futhark.Manifest: [opaqueRestore] :: OpaqueOps -> Text
+ Futhark.Manifest: [opaqueRestore] :: OpaqueOps -> CFuncName
- Futhark.Manifest: [opaqueStore] :: OpaqueOps -> Text
+ Futhark.Manifest: [opaqueStore] :: OpaqueOps -> CFuncName
- Futhark.Manifest: [outputType] :: Output -> Text
+ Futhark.Manifest: [outputType] :: Output -> TypeName
Files
- CHANGELOG.md +4/−0
- futhark-manifest.cabal +1/−1
- src/Futhark/Manifest.hs +99/−19
- tests/Tests.hs +7/−1
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for futhark-manifest +## 1.1.0.0 -- 2022-06-27++* Support records.+ ## 1.0.0.1 -- 2021-12-19 * First version. Released on an unsuspecting world.
futhark-manifest.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: futhark-manifest-version: 1.0.0.1+version: 1.1.0.0 synopsis: Definition and serialisation instances for Futhark manifests.
src/Futhark/Manifest.hs view
@@ -1,18 +1,34 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TupleSections #-} -- | C manifest data structure and serialisation to JSON. -- -- A manifest contains machine-readable information about the API of -- the compiled Futhark program. Specifically which entry points are -- available, which types are exposed, and what their C names are.+-- This module documentation is not intended as a full description of+-- the Futhark C API - you will need to consult the Futhark User's+-- Guide to understand most of the information here.+--+-- The type aliases are purely informative and do not actually enforce+-- correct usage. They are present only because most of the+-- information here is ultimately just text. module Futhark.Manifest- ( Manifest (..),+ ( -- * Type aliases+ CFuncName,+ CTypeName,+ TypeName,++ -- * Manifest+ Manifest (..), Input (..), Output (..), EntryPoint (..), Type (..), ArrayOps (..),+ RecordField (..),+ RecordOps (..), OpaqueOps (..), manifestToJSON, manifestFromJSON,@@ -28,28 +44,41 @@ import Data.Bifunctor (bimap) import Data.ByteString.Builder (toLazyByteString) import qualified Data.Map as M+import Data.Maybe (maybeToList) import qualified Data.Text as T import Data.Text.Encoding (encodeUtf8Builder) import Data.Text.Lazy (toStrict) +-- | The name of a C function.+type CFuncName = T.Text++-- | The name of a C type (often of the form @"struct foo*"@).+type CTypeName = T.Text++-- | The name of a Futhark-level type. This may be an array type+-- (without sizes, just empty brackets), a primitive type, or another+-- string denoting an opaque type. The latter must have a+-- corresponding entry in 'manifestTypes'.+type TypeName = T.Text+ -- | Manifest info for an entry point parameter. data Input = Input { inputName :: T.Text,- inputType :: T.Text,+ inputType :: TypeName, inputUnique :: Bool } deriving (Eq, Ord, Show) -- | Manifest info for an entry point return value. data Output = Output- { outputType :: T.Text,+ { outputType :: TypeName, outputUnique :: Bool } deriving (Eq, Ord, Show) -- | Manifest info for an entry point. data EntryPoint = EntryPoint- { entryPointCFun :: T.Text,+ { entryPointCFun :: CFuncName, entryPointOutputs :: [Output], entryPointInputs :: [Input] }@@ -58,19 +87,45 @@ -- | The names of the C functions implementing the operations on some -- array type. data ArrayOps = ArrayOps- { arrayFree :: T.Text,- arrayShape :: T.Text,- arrayValues :: T.Text,- arrayNew :: T.Text+ { arrayFree :: CFuncName,+ arrayShape :: CFuncName,+ arrayValues :: CFuncName,+ arrayNew :: CFuncName } deriving (Eq, Ord, Show) +-- | Information about a record field.+data RecordField = RecordField+ { -- | The original name of the field. This may be a name that is+ -- not a valid C identifier.+ recordFieldName :: T.Text,+ -- | The type of the field.+ recordFieldType :: TypeName,+ -- | The name of the projection function.+ recordFieldProject :: CFuncName+ }+ deriving (Eq, Ord, Show)++-- | Some opaque types are records, from which we can extract fields,+-- and also construct them from values for their fields. Beyond that,+-- they support the usual opaque operations. These record facilities+-- can be ignored if you wish, and the types treated as ordinary+-- opaque types.+data RecordOps = RecordOps+ { -- | Note that the ordering of fields here is semantically+ -- significant - it is also the order that the "new" function+ -- expects.+ recordFields :: [RecordField],+ recordNew :: CFuncName+ }+ deriving (Eq, Ord, Show)+ -- | The names of the C functions implementing the operations on some -- opaque type. data OpaqueOps = OpaqueOps- { opaqueFree :: T.Text,- opaqueStore :: T.Text,- opaqueRestore :: T.Text+ { opaqueFree :: CFuncName,+ opaqueStore :: CFuncName,+ opaqueRestore :: CFuncName } deriving (Eq, Ord, Show) @@ -78,8 +133,8 @@ -- of the manifest for a program. data Type = -- | ctype, Futhark elemtype, rank.- TypeArray T.Text T.Text Int ArrayOps- | TypeOpaque T.Text OpaqueOps+ TypeArray CTypeName TypeName Int ArrayOps+ | TypeOpaque CTypeName OpaqueOps (Maybe RecordOps) deriving (Eq, Ord, Show) -- | A manifest for a compiled program.@@ -91,7 +146,7 @@ -- at the C level. Should not contain any of the primitive scalar -- types. For array types, these have empty dimensions, -- e.g. @[]i32@.- manifestTypes :: M.Map T.Text Type,+ manifestTypes :: M.Map TypeName Type, -- | The compiler backend used to -- compile the program, e.g. @c@. manifestBackend :: T.Text,@@ -109,9 +164,24 @@ ("new", toJSON new) ] +instance JSON.ToJSON RecordField where+ toJSON (RecordField name typename project) =+ object+ [ ("name", toJSON name),+ ("type", toJSON typename),+ ("project", toJSON project)+ ]++instance JSON.ToJSON RecordOps where+ toJSON (RecordOps fields new) =+ object+ [ ("fields", toJSON fields),+ ("new", toJSON new)+ ]+ instance JSON.ToJSON OpaqueOps where toJSON (OpaqueOps free store restore) =- object+ object $ [ ("free", toJSON free), ("store", toJSON store), ("restore", toJSON restore)@@ -158,17 +228,26 @@ ("elemtype", toJSON et), ("ops", toJSON ops) ]- onType (TypeOpaque t ops) =- object+ onType (TypeOpaque t ops record) =+ object $ [ ("kind", "opaque"), ("ctype", toJSON t), ("ops", toJSON ops) ]+ ++ maybeToList (("record",) . toJSON <$> record) instance JSON.FromJSON ArrayOps where parseJSON = JSON.withObject "ArrayOps" $ \v -> ArrayOps <$> v .: "free" <*> v .: "shape" <*> v .: "values" <*> v .: "new" +instance JSON.FromJSON RecordField where+ parseJSON = JSON.withObject "RecordField" $ \v ->+ RecordField <$> v .: "name" <*> v .: "type" <*> v .: "project"++instance JSON.FromJSON RecordOps where+ parseJSON = JSON.withObject "RecordOps" $ \v ->+ RecordOps <$> v .: "fields" <*> v .: "new"+ instance JSON.FromJSON OpaqueOps where parseJSON = JSON.withObject "OpaqueOps" $ \v -> OpaqueOps <$> v .: "free" <*> v .: "store" <*> v .: "restore"@@ -190,13 +269,14 @@ where pArray ty = do guard . (== ("array" :: T.Text)) =<< (ty .: "kind")- TypeArray <$> ty .: "ctype"+ TypeArray+ <$> ty .: "ctype" <*> ty .: "elemtype" <*> ty .: "rank" <*> ty .: "ops" pOpaque ty = do guard . (== ("opaque" :: T.Text)) =<< (ty .: "kind")- TypeOpaque <$> ty .: "ctype" <*> ty .: "ops"+ TypeOpaque <$> ty .: "ctype" <*> ty .: "ops" <*> ty .:? "record" instance JSON.FromJSON Manifest where parseJSON = JSON.withObject "Manifest" $ \v ->
tests/Tests.hs view
@@ -15,6 +15,12 @@ instance Arbitrary ArrayOps where arbitrary = ArrayOps <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary +instance Arbitrary RecordField where+ arbitrary = RecordField <$> arbitrary <*> arbitrary <*> arbitrary++instance Arbitrary RecordOps where+ arbitrary = RecordOps <$> arbitrary <*> arbitrary+ instance Arbitrary OpaqueOps where arbitrary = OpaqueOps <$> arbitrary <*> arbitrary <*> arbitrary @@ -22,7 +28,7 @@ arbitrary = oneof [ TypeArray <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary,- TypeOpaque <$> arbitrary <*> arbitrary+ TypeOpaque <$> arbitrary <*> arbitrary <*> arbitrary ] instance Arbitrary Output where