{"action":"created","comment":{"url":"https://api.github.com/repos/scala-js/scala-js/pulls/comments/38812034","id":38812034,"diff_hunk":"@@ -81,29 +84,50 @@ class ScalaJSOptimizer(val semantics: Semantics, val outputMode: OutputMode,\n   def optimizeIR(irFiles: Traversable[VirtualScalaJSIRFile],\n       cfg: Config, logger: Logger): Unit = {\n \n-    val builder = {\n-      import cfg._\n-      if (wantSourceMap)\n-        new JSFileBuilderWithSourceMap(output.name,\n-            output.contentWriter,\n-            output.sourceMapWriter,\n-            relativizeSourceMapBase)\n-      else\n-        new JSFileBuilder(output.name, output.contentWriter)\n-    }\n+    optimizeIR { emitJS =>\n+      val builder = {\n+        import cfg._\n+        if (wantSourceMap)\n+          new JSFileBuilderWithSourceMap(output.name,\n+              output.contentWriter,\n+              output.sourceMapWriter,\n+              relativizeSourceMapBase)\n+        else\n+          new JSFileBuilder(output.name, output.contentWriter)\n+      }\n \n-    emitter.emitCustomHeader(cfg.customOutputWrapper._1, builder)\n-    emitter.emitPrelude(builder, logger)\n-    optimizeIR(irFiles, cfg, builder, logger)\n-    emitter.emitPostlude(builder, logger)\n-    emitter.emitCustomFooter(cfg.customOutputWrapper._2, builder)\n+      emitter.emitCustomHeader(cfg.customOutputWrapper._1, builder)\n+      emitter.emitPrelude(builder, logger)\n+      emitJS(builder)\n+      emitter.emitPostlude(builder, logger)\n+      emitter.emitCustomFooter(cfg.customOutputWrapper._2, builder)\n \n-    builder.complete()\n-    builder.closeWriters()\n+      builder.complete()\n+      builder.closeWriters()\n+    } { () =>\n+      import cfg._\n+      output.exists && (!wantSourceMap || output.sourceMapExists)\n+    } (irFiles, cfg, logger)\n   }\n \n   def optimizeIR(irFiles: Traversable[VirtualScalaJSIRFile],\n       cfg: OptimizerConfig, builder: JSTreeBuilder, logger: Logger): Unit = {\n+    optimizeIR(emitJS => emitJS(builder))(() => false)(irFiles, cfg, logger)\n+  }\n+\n+  /** Run the linker pipeline.\n+   *\n+   *  This method first checks whether the files have changed from the last run.\n+   *  If there is no change, [[hasOldResult]] is called. If it returns true,\n+   *  no further action is taken and [[None]] is returned.\n+   *  Otherwise, the whole pipeline is run. At the end, [[buildJS]] is called\n+   *  with a function that emits the trees to the specified builder. The result\n+   *  is wrapped into a [[Some]] and returned.\n+   */\n+  def optimizeIR[T](buildJS: (JSTreeBuilder => Unit) => T)(\n+      hasOldResult: () => Boolean)(\n+      irFiles: Traversable[VirtualScalaJSIRFile],\n+      cfg: OptimizerConfig, logger: Logger): Option[T] = {","path":"tools/shared/src/main/scala/org/scalajs/core/tools/optimizer/ScalaJSOptimizer.scala","position":74,"original_position":74,"commit_id":"51d677592b8d352304471bf5e490e645cbcc740d","original_commit_id":"51d677592b8d352304471bf5e490e645cbcc740d","user":{"login":"gzm0","id":1140323,"avatar_url":"https://avatars.githubusercontent.com/u/1140323?v=3","gravatar_id":"","url":"https://api.github.com/users/gzm0","html_url":"https://github.com/gzm0","followers_url":"https://api.github.com/users/gzm0/followers","following_url":"https://api.github.com/users/gzm0/following{/other_user}","gists_url":"https://api.github.com/users/gzm0/gists{/gist_id}","starred_url":"https://api.github.com/users/gzm0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gzm0/subscriptions","organizations_url":"https://api.github.com/users/gzm0/orgs","repos_url":"https://api.github.com/users/gzm0/repos","events_url":"https://api.github.com/users/gzm0/events{/privacy}","received_events_url":"https://api.github.com/users/gzm0/received_events","type":"User","site_admin":false},"body":"Hahaha, touché. Suggestions? `optimizeIRInternal` comes to mind, but I dislike it, since it is not internal...","created_at":"2015-09-05T16:02:27Z","updated_at":"2015-09-05T16:02:27Z","html_url":"https://github.com/scala-js/scala-js/pull/1896#discussion_r38812034","pull_request_url":"https://api.github.com/repos/scala-js/scala-js/pulls/1896","_links":{"self":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/comments/38812034"},"html":{"href":"https://github.com/scala-js/scala-js/pull/1896#discussion_r38812034"},"pull_request":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/1896"}}},"pull_request":{"url":"https://api.github.com/repos/scala-js/scala-js/pulls/1896","id":44088201,"html_url":"https://github.com/scala-js/scala-js/pull/1896","diff_url":"https://github.com/scala-js/scala-js/pull/1896.diff","patch_url":"https://github.com/scala-js/scala-js/pull/1896.patch","issue_url":"https://api.github.com/repos/scala-js/scala-js/issues/1896","number":1896,"state":"open","locked":false,"title":"Fix #1635: Only run linker if some IR changed","user":{"login":"gzm0","id":1140323,"avatar_url":"https://avatars.githubusercontent.com/u/1140323?v=3","gravatar_id":"","url":"https://api.github.com/users/gzm0","html_url":"https://github.com/gzm0","followers_url":"https://api.github.com/users/gzm0/followers","following_url":"https://api.github.com/users/gzm0/following{/other_user}","gists_url":"https://api.github.com/users/gzm0/gists{/gist_id}","starred_url":"https://api.github.com/users/gzm0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gzm0/subscriptions","organizations_url":"https://api.github.com/users/gzm0/orgs","repos_url":"https://api.github.com/users/gzm0/repos","events_url":"https://api.github.com/users/gzm0/events{/privacy}","received_events_url":"https://api.github.com/users/gzm0/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-09-03T09:57:40Z","updated_at":"2015-09-05T16:02:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ac3e725a92ffc6fdc2188ad3771903c326cb8eba","assignee":{"login":"sjrd","id":535934,"avatar_url":"https://avatars.githubusercontent.com/u/535934?v=3","gravatar_id":"","url":"https://api.github.com/users/sjrd","html_url":"https://github.com/sjrd","followers_url":"https://api.github.com/users/sjrd/followers","following_url":"https://api.github.com/users/sjrd/following{/other_user}","gists_url":"https://api.github.com/users/sjrd/gists{/gist_id}","starred_url":"https://api.github.com/users/sjrd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sjrd/subscriptions","organizations_url":"https://api.github.com/users/sjrd/orgs","repos_url":"https://api.github.com/users/sjrd/repos","events_url":"https://api.github.com/users/sjrd/events{/privacy}","received_events_url":"https://api.github.com/users/sjrd/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/scala-js/scala-js/pulls/1896/commits","review_comments_url":"https://api.github.com/repos/scala-js/scala-js/pulls/1896/comments","review_comment_url":"https://api.github.com/repos/scala-js/scala-js/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scala-js/scala-js/issues/1896/comments","statuses_url":"https://api.github.com/repos/scala-js/scala-js/statuses/51d677592b8d352304471bf5e490e645cbcc740d","head":{"label":"gzm0:no-link-unchanged","ref":"no-link-unchanged","sha":"51d677592b8d352304471bf5e490e645cbcc740d","user":{"login":"gzm0","id":1140323,"avatar_url":"https://avatars.githubusercontent.com/u/1140323?v=3","gravatar_id":"","url":"https://api.github.com/users/gzm0","html_url":"https://github.com/gzm0","followers_url":"https://api.github.com/users/gzm0/followers","following_url":"https://api.github.com/users/gzm0/following{/other_user}","gists_url":"https://api.github.com/users/gzm0/gists{/gist_id}","starred_url":"https://api.github.com/users/gzm0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gzm0/subscriptions","organizations_url":"https://api.github.com/users/gzm0/orgs","repos_url":"https://api.github.com/users/gzm0/repos","events_url":"https://api.github.com/users/gzm0/events{/privacy}","received_events_url":"https://api.github.com/users/gzm0/received_events","type":"User","site_admin":false},"repo":{"id":14925025,"name":"scala-js","full_name":"gzm0/scala-js","owner":{"login":"gzm0","id":1140323,"avatar_url":"https://avatars.githubusercontent.com/u/1140323?v=3","gravatar_id":"","url":"https://api.github.com/users/gzm0","html_url":"https://github.com/gzm0","followers_url":"https://api.github.com/users/gzm0/followers","following_url":"https://api.github.com/users/gzm0/following{/other_user}","gists_url":"https://api.github.com/users/gzm0/gists{/gist_id}","starred_url":"https://api.github.com/users/gzm0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gzm0/subscriptions","organizations_url":"https://api.github.com/users/gzm0/orgs","repos_url":"https://api.github.com/users/gzm0/repos","events_url":"https://api.github.com/users/gzm0/events{/privacy}","received_events_url":"https://api.github.com/users/gzm0/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gzm0/scala-js","description":"Scala.js, a Scala to JavaScript compiler","fork":true,"url":"https://api.github.com/repos/gzm0/scala-js","forks_url":"https://api.github.com/repos/gzm0/scala-js/forks","keys_url":"https://api.github.com/repos/gzm0/scala-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gzm0/scala-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gzm0/scala-js/teams","hooks_url":"https://api.github.com/repos/gzm0/scala-js/hooks","issue_events_url":"https://api.github.com/repos/gzm0/scala-js/issues/events{/number}","events_url":"https://api.github.com/repos/gzm0/scala-js/events","assignees_url":"https://api.github.com/repos/gzm0/scala-js/assignees{/user}","branches_url":"https://api.github.com/repos/gzm0/scala-js/branches{/branch}","tags_url":"https://api.github.com/repos/gzm0/scala-js/tags","blobs_url":"https://api.github.com/repos/gzm0/scala-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gzm0/scala-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gzm0/scala-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/gzm0/scala-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gzm0/scala-js/statuses/{sha}","languages_url":"https://api.github.com/repos/gzm0/scala-js/languages","stargazers_url":"https://api.github.com/repos/gzm0/scala-js/stargazers","contributors_url":"https://api.github.com/repos/gzm0/scala-js/contributors","subscribers_url":"https://api.github.com/repos/gzm0/scala-js/subscribers","subscription_url":"https://api.github.com/repos/gzm0/scala-js/subscription","commits_url":"https://api.github.com/repos/gzm0/scala-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/gzm0/scala-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/gzm0/scala-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/gzm0/scala-js/issues/comments{/number}","contents_url":"https://api.github.com/repos/gzm0/scala-js/contents/{+path}","compare_url":"https://api.github.com/repos/gzm0/scala-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gzm0/scala-js/merges","archive_url":"https://api.github.com/repos/gzm0/scala-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gzm0/scala-js/downloads","issues_url":"https://api.github.com/repos/gzm0/scala-js/issues{/number}","pulls_url":"https://api.github.com/repos/gzm0/scala-js/pulls{/number}","milestones_url":"https://api.github.com/repos/gzm0/scala-js/milestones{/number}","notifications_url":"https://api.github.com/repos/gzm0/scala-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gzm0/scala-js/labels{/name}","releases_url":"https://api.github.com/repos/gzm0/scala-js/releases{/id}","created_at":"2013-12-04T13:51:38Z","updated_at":"2015-05-01T16:01:20Z","pushed_at":"2015-09-03T17:47:42Z","git_url":"git://github.com/gzm0/scala-js.git","ssh_url":"git@github.com:gzm0/scala-js.git","clone_url":"https://github.com/gzm0/scala-js.git","svn_url":"https://github.com/gzm0/scala-js","homepage":"http://www.scala-js.org/","size":14075,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"scala-js:master","ref":"master","sha":"d0f87774796bc7d9d79a97acfedfa0139cd7ea09","user":{"login":"scala-js","id":6039724,"avatar_url":"https://avatars.githubusercontent.com/u/6039724?v=3","gravatar_id":"","url":"https://api.github.com/users/scala-js","html_url":"https://github.com/scala-js","followers_url":"https://api.github.com/users/scala-js/followers","following_url":"https://api.github.com/users/scala-js/following{/other_user}","gists_url":"https://api.github.com/users/scala-js/gists{/gist_id}","starred_url":"https://api.github.com/users/scala-js/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scala-js/subscriptions","organizations_url":"https://api.github.com/users/scala-js/orgs","repos_url":"https://api.github.com/users/scala-js/repos","events_url":"https://api.github.com/users/scala-js/events{/privacy}","received_events_url":"https://api.github.com/users/scala-js/received_events","type":"Organization","site_admin":false},"repo":{"id":8272315,"name":"scala-js","full_name":"scala-js/scala-js","owner":{"login":"scala-js","id":6039724,"avatar_url":"https://avatars.githubusercontent.com/u/6039724?v=3","gravatar_id":"","url":"https://api.github.com/users/scala-js","html_url":"https://github.com/scala-js","followers_url":"https://api.github.com/users/scala-js/followers","following_url":"https://api.github.com/users/scala-js/following{/other_user}","gists_url":"https://api.github.com/users/scala-js/gists{/gist_id}","starred_url":"https://api.github.com/users/scala-js/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scala-js/subscriptions","organizations_url":"https://api.github.com/users/scala-js/orgs","repos_url":"https://api.github.com/users/scala-js/repos","events_url":"https://api.github.com/users/scala-js/events{/privacy}","received_events_url":"https://api.github.com/users/scala-js/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scala-js/scala-js","description":"Scala.js, the Scala to JavaScript compiler","fork":false,"url":"https://api.github.com/repos/scala-js/scala-js","forks_url":"https://api.github.com/repos/scala-js/scala-js/forks","keys_url":"https://api.github.com/repos/scala-js/scala-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scala-js/scala-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scala-js/scala-js/teams","hooks_url":"https://api.github.com/repos/scala-js/scala-js/hooks","issue_events_url":"https://api.github.com/repos/scala-js/scala-js/issues/events{/number}","events_url":"https://api.github.com/repos/scala-js/scala-js/events","assignees_url":"https://api.github.com/repos/scala-js/scala-js/assignees{/user}","branches_url":"https://api.github.com/repos/scala-js/scala-js/branches{/branch}","tags_url":"https://api.github.com/repos/scala-js/scala-js/tags","blobs_url":"https://api.github.com/repos/scala-js/scala-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scala-js/scala-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scala-js/scala-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/scala-js/scala-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scala-js/scala-js/statuses/{sha}","languages_url":"https://api.github.com/repos/scala-js/scala-js/languages","stargazers_url":"https://api.github.com/repos/scala-js/scala-js/stargazers","contributors_url":"https://api.github.com/repos/scala-js/scala-js/contributors","subscribers_url":"https://api.github.com/repos/scala-js/scala-js/subscribers","subscription_url":"https://api.github.com/repos/scala-js/scala-js/subscription","commits_url":"https://api.github.com/repos/scala-js/scala-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/scala-js/scala-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/scala-js/scala-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/scala-js/scala-js/issues/comments{/number}","contents_url":"https://api.github.com/repos/scala-js/scala-js/contents/{+path}","compare_url":"https://api.github.com/repos/scala-js/scala-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scala-js/scala-js/merges","archive_url":"https://api.github.com/repos/scala-js/scala-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scala-js/scala-js/downloads","issues_url":"https://api.github.com/repos/scala-js/scala-js/issues{/number}","pulls_url":"https://api.github.com/repos/scala-js/scala-js/pulls{/number}","milestones_url":"https://api.github.com/repos/scala-js/scala-js/milestones{/number}","notifications_url":"https://api.github.com/repos/scala-js/scala-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scala-js/scala-js/labels{/name}","releases_url":"https://api.github.com/repos/scala-js/scala-js/releases{/id}","created_at":"2013-02-18T16:33:55Z","updated_at":"2015-09-05T14:37:32Z","pushed_at":"2015-09-04T05:57:33Z","git_url":"git://github.com/scala-js/scala-js.git","ssh_url":"git@github.com:scala-js/scala-js.git","clone_url":"https://github.com/scala-js/scala-js.git","svn_url":"https://github.com/scala-js/scala-js","homepage":"http://www.scala-js.org/","size":17541,"stargazers_count":1830,"watchers_count":1830,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":161,"mirror_url":null,"open_issues_count":64,"forks":161,"open_issues":64,"watchers":1830,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/1896"},"html":{"href":"https://github.com/scala-js/scala-js/pull/1896"},"issue":{"href":"https://api.github.com/repos/scala-js/scala-js/issues/1896"},"comments":{"href":"https://api.github.com/repos/scala-js/scala-js/issues/1896/comments"},"review_comments":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/1896/comments"},"review_comment":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/1896/commits"},"statuses":{"href":"https://api.github.com/repos/scala-js/scala-js/statuses/51d677592b8d352304471bf5e490e645cbcc740d"}}}}