{"action":"created","comment":{"url":"https://api.github.com/repos/apple/swift/pulls/comments/244525378","pull_request_review_id":188429638,"id":244525378,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0NDUyNTM3OA==","diff_hunk":"@@ -2225,6 +2225,77 @@ class PrimalGenCloner final : public SILClonerWithScopes<PrimalGenCloner> {\n     SILClonerWithScopes::visitReleaseValueInst(rvi);\n   }\n \n+  void visitStructExtractInst(StructExtractInst *sei) {\n+    // Special handling logic only applies when the `struct_extract` is active.\n+    // If not, just do standard cloning.\n+    if (!activityInfo.isActive(sei, synthesis.indices)) {\n+      LLVM_DEBUG(getADDebugStream() << \"Not active:\\n\" << *sei << '\\n');\n+      SILClonerWithScopes::visitStructExtractInst(sei);\n+      return;\n+    }\n+\n+    // This instruction is active. Replace it with a call to the corresponding\n+    // getter's VJP.\n+\n+    // Find the corresponding getter and its VJP.\n+    auto *getterDecl = sei->getField()->getGetter();\n+    assert(getterDecl);\n+    auto *getterFn = getContext().getModule().lookUpFunction(\n+        SILDeclRef(getterDecl, SILDeclRef::Kind::Func));\n+    if (!getterFn) {\n+      getContext().emitNondifferentiabilityError(\n+          sei, synthesis.task, diag::autodiff_property_not_differentiable);\n+      errorOccurred = true;\n+      return;\n+    }\n+    auto getterDiffAttrs = getterFn->getDifferentiableAttrs();\n+    if (getterDiffAttrs.size() < 1) {\n+      getContext().emitNondifferentiabilityError(\n+          sei, synthesis.task, diag::autodiff_property_not_differentiable);\n+      errorOccurred = true;\n+      return;\n+    }\n+    auto *getterDiffAttr = getterDiffAttrs[0];\n+    if (!getterDiffAttr->hasVJP()) {\n+      getContext().emitNondifferentiabilityError(\n+          sei, synthesis.task, diag::autodiff_property_not_differentiable);\n+      errorOccurred = true;\n+      return;\n+    }\n+    assert(getterDiffAttr->getIndices() ==\n+           SILAutoDiffIndices(/*source*/ 0, /*parameters*/{0}));\n+    auto *getterVJP = lookUpOrLinkFunction(getterDiffAttr->getVJPName(),\n+                                           getContext().getModule());\n+\n+    // Reference and apply the VJP.\n+    auto loc = sei->getLoc();\n+    auto *getterVJPRef = getBuilder().createFunctionRef(loc, getterVJP);\n+    auto *getterVJPApply = getBuilder().createApply(\n+        loc, getterVJPRef, /*substitutionMap*/ {},\n+        /*args*/ {getMappedValue(sei->getOperand())}, /*isNonThrowing*/ false);\n+\n+    // Get the VJP results (original results and pullback)","path":"lib/SILOptimizer/Mandatory/TFDifferentiation.cpp","position":88,"original_position":88,"commit_id":"0928c65deda63f05789bf9e41032c3b4e7982b47","original_commit_id":"0928c65deda63f05789bf9e41032c3b4e7982b47","user":{"login":"rxwei","id":856507,"node_id":"MDQ6VXNlcjg1NjUwNw==","avatar_url":"https://avatars0.githubusercontent.com/u/856507?v=4","gravatar_id":"","url":"https://api.github.com/users/rxwei","html_url":"https://github.com/rxwei","followers_url":"https://api.github.com/users/rxwei/followers","following_url":"https://api.github.com/users/rxwei/following{/other_user}","gists_url":"https://api.github.com/users/rxwei/gists{/gist_id}","starred_url":"https://api.github.com/users/rxwei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rxwei/subscriptions","organizations_url":"https://api.github.com/users/rxwei/orgs","repos_url":"https://api.github.com/users/rxwei/repos","events_url":"https://api.github.com/users/rxwei/events{/privacy}","received_events_url":"https://api.github.com/users/rxwei/received_events","type":"User","site_admin":false},"body":"Nit\r\n```suggestion\r\n    // Get the VJP results (original results and pullback).\r\n```","created_at":"2018-12-30T06:47:55Z","updated_at":"2018-12-30T06:52:43Z","html_url":"https://github.com/apple/swift/pull/21567#discussion_r244525378","pull_request_url":"https://api.github.com/repos/apple/swift/pulls/21567","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/apple/swift/pulls/comments/244525378"},"html":{"href":"https://github.com/apple/swift/pull/21567#discussion_r244525378"},"pull_request":{"href":"https://api.github.com/repos/apple/swift/pulls/21567"}}},"pull_request":{"url":"https://api.github.com/repos/apple/swift/pulls/21567","id":241472202,"node_id":"MDExOlB1bGxSZXF1ZXN0MjQxNDcyMjAy","html_url":"https://github.com/apple/swift/pull/21567","diff_url":"https://github.com/apple/swift/pull/21567.diff","patch_url":"https://github.com/apple/swift/pull/21567.patch","issue_url":"https://api.github.com/repos/apple/swift/issues/21567","number":21567,"state":"open","locked":false,"title":"differentiate struct_extract instructions using VJP","user":{"login":"marcrasi","id":5945760,"node_id":"MDQ6VXNlcjU5NDU3NjA=","avatar_url":"https://avatars0.githubusercontent.com/u/5945760?v=4","gravatar_id":"","url":"https://api.github.com/users/marcrasi","html_url":"https://github.com/marcrasi","followers_url":"https://api.github.com/users/marcrasi/followers","following_url":"https://api.github.com/users/marcrasi/following{/other_user}","gists_url":"https://api.github.com/users/marcrasi/gists{/gist_id}","starred_url":"https://api.github.com/users/marcrasi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcrasi/subscriptions","organizations_url":"https://api.github.com/users/marcrasi/orgs","repos_url":"https://api.github.com/users/marcrasi/repos","events_url":"https://api.github.com/users/marcrasi/events{/privacy}","received_events_url":"https://api.github.com/users/marcrasi/received_events","type":"User","site_admin":false},"body":"Differentiates `struct_extract` instructions using the VJP of the corresponding getter.\r\n\r\n`Float._value` has no VJP defined so AD can't differentiate `public static prefix func - (x: ${Self})`. This could be fixed by defining a VJP for `Float._value` or by adding a custom adjoint for `-`. The latter sounded less invasive so I did that.","created_at":"2018-12-30T01:58:25Z","updated_at":"2018-12-30T06:52:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d124419ddc4f393dce4bd4746aa4205333d029d4","assignee":null,"assignees":[],"requested_reviewers":[{"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}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/apple/swift/pulls/21567/commits","review_comments_url":"https://api.github.com/repos/apple/swift/pulls/21567/comments","review_comment_url":"https://api.github.com/repos/apple/swift/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apple/swift/issues/21567/comments","statuses_url":"https://api.github.com/repos/apple/swift/statuses/0928c65deda63f05789bf9e41032c3b4e7982b47","head":{"label":"marcrasi:ad-struct-extract","ref":"ad-struct-extract","sha":"0928c65deda63f05789bf9e41032c3b4e7982b47","user":{"login":"marcrasi","id":5945760,"node_id":"MDQ6VXNlcjU5NDU3NjA=","avatar_url":"https://avatars0.githubusercontent.com/u/5945760?v=4","gravatar_id":"","url":"https://api.github.com/users/marcrasi","html_url":"https://github.com/marcrasi","followers_url":"https://api.github.com/users/marcrasi/followers","following_url":"https://api.github.com/users/marcrasi/following{/other_user}","gists_url":"https://api.github.com/users/marcrasi/gists{/gist_id}","starred_url":"https://api.github.com/users/marcrasi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcrasi/subscriptions","organizations_url":"https://api.github.com/users/marcrasi/orgs","repos_url":"https://api.github.com/users/marcrasi/repos","events_url":"https://api.github.com/users/marcrasi/events{/privacy}","received_events_url":"https://api.github.com/users/marcrasi/received_events","type":"User","site_admin":false},"repo":{"id":135738994,"node_id":"MDEwOlJlcG9zaXRvcnkxMzU3Mzg5OTQ=","name":"swift","full_name":"marcrasi/swift","private":false,"owner":{"login":"marcrasi","id":5945760,"node_id":"MDQ6VXNlcjU5NDU3NjA=","avatar_url":"https://avatars0.githubusercontent.com/u/5945760?v=4","gravatar_id":"","url":"https://api.github.com/users/marcrasi","html_url":"https://github.com/marcrasi","followers_url":"https://api.github.com/users/marcrasi/followers","following_url":"https://api.github.com/users/marcrasi/following{/other_user}","gists_url":"https://api.github.com/users/marcrasi/gists{/gist_id}","starred_url":"https://api.github.com/users/marcrasi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcrasi/subscriptions","organizations_url":"https://api.github.com/users/marcrasi/orgs","repos_url":"https://api.github.com/users/marcrasi/repos","events_url":"https://api.github.com/users/marcrasi/events{/privacy}","received_events_url":"https://api.github.com/users/marcrasi/received_events","type":"User","site_admin":false},"html_url":"https://github.com/marcrasi/swift","description":"The Swift Programming Language","fork":true,"url":"https://api.github.com/repos/marcrasi/swift","forks_url":"https://api.github.com/repos/marcrasi/swift/forks","keys_url":"https://api.github.com/repos/marcrasi/swift/keys{/key_id}","collaborators_url":"https://api.github.com/repos/marcrasi/swift/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/marcrasi/swift/teams","hooks_url":"https://api.github.com/repos/marcrasi/swift/hooks","issue_events_url":"https://api.github.com/repos/marcrasi/swift/issues/events{/number}","events_url":"https://api.github.com/repos/marcrasi/swift/events","assignees_url":"https://api.github.com/repos/marcrasi/swift/assignees{/user}","branches_url":"https://api.github.com/repos/marcrasi/swift/branches{/branch}","tags_url":"https://api.github.com/repos/marcrasi/swift/tags","blobs_url":"https://api.github.com/repos/marcrasi/swift/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/marcrasi/swift/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/marcrasi/swift/git/refs{/sha}","trees_url":"https://api.github.com/repos/marcrasi/swift/git/trees{/sha}","statuses_url":"https://api.github.com/repos/marcrasi/swift/statuses/{sha}","languages_url":"https://api.github.com/repos/marcrasi/swift/languages","stargazers_url":"https://api.github.com/repos/marcrasi/swift/stargazers","contributors_url":"https://api.github.com/repos/marcrasi/swift/contributors","subscribers_url":"https://api.github.com/repos/marcrasi/swift/subscribers","subscription_url":"https://api.github.com/repos/marcrasi/swift/subscription","commits_url":"https://api.github.com/repos/marcrasi/swift/commits{/sha}","git_commits_url":"https://api.github.com/repos/marcrasi/swift/git/commits{/sha}","comments_url":"https://api.github.com/repos/marcrasi/swift/comments{/number}","issue_comment_url":"https://api.github.com/repos/marcrasi/swift/issues/comments{/number}","contents_url":"https://api.github.com/repos/marcrasi/swift/contents/{+path}","compare_url":"https://api.github.com/repos/marcrasi/swift/compare/{base}...{head}","merges_url":"https://api.github.com/repos/marcrasi/swift/merges","archive_url":"https://api.github.com/repos/marcrasi/swift/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/marcrasi/swift/downloads","issues_url":"https://api.github.com/repos/marcrasi/swift/issues{/number}","pulls_url":"https://api.github.com/repos/marcrasi/swift/pulls{/number}","milestones_url":"https://api.github.com/repos/marcrasi/swift/milestones{/number}","notifications_url":"https://api.github.com/repos/marcrasi/swift/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/marcrasi/swift/labels{/name}","releases_url":"https://api.github.com/repos/marcrasi/swift/releases{/id}","deployments_url":"https://api.github.com/repos/marcrasi/swift/deployments","created_at":"2018-06-01T16:13:26Z","updated_at":"2018-06-01T16:13:59Z","pushed_at":"2018-12-30T03:53:15Z","git_url":"git://github.com/marcrasi/swift.git","ssh_url":"git@github.com:marcrasi/swift.git","clone_url":"https://github.com/marcrasi/swift.git","svn_url":"https://github.com/marcrasi/swift","homepage":"https://swift.org/","size":361908,"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":"cb2eaccbcade753e4ba2f7b3ef90eeec7750bde5","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","private":false,"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},"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-12-30T06:30:14Z","pushed_at":"2018-12-30T06:41:08Z","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":375860,"stargazers_count":46195,"watchers_count":46195,"language":"C++","has_issues":false,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":7335,"mirror_url":null,"archived":false,"open_issues_count":464,"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":7335,"open_issues":464,"watchers":46195,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apple/swift/pulls/21567"},"html":{"href":"https://github.com/apple/swift/pull/21567"},"issue":{"href":"https://api.github.com/repos/apple/swift/issues/21567"},"comments":{"href":"https://api.github.com/repos/apple/swift/issues/21567/comments"},"review_comments":{"href":"https://api.github.com/repos/apple/swift/pulls/21567/comments"},"review_comment":{"href":"https://api.github.com/repos/apple/swift/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apple/swift/pulls/21567/commits"},"statuses":{"href":"https://api.github.com/repos/apple/swift/statuses/0928c65deda63f05789bf9e41032c3b4e7982b47"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"rxwei"}}