{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang/rustc-guide/pulls/comments/361840506","pull_request_review_id":336949665,"id":361840506,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDM2MTg0MDUwNg==","diff_hunk":"@@ -0,0 +1,107 @@\n+### Panicking in rust ###\n+\n+#### Step 1: Invocation of the `panic!` macro.\n+\n+There are actually two panic macros - one defined in `libcore`, and one defined in `libstd`.\n+This is due to the fact that code in `libcore` can panic. `libcore` is built before `libstd`,\n+but we want panics to use the same machinery at runtime, whether they originate in `libcore`\n+or `libstd`.\n+\n+##### libcore definition of panic!\n+\n+The `libcore` `panic!` macro eventually makes the following call (in `src/libcore/panicking.rs`):\n+\n+```rust\n+// NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call\n+extern \"Rust\" {\n+    #[lang = \"panic_impl\"]\n+    fn panic_impl(pi: &PanicInfo<'_>) -> !;\n+}\n+\n+let pi = PanicInfo::internal_constructor(Some(&fmt), location);\n+unsafe { panic_impl(&pi) }\n+```\n+\n+Actually resolving this goes through several layers of indirection:\n+\n+1. In `src/librustc/middle/weak_lang_items.rs`, `panic_impl` is declared as 'weak lang item',\n+   with the symbol `rust_begin_unwind`. This is used in `librustc_typeck/collect.rs`\n+   to set the actual symbol name to `rust_begin_unwind`.\n+\n+   Note that `panic_impl` is declared in an `extern \"Rust\"` block,\n+   which means that libcore will attempt to call a foreign symbol called `rust_begin_unwind`\n+   (to be resolved at link time)\n+\n+2. In `src/libstd/panicking.rs`, we have this definition:\n+\n+```rust\n+/// Entry point of panic from the libcore crate.\n+[cfg(not(test))]\n+[panic_handler]\n+[unwind(allowed)]\n+pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {\n+    ...\n+}\n+```\n+\n+The special `panic_handler` attribute is resolved via `src/librustc/middle/lang_items`.\n+The `extract` function converts the `panic_handler` attribute to a `panic_impl` lang item.\n+\n+Now, we have a matching `panic_handler` lang item in the `libstd`. This function goes\n+through the same process as the `extern { fn panic_impl }` definition in `libcore`, ending\n+up with a symbol name of `rust_begin_unwind`. At link time, the symbol refernce in `libcore`\n+will be resolved to the definition of `libstd` (the function called `begin_panic_handler` in the\n+Rust source).\n+\n+Thus, control flow will pass from libcore to std at runtime. This allows panics from `libcore`\n+to go through the same infratructure that other panics use (panic hooks, unwinding, etc)\n+\n+##### libstd implementation of panic!\n+\n+This is where the actual panic-related logic begins. In `src/libstd/pancking.rs`,\n+control passes to `rust_panic_with_hook`. This method is responsible\n+for invoking the global panic hook, and checking for double panics. Finally,\n+we call ```__rust_start_panic```, which is provided by the panic runtime.\n+\n+The call to ```__rust_start_panic``` is very weird - it is passed a ```*mut &mut dyn BoxMeUp```,\n+converted to an `usize`. Let's break this type down:\n+\n+1. `BoxMeUp` is an internal trait. It is implemented for `PanicPayload`\n+(a wrapper around the user-supplied payload type), and has a method\n+```fn box_me_up(&mut self) -> *mut (dyn Any + Send)```.","path":"src/panic-implementation.md","position":71,"original_position":71,"commit_id":"9f25a0209d51a84e883ba0e0d11d47b4d6b9ec96","original_commit_id":"9f25a0209d51a84e883ba0e0d11d47b4d6b9ec96","user":{"login":"JohnTitor","id":25030997,"node_id":"MDQ6VXNlcjI1MDMwOTk3","avatar_url":"https://avatars3.githubusercontent.com/u/25030997?v=4","gravatar_id":"","url":"https://api.github.com/users/JohnTitor","html_url":"https://github.com/JohnTitor","followers_url":"https://api.github.com/users/JohnTitor/followers","following_url":"https://api.github.com/users/JohnTitor/following{/other_user}","gists_url":"https://api.github.com/users/JohnTitor/gists{/gist_id}","starred_url":"https://api.github.com/users/JohnTitor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JohnTitor/subscriptions","organizations_url":"https://api.github.com/users/JohnTitor/orgs","repos_url":"https://api.github.com/users/JohnTitor/repos","events_url":"https://api.github.com/users/JohnTitor/events{/privacy}","received_events_url":"https://api.github.com/users/JohnTitor/received_events","type":"User","site_admin":false},"body":"```suggestion\r\n`fn box_me_up(&mut self) -> *mut (dyn Any + Send)`.\r\n```","created_at":"2019-12-29T10:26:47Z","updated_at":"2019-12-29T10:35:33Z","html_url":"https://github.com/rust-lang/rustc-guide/pull/521#discussion_r361840506","pull_request_url":"https://api.github.com/repos/rust-lang/rustc-guide/pulls/521","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rustc-guide/pulls/comments/361840506"},"html":{"href":"https://github.com/rust-lang/rustc-guide/pull/521#discussion_r361840506"},"pull_request":{"href":"https://api.github.com/repos/rust-lang/rustc-guide/pulls/521"}}},"pull_request":{"url":"https://api.github.com/repos/rust-lang/rustc-guide/pulls/521","id":344702300,"node_id":"MDExOlB1bGxSZXF1ZXN0MzQ0NzAyMzAw","html_url":"https://github.com/rust-lang/rustc-guide/pull/521","diff_url":"https://github.com/rust-lang/rustc-guide/pull/521.diff","patch_url":"https://github.com/rust-lang/rustc-guide/pull/521.patch","issue_url":"https://api.github.com/repos/rust-lang/rustc-guide/issues/521","number":521,"state":"open","locked":false,"title":"[WIP] Add panic implementation docs","user":{"login":"Aaron1011","id":1408859,"node_id":"MDQ6VXNlcjE0MDg4NTk=","avatar_url":"https://avatars1.githubusercontent.com/u/1408859?v=4","gravatar_id":"","url":"https://api.github.com/users/Aaron1011","html_url":"https://github.com/Aaron1011","followers_url":"https://api.github.com/users/Aaron1011/followers","following_url":"https://api.github.com/users/Aaron1011/following{/other_user}","gists_url":"https://api.github.com/users/Aaron1011/gists{/gist_id}","starred_url":"https://api.github.com/users/Aaron1011/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Aaron1011/subscriptions","organizations_url":"https://api.github.com/users/Aaron1011/orgs","repos_url":"https://api.github.com/users/Aaron1011/repos","events_url":"https://api.github.com/users/Aaron1011/events{/privacy}","received_events_url":"https://api.github.com/users/Aaron1011/received_events","type":"User","site_admin":false},"body":"This PR adds a descirption of the implementation of panicking in Rust, starting from the `panic!` macros and ending at the invocation of the platforms-specific unwind logic.\r\n\r\nThis is not fully complete - for one thing, it might be useful to have a description of how this works under Miri.\r\n\r\nI developed this while working on the implementation of panics in Miri. Having this document available would have made things a lot easier for me :smile: \r\n\r\n\r\nCloses #486 ","created_at":"2019-11-22T21:16:30Z","updated_at":"2019-12-29T10:35:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6ca09bc92b7c572589fc7b307a23bfeda106f1fd","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/rust-lang/rustc-guide/pulls/521/commits","review_comments_url":"https://api.github.com/repos/rust-lang/rustc-guide/pulls/521/comments","review_comment_url":"https://api.github.com/repos/rust-lang/rustc-guide/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rust-lang/rustc-guide/issues/521/comments","statuses_url":"https://api.github.com/repos/rust-lang/rustc-guide/statuses/9f25a0209d51a84e883ba0e0d11d47b4d6b9ec96","head":{"label":"Aaron1011:panic","ref":"panic","sha":"9f25a0209d51a84e883ba0e0d11d47b4d6b9ec96","user":{"login":"Aaron1011","id":1408859,"node_id":"MDQ6VXNlcjE0MDg4NTk=","avatar_url":"https://avatars1.githubusercontent.com/u/1408859?v=4","gravatar_id":"","url":"https://api.github.com/users/Aaron1011","html_url":"https://github.com/Aaron1011","followers_url":"https://api.github.com/users/Aaron1011/followers","following_url":"https://api.github.com/users/Aaron1011/following{/other_user}","gists_url":"https://api.github.com/users/Aaron1011/gists{/gist_id}","starred_url":"https://api.github.com/users/Aaron1011/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Aaron1011/subscriptions","organizations_url":"https://api.github.com/users/Aaron1011/orgs","repos_url":"https://api.github.com/users/Aaron1011/repos","events_url":"https://api.github.com/users/Aaron1011/events{/privacy}","received_events_url":"https://api.github.com/users/Aaron1011/received_events","type":"User","site_admin":false},"repo":{"id":223487549,"node_id":"MDEwOlJlcG9zaXRvcnkyMjM0ODc1NDk=","name":"rustc-guide","full_name":"Aaron1011/rustc-guide","private":false,"owner":{"login":"Aaron1011","id":1408859,"node_id":"MDQ6VXNlcjE0MDg4NTk=","avatar_url":"https://avatars1.githubusercontent.com/u/1408859?v=4","gravatar_id":"","url":"https://api.github.com/users/Aaron1011","html_url":"https://github.com/Aaron1011","followers_url":"https://api.github.com/users/Aaron1011/followers","following_url":"https://api.github.com/users/Aaron1011/following{/other_user}","gists_url":"https://api.github.com/users/Aaron1011/gists{/gist_id}","starred_url":"https://api.github.com/users/Aaron1011/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Aaron1011/subscriptions","organizations_url":"https://api.github.com/users/Aaron1011/orgs","repos_url":"https://api.github.com/users/Aaron1011/repos","events_url":"https://api.github.com/users/Aaron1011/events{/privacy}","received_events_url":"https://api.github.com/users/Aaron1011/received_events","type":"User","site_admin":false},"html_url":"https://github.com/Aaron1011/rustc-guide","description":"A guide to how rustc works and how to contribute to it.","fork":true,"url":"https://api.github.com/repos/Aaron1011/rustc-guide","forks_url":"https://api.github.com/repos/Aaron1011/rustc-guide/forks","keys_url":"https://api.github.com/repos/Aaron1011/rustc-guide/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Aaron1011/rustc-guide/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Aaron1011/rustc-guide/teams","hooks_url":"https://api.github.com/repos/Aaron1011/rustc-guide/hooks","issue_events_url":"https://api.github.com/repos/Aaron1011/rustc-guide/issues/events{/number}","events_url":"https://api.github.com/repos/Aaron1011/rustc-guide/events","assignees_url":"https://api.github.com/repos/Aaron1011/rustc-guide/assignees{/user}","branches_url":"https://api.github.com/repos/Aaron1011/rustc-guide/branches{/branch}","tags_url":"https://api.github.com/repos/Aaron1011/rustc-guide/tags","blobs_url":"https://api.github.com/repos/Aaron1011/rustc-guide/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Aaron1011/rustc-guide/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Aaron1011/rustc-guide/git/refs{/sha}","trees_url":"https://api.github.com/repos/Aaron1011/rustc-guide/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Aaron1011/rustc-guide/statuses/{sha}","languages_url":"https://api.github.com/repos/Aaron1011/rustc-guide/languages","stargazers_url":"https://api.github.com/repos/Aaron1011/rustc-guide/stargazers","contributors_url":"https://api.github.com/repos/Aaron1011/rustc-guide/contributors","subscribers_url":"https://api.github.com/repos/Aaron1011/rustc-guide/subscribers","subscription_url":"https://api.github.com/repos/Aaron1011/rustc-guide/subscription","commits_url":"https://api.github.com/repos/Aaron1011/rustc-guide/commits{/sha}","git_commits_url":"https://api.github.com/repos/Aaron1011/rustc-guide/git/commits{/sha}","comments_url":"https://api.github.com/repos/Aaron1011/rustc-guide/comments{/number}","issue_comment_url":"https://api.github.com/repos/Aaron1011/rustc-guide/issues/comments{/number}","contents_url":"https://api.github.com/repos/Aaron1011/rustc-guide/contents/{+path}","compare_url":"https://api.github.com/repos/Aaron1011/rustc-guide/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Aaron1011/rustc-guide/merges","archive_url":"https://api.github.com/repos/Aaron1011/rustc-guide/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Aaron1011/rustc-guide/downloads","issues_url":"https://api.github.com/repos/Aaron1011/rustc-guide/issues{/number}","pulls_url":"https://api.github.com/repos/Aaron1011/rustc-guide/pulls{/number}","milestones_url":"https://api.github.com/repos/Aaron1011/rustc-guide/milestones{/number}","notifications_url":"https://api.github.com/repos/Aaron1011/rustc-guide/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Aaron1011/rustc-guide/labels{/name}","releases_url":"https://api.github.com/repos/Aaron1011/rustc-guide/releases{/id}","deployments_url":"https://api.github.com/repos/Aaron1011/rustc-guide/deployments","created_at":"2019-11-22T21:14:14Z","updated_at":"2019-11-22T21:14:16Z","pushed_at":"2019-12-07T04:50:07Z","git_url":"git://github.com/Aaron1011/rustc-guide.git","ssh_url":"git@github.com:Aaron1011/rustc-guide.git","clone_url":"https://github.com/Aaron1011/rustc-guide.git","svn_url":"https://github.com/Aaron1011/rustc-guide","homepage":"https://rust-lang.github.io/rustc-guide/","size":2650,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rust-lang:master","ref":"master","sha":"7c56708aab7986ca390221e8e8902f7de7f9b076","user":{"login":"rust-lang","id":5430905,"node_id":"MDEyOk9yZ2FuaXphdGlvbjU0MzA5MDU=","avatar_url":"https://avatars1.githubusercontent.com/u/5430905?v=4","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"repo":{"id":117744230,"node_id":"MDEwOlJlcG9zaXRvcnkxMTc3NDQyMzA=","name":"rustc-guide","full_name":"rust-lang/rustc-guide","private":false,"owner":{"login":"rust-lang","id":5430905,"node_id":"MDEyOk9yZ2FuaXphdGlvbjU0MzA5MDU=","avatar_url":"https://avatars1.githubusercontent.com/u/5430905?v=4","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/rust-lang/rustc-guide","description":"A guide to how rustc works and how to contribute to it.","fork":false,"url":"https://api.github.com/repos/rust-lang/rustc-guide","forks_url":"https://api.github.com/repos/rust-lang/rustc-guide/forks","keys_url":"https://api.github.com/repos/rust-lang/rustc-guide/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rust-lang/rustc-guide/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rust-lang/rustc-guide/teams","hooks_url":"https://api.github.com/repos/rust-lang/rustc-guide/hooks","issue_events_url":"https://api.github.com/repos/rust-lang/rustc-guide/issues/events{/number}","events_url":"https://api.github.com/repos/rust-lang/rustc-guide/events","assignees_url":"https://api.github.com/repos/rust-lang/rustc-guide/assignees{/user}","branches_url":"https://api.github.com/repos/rust-lang/rustc-guide/branches{/branch}","tags_url":"https://api.github.com/repos/rust-lang/rustc-guide/tags","blobs_url":"https://api.github.com/repos/rust-lang/rustc-guide/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rust-lang/rustc-guide/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rust-lang/rustc-guide/git/refs{/sha}","trees_url":"https://api.github.com/repos/rust-lang/rustc-guide/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rust-lang/rustc-guide/statuses/{sha}","languages_url":"https://api.github.com/repos/rust-lang/rustc-guide/languages","stargazers_url":"https://api.github.com/repos/rust-lang/rustc-guide/stargazers","contributors_url":"https://api.github.com/repos/rust-lang/rustc-guide/contributors","subscribers_url":"https://api.github.com/repos/rust-lang/rustc-guide/subscribers","subscription_url":"https://api.github.com/repos/rust-lang/rustc-guide/subscription","commits_url":"https://api.github.com/repos/rust-lang/rustc-guide/commits{/sha}","git_commits_url":"https://api.github.com/repos/rust-lang/rustc-guide/git/commits{/sha}","comments_url":"https://api.github.com/repos/rust-lang/rustc-guide/comments{/number}","issue_comment_url":"https://api.github.com/repos/rust-lang/rustc-guide/issues/comments{/number}","contents_url":"https://api.github.com/repos/rust-lang/rustc-guide/contents/{+path}","compare_url":"https://api.github.com/repos/rust-lang/rustc-guide/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rust-lang/rustc-guide/merges","archive_url":"https://api.github.com/repos/rust-lang/rustc-guide/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rust-lang/rustc-guide/downloads","issues_url":"https://api.github.com/repos/rust-lang/rustc-guide/issues{/number}","pulls_url":"https://api.github.com/repos/rust-lang/rustc-guide/pulls{/number}","milestones_url":"https://api.github.com/repos/rust-lang/rustc-guide/milestones{/number}","notifications_url":"https://api.github.com/repos/rust-lang/rustc-guide/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rust-lang/rustc-guide/labels{/name}","releases_url":"https://api.github.com/repos/rust-lang/rustc-guide/releases{/id}","deployments_url":"https://api.github.com/repos/rust-lang/rustc-guide/deployments","created_at":"2018-01-16T21:26:54Z","updated_at":"2019-12-29T07:15:31Z","pushed_at":"2019-12-28T23:03:48Z","git_url":"git://github.com/rust-lang/rustc-guide.git","ssh_url":"git@github.com:rust-lang/rustc-guide.git","clone_url":"https://github.com/rust-lang/rustc-guide.git","svn_url":"https://github.com/rust-lang/rustc-guide","homepage":"https://rust-lang.github.io/rustc-guide/","size":3034,"stargazers_count":507,"watchers_count":507,"language":"HTML","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":135,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":86,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":135,"open_issues":86,"watchers":507,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rustc-guide/pulls/521"},"html":{"href":"https://github.com/rust-lang/rustc-guide/pull/521"},"issue":{"href":"https://api.github.com/repos/rust-lang/rustc-guide/issues/521"},"comments":{"href":"https://api.github.com/repos/rust-lang/rustc-guide/issues/521/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang/rustc-guide/pulls/521/comments"},"review_comment":{"href":"https://api.github.com/repos/rust-lang/rustc-guide/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rust-lang/rustc-guide/pulls/521/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang/rustc-guide/statuses/9f25a0209d51a84e883ba0e0d11d47b4d6b9ec96"}},"author_association":"NONE"}}
{"actor":{"display_login":"JohnTitor"}}