{"action":"created","comment":{"url":"https://api.github.com/repos/WebAssembly/binaryen/pulls/comments/61113479","id":61113479,"diff_hunk":"@@ -49,13 +49,38 @@ void Linker::placeStackPointer(size_t stackAllocation) {\n }\n \n void Linker::layout() {\n+  // Convert calls to undefined functions to call_imports\n+  for (const auto& f : out.undefinedFunctions) {\n+    Name target = f.first;\n+    // Create an import for the target if necessary.\n+    if (!out.wasm.checkImport(target)) {\n+      auto import = out.wasm.allocator.alloc<Import>();\n+      import->name = import->base = target;\n+      import->module = ENV;\n+      import->type = ensureFunctionType(getSig(*f.second.begin()), &out.wasm,\n+                                        out.wasm.allocator);\n+      out.wasm.addImport(import);\n+    }\n+    // Change each call. The target is the same since it's still the name.\n+    // Delete and re-allocate the Expression as CallImport to avoid undefined\n+    // behavior.\n+    for (auto* call : f.second) {\n+      Call callCopy = std::move(*call);\n+      call->~Call();\n+      CallImport* newCall = new (call) CallImport;","path":"src/wasm-linker.cpp","position":22,"original_position":22,"commit_id":"41f6780e4f9423cca5e0b9139b5cde0307e47c85","original_commit_id":"41f6780e4f9423cca5e0b9139b5cde0307e47c85","user":{"login":"dschuff","id":1122856,"avatar_url":"https://avatars.githubusercontent.com/u/1122856?v=3","gravatar_id":"","url":"https://api.github.com/users/dschuff","html_url":"https://github.com/dschuff","followers_url":"https://api.github.com/users/dschuff/followers","following_url":"https://api.github.com/users/dschuff/following{/other_user}","gists_url":"https://api.github.com/users/dschuff/gists{/gist_id}","starred_url":"https://api.github.com/users/dschuff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dschuff/subscriptions","organizations_url":"https://api.github.com/users/dschuff/orgs","repos_url":"https://api.github.com/users/dschuff/repos","events_url":"https://api.github.com/users/dschuff/events{/privacy}","received_events_url":"https://api.github.com/users/dschuff/received_events","type":"User","site_admin":false},"body":"Actually we have to keep the allocation in the same place, because some AST node has a pointer to this call as its operand. So if we allocate a new node that pointer will dangle. Since we don't have parent pointers in the AST nodes, the only alternative is to write a pass to traverse the whole AST and replace the nodes, which I was hoping to avoid.","created_at":"2016-04-26T16:01:31Z","updated_at":"2016-04-26T16:01:31Z","html_url":"https://github.com/WebAssembly/binaryen/pull/395#discussion_r61113479","pull_request_url":"https://api.github.com/repos/WebAssembly/binaryen/pulls/395","_links":{"self":{"href":"https://api.github.com/repos/WebAssembly/binaryen/pulls/comments/61113479"},"html":{"href":"https://github.com/WebAssembly/binaryen/pull/395#discussion_r61113479"},"pull_request":{"href":"https://api.github.com/repos/WebAssembly/binaryen/pulls/395"}}},"pull_request":{"url":"https://api.github.com/repos/WebAssembly/binaryen/pulls/395","id":67809858,"html_url":"https://github.com/WebAssembly/binaryen/pull/395","diff_url":"https://github.com/WebAssembly/binaryen/pull/395.diff","patch_url":"https://github.com/WebAssembly/binaryen/pull/395.patch","issue_url":"https://api.github.com/repos/WebAssembly/binaryen/issues/395","number":395,"state":"open","locked":false,"title":"Defer creation of CallImports to link time","user":{"login":"dschuff","id":1122856,"avatar_url":"https://avatars.githubusercontent.com/u/1122856?v=3","gravatar_id":"","url":"https://api.github.com/users/dschuff","html_url":"https://github.com/dschuff","followers_url":"https://api.github.com/users/dschuff/followers","following_url":"https://api.github.com/users/dschuff/following{/other_user}","gists_url":"https://api.github.com/users/dschuff/gists{/gist_id}","starred_url":"https://api.github.com/users/dschuff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dschuff/subscriptions","organizations_url":"https://api.github.com/users/dschuff/orgs","repos_url":"https://api.github.com/users/dschuff/repos","events_url":"https://api.github.com/users/dschuff/events{/privacy}","received_events_url":"https://api.github.com/users/dschuff/received_events","type":"User","site_admin":false},"body":"s2wasm currently creates a Call AST node if the target is implemented in the current object (thus far assumed to be the final executable) and a CallImport node if not. In preparation for adding additional objects to the link before layout time, we make only Call nodes until link time, and then convert them to CallImport if they are undefined at that time.","created_at":"2016-04-26T00:28:07Z","updated_at":"2016-04-26T16:01:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8f4c049c84a637538773c78a5165649ef738c635","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/WebAssembly/binaryen/pulls/395/commits","review_comments_url":"https://api.github.com/repos/WebAssembly/binaryen/pulls/395/comments","review_comment_url":"https://api.github.com/repos/WebAssembly/binaryen/pulls/comments{/number}","comments_url":"https://api.github.com/repos/WebAssembly/binaryen/issues/395/comments","statuses_url":"https://api.github.com/repos/WebAssembly/binaryen/statuses/41f6780e4f9423cca5e0b9139b5cde0307e47c85","head":{"label":"WebAssembly:defer-imports","ref":"defer-imports","sha":"41f6780e4f9423cca5e0b9139b5cde0307e47c85","user":{"login":"WebAssembly","id":11578470,"avatar_url":"https://avatars.githubusercontent.com/u/11578470?v=3","gravatar_id":"","url":"https://api.github.com/users/WebAssembly","html_url":"https://github.com/WebAssembly","followers_url":"https://api.github.com/users/WebAssembly/followers","following_url":"https://api.github.com/users/WebAssembly/following{/other_user}","gists_url":"https://api.github.com/users/WebAssembly/gists{/gist_id}","starred_url":"https://api.github.com/users/WebAssembly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WebAssembly/subscriptions","organizations_url":"https://api.github.com/users/WebAssembly/orgs","repos_url":"https://api.github.com/users/WebAssembly/repos","events_url":"https://api.github.com/users/WebAssembly/events{/privacy}","received_events_url":"https://api.github.com/users/WebAssembly/received_events","type":"Organization","site_admin":false},"repo":{"id":45208608,"name":"binaryen","full_name":"WebAssembly/binaryen","owner":{"login":"WebAssembly","id":11578470,"avatar_url":"https://avatars.githubusercontent.com/u/11578470?v=3","gravatar_id":"","url":"https://api.github.com/users/WebAssembly","html_url":"https://github.com/WebAssembly","followers_url":"https://api.github.com/users/WebAssembly/followers","following_url":"https://api.github.com/users/WebAssembly/following{/other_user}","gists_url":"https://api.github.com/users/WebAssembly/gists{/gist_id}","starred_url":"https://api.github.com/users/WebAssembly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WebAssembly/subscriptions","organizations_url":"https://api.github.com/users/WebAssembly/orgs","repos_url":"https://api.github.com/users/WebAssembly/repos","events_url":"https://api.github.com/users/WebAssembly/events{/privacy}","received_events_url":"https://api.github.com/users/WebAssembly/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/WebAssembly/binaryen","description":"Compiler infrastructure and toolchain library for WebAssembly, in C++","fork":false,"url":"https://api.github.com/repos/WebAssembly/binaryen","forks_url":"https://api.github.com/repos/WebAssembly/binaryen/forks","keys_url":"https://api.github.com/repos/WebAssembly/binaryen/keys{/key_id}","collaborators_url":"https://api.github.com/repos/WebAssembly/binaryen/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/WebAssembly/binaryen/teams","hooks_url":"https://api.github.com/repos/WebAssembly/binaryen/hooks","issue_events_url":"https://api.github.com/repos/WebAssembly/binaryen/issues/events{/number}","events_url":"https://api.github.com/repos/WebAssembly/binaryen/events","assignees_url":"https://api.github.com/repos/WebAssembly/binaryen/assignees{/user}","branches_url":"https://api.github.com/repos/WebAssembly/binaryen/branches{/branch}","tags_url":"https://api.github.com/repos/WebAssembly/binaryen/tags","blobs_url":"https://api.github.com/repos/WebAssembly/binaryen/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/WebAssembly/binaryen/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/WebAssembly/binaryen/git/refs{/sha}","trees_url":"https://api.github.com/repos/WebAssembly/binaryen/git/trees{/sha}","statuses_url":"https://api.github.com/repos/WebAssembly/binaryen/statuses/{sha}","languages_url":"https://api.github.com/repos/WebAssembly/binaryen/languages","stargazers_url":"https://api.github.com/repos/WebAssembly/binaryen/stargazers","contributors_url":"https://api.github.com/repos/WebAssembly/binaryen/contributors","subscribers_url":"https://api.github.com/repos/WebAssembly/binaryen/subscribers","subscription_url":"https://api.github.com/repos/WebAssembly/binaryen/subscription","commits_url":"https://api.github.com/repos/WebAssembly/binaryen/commits{/sha}","git_commits_url":"https://api.github.com/repos/WebAssembly/binaryen/git/commits{/sha}","comments_url":"https://api.github.com/repos/WebAssembly/binaryen/comments{/number}","issue_comment_url":"https://api.github.com/repos/WebAssembly/binaryen/issues/comments{/number}","contents_url":"https://api.github.com/repos/WebAssembly/binaryen/contents/{+path}","compare_url":"https://api.github.com/repos/WebAssembly/binaryen/compare/{base}...{head}","merges_url":"https://api.github.com/repos/WebAssembly/binaryen/merges","archive_url":"https://api.github.com/repos/WebAssembly/binaryen/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/WebAssembly/binaryen/downloads","issues_url":"https://api.github.com/repos/WebAssembly/binaryen/issues{/number}","pulls_url":"https://api.github.com/repos/WebAssembly/binaryen/pulls{/number}","milestones_url":"https://api.github.com/repos/WebAssembly/binaryen/milestones{/number}","notifications_url":"https://api.github.com/repos/WebAssembly/binaryen/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/WebAssembly/binaryen/labels{/name}","releases_url":"https://api.github.com/repos/WebAssembly/binaryen/releases{/id}","deployments_url":"https://api.github.com/repos/WebAssembly/binaryen/deployments","created_at":"2015-10-29T20:26:28Z","updated_at":"2016-04-25T17:57:16Z","pushed_at":"2016-04-26T03:47:07Z","git_url":"git://github.com/WebAssembly/binaryen.git","ssh_url":"git@github.com:WebAssembly/binaryen.git","clone_url":"https://github.com/WebAssembly/binaryen.git","svn_url":"https://github.com/WebAssembly/binaryen","homepage":"","size":17157,"stargazers_count":621,"watchers_count":621,"language":"Assembly","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":53,"mirror_url":null,"open_issues_count":60,"forks":53,"open_issues":60,"watchers":621,"default_branch":"master"}},"base":{"label":"WebAssembly:master","ref":"master","sha":"cb35ee67868bdc2b8839766b7e10b65e8fcc122a","user":{"login":"WebAssembly","id":11578470,"avatar_url":"https://avatars.githubusercontent.com/u/11578470?v=3","gravatar_id":"","url":"https://api.github.com/users/WebAssembly","html_url":"https://github.com/WebAssembly","followers_url":"https://api.github.com/users/WebAssembly/followers","following_url":"https://api.github.com/users/WebAssembly/following{/other_user}","gists_url":"https://api.github.com/users/WebAssembly/gists{/gist_id}","starred_url":"https://api.github.com/users/WebAssembly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WebAssembly/subscriptions","organizations_url":"https://api.github.com/users/WebAssembly/orgs","repos_url":"https://api.github.com/users/WebAssembly/repos","events_url":"https://api.github.com/users/WebAssembly/events{/privacy}","received_events_url":"https://api.github.com/users/WebAssembly/received_events","type":"Organization","site_admin":false},"repo":{"id":45208608,"name":"binaryen","full_name":"WebAssembly/binaryen","owner":{"login":"WebAssembly","id":11578470,"avatar_url":"https://avatars.githubusercontent.com/u/11578470?v=3","gravatar_id":"","url":"https://api.github.com/users/WebAssembly","html_url":"https://github.com/WebAssembly","followers_url":"https://api.github.com/users/WebAssembly/followers","following_url":"https://api.github.com/users/WebAssembly/following{/other_user}","gists_url":"https://api.github.com/users/WebAssembly/gists{/gist_id}","starred_url":"https://api.github.com/users/WebAssembly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WebAssembly/subscriptions","organizations_url":"https://api.github.com/users/WebAssembly/orgs","repos_url":"https://api.github.com/users/WebAssembly/repos","events_url":"https://api.github.com/users/WebAssembly/events{/privacy}","received_events_url":"https://api.github.com/users/WebAssembly/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/WebAssembly/binaryen","description":"Compiler infrastructure and toolchain library for WebAssembly, in C++","fork":false,"url":"https://api.github.com/repos/WebAssembly/binaryen","forks_url":"https://api.github.com/repos/WebAssembly/binaryen/forks","keys_url":"https://api.github.com/repos/WebAssembly/binaryen/keys{/key_id}","collaborators_url":"https://api.github.com/repos/WebAssembly/binaryen/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/WebAssembly/binaryen/teams","hooks_url":"https://api.github.com/repos/WebAssembly/binaryen/hooks","issue_events_url":"https://api.github.com/repos/WebAssembly/binaryen/issues/events{/number}","events_url":"https://api.github.com/repos/WebAssembly/binaryen/events","assignees_url":"https://api.github.com/repos/WebAssembly/binaryen/assignees{/user}","branches_url":"https://api.github.com/repos/WebAssembly/binaryen/branches{/branch}","tags_url":"https://api.github.com/repos/WebAssembly/binaryen/tags","blobs_url":"https://api.github.com/repos/WebAssembly/binaryen/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/WebAssembly/binaryen/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/WebAssembly/binaryen/git/refs{/sha}","trees_url":"https://api.github.com/repos/WebAssembly/binaryen/git/trees{/sha}","statuses_url":"https://api.github.com/repos/WebAssembly/binaryen/statuses/{sha}","languages_url":"https://api.github.com/repos/WebAssembly/binaryen/languages","stargazers_url":"https://api.github.com/repos/WebAssembly/binaryen/stargazers","contributors_url":"https://api.github.com/repos/WebAssembly/binaryen/contributors","subscribers_url":"https://api.github.com/repos/WebAssembly/binaryen/subscribers","subscription_url":"https://api.github.com/repos/WebAssembly/binaryen/subscription","commits_url":"https://api.github.com/repos/WebAssembly/binaryen/commits{/sha}","git_commits_url":"https://api.github.com/repos/WebAssembly/binaryen/git/commits{/sha}","comments_url":"https://api.github.com/repos/WebAssembly/binaryen/comments{/number}","issue_comment_url":"https://api.github.com/repos/WebAssembly/binaryen/issues/comments{/number}","contents_url":"https://api.github.com/repos/WebAssembly/binaryen/contents/{+path}","compare_url":"https://api.github.com/repos/WebAssembly/binaryen/compare/{base}...{head}","merges_url":"https://api.github.com/repos/WebAssembly/binaryen/merges","archive_url":"https://api.github.com/repos/WebAssembly/binaryen/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/WebAssembly/binaryen/downloads","issues_url":"https://api.github.com/repos/WebAssembly/binaryen/issues{/number}","pulls_url":"https://api.github.com/repos/WebAssembly/binaryen/pulls{/number}","milestones_url":"https://api.github.com/repos/WebAssembly/binaryen/milestones{/number}","notifications_url":"https://api.github.com/repos/WebAssembly/binaryen/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/WebAssembly/binaryen/labels{/name}","releases_url":"https://api.github.com/repos/WebAssembly/binaryen/releases{/id}","deployments_url":"https://api.github.com/repos/WebAssembly/binaryen/deployments","created_at":"2015-10-29T20:26:28Z","updated_at":"2016-04-25T17:57:16Z","pushed_at":"2016-04-26T03:47:07Z","git_url":"git://github.com/WebAssembly/binaryen.git","ssh_url":"git@github.com:WebAssembly/binaryen.git","clone_url":"https://github.com/WebAssembly/binaryen.git","svn_url":"https://github.com/WebAssembly/binaryen","homepage":"","size":17157,"stargazers_count":621,"watchers_count":621,"language":"Assembly","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":53,"mirror_url":null,"open_issues_count":60,"forks":53,"open_issues":60,"watchers":621,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/WebAssembly/binaryen/pulls/395"},"html":{"href":"https://github.com/WebAssembly/binaryen/pull/395"},"issue":{"href":"https://api.github.com/repos/WebAssembly/binaryen/issues/395"},"comments":{"href":"https://api.github.com/repos/WebAssembly/binaryen/issues/395/comments"},"review_comments":{"href":"https://api.github.com/repos/WebAssembly/binaryen/pulls/395/comments"},"review_comment":{"href":"https://api.github.com/repos/WebAssembly/binaryen/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/WebAssembly/binaryen/pulls/395/commits"},"statuses":{"href":"https://api.github.com/repos/WebAssembly/binaryen/statuses/41f6780e4f9423cca5e0b9139b5cde0307e47c85"}}}}