diff --git a/data/sea/52-psv.h b/data/sea/52-psv.h index 2f876c67..598ccf9b 100644 --- a/data/sea/52-psv.h +++ b/data/sea/52-psv.h @@ -23,6 +23,11 @@ typedef struct { const size_t facts_limit; /* maximum number of facts per entity-attribute */ const ibool_t has_drop; /* whether to write discarded facts to output or drop log */ + /* constants */ + const size_t psv_input_buffer_size; + const size_t psv_output_buffer_size; + const size_t psv_max_row_count; + } psv_config_t; typedef struct { @@ -67,7 +72,7 @@ typedef struct { /* forward declarations for functions, implemented by generated code */ -static ifleet_t * INLINE psv_alloc_fleet (iint_t max_chord_count); +static ifleet_t * INLINE psv_alloc_fleet (const iint_t max_chord_count, const iint_t max_row_count); static void INLINE psv_collect_fleet (ifleet_t *fleet); @@ -89,7 +94,8 @@ static ierror_loc_t INLINE psv_read_fact , const char *time_ptr , const size_t time_size , ifleet_t *fleet - , const size_t max_ent_attr_count); + , const size_t facts_limit + , const iint_t max_row_count ); #else static ierror_loc_t INLINE psv_read_fact ( const char *entity_ptr @@ -99,7 +105,8 @@ static ierror_loc_t INLINE psv_read_fact , const char *time_ptr , const size_t time_size , ifleet_t *fleet - , const size_t max_ent_attr_count); + , const size_t facts_limit + , const iint_t max_row_count ); #endif static ierror_msg_t INLINE psv_write_output @@ -276,7 +283,7 @@ static ierror_loc_t psv_write_dropped_entity_cur (psv_state_t *s, const ierror_l return 0; } -static ierror_loc_t psv_read_buffer (psv_state_t *s, const size_t facts_limit) +static ierror_loc_t psv_read_buffer (psv_state_t *s, const size_t facts_limit, const iint_t max_row_count) { ierror_loc_t error; @@ -417,11 +424,11 @@ static ierror_loc_t psv_read_buffer (psv_state_t *s, const size_t facts_limit) } #if ICICLE_PSV_INPUT_SPARSE - error = psv_read_fact (entity_ptr, entity_size, attrib_ptr, attrib_size, value_ptr, value_size, time_ptr, time_size, s->fleet, facts_limit); + error = psv_read_fact (entity_ptr, entity_size, attrib_ptr, attrib_size, value_ptr, value_size, time_ptr, time_size, s->fleet, facts_limit, max_row_count); if (error) goto on_error; #else - error = psv_read_fact (entity_ptr, entity_size, value_ptr, value_size, time_ptr, time_size, s->fleet, facts_limit); + error = psv_read_fact (entity_ptr, entity_size, value_ptr, value_size, time_ptr, time_size, s->fleet, facts_limit, max_row_count); if (error) goto on_error; #endif @@ -450,7 +457,7 @@ static ierror_loc_t psv_read_whole_buffer (psv_config_t *cfg, psv_state_t *s) ierror_loc_t error = 0; while (keep_going) { - error = psv_read_buffer (s, cfg->facts_limit); + error = psv_read_buffer (s, cfg->facts_limit, cfg->psv_max_row_count); if (error) { /* try to skip to the next entity, if there is no new entity @@ -584,11 +591,11 @@ void psv_snapshot (piano_t *piano, psv_config_t *cfg) return; } - ifleet_t *fleet = psv_alloc_fleet (chord_file.max_chord_count); + ifleet_t *fleet = psv_alloc_fleet (chord_file.max_chord_count, cfg->psv_max_row_count); - char *input_ptr = calloc (psv_input_buffer_size + 1, 1); - char *entity_cur = calloc (psv_input_buffer_size + 1, 1); - char *output_ptr = calloc (psv_output_buffer_size + 1, 1); + char *input_ptr = calloc (cfg->psv_input_buffer_size + 1, 1); + char *entity_cur = calloc (cfg->psv_input_buffer_size + 1, 1); + char *output_ptr = calloc (cfg->psv_output_buffer_size + 1, 1); static const psv_state_t empty_state; psv_state_t state = empty_state; @@ -597,7 +604,7 @@ void psv_snapshot (piano_t *piano, psv_config_t *cfg) state.input_ptr = input_ptr; state.entity_cur = entity_cur; state.output_start = output_ptr; - state.output_end = output_ptr + psv_output_buffer_size - 1; + state.output_end = output_ptr + cfg->psv_output_buffer_size - 1; state.output_ptr = output_ptr; state.fleet = fleet; state.output_fd = output_fd; @@ -612,7 +619,7 @@ void psv_snapshot (piano_t *piano, psv_config_t *cfg) size_t bytes_read = read ( input_fd , input_ptr + input_offset - , psv_input_buffer_size - input_offset ); + , cfg->psv_input_buffer_size - input_offset ); if (bytes_read == psv_read_error) { cfg->error = ierror_msg_alloc ("error reading input", 0, 0); diff --git a/data/sea/54-zebra.h b/data/sea/54-zebra.h index 23172faa..abb4fc73 100644 --- a/data/sea/54-zebra.h +++ b/data/sea/54-zebra.h @@ -13,6 +13,7 @@ typedef struct { const char *error; iint_t fact_count; iint_t entity_count; + const size_t output_buffer_size; } zebra_config_t; @@ -189,11 +190,12 @@ zebra_state_t *zebra_alloc_state (piano_t *piano, zebra_config_t *cfg) max_chord_count = 1; } - ifleet_t *fleet = psv_alloc_fleet (max_chord_count); - char *output_ptr = calloc (psv_output_buffer_size + 1, 1); + /* max_row_count is unused */ + ifleet_t *fleet = psv_alloc_fleet (max_chord_count, 0); + char *output_ptr = calloc (cfg->output_buffer_size + 1, 1); state->output_start = output_ptr; - state->output_end = output_ptr + psv_output_buffer_size - 1; + state->output_end = output_ptr + cfg->output_buffer_size - 1; state->output_ptr = output_ptr; state->fleet = fleet; state->output_fd = output_fd; diff --git a/icicle-compiler/icicle.cabal b/icicle-compiler/icicle.cabal index fd1e3323..5c6e6438 100644 --- a/icicle-compiler/icicle.cabal +++ b/icicle-compiler/icicle.cabal @@ -220,6 +220,28 @@ test-suite test hs-source-dirs: test + other-modules: + -- Icicle.Test.Sea.Bindings + + include-dirs: + data/sea + + install-includes: + 00-includes.h + 05-error.h + 06-segv.h + 20-simple.h + 21-time.h + 30-array.h + 31-buffer.h + 40-grisu2-powers.h + 41-grisu2.h + 42-text-conversion.h + 50-chord.h + 51-piano.h + 52-psv.h + 53-zebra-data.h + 54-zebra.h build-depends: base >= 3 && < 5 @@ -235,7 +257,10 @@ test-suite test , ambiata-jetski , ambiata-x-eithert , ambiata-x-file-embed + , ambiata-anemone + , ambiata-zebra , bifunctors >= 4.2 && < 5.4 + , bindings-DSL >= 1.0.0 && <= 1.0.23 , aeson , bytestring , containers @@ -274,6 +299,7 @@ test-suite test-io , icicle-source , icicle-core , icicle + , ambiata-zebra , ambiata-disorder-core , ambiata-disorder-corpus , ambiata-p diff --git a/icicle-compiler/main/icicle-make.hs b/icicle-compiler/main/icicle-make.hs index 0cdccc21..b8d1bb54 100644 --- a/icicle-compiler/main/icicle-make.hs +++ b/icicle-compiler/main/icicle-make.hs @@ -111,7 +111,7 @@ main = PsvOutputConfig mode PsvOutputSparse defaultOutputMissing format = - FormatPsv (psvDefaultConstants inputConfig outputConfig) + FormatPsv (PsvConfig inputConfig outputConfig) inputOptions = InputOpts AllowDupTime $ tombstonesOfDictionary loadedDictionary diff --git a/icicle-compiler/main/icicle.hs b/icicle-compiler/main/icicle.hs index 32b89056..1410ddc5 100644 --- a/icicle-compiler/main/icicle.hs +++ b/icicle-compiler/main/icicle.hs @@ -177,13 +177,9 @@ pChord :: Parser (Scope ()) pChord = flag' (ScopeChord ()) (long "chord") -defaultFactsLimit :: Int -defaultFactsLimit = - 1024 * 1024 - pLimit :: Parser Int pLimit = - flip option (long "facts-limit" <> value defaultFactsLimit) $ + flip option (long "facts-limit" <> value defaultPsvFactsLimit) $ readerAsk >>= \s -> case readMaybe s of Just i -> return i Nothing -> readerError "--facts-limit NUMBER" @@ -211,6 +207,7 @@ runCommand = \case end <- liftIO getCurrentTime let secs = realToFrac (end `diffUTCTime` start) :: Double + liftIO (printf "icicle: compilation time = %.2fs\n" secs) IcicleQuery q -> do diff --git a/icicle-compiler/src/Icicle/Command.hs b/icicle-compiler/src/Icicle/Command.hs index 1e9ed331..05b04911 100644 --- a/icicle-compiler/src/Icicle/Command.hs +++ b/icicle-compiler/src/Icicle/Command.hs @@ -221,11 +221,11 @@ mkQueryFleet input chord source = do -- we actually only need to differentiate between psv/zebra, make this better let format = case inputFormat input of InputSparsePsv -> - FormatPsv $ psvDefaultConstants + FormatPsv $ PsvConfig (PsvInputConfig Chords PsvInputSparse) (PsvOutputConfig Chords PsvOutputSparse defaultOutputMissing) InputDensePsv -> - FormatPsv $ psvDefaultConstants + FormatPsv $ PsvConfig (PsvInputConfig Chords PsvInputSparse) (PsvOutputConfig Chords PsvOutputSparse defaultOutputMissing) InputZebra -> @@ -272,13 +272,14 @@ loadDictionary path iformat oformat0 scope = oconfig = PsvOutputConfig mode oformat defaultOutputMissing + in case iformat of InputSparsePsv -> do d <- firstEitherT IcicleDictionaryImportError $ Toml.loadDictionary Source.optionSmallData Toml.ImplicitPrelude path - let f = FormatPsv $ psvDefaultConstants + let f = FormatPsv $ PsvConfig (PsvInputConfig mode PsvInputSparse) oconfig @@ -288,7 +289,7 @@ loadDictionary path iformat oformat0 scope = (d, dense) <- firstEitherT IcicleDictionaryImportError $ Toml.loadDenseDictionary Source.optionSmallData Toml.ImplicitPrelude path Nothing - let f = FormatPsv $ psvDefaultConstants + let f = FormatPsv $ PsvConfig (PsvInputConfig mode (PsvInputDense dense (denseSelectedFeed dense))) oconfig @@ -338,12 +339,12 @@ runPsvQuery b = do output = queryOutputPath b dropPath = queryDropPath b chordPath = queryChordPath b - limit = queryFactsLimit b discard = queryUseDrop b + constants = defaultPsvConstants { psvFactsLimit = queryFactsLimit b } start <- liftIO getCurrentTime stats <- firstEitherT IcicleSeaError - $ seaPsvSnapshotFilePath fleet input output dropPath chordPath limit discard + $ seaPsvSnapshotFilePath fleet input output dropPath chordPath discard constants end <- liftIO getCurrentTime size <- liftIO (withFile input ReadMode hFileSize) diff --git a/icicle-compiler/src/Icicle/Sea/Eval.hs b/icicle-compiler/src/Icicle/Sea/Eval.hs index b6e8af96..47236741 100644 --- a/icicle-compiler/src/Icicle/Sea/Eval.hs +++ b/icicle-compiler/src/Icicle/Sea/Eval.hs @@ -80,11 +80,12 @@ seaZebraSnapshotFd :: SeaFleet ZebraState -> Maybe Posix.Fd -> EitherT SeaError IO ZebraStats seaZebraSnapshotFd fleet input output mchords = do - withWords 6 $ \pState -> do + withWords 7 $ \pState -> do input_path <- liftIO $ newCString input pokeWordOff pState 0 input_path pokeWordOff pState 1 output pokeWordOff pState 2 (fromMaybe 0 mchords) + pokeWordOff pState 6 (defaultPsvOutputBufferSize) sfSnapshot fleet pState @@ -110,10 +111,10 @@ seaPsvSnapshotFilePath :: SeaFleet PsvState -> FilePath -> FilePath -> Maybe FilePath - -> Int -> FlagUseDrop + -> PsvConstants -> EitherT SeaError IO PsvStats -seaPsvSnapshotFilePath fleet input output dropped mchords limit discard = do +seaPsvSnapshotFilePath fleet input output dropped mchords discard conf = do bracketEitherT' (liftIO $ Posix.openFd input Posix.ReadOnly Nothing Posix.defaultFileFlags) (liftIO . Posix.closeFd) $ \ifd -> do bracketEitherT' (liftIO $ Posix.createFile output (Posix.CMode 0O644)) @@ -122,7 +123,7 @@ seaPsvSnapshotFilePath fleet input output dropped mchords limit discard = do (liftIO . Posix.closeFd) $ \dfd -> do bracketEitherT' (liftIO $ maybeOpen mchords) (liftIO . maybeClose) $ \mcfd -> do - seaPsvSnapshotFd fleet ifd ofd dfd mcfd limit discard + seaPsvSnapshotFd fleet ifd ofd dfd mcfd discard conf @@ -131,18 +132,21 @@ seaPsvSnapshotFd :: SeaFleet PsvState -> Posix.Fd -> Posix.Fd -> Maybe Posix.Fd - -> Int -> FlagUseDrop + -> PsvConstants -> EitherT SeaError IO PsvStats -seaPsvSnapshotFd fleet input output dropped mchords limit discard = - withWords 9 $ \pState -> do - - pokeWordOff pState 0 input - pokeWordOff pState 1 output - pokeWordOff pState 2 dropped - pokeWordOff pState 3 (fromMaybe 0 mchords) - pokeWordOff pState 7 limit - pokeWordOff pState 8 (discard == FlagUseDropFile) +seaPsvSnapshotFd fleet input output dropped mchords discard conf = + withWords 12 $ \pState -> do + + pokeWordOff pState 0 input + pokeWordOff pState 1 output + pokeWordOff pState 2 dropped + pokeWordOff pState 3 (fromMaybe 0 mchords) + pokeWordOff pState 7 (psvFactsLimit conf) + pokeWordOff pState 8 (discard == FlagUseDropFile) + pokeWordOff pState 9 (psvInputBufferSize conf) + pokeWordOff pState 10 (psvOutputBufferSize conf) + pokeWordOff pState 11 (psvMaxRowCount conf) sfSnapshot fleet pState diff --git a/icicle-compiler/src/Icicle/Sea/Eval/Base.hs b/icicle-compiler/src/Icicle/Sea/Eval/Base.hs index 7c8c523c..d0b856cb 100644 --- a/icicle-compiler/src/Icicle/Sea/Eval/Base.hs +++ b/icicle-compiler/src/Icicle/Sea/Eval/Base.hs @@ -302,19 +302,13 @@ codeOfPrograms input attributes programs = do case input of NoInput -> do - let consts = seaOfDefaultConstants pure . textOfDoc . vsep $ [ "#define ICICLE_NO_INPUT 1" - , consts , seaPreamble , defs ] <> progs HasInput format opts _ -> do doc <- seaOfDriver format opts attributes states - let cnst = case format of - FormatPsv conf - -> seaOfConstants conf - _ -> seaOfDefaultConstants let def = case format of FormatPsv conf -> vsep [ defOfPsvInput (psvInputConfig conf), defOfPsvOutput (psvOutputConfig conf) ] @@ -323,7 +317,7 @@ codeOfPrograms input attributes programs = do , "#define ICICLE_ZEBRA 1" ] - pure . textOfDoc . vsep $ [def, cnst, seaPreamble, defs] <> progs <> ["", doc] + pure . textOfDoc . vsep $ [def, seaPreamble, defs] <> progs <> ["", doc] textOfDoc :: Doc -> Text textOfDoc doc = T.pack (displayS (renderPretty 0.8 80 (pretty doc)) "") diff --git a/icicle-compiler/src/Icicle/Sea/IO.hs b/icicle-compiler/src/Icicle/Sea/IO.hs index 8eadc9fb..fba0d22a 100644 --- a/icicle-compiler/src/Icicle/Sea/IO.hs +++ b/icicle-compiler/src/Icicle/Sea/IO.hs @@ -6,17 +6,17 @@ {-# LANGUAGE NamedFieldPuns #-} module Icicle.Sea.IO ( seaOfDriver - , seaOfConstants - , seaOfDefaultConstants , defaultOutputMissing + , defaultPsvConstants + , defaultPsvFactsLimit , defaultPsvMaxRowCount , defaultPsvInputBufferSize , defaultPsvOutputBufferSize - , psvDefaultConstants , Mode(..) , IOFormat (..) , InputOpts (..) , InputAllowDupTime (..) + , PsvConstants (..) , PsvConfig(..) , PsvInputConfig(..) , PsvInputFormat(..) @@ -47,11 +47,13 @@ data IOFormat seaOfDriver :: IOFormat -> InputOpts -> [Attribute] -> [SeaProgramState] -> Either SeaError Doc seaOfDriver format opts attributes states = case format of - FormatPsv conf - -> seaOfPsvDriver opts conf states - FormatZebra mode outputConfig - -> -- FIXME generate code for psv as well when using zebra, because we - -- are relying on some psv functions, they should be factored out or something - do x <- seaOfPsvDriver opts (psvDefaultConstants (PsvInputConfig mode PsvInputSparse) outputConfig) states - y <- seaOfZebraDriver attributes states - return $ vsep [x, "", y] + FormatPsv conf -> do + seaOfPsvDriver opts conf states + FormatZebra mode outputConfig -> do + -- FIXME generate code for psv as well when using zebra, because we + -- are relying on some psv functions, they should be factored out or something + let psvConfig = + PsvConfig (PsvInputConfig mode PsvInputSparse) outputConfig + x <- seaOfPsvDriver opts psvConfig states + y <- seaOfZebraDriver attributes states + return $ vsep [x, "", y] diff --git a/icicle-compiler/src/Icicle/Sea/IO/Base.hs b/icicle-compiler/src/Icicle/Sea/IO/Base.hs index c5460d27..d3b24b0d 100644 --- a/icicle-compiler/src/Icicle/Sea/IO/Base.hs +++ b/icicle-compiler/src/Icicle/Sea/IO/Base.hs @@ -203,7 +203,7 @@ seaOfAllocFleet :: [SeaProgramState] -> Doc seaOfAllocFleet states = vsep [ "#line 1 \"allocate fleet state\"" - , "static ifleet_t * psv_alloc_fleet (iint_t max_chord_count)" + , "static ifleet_t * psv_alloc_fleet (iint_t max_chord_count, iint_t max_row_count)" , "{" , " ifleet_t *fleet = calloc (1, sizeof (ifleet_t));" , "" @@ -226,7 +226,7 @@ seaOfAllocProgram state go (n, t) = program <> stateInputNew (pretty n) <> " = " - <> calloc "psv_max_row_count" (seaOfValType t) + <> calloc "max_row_count" (seaOfValType t) in vsep [ "/* " <> seaOfAttributeDesc (stateAttribute state) <> " */" , programs <> " = " <> calloc "max_chord_count" stype diff --git a/icicle-compiler/src/Icicle/Sea/IO/Psv.hs b/icicle-compiler/src/Icicle/Sea/IO/Psv.hs index a3541ab3..f4622f66 100644 --- a/icicle-compiler/src/Icicle/Sea/IO/Psv.hs +++ b/icicle-compiler/src/Icicle/Sea/IO/Psv.hs @@ -4,16 +4,16 @@ {-# LANGUAGE PatternGuards #-} module Icicle.Sea.IO.Psv ( PsvConfig (..) + , PsvConstants (..) , PsvInputConfig(..) , PsvOutputConfig(..) , PsvOutputFormat(..) , PsvInputFormat(..) , PsvInputDenseDict(..) - , seaOfConstants - , seaOfDefaultConstants , seaOfPsvDriver - , psvDefaultConstants + , defaultPsvConstants , defaultOutputMissing + , defaultPsvFactsLimit , defaultPsvMaxRowCount , defaultPsvInputBufferSize , defaultPsvOutputBufferSize @@ -33,15 +33,18 @@ import P data PsvConfig = PsvConfig { psvInputConfig :: PsvInputConfig , psvOutputConfig :: PsvOutputConfig - -- static constants to be declared - , psvMaxRowCount :: Int + } deriving (Eq, Show) + +data PsvConstants = PsvConstants { + psvMaxRowCount :: Int , psvInputBufferSize :: Int , psvOutputBufferSize :: Int - } deriving (Eq, Show) + , psvFactsLimit :: Int + } deriving (Eq, Ord, Show) -psvDefaultConstants :: PsvInputConfig -> PsvOutputConfig -> PsvConfig -psvDefaultConstants x y - = PsvConfig x y defaultPsvMaxRowCount defaultPsvInputBufferSize defaultPsvOutputBufferSize +defaultPsvConstants :: PsvConstants +defaultPsvConstants = + PsvConstants defaultPsvMaxRowCount defaultPsvInputBufferSize defaultPsvOutputBufferSize defaultPsvFactsLimit defaultPsvMaxRowCount :: Int defaultPsvMaxRowCount = 128 @@ -52,25 +55,8 @@ defaultPsvInputBufferSize = 256 * 1024 defaultPsvOutputBufferSize :: Int defaultPsvOutputBufferSize = 256 * 1024 -seaOfConstants :: PsvConfig -> Doc -seaOfConstants config - = vsep - [ seaOfConstant "int" "psv_max_row_count" (pretty (psvMaxRowCount config)) - , seaOfConstant "int" "psv_input_buffer_size" (pretty (psvInputBufferSize config)) - , seaOfConstant "int" "psv_output_buffer_size" (pretty (psvOutputBufferSize config)) - ] - -seaOfDefaultConstants :: Doc -seaOfDefaultConstants - = vsep - [ seaOfConstant "int" "psv_max_row_count" (pretty defaultPsvMaxRowCount) - , seaOfConstant "int" "psv_input_buffer_size" (pretty defaultPsvInputBufferSize) - , seaOfConstant "int" "psv_output_buffer_size" (pretty defaultPsvOutputBufferSize) - ] - -seaOfConstant :: Doc -> Doc -> Doc -> Doc -seaOfConstant ty name val - = "static const" <+> ty <+> name <+> "=" <+> val <> ";" +defaultPsvFactsLimit :: Int +defaultPsvFactsLimit = 1024 * 1024 ------------------------------------------------------------------------ diff --git a/icicle-compiler/src/Icicle/Sea/IO/Psv/Input.hs b/icicle-compiler/src/Icicle/Sea/IO/Psv/Input.hs index 0fb57631..bc1e72e6 100644 --- a/icicle-compiler/src/Icicle/Sea/IO/Psv/Input.hs +++ b/icicle-compiler/src/Icicle/Sea/IO/Psv/Input.hs @@ -10,7 +10,6 @@ module Icicle.Sea.IO.Psv.Input , PsvInputConfig (..) ) where - import qualified Data.List as List import qualified Data.Map as Map import qualified Data.Set as Set @@ -149,7 +148,14 @@ seaOfReadNamedFact errs allowDupTime state , indent 8 $ seaInputErrorCountExceedLimit errs , " }" , "" - , " return " <> fun <> " (value_ptr, value_size, time, fleet->mempool, chord_count, fleet->" <> pname <> ");" + , " return " <> fun + , " ( value_ptr" + , " , value_size" + , " , time" + , " , fleet->mempool" + , " , chord_count" + , " , max_row_count" + , " , fleet->" <> pname <> ");" , "" , "}" , "" @@ -167,7 +173,7 @@ seaOfReadFact state tombstones input readInput checkCount = , "static ierror_loc_t INLINE" <+> pretty (nameOfReadFact state) <+> "(" <> "const char *value_ptr, const size_t value_size, itime_t time, " - <> "anemone_mempool_t *mempool, iint_t chord_count, " + <> "anemone_mempool_t *mempool, iint_t chord_count, iint_t max_row_count, " <> pretty (nameOfStateType state) <+> "*programs)" , "{" , " ierror_loc_t error;" @@ -236,7 +242,8 @@ seaOfReadAnyFactPsv opts config states = do , " , const char *time_ptr" , " , const size_t time_size" , " , ifleet_t *fleet" - , " , const size_t facts_limit)" + , " , const size_t facts_limit" + , " , const iint_t max_row_count )" , "{" , indent 4 (vsep (fmap (seaOfReadNamedFactSparse opts) states)) , " return 0;" @@ -259,7 +266,8 @@ seaOfReadAnyFactPsv opts config states = do , " , const char *time_ptr" , " , const size_t time_size" , " , ifleet_t *fleet" - , " , const size_t facts_limit)" + , " , const size_t facts_limit" + , " , const iint_t max_row_count )" , "{" , indent 4 (seaOfReadNamedFactDense opts state) , " return 0;" @@ -466,13 +474,13 @@ seaOfReadFactSparse state tombstones = do seaOfCheckCount :: SeaProgramState -> CStmt seaOfCheckCount state = vsep - [ "if (new_count == psv_max_row_count) {" + [ "if (new_count == max_row_count) {" -- We need to set the program count before executing it. -- Otherwise, it won't evaluate the last row , " program->input.new_count = new_count;" , " " <> pretty (nameOfProgram state) <> " (program);" , " new_count = 0;" - , "} else if (new_count > psv_max_row_count) {" + , "} else if (new_count > max_row_count) {" , " return ierror_loc_format (0, 0, \"" <> pretty (nameOfReadFact state) <> ": new_count > max_count\");" , "}" ] diff --git a/icicle-compiler/test/Icicle/Test/Sea/Psv.hs b/icicle-compiler/test/Icicle/Test/Sea/Psv.hs index e195da4b..419bb49e 100644 --- a/icicle-compiler/test/Icicle/Test/Sea/Psv.hs +++ b/icicle-compiler/test/Icicle/Test/Sea/Psv.hs @@ -6,6 +6,7 @@ {-# LANGUAGE TemplateHaskell#-} {-# LANGUAGE TupleSections #-} {-# OPTIONS_GHC -fno-warn-missing-signatures #-} + module Icicle.Test.Sea.Psv where import Control.Monad.IO.Class (liftIO) @@ -30,7 +31,9 @@ import Icicle.Common.Data import Icicle.Common.Base import Icicle.Common.Type +import Icicle.Sea.Eval (SeaError(..)) import qualified Icicle.Sea.Eval as S +import Icicle.Sea.Fleet import Icicle.Test.Arbitrary @@ -210,8 +213,8 @@ genPsvOpts wt = do let outputBuf = inputBuf return $ PsvOpts maxRowCount inputBuf outputBuf -runTest :: WellTyped -> PsvOpts -> TestOpts -> EitherT S.SeaError IO () -runTest wt (PsvOpts psvMaxRowCount psvInputBufferSize psvOutputBufferSize) (TestOpts showInput showOutput inputFormat allowDupTime) = do +compileTest :: WellTyped -> TestOpts -> EitherT SeaError IO (SeaFleet S.PsvState) +compileTest wt (TestOpts _ _ inputFormat allowDupTime) = do options0 <- S.getCompilerOptions let options = options0 <> ["-O0", "-DICICLE_NOINLINE=1"] @@ -223,13 +226,19 @@ runTest wt (PsvOpts psvMaxRowCount psvInputBufferSize psvOutputBufferSize) (Test (S.Snapshot (wtTime wt)) (S.PsvOutputSparse) (S.defaultOutputMissing) - conf = S.PsvConfig iconfig oconfig psvMaxRowCount psvInputBufferSize psvOutputBufferSize + conf = S.PsvConfig iconfig oconfig iformat = S.FormatPsv conf iopts = S.InputOpts allowDupTime (Map.singleton (wtAttribute wt) (Set.singleton tombstone)) attrs = [wtAttribute wt] - let compile = S.seaCompileFleet options S.NoCacheSea (S.HasInput iformat iopts "dummy_path") attrs programs Nothing + S.seaCompileFleet options S.NoCacheSea (S.HasInput iformat iopts "dummy_path") attrs programs Nothing + +runTest :: WellTyped -> PsvOpts -> TestOpts -> EitherT S.SeaError IO () +runTest wt (PsvOpts psvMaxRowCount psvInputBufferSize psvOutputBufferSize) + testOpts@(TestOpts showInput showOutput _ _) = do + let compile = compileTest wt testOpts release = S.seaRelease + bracketEitherT' compile release $ \fleet -> do let install = liftIO (S.sfSegvInstall fleet (show wt)) @@ -243,15 +252,16 @@ runTest wt (PsvOpts psvMaxRowCount psvInputBufferSize psvOutputBufferSize) (Test output = dir <> "/output.psv" dropped = dir <> "/dropped.txt" chords = Nothing - limit = 4096 discard = S.FlagUseDropFile + limit = 4096 + consts = S.PsvConstants psvMaxRowCount psvInputBufferSize psvOutputBufferSize limit liftIO (LT.writeFile program (LT.fromStrict source)) let inputPsv = textOfFacts (wtEntities wt) (wtAttribute wt) (wtFacts wt) liftIO (L.writeFile input (LT.encodeUtf8 inputPsv)) - result <- liftIO (runEitherT (S.seaPsvSnapshotFilePath fleet input output dropped chords limit discard)) + result <- liftIO (runEitherT (S.seaPsvSnapshotFilePath fleet input output dropped chords discard consts)) case result of Left err -> do diff --git a/icicle-compiler/test/test.hs b/icicle-compiler/test/test.hs index 0194ba58..d42f28d4 100644 --- a/icicle-compiler/test/test.hs +++ b/icicle-compiler/test/test.hs @@ -31,6 +31,7 @@ import qualified Icicle.Test.Source.Convert import qualified Icicle.Test.Source.History import qualified Icicle.Test.Sea.Psv +--import qualified Icicle.Test.Sea.Zebra import qualified Icicle.Test.Sea.Seaworthy import qualified Icicle.Test.Sea.Text @@ -65,6 +66,7 @@ main , Icicle.Test.Avalanche.Melt.tests , Icicle.Test.Sea.Psv.tests +-- , Icicle.Test.Sea.Zebra.tests , Icicle.Test.Sea.Seaworthy.tests , Icicle.Test.Sea.Text.tests