{"action":"created","issue":{"url":"https://api.github.com/repos/arcfide/Co-dfns/issues/130","labels_url":"https://api.github.com/repos/arcfide/Co-dfns/issues/130/labels{/name}","comments_url":"https://api.github.com/repos/arcfide/Co-dfns/issues/130/comments","events_url":"https://api.github.com/repos/arcfide/Co-dfns/issues/130/events","html_url":"https://github.com/arcfide/Co-dfns/issues/130","id":79182646,"number":130,"title":"Deal with constant and variable return values","user":{"login":"arcfide","id":1235230,"avatar_url":"https://avatars.githubusercontent.com/u/1235230?v=3","gravatar_id":"","url":"https://api.github.com/users/arcfide","html_url":"https://github.com/arcfide","followers_url":"https://api.github.com/users/arcfide/followers","following_url":"https://api.github.com/users/arcfide/following{/other_user}","gists_url":"https://api.github.com/users/arcfide/gists{/gist_id}","starred_url":"https://api.github.com/users/arcfide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arcfide/subscriptions","organizations_url":"https://api.github.com/users/arcfide/orgs","repos_url":"https://api.github.com/users/arcfide/repos","events_url":"https://api.github.com/users/arcfide/events{/privacy}","received_events_url":"https://api.github.com/users/arcfide/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/arcfide/Co-dfns/labels/problem","name":"problem","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/arcfide/Co-dfns/milestones/10","html_url":"https://github.com/arcfide/Co-dfns/milestones/Release%20v0.5","labels_url":"https://api.github.com/repos/arcfide/Co-dfns/milestones/10/labels","id":1121944,"number":10,"title":"Release v0.5","description":"This milestone is mostly about improving capabilities and robustness.","creator":{"login":"arcfide","id":1235230,"avatar_url":"https://avatars.githubusercontent.com/u/1235230?v=3","gravatar_id":"","url":"https://api.github.com/users/arcfide","html_url":"https://github.com/arcfide","followers_url":"https://api.github.com/users/arcfide/followers","following_url":"https://api.github.com/users/arcfide/following{/other_user}","gists_url":"https://api.github.com/users/arcfide/gists{/gist_id}","starred_url":"https://api.github.com/users/arcfide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arcfide/subscriptions","organizations_url":"https://api.github.com/users/arcfide/orgs","repos_url":"https://api.github.com/users/arcfide/repos","events_url":"https://api.github.com/users/arcfide/events{/privacy}","received_events_url":"https://api.github.com/users/arcfide/received_events","type":"User","site_admin":false},"open_issues":29,"closed_issues":35,"state":"open","created_at":"2015-05-20T20:21:19Z","updated_at":"2015-07-27T23:58:46Z","due_on":"2015-07-31T04:00:00Z","closed_at":null},"comments":1,"created_at":"2015-05-21T22:14:43Z","updated_at":"2015-07-28T00:04:25Z","closed_at":null,"body":"Current `fe` assumes that variables are always in expressions and do not appear at the top level. The constant propagation assumes that all constants will be contained inside of an expression, leading to an empty function if the optimization eliminates all expressions from the body."},"comment":{"url":"https://api.github.com/repos/arcfide/Co-dfns/issues/comments/125382536","html_url":"https://github.com/arcfide/Co-dfns/issues/130#issuecomment-125382536","issue_url":"https://api.github.com/repos/arcfide/Co-dfns/issues/130","id":125382536,"user":{"login":"arcfide","id":1235230,"avatar_url":"https://avatars.githubusercontent.com/u/1235230?v=3","gravatar_id":"","url":"https://api.github.com/users/arcfide","html_url":"https://github.com/arcfide","followers_url":"https://api.github.com/users/arcfide/followers","following_url":"https://api.github.com/users/arcfide/following{/other_user}","gists_url":"https://api.github.com/users/arcfide/gists{/gist_id}","starred_url":"https://api.github.com/users/arcfide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arcfide/subscriptions","organizations_url":"https://api.github.com/users/arcfide/orgs","repos_url":"https://api.github.com/users/arcfide/repos","events_url":"https://api.github.com/users/arcfide/events{/privacy}","received_events_url":"https://api.github.com/users/arcfide/received_events","type":"User","site_admin":false},"created_at":"2015-07-28T00:04:25Z","updated_at":"2015-07-28T00:04:25Z","body":"@gavwhela and I spent some time a few days ago diagnosing this issue and we've come up with an approach to fix it. Basically, the issue revolves around a failure of the constant propagation to properly handle return values. When the return value is a variable or a constant, then the constant will be removed as a part of the propagation stage, and the variable case causes issues further on because of the handling of the body of functions after the constant folding is complete. Namely, function bodies after constant folding are expected to consist of only expressions, and not other node types.\r\n\r\nFortunately, we can fix this by adding a pass to wrap up these atomic sorts of return values before propagating constants by treating them as a monadic application of `⊢`. Then, we can mark them specially during constant folding to prevent them from being folded away. After this we can remove this mark and let the rest of the compiler treat it just like a mixed function application, which is exactly what we want anyways. "}}