{"action":"created","issue":{"url":"https://api.github.com/repos/CoreASM/coreasm.core/issues/20","repository_url":"https://api.github.com/repos/CoreASM/coreasm.core","labels_url":"https://api.github.com/repos/CoreASM/coreasm.core/issues/20/labels{/name}","comments_url":"https://api.github.com/repos/CoreASM/coreasm.core/issues/20/comments","events_url":"https://api.github.com/repos/CoreASM/coreasm.core/issues/20/events","html_url":"https://github.com/CoreASM/coreasm.core/issues/20","id":120224301,"number":20,"title":"CoreASMError: Cannot apply updates when state stack is empty","user":{"login":"Locke","id":53905,"avatar_url":"https://avatars.githubusercontent.com/u/53905?v=3","gravatar_id":"","url":"https://api.github.com/users/Locke","html_url":"https://github.com/Locke","followers_url":"https://api.github.com/users/Locke/followers","following_url":"https://api.github.com/users/Locke/following{/other_user}","gists_url":"https://api.github.com/users/Locke/gists{/gist_id}","starred_url":"https://api.github.com/users/Locke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Locke/subscriptions","organizations_url":"https://api.github.com/users/Locke/orgs","repos_url":"https://api.github.com/users/Locke/repos","events_url":"https://api.github.com/users/Locke/events{/privacy}","received_events_url":"https://api.github.com/users/Locke/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-12-03T17:15:30Z","updated_at":"2016-04-21T18:34:00Z","closed_at":null,"body":"Hi,\r\n\r\nafter a minor refactoring of my specification the Engine crashs now with the CoreASMError: `Cannot apply updates when state stack is empty` from HashStorage.java:475 (using the current master). It also crashes in 3966cc7c4b1944c9c6b2c34fbddadb99b1dbd5c5, but I can't test older revisions as I use `foreach`.\r\n\r\nWhen I revert to the state before the refactoring it works fine. However I couldn't narrow down which of my edits is responsible for the crash, I'm still working on that. But even if I did something wrong in my specification the Engine should crash with a nicer message, so I assume a bug in the Engine.\r\n\r\nHere is the stacktrace (some line numbers could be wrong as I added some logging statements):\r\n\r\n```\r\norg.coreasm.engine.CoreASMError: Cannot apply updates when state stack is empty.\r\n\tat org.coreasm.engine.Engine.error(Engine.java:632)\r\n\tat org.coreasm.engine.Engine.error(Engine.java:618)\r\n\tat org.coreasm.engine.absstorage.HashStorage.apply(HashStorage.java:486)\r\n\tat org.coreasm.engine.plugins.turboasm.TurboASMPlugin.interpret(TurboASMPlugin.java:435)\r\n\tat org.coreasm.engine.interpreter.InterpreterImp.executeTree(InterpreterImp.java:144)\r\n\tat org.coreasm.engine.scheduler.ConcurrentProgramEvaluator.evaluate(ConcurrentProgramEvaluator.java:176)\r\n\tat org.coreasm.engine.scheduler.ConcurrentProgramEvaluator.run(ConcurrentProgramEvaluator.java:115)\r\n\tat EDU.oswego.cs.dl.util.concurrent.FJTaskRunner.scanWhileIdling(Unknown Source)\r\n\tat EDU.oswego.cs.dl.util.concurrent.FJTaskRunner.run(Unknown Source)\r\n```\r\n\r\nI cannot give you the full specification, and also couldn't write a small \"crashing\" example / testcase.\r\n\r\nBasicly the specification has a main loop like this:\r\n\r\n```\r\nfunction agentTasks : Agents -> LIST\r\nfunction skipNextTasks : Agents -> BOOLEAN\r\nfunction tasks : -> LIST\r\n\r\nrule MainLoop = {\r\n\tlocal tasks in seqblock\r\n\t\ttasks := agentTasks(self)\r\n\r\n\t\twhile (|tasks| > 0) do\r\n\t\tlet currentTask     = head(tasks) in\r\n\t\tlet currentTaskID   = nth(currentTask, 1) in \r\n\t\tlet currentTaskType = nth(currentTask, 2) in seqblock\r\n\r\n\t\t\tExecuteTask(currentTaskID)\r\n\r\n\t\t\tif (skipNextTasks(self) = true) then {\r\n\t\t\t\tdebuginfo MainLoop \"next tasks should not be executed\"\r\n\t\t\t\ttasks := []\r\n\t\t\t}\r\n\t\t\telse if (currentTaskType = \"special\") then {\r\n\t\t\t\tdebuginfo MainLoop \"only special next tasks should be executed\"\r\n\t\t\t\ttasks := filterSpecial(tasks)\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tdebuginfo MainLoop \"continue with next tasks (unfiltered)\"\r\n\t\t\t\ttasks := tail(tasks)\r\n\t\t\t}\r\n\r\n\t\t\tdebuginfo MainLoop \"next tasks: \" + tasks\r\n\t\tendseqblock\r\n\r\n\t\tdebuginfo MainLoop \"main loop ended\"\r\n\tendseqblock\r\n}\r\n\r\nrule Execute = seqblock\r\n\tDebug_PrintState\r\n\r\n\tMainLoop\r\nendseqblock\r\n```\r\n\r\nWithin ExecuteTask lies the complete logic like modifying `agentTasks` for the next iteration, and having a lot of `let`, `foreach`, `while` and even again `local tasks` in sub-rules / derived functions.\r\n\r\nI get the debug info \"next tasks: []\", but then the crash occurs and \"main loop ended\" will not be printed.\r\n\r\nFrom what I've read in `HashStorage.java` incremental updates (like seq, while, foreach) work with stacked states, so I've logged all calls to `pushState` and `popState`:\r\n\r\n```\r\nlocke@VirtualBox:/tmp$ cat log | grep pushState | grep TurboASMPlugin | wc -l\r\n237\r\nlocke@VirtualBox:/tmp$ cat log | grep popState | grep TurboASMPlug | wc -l\r\n227\r\n\r\n\r\nlocke@VirtualBox:/tmp$ cat log | grep pushState | grep LetRulePlugin | wc -l\r\n189\r\nlocke@VirtualBox:/tmp$ cat log | grep popState | grep LetRulePlugin | wc -l\r\n193\r\n\r\n\r\nlocke@VirtualBox:/tmp$ cat log | grep pushState | grep ForeachRulePlugin | wc -l\r\n18\r\nlocke@VirtualBox:/tmp$ cat log | grep popState | grep ForeachRulePlugin | wc -l\r\n34\r\n```\r\n\r\nI expected these numbers to be identical or about off-by-one and hoped to find the error by myself, however I'm suprised that there are a lot more `popState` than `pushState`. So without more knowledge about the internals I'm stuck.\r\n\r\nAs I can't give a full example: can you give me some ideas how I could continue identifying the problem, or do you even see from the example and description what went wrong?\r\n"},"comment":{"url":"https://api.github.com/repos/CoreASM/coreasm.core/issues/comments/213056600","html_url":"https://github.com/CoreASM/coreasm.core/issues/20#issuecomment-213056600","issue_url":"https://api.github.com/repos/CoreASM/coreasm.core/issues/20","id":213056600,"user":{"login":"mstegmaier","id":2619624,"avatar_url":"https://avatars.githubusercontent.com/u/2619624?v=3","gravatar_id":"","url":"https://api.github.com/users/mstegmaier","html_url":"https://github.com/mstegmaier","followers_url":"https://api.github.com/users/mstegmaier/followers","following_url":"https://api.github.com/users/mstegmaier/following{/other_user}","gists_url":"https://api.github.com/users/mstegmaier/gists{/gist_id}","starred_url":"https://api.github.com/users/mstegmaier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mstegmaier/subscriptions","organizations_url":"https://api.github.com/users/mstegmaier/orgs","repos_url":"https://api.github.com/users/mstegmaier/repos","events_url":"https://api.github.com/users/mstegmaier/events{/privacy}","received_events_url":"https://api.github.com/users/mstegmaier/received_events","type":"User","site_admin":false},"created_at":"2016-04-21T18:34:00Z","updated_at":"2016-04-21T18:34:00Z","body":"I just tried both of your examples multiple times and they always behaved the same way as expected. Could you please provide examples that actually let me reproduce the described behavior? It might already be helpful if you specified what you mean by \"under some conditions\"."}}