{"action":"created","comment":{"url":"https://api.github.com/repos/apple/swift/pulls/comments/196545988","pull_request_review_id":130120257,"id":196545988,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5NjU0NTk4OA==","diff_hunk":"@@ -3015,9 +3015,38 @@ visitValueAndGradientExpr(ValueAndGradientExpr *E, SGFContext C) {\n   return emitGradientInst(*this, C, E, /*isValueAndGrad*/ true);\n }\n \n+// SWIFT_ENABLE_TENSORFLOW\n RValue RValueEmitter::\n visitAdjointExpr(AdjointExpr *E, SGFContext C) {\n-  llvm_unreachable(\"handle #adjoint\");\n+  ConcreteDeclRef adjointFunc = E->getAdjointFunction();\n+  FuncDecl *adjointDecl = cast<FuncDecl>(adjointFunc.getDecl());\n+  SILLocation loc(adjointDecl);\n+  SILDeclRef adjointDeclRef(adjointDecl);\n+\n+  // If adjoint has multiple parameter lists, mark as curried.\n+  if (adjointDecl->getNumParameterLists() == 2) {\n+    adjointDeclRef = adjointDeclRef.asCurried();\n+  }\n+  auto adjointInfo = SGF.getConstantInfo(adjointDeclRef);\n+\n+  // Convert function ref to thick function type.\n+  if (!adjointDecl->isStatic()) {\n+    auto resultTy = E->getType()->getCanonicalType();\n+    ManagedValue result =\n+      SGF.emitClosureValue(loc, adjointDeclRef, resultTy,\n+                           adjointFunc.getSubstitutions().toList());\n+    return RValue(SGF, loc, resultTy, result);\n+  }\n+  // Otherwise, partially apply metatype to static adjoint method.\n+  SILValue ref = SGF.emitGlobalFunctionRef(loc, adjointDeclRef, adjointInfo);\n+  auto subs = adjointFunc.getSubstitutions();\n+  auto baseMeta = adjointInfo.SILFnType->substGenericArgs(SGF.SGM.M, subs)\n+    ->getSelfParameter().getType();\n+  auto metatype = SGF.B.createMetatype(loc, SGF.getLoweredType(baseMeta));\n+  auto partialApply =","path":"lib/SILGen/SILGenExpr.cpp","position":null,"original_position":33,"commit_id":"a0430569ece5630639fce172fe9c4dbfa56f2af5","original_commit_id":"a9d11c9488e61990debe7a69cd3cab354ecf83d4","user":{"login":"dan-zheng","id":5590046,"node_id":"MDQ6VXNlcjU1OTAwNDY=","avatar_url":"https://avatars0.githubusercontent.com/u/5590046?v=4","gravatar_id":"","url":"https://api.github.com/users/dan-zheng","html_url":"https://github.com/dan-zheng","followers_url":"https://api.github.com/users/dan-zheng/followers","following_url":"https://api.github.com/users/dan-zheng/following{/other_user}","gists_url":"https://api.github.com/users/dan-zheng/gists{/gist_id}","starred_url":"https://api.github.com/users/dan-zheng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dan-zheng/subscriptions","organizations_url":"https://api.github.com/users/dan-zheng/orgs","repos_url":"https://api.github.com/users/dan-zheng/repos","events_url":"https://api.github.com/users/dan-zheng/events{/privacy}","received_events_url":"https://api.github.com/users/dan-zheng/received_events","type":"User","site_admin":false},"body":"Done, thanks.","created_at":"2018-06-19T19:14:31Z","updated_at":"2018-06-19T19:14:31Z","html_url":"https://github.com/apple/swift/pull/17324#discussion_r196545988","pull_request_url":"https://api.github.com/repos/apple/swift/pulls/17324","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/apple/swift/pulls/comments/196545988"},"html":{"href":"https://github.com/apple/swift/pull/17324#discussion_r196545988"},"pull_request":{"href":"https://api.github.com/repos/apple/swift/pulls/17324"}},"in_reply_to_id":196539884},"pull_request":{"url":"https://api.github.com/repos/apple/swift/pulls/17324","id":195870972,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk1ODcwOTcy","html_url":"https://github.com/apple/swift/pull/17324","diff_url":"https://github.com/apple/swift/pull/17324.diff","patch_url":"https://github.com/apple/swift/pull/17324.patch","issue_url":"https://api.github.com/repos/apple/swift/issues/17324","number":17324,"state":"open","locked":false,"title":"[AutoDiff] Finish #adjoint expression (Sema and SILGen).","user":{"login":"dan-zheng","id":5590046,"node_id":"MDQ6VXNlcjU1OTAwNDY=","avatar_url":"https://avatars0.githubusercontent.com/u/5590046?v=4","gravatar_id":"","url":"https://api.github.com/users/dan-zheng","html_url":"https://github.com/dan-zheng","followers_url":"https://api.github.com/users/dan-zheng/followers","following_url":"https://api.github.com/users/dan-zheng/following{/other_user}","gists_url":"https://api.github.com/users/dan-zheng/gists{/gist_id}","starred_url":"https://api.github.com/users/dan-zheng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dan-zheng/subscriptions","organizations_url":"https://api.github.com/users/dan-zheng/orgs","repos_url":"https://api.github.com/users/dan-zheng/repos","events_url":"https://api.github.com/users/dan-zheng/events{/privacy}","received_events_url":"https://api.github.com/users/dan-zheng/received_events","type":"User","site_admin":false},"body":"The purpose of `#adjoint` is to lookup and return the adjoint function\r\ncorresponding to a `@differentiable` function.\r\n\r\n- Change AdjointExpr to represent original function as a DeclName (and optional\r\n  base type) rather than an expression.\r\n  - The argument of `#adjoint(...)` is a function identifier: this is better\r\n    modeled as a DeclName (and optional base type) rather than an expression,\r\n    which is overly general.\r\n  - Representing the original function as an expression also makes\r\n    type-checking difficult. The relationship between the types of the original\r\n    and adjoint cannot be easily modeled using the constraint system.\r\n- SILGen AdjointExpr.\r\n  - Rather than rewriting AdjointExpr to a different Expr in CSApply (e.g.\r\n    a DeclRefExpr referencing the adjoint function), custom SILGen is used\r\n    because AdjointExpr can represent functions that are normally inaccessible.\r\n    Such DeclRefExprs would be invalid in the AST.","created_at":"2018-06-19T15:37:49Z","updated_at":"2018-06-19T19:14:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"de6d60187408ddb0c6c614fe044e70f8af3ef13c","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":955546636,"node_id":"MDU6TGFiZWw5NTU1NDY2MzY=","url":"https://api.github.com/repos/apple/swift/labels/tensorflow","name":"tensorflow","color":"EF6C00","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/apple/swift/pulls/17324/commits","review_comments_url":"https://api.github.com/repos/apple/swift/pulls/17324/comments","review_comment_url":"https://api.github.com/repos/apple/swift/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apple/swift/issues/17324/comments","statuses_url":"https://api.github.com/repos/apple/swift/statuses/a0430569ece5630639fce172fe9c4dbfa56f2af5","head":{"label":"dan-zheng:autodiff","ref":"autodiff","sha":"a0430569ece5630639fce172fe9c4dbfa56f2af5","user":{"login":"dan-zheng","id":5590046,"node_id":"MDQ6VXNlcjU1OTAwNDY=","avatar_url":"https://avatars0.githubusercontent.com/u/5590046?v=4","gravatar_id":"","url":"https://api.github.com/users/dan-zheng","html_url":"https://github.com/dan-zheng","followers_url":"https://api.github.com/users/dan-zheng/followers","following_url":"https://api.github.com/users/dan-zheng/following{/other_user}","gists_url":"https://api.github.com/users/dan-zheng/gists{/gist_id}","starred_url":"https://api.github.com/users/dan-zheng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dan-zheng/subscriptions","organizations_url":"https://api.github.com/users/dan-zheng/orgs","repos_url":"https://api.github.com/users/dan-zheng/repos","events_url":"https://api.github.com/users/dan-zheng/events{/privacy}","received_events_url":"https://api.github.com/users/dan-zheng/received_events","type":"User","site_admin":false},"repo":{"id":135949956,"node_id":"MDEwOlJlcG9zaXRvcnkxMzU5NDk5NTY=","name":"swift","full_name":"dan-zheng/swift","owner":{"login":"dan-zheng","id":5590046,"node_id":"MDQ6VXNlcjU1OTAwNDY=","avatar_url":"https://avatars0.githubusercontent.com/u/5590046?v=4","gravatar_id":"","url":"https://api.github.com/users/dan-zheng","html_url":"https://github.com/dan-zheng","followers_url":"https://api.github.com/users/dan-zheng/followers","following_url":"https://api.github.com/users/dan-zheng/following{/other_user}","gists_url":"https://api.github.com/users/dan-zheng/gists{/gist_id}","starred_url":"https://api.github.com/users/dan-zheng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dan-zheng/subscriptions","organizations_url":"https://api.github.com/users/dan-zheng/orgs","repos_url":"https://api.github.com/users/dan-zheng/repos","events_url":"https://api.github.com/users/dan-zheng/events{/privacy}","received_events_url":"https://api.github.com/users/dan-zheng/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dan-zheng/swift","description":"The Swift Programming Language","fork":true,"url":"https://api.github.com/repos/dan-zheng/swift","forks_url":"https://api.github.com/repos/dan-zheng/swift/forks","keys_url":"https://api.github.com/repos/dan-zheng/swift/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dan-zheng/swift/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dan-zheng/swift/teams","hooks_url":"https://api.github.com/repos/dan-zheng/swift/hooks","issue_events_url":"https://api.github.com/repos/dan-zheng/swift/issues/events{/number}","events_url":"https://api.github.com/repos/dan-zheng/swift/events","assignees_url":"https://api.github.com/repos/dan-zheng/swift/assignees{/user}","branches_url":"https://api.github.com/repos/dan-zheng/swift/branches{/branch}","tags_url":"https://api.github.com/repos/dan-zheng/swift/tags","blobs_url":"https://api.github.com/repos/dan-zheng/swift/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dan-zheng/swift/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dan-zheng/swift/git/refs{/sha}","trees_url":"https://api.github.com/repos/dan-zheng/swift/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dan-zheng/swift/statuses/{sha}","languages_url":"https://api.github.com/repos/dan-zheng/swift/languages","stargazers_url":"https://api.github.com/repos/dan-zheng/swift/stargazers","contributors_url":"https://api.github.com/repos/dan-zheng/swift/contributors","subscribers_url":"https://api.github.com/repos/dan-zheng/swift/subscribers","subscription_url":"https://api.github.com/repos/dan-zheng/swift/subscription","commits_url":"https://api.github.com/repos/dan-zheng/swift/commits{/sha}","git_commits_url":"https://api.github.com/repos/dan-zheng/swift/git/commits{/sha}","comments_url":"https://api.github.com/repos/dan-zheng/swift/comments{/number}","issue_comment_url":"https://api.github.com/repos/dan-zheng/swift/issues/comments{/number}","contents_url":"https://api.github.com/repos/dan-zheng/swift/contents/{+path}","compare_url":"https://api.github.com/repos/dan-zheng/swift/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dan-zheng/swift/merges","archive_url":"https://api.github.com/repos/dan-zheng/swift/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dan-zheng/swift/downloads","issues_url":"https://api.github.com/repos/dan-zheng/swift/issues{/number}","pulls_url":"https://api.github.com/repos/dan-zheng/swift/pulls{/number}","milestones_url":"https://api.github.com/repos/dan-zheng/swift/milestones{/number}","notifications_url":"https://api.github.com/repos/dan-zheng/swift/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dan-zheng/swift/labels{/name}","releases_url":"https://api.github.com/repos/dan-zheng/swift/releases{/id}","deployments_url":"https://api.github.com/repos/dan-zheng/swift/deployments","created_at":"2018-06-03T23:56:41Z","updated_at":"2018-06-04T07:15:27Z","pushed_at":"2018-06-19T19:13:21Z","git_url":"git://github.com/dan-zheng/swift.git","ssh_url":"git@github.com:dan-zheng/swift.git","clone_url":"https://github.com/dan-zheng/swift.git","svn_url":"https://github.com/dan-zheng/swift","homepage":"https://swift.org/","size":299357,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apple:tensorflow","ref":"tensorflow","sha":"4dca7e7be709fdc7f0b708a3a7dfb6488087d964","user":{"login":"apple","id":10639145,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEwNjM5MTQ1","avatar_url":"https://avatars0.githubusercontent.com/u/10639145?v=4","gravatar_id":"","url":"https://api.github.com/users/apple","html_url":"https://github.com/apple","followers_url":"https://api.github.com/users/apple/followers","following_url":"https://api.github.com/users/apple/following{/other_user}","gists_url":"https://api.github.com/users/apple/gists{/gist_id}","starred_url":"https://api.github.com/users/apple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apple/subscriptions","organizations_url":"https://api.github.com/users/apple/orgs","repos_url":"https://api.github.com/users/apple/repos","events_url":"https://api.github.com/users/apple/events{/privacy}","received_events_url":"https://api.github.com/users/apple/received_events","type":"Organization","site_admin":false},"repo":{"id":44838949,"node_id":"MDEwOlJlcG9zaXRvcnk0NDgzODk0OQ==","name":"swift","full_name":"apple/swift","owner":{"login":"apple","id":10639145,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEwNjM5MTQ1","avatar_url":"https://avatars0.githubusercontent.com/u/10639145?v=4","gravatar_id":"","url":"https://api.github.com/users/apple","html_url":"https://github.com/apple","followers_url":"https://api.github.com/users/apple/followers","following_url":"https://api.github.com/users/apple/following{/other_user}","gists_url":"https://api.github.com/users/apple/gists{/gist_id}","starred_url":"https://api.github.com/users/apple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apple/subscriptions","organizations_url":"https://api.github.com/users/apple/orgs","repos_url":"https://api.github.com/users/apple/repos","events_url":"https://api.github.com/users/apple/events{/privacy}","received_events_url":"https://api.github.com/users/apple/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apple/swift","description":"The Swift Programming Language","fork":false,"url":"https://api.github.com/repos/apple/swift","forks_url":"https://api.github.com/repos/apple/swift/forks","keys_url":"https://api.github.com/repos/apple/swift/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apple/swift/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apple/swift/teams","hooks_url":"https://api.github.com/repos/apple/swift/hooks","issue_events_url":"https://api.github.com/repos/apple/swift/issues/events{/number}","events_url":"https://api.github.com/repos/apple/swift/events","assignees_url":"https://api.github.com/repos/apple/swift/assignees{/user}","branches_url":"https://api.github.com/repos/apple/swift/branches{/branch}","tags_url":"https://api.github.com/repos/apple/swift/tags","blobs_url":"https://api.github.com/repos/apple/swift/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apple/swift/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apple/swift/git/refs{/sha}","trees_url":"https://api.github.com/repos/apple/swift/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apple/swift/statuses/{sha}","languages_url":"https://api.github.com/repos/apple/swift/languages","stargazers_url":"https://api.github.com/repos/apple/swift/stargazers","contributors_url":"https://api.github.com/repos/apple/swift/contributors","subscribers_url":"https://api.github.com/repos/apple/swift/subscribers","subscription_url":"https://api.github.com/repos/apple/swift/subscription","commits_url":"https://api.github.com/repos/apple/swift/commits{/sha}","git_commits_url":"https://api.github.com/repos/apple/swift/git/commits{/sha}","comments_url":"https://api.github.com/repos/apple/swift/comments{/number}","issue_comment_url":"https://api.github.com/repos/apple/swift/issues/comments{/number}","contents_url":"https://api.github.com/repos/apple/swift/contents/{+path}","compare_url":"https://api.github.com/repos/apple/swift/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apple/swift/merges","archive_url":"https://api.github.com/repos/apple/swift/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apple/swift/downloads","issues_url":"https://api.github.com/repos/apple/swift/issues{/number}","pulls_url":"https://api.github.com/repos/apple/swift/pulls{/number}","milestones_url":"https://api.github.com/repos/apple/swift/milestones{/number}","notifications_url":"https://api.github.com/repos/apple/swift/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apple/swift/labels{/name}","releases_url":"https://api.github.com/repos/apple/swift/releases{/id}","deployments_url":"https://api.github.com/repos/apple/swift/deployments","created_at":"2015-10-23T21:15:07Z","updated_at":"2018-06-19T19:04:59Z","pushed_at":"2018-06-19T19:13:23Z","git_url":"git://github.com/apple/swift.git","ssh_url":"git@github.com:apple/swift.git","clone_url":"https://github.com/apple/swift.git","svn_url":"https://github.com/apple/swift","homepage":"https://swift.org/","size":301015,"stargazers_count":44234,"watchers_count":44234,"language":"C++","has_issues":false,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":6970,"mirror_url":null,"archived":false,"open_issues_count":359,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":6970,"open_issues":359,"watchers":44234,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apple/swift/pulls/17324"},"html":{"href":"https://github.com/apple/swift/pull/17324"},"issue":{"href":"https://api.github.com/repos/apple/swift/issues/17324"},"comments":{"href":"https://api.github.com/repos/apple/swift/issues/17324/comments"},"review_comments":{"href":"https://api.github.com/repos/apple/swift/pulls/17324/comments"},"review_comment":{"href":"https://api.github.com/repos/apple/swift/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apple/swift/pulls/17324/commits"},"statuses":{"href":"https://api.github.com/repos/apple/swift/statuses/a0430569ece5630639fce172fe9c4dbfa56f2af5"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"dan-zheng"}}