{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments/33909503","id":33909503,"diff_hunk":"@@ -0,0 +1,81 @@\n+- Feature Name: N/A\n+- Start Date: 2015-07-06\n+- RFC PR: (leave this empty)\n+- Rust Issue: (leave this empty)\n+\n+\n+# Summary\n+\n+Add a high-level intermediate representation (HIR) to the compiler. This is\n+basically a new (and additional) AST more suited for use by the compiler.\n+\n+This is purely an implementation detail of the compiler. It has no effect on the\n+language.\n+\n+Note that adding a HIR does not preclude adding a MIR or LIR in the future.\n+\n+\n+# Motivation\n+\n+Currently the AST is used by libsyntax for syntactic operations, by the compiler\n+for pretty much everything, and in syntax extensions. I propose splitting the\n+AST into a libsyntax version that is specialised for syntactic operation and\n+will eventually be stabilised for use by syntax extensions and tools, and the\n+HIR which is entirely internal to the compiler.\n+\n+The benefit of this split is that each AST can be specialised to its task and we\n+can separate the interface to the compiler (the AST) from its implementation\n+(the HIR). Specific changes I see that could happen are more ids and spans in\n+the AST, the AST adhering more closely to the surface syntax, the HIR becoming\n+more abstract (e.g., combining structs and enums), and using resolved names in\n+the HIR (i.e., performing name resolution as part of the AST->HIR lowering).\n+\n+Not using the AST in the compiler means we can work to stabilise it for syntax\n+extensions and tools: it will become part of the interface to the compiler.\n+\n+I also envisage all syntactic expansion of language constructs (e.g., `for`\n+loops, `if let`) moving to the lowering step from AST to HIR, rather than being\n+AST manipulations. That should make both error messages and tool support better\n+for such constructs. It would be nice to move lifetime elision to the lowering\n+step too, in order to make the HIR as explicit as possible.\n+\n+\n+# Detailed design\n+\n+Initially, the HIR will be an (almost) identical copy of the AST and the\n+lowering step will simply be a copy operation. Since some constructs (macros,\n+`for` loops, etc.) are expanded away in libsyntax, these will not be part of the\n+HIR. Tools such as the AST visitor will need to be duplicated.\n+\n+The compiler will be changed to use the HIR throughout (this should mostly be a\n+matter of change the imports). Incrementally, I expect to move expansion of\n+language constructs to the lowering step. Further in the future, the HIR should\n+get more abstract and compact, and the AST should get closer to the surface\n+syntax.\n+","path":"text/0000-hir.md","position":55,"original_position":55,"commit_id":"f03c50b9e86288cd1627ac134e2d908926d42eea","original_commit_id":"f03c50b9e86288cd1627ac134e2d908926d42eea","user":{"login":"oli-obk","id":332036,"avatar_url":"https://avatars.githubusercontent.com/u/332036?v=3","gravatar_id":"","url":"https://api.github.com/users/oli-obk","html_url":"https://github.com/oli-obk","followers_url":"https://api.github.com/users/oli-obk/followers","following_url":"https://api.github.com/users/oli-obk/following{/other_user}","gists_url":"https://api.github.com/users/oli-obk/gists{/gist_id}","starred_url":"https://api.github.com/users/oli-obk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oli-obk/subscriptions","organizations_url":"https://api.github.com/users/oli-obk/orgs","repos_url":"https://api.github.com/users/oli-obk/repos","events_url":"https://api.github.com/users/oli-obk/events{/privacy}","received_events_url":"https://api.github.com/users/oli-obk/received_events","type":"User","site_admin":false},"body":"This RFC needs a kind of road-map of steps that need to be done (and each step should get an issue). It's too general right now.\r\n\r\n1. copy the AST to HIR after all AST transforms have been applied and have all other passes operate on the HIR\r\n2. remove some ast transforms\r\n  * [ ] remove `if let` ast transform and apply it during the AST -> HIR step\r\n  * [ ] remove `while let` ast transform and apply it during the AST -> HIR step\r\n  * [ ] remove `for` ast transform and apply it during the AST -> HIR step\r\n  * [ ] cfg-attribute application step?\r\n  * [ ] erase all unresolved names from HIR and resolve names in the AST -> HIR step\r\n  * [ ] elide lifetimes in the AST -> HIR step and erase unresolved lifetimes from the HIR\r\n3. things that can be moved from tables to HIR\r\n  * i have no clue ;)","created_at":"2015-07-06T06:55:50Z","updated_at":"2015-07-06T06:55:50Z","html_url":"https://github.com/rust-lang/rfcs/pull/1191#discussion_r33909503","pull_request_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/1191","_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments/33909503"},"html":{"href":"https://github.com/rust-lang/rfcs/pull/1191#discussion_r33909503"},"pull_request":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/1191"}}},"pull_request":{"url":"https://api.github.com/repos/rust-lang/rfcs/pulls/1191","id":39235352,"html_url":"https://github.com/rust-lang/rfcs/pull/1191","diff_url":"https://github.com/rust-lang/rfcs/pull/1191.diff","patch_url":"https://github.com/rust-lang/rfcs/pull/1191.patch","issue_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1191","number":1191,"state":"open","locked":false,"title":"Add a HIR to the compiler","user":{"login":"nrc","id":762626,"avatar_url":"https://avatars.githubusercontent.com/u/762626?v=3","gravatar_id":"","url":"https://api.github.com/users/nrc","html_url":"https://github.com/nrc","followers_url":"https://api.github.com/users/nrc/followers","following_url":"https://api.github.com/users/nrc/following{/other_user}","gists_url":"https://api.github.com/users/nrc/gists{/gist_id}","starred_url":"https://api.github.com/users/nrc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nrc/subscriptions","organizations_url":"https://api.github.com/users/nrc/orgs","repos_url":"https://api.github.com/users/nrc/repos","events_url":"https://api.github.com/users/nrc/events{/privacy}","received_events_url":"https://api.github.com/users/nrc/received_events","type":"User","site_admin":false},"body":"Add a high-level intermediate representation (HIR) to the compiler. This is\r\nbasically a new (and additional) AST more suited for use by the compiler.\r\n\r\nThis is purely an implementation detail of the compiler. It has no effect on the\r\nlanguage.\r\n\r\nNote that adding a HIR does not preclude adding a MIR or LIR in the future.","created_at":"2015-07-06T04:27:15Z","updated_at":"2015-07-06T06:55:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1b9cbe2021e86667a66d23cd993c6d15d0720b4f","assignee":{"login":"nrc","id":762626,"avatar_url":"https://avatars.githubusercontent.com/u/762626?v=3","gravatar_id":"","url":"https://api.github.com/users/nrc","html_url":"https://github.com/nrc","followers_url":"https://api.github.com/users/nrc/followers","following_url":"https://api.github.com/users/nrc/following{/other_user}","gists_url":"https://api.github.com/users/nrc/gists{/gist_id}","starred_url":"https://api.github.com/users/nrc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nrc/subscriptions","organizations_url":"https://api.github.com/users/nrc/orgs","repos_url":"https://api.github.com/users/nrc/repos","events_url":"https://api.github.com/users/nrc/events{/privacy}","received_events_url":"https://api.github.com/users/nrc/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/1191/commits","review_comments_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/1191/comments","review_comment_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1191/comments","statuses_url":"https://api.github.com/repos/rust-lang/rfcs/statuses/f03c50b9e86288cd1627ac134e2d908926d42eea","head":{"label":"nrc:hir","ref":"hir","sha":"f03c50b9e86288cd1627ac134e2d908926d42eea","user":{"login":"nrc","id":762626,"avatar_url":"https://avatars.githubusercontent.com/u/762626?v=3","gravatar_id":"","url":"https://api.github.com/users/nrc","html_url":"https://github.com/nrc","followers_url":"https://api.github.com/users/nrc/followers","following_url":"https://api.github.com/users/nrc/following{/other_user}","gists_url":"https://api.github.com/users/nrc/gists{/gist_id}","starred_url":"https://api.github.com/users/nrc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nrc/subscriptions","organizations_url":"https://api.github.com/users/nrc/orgs","repos_url":"https://api.github.com/users/nrc/repos","events_url":"https://api.github.com/users/nrc/events{/privacy}","received_events_url":"https://api.github.com/users/nrc/received_events","type":"User","site_admin":false},"repo":{"id":17579664,"name":"rfcs","full_name":"nrc/rfcs","owner":{"login":"nrc","id":762626,"avatar_url":"https://avatars.githubusercontent.com/u/762626?v=3","gravatar_id":"","url":"https://api.github.com/users/nrc","html_url":"https://github.com/nrc","followers_url":"https://api.github.com/users/nrc/followers","following_url":"https://api.github.com/users/nrc/following{/other_user}","gists_url":"https://api.github.com/users/nrc/gists{/gist_id}","starred_url":"https://api.github.com/users/nrc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nrc/subscriptions","organizations_url":"https://api.github.com/users/nrc/orgs","repos_url":"https://api.github.com/users/nrc/repos","events_url":"https://api.github.com/users/nrc/events{/privacy}","received_events_url":"https://api.github.com/users/nrc/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nrc/rfcs","description":"RFCs for changes to Rust","fork":true,"url":"https://api.github.com/repos/nrc/rfcs","forks_url":"https://api.github.com/repos/nrc/rfcs/forks","keys_url":"https://api.github.com/repos/nrc/rfcs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nrc/rfcs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nrc/rfcs/teams","hooks_url":"https://api.github.com/repos/nrc/rfcs/hooks","issue_events_url":"https://api.github.com/repos/nrc/rfcs/issues/events{/number}","events_url":"https://api.github.com/repos/nrc/rfcs/events","assignees_url":"https://api.github.com/repos/nrc/rfcs/assignees{/user}","branches_url":"https://api.github.com/repos/nrc/rfcs/branches{/branch}","tags_url":"https://api.github.com/repos/nrc/rfcs/tags","blobs_url":"https://api.github.com/repos/nrc/rfcs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nrc/rfcs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nrc/rfcs/git/refs{/sha}","trees_url":"https://api.github.com/repos/nrc/rfcs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nrc/rfcs/statuses/{sha}","languages_url":"https://api.github.com/repos/nrc/rfcs/languages","stargazers_url":"https://api.github.com/repos/nrc/rfcs/stargazers","contributors_url":"https://api.github.com/repos/nrc/rfcs/contributors","subscribers_url":"https://api.github.com/repos/nrc/rfcs/subscribers","subscription_url":"https://api.github.com/repos/nrc/rfcs/subscription","commits_url":"https://api.github.com/repos/nrc/rfcs/commits{/sha}","git_commits_url":"https://api.github.com/repos/nrc/rfcs/git/commits{/sha}","comments_url":"https://api.github.com/repos/nrc/rfcs/comments{/number}","issue_comment_url":"https://api.github.com/repos/nrc/rfcs/issues/comments{/number}","contents_url":"https://api.github.com/repos/nrc/rfcs/contents/{+path}","compare_url":"https://api.github.com/repos/nrc/rfcs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nrc/rfcs/merges","archive_url":"https://api.github.com/repos/nrc/rfcs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nrc/rfcs/downloads","issues_url":"https://api.github.com/repos/nrc/rfcs/issues{/number}","pulls_url":"https://api.github.com/repos/nrc/rfcs/pulls{/number}","milestones_url":"https://api.github.com/repos/nrc/rfcs/milestones{/number}","notifications_url":"https://api.github.com/repos/nrc/rfcs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nrc/rfcs/labels{/name}","releases_url":"https://api.github.com/repos/nrc/rfcs/releases{/id}","created_at":"2014-03-10T02:38:22Z","updated_at":"2014-11-18T22:47:20Z","pushed_at":"2015-07-06T04:26:34Z","git_url":"git://github.com/nrc/rfcs.git","ssh_url":"git@github.com:nrc/rfcs.git","clone_url":"https://github.com/nrc/rfcs.git","svn_url":"https://github.com/nrc/rfcs","homepage":"","size":2218,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rust-lang:master","ref":"master","sha":"03b6bc754631eff13a032745787fa2a5bb861758","user":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","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":17527989,"name":"rfcs","full_name":"rust-lang/rfcs","owner":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","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},"private":false,"html_url":"https://github.com/rust-lang/rfcs","description":"RFCs for changes to Rust","fork":false,"url":"https://api.github.com/repos/rust-lang/rfcs","forks_url":"https://api.github.com/repos/rust-lang/rfcs/forks","keys_url":"https://api.github.com/repos/rust-lang/rfcs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rust-lang/rfcs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rust-lang/rfcs/teams","hooks_url":"https://api.github.com/repos/rust-lang/rfcs/hooks","issue_events_url":"https://api.github.com/repos/rust-lang/rfcs/issues/events{/number}","events_url":"https://api.github.com/repos/rust-lang/rfcs/events","assignees_url":"https://api.github.com/repos/rust-lang/rfcs/assignees{/user}","branches_url":"https://api.github.com/repos/rust-lang/rfcs/branches{/branch}","tags_url":"https://api.github.com/repos/rust-lang/rfcs/tags","blobs_url":"https://api.github.com/repos/rust-lang/rfcs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rust-lang/rfcs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rust-lang/rfcs/git/refs{/sha}","trees_url":"https://api.github.com/repos/rust-lang/rfcs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rust-lang/rfcs/statuses/{sha}","languages_url":"https://api.github.com/repos/rust-lang/rfcs/languages","stargazers_url":"https://api.github.com/repos/rust-lang/rfcs/stargazers","contributors_url":"https://api.github.com/repos/rust-lang/rfcs/contributors","subscribers_url":"https://api.github.com/repos/rust-lang/rfcs/subscribers","subscription_url":"https://api.github.com/repos/rust-lang/rfcs/subscription","commits_url":"https://api.github.com/repos/rust-lang/rfcs/commits{/sha}","git_commits_url":"https://api.github.com/repos/rust-lang/rfcs/git/commits{/sha}","comments_url":"https://api.github.com/repos/rust-lang/rfcs/comments{/number}","issue_comment_url":"https://api.github.com/repos/rust-lang/rfcs/issues/comments{/number}","contents_url":"https://api.github.com/repos/rust-lang/rfcs/contents/{+path}","compare_url":"https://api.github.com/repos/rust-lang/rfcs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rust-lang/rfcs/merges","archive_url":"https://api.github.com/repos/rust-lang/rfcs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rust-lang/rfcs/downloads","issues_url":"https://api.github.com/repos/rust-lang/rfcs/issues{/number}","pulls_url":"https://api.github.com/repos/rust-lang/rfcs/pulls{/number}","milestones_url":"https://api.github.com/repos/rust-lang/rfcs/milestones{/number}","notifications_url":"https://api.github.com/repos/rust-lang/rfcs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rust-lang/rfcs/labels{/name}","releases_url":"https://api.github.com/repos/rust-lang/rfcs/releases{/id}","created_at":"2014-03-07T21:29:00Z","updated_at":"2015-07-05T23:39:41Z","pushed_at":"2015-07-06T04:27:15Z","git_url":"git://github.com/rust-lang/rfcs.git","ssh_url":"git@github.com:rust-lang/rfcs.git","clone_url":"https://github.com/rust-lang/rfcs.git","svn_url":"https://github.com/rust-lang/rfcs","homepage":"","size":10837,"stargazers_count":400,"watchers_count":400,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":213,"mirror_url":null,"open_issues_count":524,"forks":213,"open_issues":524,"watchers":400,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/1191"},"html":{"href":"https://github.com/rust-lang/rfcs/pull/1191"},"issue":{"href":"https://api.github.com/repos/rust-lang/rfcs/issues/1191"},"comments":{"href":"https://api.github.com/repos/rust-lang/rfcs/issues/1191/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/1191/comments"},"review_comment":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/1191/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang/rfcs/statuses/f03c50b9e86288cd1627ac134e2d908926d42eea"}}}}