{"action":"created","comment":{"url":"https://api.github.com/repos/flix/flix/pulls/comments/69574694","id":69574694,"diff_hunk":"@@ -0,0 +1,170 @@\n+/*\n+ * Copyright 2015-2016 Magnus Madsen\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *   http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package ca.uwaterloo.flix.language.phase\n+\n+import ca.uwaterloo.flix.language.ast.SimplifiedAst.Definition.Constant\n+import ca.uwaterloo.flix.language.ast.SimplifiedAst.Expression._\n+import ca.uwaterloo.flix.language.ast.SimplifiedAst.{Expression, ExpressionFolder, FreeVar, Root}\n+import ca.uwaterloo.flix.language.ast.{BinaryOperator, Name, SourceLocation, Type}\n+\n+object Optimizer {\n+\n+  def optimize(root: Root): Root = {\n+    val constants = root.constants.map {\n+      case (name, defn) =>\n+        var fn = defn\n+\n+        // Do simple copy propagation to get rid of targets of direct assignment\n+        fn = CopyPropagation.optimize(fn)\n+\n+        // Replace Unit == Unit checks\n+        fn = EliminateUnitChecks.optimize(fn)\n+\n+        // Clean up by removing code\n+        fn = DeadCodeElimination.optimize(fn)\n+\n+        name -> fn\n+    }\n+\n+    root.copy(constants = constants)\n+  }\n+\n+  object EliminateUnitChecks {\n+\n+    def optimize(f: Constant): Constant = {\n+\n+      object ReplaceUnitCheckWithTrue extends ExpressionFolder {\n+        override def foldBinary(op: BinaryOperator,\n+                                exp1: Expression,\n+                                exp2: Expression,\n+                                tpe: Type,\n+                                loc: SourceLocation): Expression = (op, exp1.tpe) match {","path":"main/src/ca/uwaterloo/flix/language/phase/Optimizer.scala","position":55,"original_position":55,"commit_id":"bf6173610e94f4c45f4b946b6bfe830197de4fee","original_commit_id":"bf6173610e94f4c45f4b946b6bfe830197de4fee","user":{"login":"mhyee","id":547059,"avatar_url":"https://avatars.githubusercontent.com/u/547059?v=3","gravatar_id":"","url":"https://api.github.com/users/mhyee","html_url":"https://github.com/mhyee","followers_url":"https://api.github.com/users/mhyee/followers","following_url":"https://api.github.com/users/mhyee/following{/other_user}","gists_url":"https://api.github.com/users/mhyee/gists{/gist_id}","starred_url":"https://api.github.com/users/mhyee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhyee/subscriptions","organizations_url":"https://api.github.com/users/mhyee/orgs","repos_url":"https://api.github.com/users/mhyee/repos","events_url":"https://api.github.com/users/mhyee/events{/privacy}","received_events_url":"https://api.github.com/users/mhyee/received_events","type":"User","site_admin":false},"body":"Maybe I'm not thinking \"functionally\" enough, but `if (op == BinaryOperator.Equal && exp1.tpe == Unit.tpe) ...` looks clearer to me. I had to stare at the pattern match for a few seconds.\r\n\r\nAlso, I think you could write a comment that exp1.tpe == exp2.tpe == Unit.tpe is guaranteed by the typechecker, instead of explicitly doing both checks.","created_at":"2016-07-05T14:40:35Z","updated_at":"2016-07-05T14:40:35Z","html_url":"https://github.com/flix/flix/pull/186#discussion_r69574694","pull_request_url":"https://api.github.com/repos/flix/flix/pulls/186","_links":{"self":{"href":"https://api.github.com/repos/flix/flix/pulls/comments/69574694"},"html":{"href":"https://github.com/flix/flix/pull/186#discussion_r69574694"},"pull_request":{"href":"https://api.github.com/repos/flix/flix/pulls/186"}}},"pull_request":{"url":"https://api.github.com/repos/flix/flix/pulls/186","id":76198475,"html_url":"https://github.com/flix/flix/pull/186","diff_url":"https://github.com/flix/flix/pull/186.diff","patch_url":"https://github.com/flix/flix/pull/186.patch","issue_url":"https://api.github.com/repos/flix/flix/issues/186","number":186,"state":"open","locked":false,"title":"Simple Optimizations for the Functional Language","user":{"login":"magnus-madsen","id":2287953,"avatar_url":"https://avatars.githubusercontent.com/u/2287953?v=3","gravatar_id":"","url":"https://api.github.com/users/magnus-madsen","html_url":"https://github.com/magnus-madsen","followers_url":"https://api.github.com/users/magnus-madsen/followers","following_url":"https://api.github.com/users/magnus-madsen/following{/other_user}","gists_url":"https://api.github.com/users/magnus-madsen/gists{/gist_id}","starred_url":"https://api.github.com/users/magnus-madsen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/magnus-madsen/subscriptions","organizations_url":"https://api.github.com/users/magnus-madsen/orgs","repos_url":"https://api.github.com/users/magnus-madsen/repos","events_url":"https://api.github.com/users/magnus-madsen/events{/privacy}","received_events_url":"https://api.github.com/users/magnus-madsen/received_events","type":"User","site_admin":false},"body":"I am creating a pull request so we can discuss the code. \r\nWe will merge it later when we are satisfied with the changes.","created_at":"2016-07-04T20:31:29Z","updated_at":"2016-07-05T14:40:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0dcd9d8c6dab4b6b373b66da48b2daa7c99291c1","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/flix/flix/pulls/186/commits","review_comments_url":"https://api.github.com/repos/flix/flix/pulls/186/comments","review_comment_url":"https://api.github.com/repos/flix/flix/pulls/comments{/number}","comments_url":"https://api.github.com/repos/flix/flix/issues/186/comments","statuses_url":"https://api.github.com/repos/flix/flix/statuses/bf6173610e94f4c45f4b946b6bfe830197de4fee","head":{"label":"flix:optimization","ref":"optimization","sha":"bf6173610e94f4c45f4b946b6bfe830197de4fee","user":{"login":"flix","id":16831634,"avatar_url":"https://avatars.githubusercontent.com/u/16831634?v=3","gravatar_id":"","url":"https://api.github.com/users/flix","html_url":"https://github.com/flix","followers_url":"https://api.github.com/users/flix/followers","following_url":"https://api.github.com/users/flix/following{/other_user}","gists_url":"https://api.github.com/users/flix/gists{/gist_id}","starred_url":"https://api.github.com/users/flix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flix/subscriptions","organizations_url":"https://api.github.com/users/flix/orgs","repos_url":"https://api.github.com/users/flix/repos","events_url":"https://api.github.com/users/flix/events{/privacy}","received_events_url":"https://api.github.com/users/flix/received_events","type":"Organization","site_admin":false},"repo":{"id":37299718,"name":"flix","full_name":"flix/flix","owner":{"login":"flix","id":16831634,"avatar_url":"https://avatars.githubusercontent.com/u/16831634?v=3","gravatar_id":"","url":"https://api.github.com/users/flix","html_url":"https://github.com/flix","followers_url":"https://api.github.com/users/flix/followers","following_url":"https://api.github.com/users/flix/following{/other_user}","gists_url":"https://api.github.com/users/flix/gists{/gist_id}","starred_url":"https://api.github.com/users/flix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flix/subscriptions","organizations_url":"https://api.github.com/users/flix/orgs","repos_url":"https://api.github.com/users/flix/repos","events_url":"https://api.github.com/users/flix/events{/privacy}","received_events_url":"https://api.github.com/users/flix/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/flix/flix","description":"The Flix Programming Language","fork":false,"url":"https://api.github.com/repos/flix/flix","forks_url":"https://api.github.com/repos/flix/flix/forks","keys_url":"https://api.github.com/repos/flix/flix/keys{/key_id}","collaborators_url":"https://api.github.com/repos/flix/flix/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/flix/flix/teams","hooks_url":"https://api.github.com/repos/flix/flix/hooks","issue_events_url":"https://api.github.com/repos/flix/flix/issues/events{/number}","events_url":"https://api.github.com/repos/flix/flix/events","assignees_url":"https://api.github.com/repos/flix/flix/assignees{/user}","branches_url":"https://api.github.com/repos/flix/flix/branches{/branch}","tags_url":"https://api.github.com/repos/flix/flix/tags","blobs_url":"https://api.github.com/repos/flix/flix/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/flix/flix/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/flix/flix/git/refs{/sha}","trees_url":"https://api.github.com/repos/flix/flix/git/trees{/sha}","statuses_url":"https://api.github.com/repos/flix/flix/statuses/{sha}","languages_url":"https://api.github.com/repos/flix/flix/languages","stargazers_url":"https://api.github.com/repos/flix/flix/stargazers","contributors_url":"https://api.github.com/repos/flix/flix/contributors","subscribers_url":"https://api.github.com/repos/flix/flix/subscribers","subscription_url":"https://api.github.com/repos/flix/flix/subscription","commits_url":"https://api.github.com/repos/flix/flix/commits{/sha}","git_commits_url":"https://api.github.com/repos/flix/flix/git/commits{/sha}","comments_url":"https://api.github.com/repos/flix/flix/comments{/number}","issue_comment_url":"https://api.github.com/repos/flix/flix/issues/comments{/number}","contents_url":"https://api.github.com/repos/flix/flix/contents/{+path}","compare_url":"https://api.github.com/repos/flix/flix/compare/{base}...{head}","merges_url":"https://api.github.com/repos/flix/flix/merges","archive_url":"https://api.github.com/repos/flix/flix/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/flix/flix/downloads","issues_url":"https://api.github.com/repos/flix/flix/issues{/number}","pulls_url":"https://api.github.com/repos/flix/flix/pulls{/number}","milestones_url":"https://api.github.com/repos/flix/flix/milestones{/number}","notifications_url":"https://api.github.com/repos/flix/flix/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/flix/flix/labels{/name}","releases_url":"https://api.github.com/repos/flix/flix/releases{/id}","deployments_url":"https://api.github.com/repos/flix/flix/deployments","created_at":"2015-06-12T03:20:35Z","updated_at":"2016-07-04T12:50:31Z","pushed_at":"2016-07-05T03:58:11Z","git_url":"git://github.com/flix/flix.git","ssh_url":"git@github.com:flix/flix.git","clone_url":"https://github.com/flix/flix.git","svn_url":"https://github.com/flix/flix","homepage":"http://flix.github.io","size":46631,"stargazers_count":24,"watchers_count":24,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":38,"forks":1,"open_issues":38,"watchers":24,"default_branch":"master"}},"base":{"label":"flix:master","ref":"master","sha":"f6e8c2334cbe88fffc9a1d673fbf5f6bce2c90d5","user":{"login":"flix","id":16831634,"avatar_url":"https://avatars.githubusercontent.com/u/16831634?v=3","gravatar_id":"","url":"https://api.github.com/users/flix","html_url":"https://github.com/flix","followers_url":"https://api.github.com/users/flix/followers","following_url":"https://api.github.com/users/flix/following{/other_user}","gists_url":"https://api.github.com/users/flix/gists{/gist_id}","starred_url":"https://api.github.com/users/flix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flix/subscriptions","organizations_url":"https://api.github.com/users/flix/orgs","repos_url":"https://api.github.com/users/flix/repos","events_url":"https://api.github.com/users/flix/events{/privacy}","received_events_url":"https://api.github.com/users/flix/received_events","type":"Organization","site_admin":false},"repo":{"id":37299718,"name":"flix","full_name":"flix/flix","owner":{"login":"flix","id":16831634,"avatar_url":"https://avatars.githubusercontent.com/u/16831634?v=3","gravatar_id":"","url":"https://api.github.com/users/flix","html_url":"https://github.com/flix","followers_url":"https://api.github.com/users/flix/followers","following_url":"https://api.github.com/users/flix/following{/other_user}","gists_url":"https://api.github.com/users/flix/gists{/gist_id}","starred_url":"https://api.github.com/users/flix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flix/subscriptions","organizations_url":"https://api.github.com/users/flix/orgs","repos_url":"https://api.github.com/users/flix/repos","events_url":"https://api.github.com/users/flix/events{/privacy}","received_events_url":"https://api.github.com/users/flix/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/flix/flix","description":"The Flix Programming Language","fork":false,"url":"https://api.github.com/repos/flix/flix","forks_url":"https://api.github.com/repos/flix/flix/forks","keys_url":"https://api.github.com/repos/flix/flix/keys{/key_id}","collaborators_url":"https://api.github.com/repos/flix/flix/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/flix/flix/teams","hooks_url":"https://api.github.com/repos/flix/flix/hooks","issue_events_url":"https://api.github.com/repos/flix/flix/issues/events{/number}","events_url":"https://api.github.com/repos/flix/flix/events","assignees_url":"https://api.github.com/repos/flix/flix/assignees{/user}","branches_url":"https://api.github.com/repos/flix/flix/branches{/branch}","tags_url":"https://api.github.com/repos/flix/flix/tags","blobs_url":"https://api.github.com/repos/flix/flix/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/flix/flix/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/flix/flix/git/refs{/sha}","trees_url":"https://api.github.com/repos/flix/flix/git/trees{/sha}","statuses_url":"https://api.github.com/repos/flix/flix/statuses/{sha}","languages_url":"https://api.github.com/repos/flix/flix/languages","stargazers_url":"https://api.github.com/repos/flix/flix/stargazers","contributors_url":"https://api.github.com/repos/flix/flix/contributors","subscribers_url":"https://api.github.com/repos/flix/flix/subscribers","subscription_url":"https://api.github.com/repos/flix/flix/subscription","commits_url":"https://api.github.com/repos/flix/flix/commits{/sha}","git_commits_url":"https://api.github.com/repos/flix/flix/git/commits{/sha}","comments_url":"https://api.github.com/repos/flix/flix/comments{/number}","issue_comment_url":"https://api.github.com/repos/flix/flix/issues/comments{/number}","contents_url":"https://api.github.com/repos/flix/flix/contents/{+path}","compare_url":"https://api.github.com/repos/flix/flix/compare/{base}...{head}","merges_url":"https://api.github.com/repos/flix/flix/merges","archive_url":"https://api.github.com/repos/flix/flix/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/flix/flix/downloads","issues_url":"https://api.github.com/repos/flix/flix/issues{/number}","pulls_url":"https://api.github.com/repos/flix/flix/pulls{/number}","milestones_url":"https://api.github.com/repos/flix/flix/milestones{/number}","notifications_url":"https://api.github.com/repos/flix/flix/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/flix/flix/labels{/name}","releases_url":"https://api.github.com/repos/flix/flix/releases{/id}","deployments_url":"https://api.github.com/repos/flix/flix/deployments","created_at":"2015-06-12T03:20:35Z","updated_at":"2016-07-04T12:50:31Z","pushed_at":"2016-07-05T03:58:11Z","git_url":"git://github.com/flix/flix.git","ssh_url":"git@github.com:flix/flix.git","clone_url":"https://github.com/flix/flix.git","svn_url":"https://github.com/flix/flix","homepage":"http://flix.github.io","size":46631,"stargazers_count":24,"watchers_count":24,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":38,"forks":1,"open_issues":38,"watchers":24,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/flix/flix/pulls/186"},"html":{"href":"https://github.com/flix/flix/pull/186"},"issue":{"href":"https://api.github.com/repos/flix/flix/issues/186"},"comments":{"href":"https://api.github.com/repos/flix/flix/issues/186/comments"},"review_comments":{"href":"https://api.github.com/repos/flix/flix/pulls/186/comments"},"review_comment":{"href":"https://api.github.com/repos/flix/flix/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/flix/flix/pulls/186/commits"},"statuses":{"href":"https://api.github.com/repos/flix/flix/statuses/bf6173610e94f4c45f4b946b6bfe830197de4fee"}}}}
{"actor":{"display_login":"mhyee"}}