Verified Commit c67e403c authored by Camil Staps's avatar Camil Staps 🚀

Make removedTasks in TaskEvalInfo strict to save memory

parent 7b14aca0
......@@ -27,8 +27,14 @@ mkEvalOpts :: TaskEvalOpts
//* External information passed from the task
:: TaskEvalInfo =
{ lastEvent :: !TaskTime //When was the last event in this task
, removedTasks :: ![(TaskId,TaskId)] //Which embedded parallel tasks were removed (listId,taskId)
{ lastEvent :: !TaskTime //* When was the last event in this task
, removedTasks :: ![#RemovedTask!] //* Which embedded parallel tasks were removed
}
//* A task removed from a list. This type is used in `TaskEvalInfo`.
:: RemovedTask =
{ removedTaskId :: !TaskId //* The ID of the removed task.
, removedTaskListId :: !TaskId //* The list the task was removed from.
}
:: TaskTime :== Int
......
......@@ -50,8 +50,8 @@ from Control.Applicative import class Alternative(<|>)
import Data.GenEq
import qualified Control.Monad
derive JSONEncode TaskMeta, InstanceType, TaskChange, TaskResult, TaskEvalInfo, ExtendedTaskListFilter
derive JSONDecode TaskMeta, InstanceType, TaskChange, TaskResult, TaskEvalInfo, ExtendedTaskListFilter
derive JSONEncode TaskMeta, InstanceType, TaskChange, TaskResult, TaskEvalInfo, ExtendedTaskListFilter, RemovedTask
derive JSONDecode TaskMeta, InstanceType, TaskChange, TaskResult, TaskEvalInfo, ExtendedTaskListFilter, RemovedTask
derive gDefault InstanceType, TaskId, TaskListFilter
......
implementation module iTasks.Internal.Util
import StdBool, StdChar, StdList, StdFile, StdMisc, StdArray, StdString, StdTuple, StdFunc, StdGeneric, StdOrdList
import StdEnv
import Data.Tuple, Data.Func, System.Time, System.OS, Text, System.FilePath, System.Directory, Text.GenJSON, Data.Error, Data.GenEq
import Data.Error, System.OSError, System.File
import iTasks.Engine
......@@ -96,7 +96,7 @@ isDestroyOrInterrupt ServerInterruptedEvent = True
isDestroyOrInterrupt _ = False
mkTaskEvalInfo :: !TaskTime -> TaskEvalInfo
mkTaskEvalInfo ts = {TaskEvalInfo|lastEvent=ts,removedTasks=[]}
mkTaskEvalInfo ts = {TaskEvalInfo|lastEvent=ts,removedTasks=[|]}
mkUIIfReset :: !Event !UI -> UIChange
mkUIIfReset ResetEvent ui = ReplaceUI ui
......
implementation module iTasks.WF.Combinators.Core
import StdEnv
import StdOverloadedList
import iTasks.SDS.Combinators.Common
import iTasks.SDS.Definition
......@@ -131,7 +132,7 @@ where
//No match
?None = (Left (ExceptionResult e), iworld)
//A match
?Just rewrite = (Right (rewrite, lastEval, []), iworld)
?Just rewrite = (Right (rewrite, lastEval, [|]), iworld)
= case mbCont of
//No match, just pass through
Left res = (res, iworld)
......@@ -141,7 +142,7 @@ where
# (resb, iworld) = rhs ResetEvent evalOpts iworld
= case resb of
ValueResult val info change=:(ReplaceUI _) (Task rhs)
# info = {TaskEvalInfo|info & lastEvent = max lastEvent info.TaskEvalInfo.lastEvent, removedTasks = removedTasks ++ info.TaskEvalInfo.removedTasks}
# info = {TaskEvalInfo|info & lastEvent = max lastEvent info.TaskEvalInfo.lastEvent, removedTasks = removedTasks ++| info.TaskEvalInfo.removedTasks}
= (ValueResult
val
info
......@@ -284,11 +285,11 @@ where
exceptionResult (ExceptionResult _) e = ExceptionResult e
genParallelEvalInfo :: [TaskResult a] -> TaskEvalInfo
genParallelEvalInfo results = foldr addResult {TaskEvalInfo|lastEvent=0,removedTasks=[]} results
genParallelEvalInfo results = foldr addResult {TaskEvalInfo|lastEvent=0,removedTasks=[|]} results
where
addResult (ValueResult _ i1 _ _) i2
# lastEvent = max i1.TaskEvalInfo.lastEvent i2.TaskEvalInfo.lastEvent
# removedTasks = i1.TaskEvalInfo.removedTasks ++ i2.TaskEvalInfo.removedTasks
# removedTasks = i1.TaskEvalInfo.removedTasks ++| i2.TaskEvalInfo.removedTasks
= {TaskEvalInfo|lastEvent=lastEvent,removedTasks=removedTasks}
addResult _ i = i
......@@ -381,7 +382,7 @@ evalParallelTasks event evalOpts=:{TaskEvalOpts|taskId=listId} conts completed [
//Add the current result before checking for removals
# completed = [(taskId, result):completed]
//Check if in the branch tasks from this list were removed but that were already evaluated
# removed = [t \\ (l,t=:(TaskId _ n)) <- removedTasks | l == listId && n <= taskNo]
# removed = [t \\ {removedTaskListId=l,removedTaskId=t=:(TaskId _ n)} <|- removedTasks | l == listId && n <= taskNo]
# (completed,iworld) = destroyRemoved listId removed completed iworld
= evalParallelTasks event evalOpts conts completed todo values iworld
(Ok result=:DestroyedResult, iworld)
......@@ -405,7 +406,7 @@ where
(Error e,iworld) = (Error e,iworld)
(Ok (ReadingDone (detachedMeta,encoded)),iworld)
# value = decode encoded
# evalInfo = {TaskEvalInfo|lastEvent=0,removedTasks=[]}
# evalInfo = {TaskEvalInfo|lastEvent=0,removedTasks=[|]}
# result = ValueResult value evalInfo NoChange nopTask
//Synchronize the record in the local list with the entry in the global list
# (mbError,iworld) = write detachedMeta (sdsFocus (listId,taskId,False) taskInstanceParallelTaskListItem) EmptyContext iworld
......@@ -612,11 +613,11 @@ where
switch False name = if (isMember name prevEnabledActions) (ChangeUI [SetAttribute "enabled" (JSONBool False)] []) NoChange
genParallelEvalInfo :: [TaskResult a] -> TaskEvalInfo
genParallelEvalInfo results = foldr addResult {TaskEvalInfo|lastEvent=0,removedTasks=[]} results
genParallelEvalInfo results = foldr addResult {TaskEvalInfo|lastEvent=0,removedTasks=[|]} results
where
addResult (ValueResult _ i1 _ _) i2
# lastEvent = max i1.TaskEvalInfo.lastEvent i2.TaskEvalInfo.lastEvent
# removedTasks = i1.TaskEvalInfo.removedTasks ++ i2.TaskEvalInfo.removedTasks
# removedTasks = i1.TaskEvalInfo.removedTasks ++| i2.TaskEvalInfo.removedTasks
= {TaskEvalInfo|lastEvent=lastEvent,removedTasks=removedTasks}
addResult _ i = i
......@@ -678,9 +679,9 @@ where
| taskNo == 0 //(if the taskNo equals zero the instance is embedded)
# (mbe,iworld) = deleteTaskInstance instanceNo iworld
| mbe =: (Error _) = (ExceptionResult (fromError mbe),iworld)
= (ValueResult (Value () True) {lastEvent=lastEval,removedTasks=[]} (mkEmptyUI event) (return ()), iworld)
= (ValueResult (Value () True) {lastEvent=lastEval,removedTasks=[|]} (mkEmptyUI event) (return ()), iworld)
//Pass removal information up
= (ValueResult (Value () True) {lastEvent=lastEval,removedTasks=[(listId,removeId)]} (mkEmptyUI event) (return ()), iworld)
= (ValueResult (Value () True) {lastEvent=lastEval,removedTasks=[|{removedTaskListId=listId,removedTaskId=removeId}]} (mkEmptyUI event) (return ()), iworld)
//When a task is marked as removed, the index of the tasks after that are decreased
markAsRemoved removeId [] = []
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment