{"action":"created","comment":{"url":"https://api.github.com/repos/rstudio/rstudio/pulls/comments/27897227","id":27897227,"diff_hunk":"@@ -1034,36 +1129,209 @@ core::Error getNamespaceExports(SEXP ns,\n    return error;\n }\n \n-core::Error extractFormalNames(SEXP functionSEXP,\n-                               std::vector<std::string>* pNames)\n+namespace detail {\n+\n+bool addSymbolCheckedForMissingness(\n+      SEXP nodeSEXP,\n+      StringSet* pSymbolsCheckedForMissingness)\n {\n+   if (TYPEOF(nodeSEXP) == LANGSXP &&\n+       TYPEOF(CAR(nodeSEXP)) == SYMSXP &&\n+       CDR(nodeSEXP) != R_NilValue &&\n+       TYPEOF(CADR(nodeSEXP)) == SYMSXP &&\n+       CDDR(nodeSEXP) == R_NilValue &&\n+       strcmp(CHAR(PRINTNAME(CAR(nodeSEXP))), \"missing\") == 0)\n+   {\n+      DEBUG(\"Handling 'missing(\" << CHAR(PRINTNAME(CADR(nodeSEXP))) << \")'\");\n+      pSymbolsCheckedForMissingness->insert(CHAR(PRINTNAME(CADR(nodeSEXP))));\n+   }\n+   return false;\n+}\n+\n+bool addSymbols(\n+      SEXP nodeSEXP,\n+      StringSet* pSymbolsUsed)\n+{\n+   if (TYPEOF(nodeSEXP) == SYMSXP)\n+   {\n+      DEBUG(\"Reporting symbol '\" << CHAR(PRINTNAME(nodeSEXP)) << \"' as used\");\n+      pSymbolsUsed->insert(CHAR(PRINTNAME(nodeSEXP)));\n+   }\n+   return false;\n+}\n+\n+void examineSymbolUsage(\n+      SEXP nodeSEXP,\n+      FunctionSymbolUsage* usage)\n+{\n+   CallRecurser recurser(nodeSEXP);\n+   recurser.add(boost::bind(addSymbols, _1, &(usage->symbolsUsed)));\n+   recurser.add(boost::bind(addSymbolCheckedForMissingness, _1,\n+                            &(usage->symbolsCheckedForMissingness)));\n+   recurser.run();\n+}\n+\n+} // namespace detail\n+\n+void examineSymbolUsage(\n+      SEXP functionSEXP,\n+      FunctionInformation* pInfo)\n+{\n+   if (Rf_isPrimitive(functionSEXP))\n+      return;\n+   \n+   SEXP bodySEXP = BODY_EXPR(functionSEXP);\n+   \n+   FunctionSymbolUsageCache& cache = functionSymbolUsageCache();\n+   FunctionSymbolUsage usage;\n+   \n+   if (cache.contains(functionSEXP))\n+   {\n+      usage = cache.get(functionSEXP);\n+   }\n+   else\n+   {\n+      detail::examineSymbolUsage(bodySEXP, &usage);\n+      cache.put(functionSEXP, usage);\n+   }\n+   \n+   // fill output\n+   BOOST_FOREACH(FormalInformation& info, pInfo->formals())\n+   {\n+      const std::string& name = info.name;\n+      info.isUsed = usage.symbolsUsed.contains(name.c_str());\n+      \n+      bool isInternalFunction = \n+            usage.symbolsUsed.contains(\".Internal\") ||\n+            usage.symbolsUsed.contains(\".Primitive\");\n+      \n+      info.missingnessHandled =\n+            isInternalFunction ||\n+            usage.symbolsCheckedForMissingness.contains(name.c_str());\n+   }\n+}\n+\n+class PrimitiveWrappers : boost::noncopyable\n+{\n+   \n+public:\n+   \n+   SEXP operator[](SEXP primitiveSEXP)\n+   {\n+      if (contains(primitiveSEXP))\n+         return get(primitiveSEXP);\n+      \n+      r::sexp::Protect protect;\n+      SEXP wrapperSEXP;\n+      r::exec::RFunction makePrimitiveWrapper(\".rs.makePrimitiveWrapper\");\n+      makePrimitiveWrapper.addParam(primitiveSEXP);\n+      Error error = makePrimitiveWrapper.call(&wrapperSEXP, &protect);\n+      if (error)\n+         LOG_ERROR(error);\n+      \n+      R_PreserveObject(wrapperSEXP);","path":"src/cpp/r/RSexp.cpp","position":229,"original_position":229,"commit_id":"9a989d70be8239d04546a22a1bf77a3da3e37eae","original_commit_id":"9a989d70be8239d04546a22a1bf77a3da3e37eae","user":{"login":"jjallaire","id":104391,"avatar_url":"https://avatars.githubusercontent.com/u/104391?v=3","gravatar_id":"","url":"https://api.github.com/users/jjallaire","html_url":"https://github.com/jjallaire","followers_url":"https://api.github.com/users/jjallaire/followers","following_url":"https://api.github.com/users/jjallaire/following{/other_user}","gists_url":"https://api.github.com/users/jjallaire/gists{/gist_id}","starred_url":"https://api.github.com/users/jjallaire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jjallaire/subscriptions","organizations_url":"https://api.github.com/users/jjallaire/orgs","repos_url":"https://api.github.com/users/jjallaire/repos","events_url":"https://api.github.com/users/jjallaire/events{/privacy}","received_events_url":"https://api.github.com/users/jjallaire/received_events","type":"User","site_admin":false},"body":"We have the PreservedSEXP class for this but perhaps it's overkill since you will never release these objects (since they are in a static map). Does that sound right?","created_at":"2015-04-07T16:57:31Z","updated_at":"2015-04-07T16:57:31Z","html_url":"https://github.com/rstudio/rstudio/pull/379#discussion_r27897227","pull_request_url":"https://api.github.com/repos/rstudio/rstudio/pulls/379","_links":{"self":{"href":"https://api.github.com/repos/rstudio/rstudio/pulls/comments/27897227"},"html":{"href":"https://github.com/rstudio/rstudio/pull/379#discussion_r27897227"},"pull_request":{"href":"https://api.github.com/repos/rstudio/rstudio/pulls/379"}}},"pull_request":{"url":"https://api.github.com/repos/rstudio/rstudio/pulls/379","id":32703493,"html_url":"https://github.com/rstudio/rstudio/pull/379","diff_url":"https://github.com/rstudio/rstudio/pull/379.diff","patch_url":"https://github.com/rstudio/rstudio/pull/379.patch","issue_url":"https://api.github.com/repos/rstudio/rstudio/issues/379","number":379,"state":"open","locked":false,"title":"Improve internal match.call; provide optimizations for hot code paths","user":{"login":"kevinushey","id":1976582,"avatar_url":"https://avatars.githubusercontent.com/u/1976582?v=3","gravatar_id":"","url":"https://api.github.com/users/kevinushey","html_url":"https://github.com/kevinushey","followers_url":"https://api.github.com/users/kevinushey/followers","following_url":"https://api.github.com/users/kevinushey/following{/other_user}","gists_url":"https://api.github.com/users/kevinushey/gists{/gist_id}","starred_url":"https://api.github.com/users/kevinushey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevinushey/subscriptions","organizations_url":"https://api.github.com/users/kevinushey/orgs","repos_url":"https://api.github.com/users/kevinushey/repos","events_url":"https://api.github.com/users/kevinushey/events{/privacy}","received_events_url":"https://api.github.com/users/kevinushey/received_events","type":"User","site_admin":false},"body":"NOTE: Not quite ready for merge.\r\n\r\nThis PR encompasses an improved internal `match.call()` that provides information on function calls both in-source and in-session, and allows us to use the results from both.","created_at":"2015-04-06T19:29:56Z","updated_at":"2015-04-07T16:57:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"149601a25dac56267a8280d8fae3c4f27f491c20","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rstudio/rstudio/pulls/379/commits","review_comments_url":"https://api.github.com/repos/rstudio/rstudio/pulls/379/comments","review_comment_url":"https://api.github.com/repos/rstudio/rstudio/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rstudio/rstudio/issues/379/comments","statuses_url":"https://api.github.com/repos/rstudio/rstudio/statuses/9a989d70be8239d04546a22a1bf77a3da3e37eae","head":{"label":"rstudio:feature/match-call","ref":"feature/match-call","sha":"9a989d70be8239d04546a22a1bf77a3da3e37eae","user":{"login":"rstudio","id":513560,"avatar_url":"https://avatars.githubusercontent.com/u/513560?v=3","gravatar_id":"","url":"https://api.github.com/users/rstudio","html_url":"https://github.com/rstudio","followers_url":"https://api.github.com/users/rstudio/followers","following_url":"https://api.github.com/users/rstudio/following{/other_user}","gists_url":"https://api.github.com/users/rstudio/gists{/gist_id}","starred_url":"https://api.github.com/users/rstudio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rstudio/subscriptions","organizations_url":"https://api.github.com/users/rstudio/orgs","repos_url":"https://api.github.com/users/rstudio/repos","events_url":"https://api.github.com/users/rstudio/events{/privacy}","received_events_url":"https://api.github.com/users/rstudio/received_events","type":"Organization","site_admin":false},"repo":{"id":1147463,"name":"rstudio","full_name":"rstudio/rstudio","owner":{"login":"rstudio","id":513560,"avatar_url":"https://avatars.githubusercontent.com/u/513560?v=3","gravatar_id":"","url":"https://api.github.com/users/rstudio","html_url":"https://github.com/rstudio","followers_url":"https://api.github.com/users/rstudio/followers","following_url":"https://api.github.com/users/rstudio/following{/other_user}","gists_url":"https://api.github.com/users/rstudio/gists{/gist_id}","starred_url":"https://api.github.com/users/rstudio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rstudio/subscriptions","organizations_url":"https://api.github.com/users/rstudio/orgs","repos_url":"https://api.github.com/users/rstudio/repos","events_url":"https://api.github.com/users/rstudio/events{/privacy}","received_events_url":"https://api.github.com/users/rstudio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rstudio/rstudio","description":"RStudio is an integrated development environment (IDE) for R","fork":false,"url":"https://api.github.com/repos/rstudio/rstudio","forks_url":"https://api.github.com/repos/rstudio/rstudio/forks","keys_url":"https://api.github.com/repos/rstudio/rstudio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rstudio/rstudio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rstudio/rstudio/teams","hooks_url":"https://api.github.com/repos/rstudio/rstudio/hooks","issue_events_url":"https://api.github.com/repos/rstudio/rstudio/issues/events{/number}","events_url":"https://api.github.com/repos/rstudio/rstudio/events","assignees_url":"https://api.github.com/repos/rstudio/rstudio/assignees{/user}","branches_url":"https://api.github.com/repos/rstudio/rstudio/branches{/branch}","tags_url":"https://api.github.com/repos/rstudio/rstudio/tags","blobs_url":"https://api.github.com/repos/rstudio/rstudio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rstudio/rstudio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rstudio/rstudio/git/refs{/sha}","trees_url":"https://api.github.com/repos/rstudio/rstudio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rstudio/rstudio/statuses/{sha}","languages_url":"https://api.github.com/repos/rstudio/rstudio/languages","stargazers_url":"https://api.github.com/repos/rstudio/rstudio/stargazers","contributors_url":"https://api.github.com/repos/rstudio/rstudio/contributors","subscribers_url":"https://api.github.com/repos/rstudio/rstudio/subscribers","subscription_url":"https://api.github.com/repos/rstudio/rstudio/subscription","commits_url":"https://api.github.com/repos/rstudio/rstudio/commits{/sha}","git_commits_url":"https://api.github.com/repos/rstudio/rstudio/git/commits{/sha}","comments_url":"https://api.github.com/repos/rstudio/rstudio/comments{/number}","issue_comment_url":"https://api.github.com/repos/rstudio/rstudio/issues/comments{/number}","contents_url":"https://api.github.com/repos/rstudio/rstudio/contents/{+path}","compare_url":"https://api.github.com/repos/rstudio/rstudio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rstudio/rstudio/merges","archive_url":"https://api.github.com/repos/rstudio/rstudio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rstudio/rstudio/downloads","issues_url":"https://api.github.com/repos/rstudio/rstudio/issues{/number}","pulls_url":"https://api.github.com/repos/rstudio/rstudio/pulls{/number}","milestones_url":"https://api.github.com/repos/rstudio/rstudio/milestones{/number}","notifications_url":"https://api.github.com/repos/rstudio/rstudio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rstudio/rstudio/labels{/name}","releases_url":"https://api.github.com/repos/rstudio/rstudio/releases{/id}","created_at":"2010-12-07T19:10:25Z","updated_at":"2015-04-07T09:38:28Z","pushed_at":"2015-04-07T16:52:47Z","git_url":"git://github.com/rstudio/rstudio.git","ssh_url":"git@github.com:rstudio/rstudio.git","clone_url":"https://github.com/rstudio/rstudio.git","svn_url":"https://github.com/rstudio/rstudio","homepage":"http://www.rstudio.org","size":347936,"stargazers_count":981,"watchers_count":981,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":199,"mirror_url":null,"open_issues_count":3,"forks":199,"open_issues":3,"watchers":981,"default_branch":"master"}},"base":{"label":"rstudio:master","ref":"master","sha":"be0927f0dc906d463997ca8755d73ff4c2df3f8a","user":{"login":"rstudio","id":513560,"avatar_url":"https://avatars.githubusercontent.com/u/513560?v=3","gravatar_id":"","url":"https://api.github.com/users/rstudio","html_url":"https://github.com/rstudio","followers_url":"https://api.github.com/users/rstudio/followers","following_url":"https://api.github.com/users/rstudio/following{/other_user}","gists_url":"https://api.github.com/users/rstudio/gists{/gist_id}","starred_url":"https://api.github.com/users/rstudio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rstudio/subscriptions","organizations_url":"https://api.github.com/users/rstudio/orgs","repos_url":"https://api.github.com/users/rstudio/repos","events_url":"https://api.github.com/users/rstudio/events{/privacy}","received_events_url":"https://api.github.com/users/rstudio/received_events","type":"Organization","site_admin":false},"repo":{"id":1147463,"name":"rstudio","full_name":"rstudio/rstudio","owner":{"login":"rstudio","id":513560,"avatar_url":"https://avatars.githubusercontent.com/u/513560?v=3","gravatar_id":"","url":"https://api.github.com/users/rstudio","html_url":"https://github.com/rstudio","followers_url":"https://api.github.com/users/rstudio/followers","following_url":"https://api.github.com/users/rstudio/following{/other_user}","gists_url":"https://api.github.com/users/rstudio/gists{/gist_id}","starred_url":"https://api.github.com/users/rstudio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rstudio/subscriptions","organizations_url":"https://api.github.com/users/rstudio/orgs","repos_url":"https://api.github.com/users/rstudio/repos","events_url":"https://api.github.com/users/rstudio/events{/privacy}","received_events_url":"https://api.github.com/users/rstudio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rstudio/rstudio","description":"RStudio is an integrated development environment (IDE) for R","fork":false,"url":"https://api.github.com/repos/rstudio/rstudio","forks_url":"https://api.github.com/repos/rstudio/rstudio/forks","keys_url":"https://api.github.com/repos/rstudio/rstudio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rstudio/rstudio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rstudio/rstudio/teams","hooks_url":"https://api.github.com/repos/rstudio/rstudio/hooks","issue_events_url":"https://api.github.com/repos/rstudio/rstudio/issues/events{/number}","events_url":"https://api.github.com/repos/rstudio/rstudio/events","assignees_url":"https://api.github.com/repos/rstudio/rstudio/assignees{/user}","branches_url":"https://api.github.com/repos/rstudio/rstudio/branches{/branch}","tags_url":"https://api.github.com/repos/rstudio/rstudio/tags","blobs_url":"https://api.github.com/repos/rstudio/rstudio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rstudio/rstudio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rstudio/rstudio/git/refs{/sha}","trees_url":"https://api.github.com/repos/rstudio/rstudio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rstudio/rstudio/statuses/{sha}","languages_url":"https://api.github.com/repos/rstudio/rstudio/languages","stargazers_url":"https://api.github.com/repos/rstudio/rstudio/stargazers","contributors_url":"https://api.github.com/repos/rstudio/rstudio/contributors","subscribers_url":"https://api.github.com/repos/rstudio/rstudio/subscribers","subscription_url":"https://api.github.com/repos/rstudio/rstudio/subscription","commits_url":"https://api.github.com/repos/rstudio/rstudio/commits{/sha}","git_commits_url":"https://api.github.com/repos/rstudio/rstudio/git/commits{/sha}","comments_url":"https://api.github.com/repos/rstudio/rstudio/comments{/number}","issue_comment_url":"https://api.github.com/repos/rstudio/rstudio/issues/comments{/number}","contents_url":"https://api.github.com/repos/rstudio/rstudio/contents/{+path}","compare_url":"https://api.github.com/repos/rstudio/rstudio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rstudio/rstudio/merges","archive_url":"https://api.github.com/repos/rstudio/rstudio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rstudio/rstudio/downloads","issues_url":"https://api.github.com/repos/rstudio/rstudio/issues{/number}","pulls_url":"https://api.github.com/repos/rstudio/rstudio/pulls{/number}","milestones_url":"https://api.github.com/repos/rstudio/rstudio/milestones{/number}","notifications_url":"https://api.github.com/repos/rstudio/rstudio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rstudio/rstudio/labels{/name}","releases_url":"https://api.github.com/repos/rstudio/rstudio/releases{/id}","created_at":"2010-12-07T19:10:25Z","updated_at":"2015-04-07T09:38:28Z","pushed_at":"2015-04-07T16:52:47Z","git_url":"git://github.com/rstudio/rstudio.git","ssh_url":"git@github.com:rstudio/rstudio.git","clone_url":"https://github.com/rstudio/rstudio.git","svn_url":"https://github.com/rstudio/rstudio","homepage":"http://www.rstudio.org","size":347936,"stargazers_count":981,"watchers_count":981,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":199,"mirror_url":null,"open_issues_count":3,"forks":199,"open_issues":3,"watchers":981,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rstudio/rstudio/pulls/379"},"html":{"href":"https://github.com/rstudio/rstudio/pull/379"},"issue":{"href":"https://api.github.com/repos/rstudio/rstudio/issues/379"},"comments":{"href":"https://api.github.com/repos/rstudio/rstudio/issues/379/comments"},"review_comments":{"href":"https://api.github.com/repos/rstudio/rstudio/pulls/379/comments"},"review_comment":{"href":"https://api.github.com/repos/rstudio/rstudio/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rstudio/rstudio/pulls/379/commits"},"statuses":{"href":"https://api.github.com/repos/rstudio/rstudio/statuses/9a989d70be8239d04546a22a1bf77a3da3e37eae"}}}}