{"action":"created","comment":{"url":"https://api.github.com/repos/shader-slang/slang/pulls/comments/150939325","pull_request_review_id":76566595,"id":150939325,"diff_hunk":"@@ -0,0 +1,8 @@\n+10","path":"tests/compute/switch-stmt.slang.1.expected.txt","position":1,"original_position":1,"commit_id":"7fddac35c8593bb37b8485f363c3929637db8ab4","original_commit_id":"7fddac35c8593bb37b8485f363c3929637db8ab4","user":{"login":"tfoleyNV","id":10618364,"avatar_url":"https://avatars2.githubusercontent.com/u/10618364?v=4","gravatar_id":"","url":"https://api.github.com/users/tfoleyNV","html_url":"https://github.com/tfoleyNV","followers_url":"https://api.github.com/users/tfoleyNV/followers","following_url":"https://api.github.com/users/tfoleyNV/following{/other_user}","gists_url":"https://api.github.com/users/tfoleyNV/gists{/gist_id}","starred_url":"https://api.github.com/users/tfoleyNV/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tfoleyNV/subscriptions","organizations_url":"https://api.github.com/users/tfoleyNV/orgs","repos_url":"https://api.github.com/users/tfoleyNV/repos","events_url":"https://api.github.com/users/tfoleyNV/events{/privacy}","received_events_url":"https://api.github.com/users/tfoleyNV/received_events","type":"User","site_admin":false},"body":"If a test file has multiple `//TEST:...` lines, then we will use the same file to run multiple tests, where the \"output stem\" will take the form `name`, then `name.1`, then `name.2`, etc.\r\n\r\nSo this file is the expected output for the second `//TEST:...` line in `switch-stmt.slang`.","created_at":"2017-11-14T19:33:31Z","updated_at":"2017-11-14T19:33:32Z","html_url":"https://github.com/shader-slang/slang/pull/278#discussion_r150939325","pull_request_url":"https://api.github.com/repos/shader-slang/slang/pulls/278","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/shader-slang/slang/pulls/comments/150939325"},"html":{"href":"https://github.com/shader-slang/slang/pull/278#discussion_r150939325"},"pull_request":{"href":"https://api.github.com/repos/shader-slang/slang/pulls/278"}},"in_reply_to_id":150937175},"pull_request":{"url":"https://api.github.com/repos/shader-slang/slang/pulls/278","id":152583745,"html_url":"https://github.com/shader-slang/slang/pull/278","diff_url":"https://github.com/shader-slang/slang/pull/278.diff","patch_url":"https://github.com/shader-slang/slang/pull/278.patch","issue_url":"https://api.github.com/repos/shader-slang/slang/issues/278","number":278,"state":"open","locked":false,"title":"IR: add support for `switch` statements","user":{"login":"tfoleyNV","id":10618364,"avatar_url":"https://avatars2.githubusercontent.com/u/10618364?v=4","gravatar_id":"","url":"https://api.github.com/users/tfoleyNV","html_url":"https://github.com/tfoleyNV","followers_url":"https://api.github.com/users/tfoleyNV/followers","following_url":"https://api.github.com/users/tfoleyNV/following{/other_user}","gists_url":"https://api.github.com/users/tfoleyNV/gists{/gist_id}","starred_url":"https://api.github.com/users/tfoleyNV/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tfoleyNV/subscriptions","organizations_url":"https://api.github.com/users/tfoleyNV/orgs","repos_url":"https://api.github.com/users/tfoleyNV/repos","events_url":"https://api.github.com/users/tfoleyNV/events{/privacy}","received_events_url":"https://api.github.com/users/tfoleyNV/received_events","type":"User","site_admin":false},"body":"Fixes #273\r\n\r\nThis is just something we hadn't gotten to yet on the IR. The actual design of the instruction is unsurprising (once you take into consideration the requirement for structured control flow). A `switch` instruction takes the form:\r\n\r\n    switch <condition> <breakLabel> <defaultLabel> [<caseVal> <caseLabel>]*\r\n\r\nWhere `condition` is the value to switch on, `breakLabel` is the \"join point\" after the original `switch` statement, `defaultLabel` is where to go if the value doesn't match any case, and each pair of `caseVal` and `caseLabel` is what to do on a particular value. It is required that `caseVal` be a literal, but this isn't currently being enforced in the IR (the front-end should be making a check and constant-folding the case labels).\r\n\r\nFor structured control flow, we also make the assumption that the cases are in order: cases with the same label must be grouped together, and any case that falls through to another must come right before it.\r\n\r\nGiven this representation, the emit logic can reconstruct a `switch` statement with relative ease, given the machinery we already have. It makes sure to group together case values with the same label (again, assuming they are contiguous), and will insert the `default:` label in with whatever group it belongs to.\r\n\r\nActually emitting code for a `switch` statement seems superficially simple, until you realize that a complete implementation needs to handle stuff like \"Duff's Device.\" The current implementation makes the assumption that all `case` and `default` statements are directly nested under a `switch`, and that there is no way for control flow to enter a case except by the `switch` itself, or fall-through.\r\n\r\nIn order to facilitate the grouping of cases in the IR-to-HLSL emit logic, the AST-to-IR lowering logic tries to detect cases where there are multiple `case`s in a row, and emit only a single label for them.\r\n\r\nOne big/annoying gotcha is that we don't properly handle the case where a `default:` case has a non-trivial fall-throguh to another case. That seems fine for now since HLSL doesn't support fall-through anyway, but it probably needs to get detected somewhere in the Slang compiler (e.g., maybe we should add a diagnostic pass over the IR that detects target-specific problems like that and emits errors).","created_at":"2017-11-14T18:34:58Z","updated_at":"2017-11-14T19:33:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5cfe265823b7151edf0917fd0f0cb708d899ebf8","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/shader-slang/slang/pulls/278/commits","review_comments_url":"https://api.github.com/repos/shader-slang/slang/pulls/278/comments","review_comment_url":"https://api.github.com/repos/shader-slang/slang/pulls/comments{/number}","comments_url":"https://api.github.com/repos/shader-slang/slang/issues/278/comments","statuses_url":"https://api.github.com/repos/shader-slang/slang/statuses/7fddac35c8593bb37b8485f363c3929637db8ab4","head":{"label":"tfoleyNV:ir-switch-stmt","ref":"ir-switch-stmt","sha":"7fddac35c8593bb37b8485f363c3929637db8ab4","user":{"login":"tfoleyNV","id":10618364,"avatar_url":"https://avatars2.githubusercontent.com/u/10618364?v=4","gravatar_id":"","url":"https://api.github.com/users/tfoleyNV","html_url":"https://github.com/tfoleyNV","followers_url":"https://api.github.com/users/tfoleyNV/followers","following_url":"https://api.github.com/users/tfoleyNV/following{/other_user}","gists_url":"https://api.github.com/users/tfoleyNV/gists{/gist_id}","starred_url":"https://api.github.com/users/tfoleyNV/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tfoleyNV/subscriptions","organizations_url":"https://api.github.com/users/tfoleyNV/orgs","repos_url":"https://api.github.com/users/tfoleyNV/repos","events_url":"https://api.github.com/users/tfoleyNV/events{/privacy}","received_events_url":"https://api.github.com/users/tfoleyNV/received_events","type":"User","site_admin":false},"repo":{"id":94112578,"name":"slang","full_name":"tfoleyNV/slang","owner":{"login":"tfoleyNV","id":10618364,"avatar_url":"https://avatars2.githubusercontent.com/u/10618364?v=4","gravatar_id":"","url":"https://api.github.com/users/tfoleyNV","html_url":"https://github.com/tfoleyNV","followers_url":"https://api.github.com/users/tfoleyNV/followers","following_url":"https://api.github.com/users/tfoleyNV/following{/other_user}","gists_url":"https://api.github.com/users/tfoleyNV/gists{/gist_id}","starred_url":"https://api.github.com/users/tfoleyNV/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tfoleyNV/subscriptions","organizations_url":"https://api.github.com/users/tfoleyNV/orgs","repos_url":"https://api.github.com/users/tfoleyNV/repos","events_url":"https://api.github.com/users/tfoleyNV/events{/privacy}","received_events_url":"https://api.github.com/users/tfoleyNV/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tfoleyNV/slang","description":"Making it easier to work with shaders","fork":true,"url":"https://api.github.com/repos/tfoleyNV/slang","forks_url":"https://api.github.com/repos/tfoleyNV/slang/forks","keys_url":"https://api.github.com/repos/tfoleyNV/slang/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tfoleyNV/slang/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tfoleyNV/slang/teams","hooks_url":"https://api.github.com/repos/tfoleyNV/slang/hooks","issue_events_url":"https://api.github.com/repos/tfoleyNV/slang/issues/events{/number}","events_url":"https://api.github.com/repos/tfoleyNV/slang/events","assignees_url":"https://api.github.com/repos/tfoleyNV/slang/assignees{/user}","branches_url":"https://api.github.com/repos/tfoleyNV/slang/branches{/branch}","tags_url":"https://api.github.com/repos/tfoleyNV/slang/tags","blobs_url":"https://api.github.com/repos/tfoleyNV/slang/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tfoleyNV/slang/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tfoleyNV/slang/git/refs{/sha}","trees_url":"https://api.github.com/repos/tfoleyNV/slang/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tfoleyNV/slang/statuses/{sha}","languages_url":"https://api.github.com/repos/tfoleyNV/slang/languages","stargazers_url":"https://api.github.com/repos/tfoleyNV/slang/stargazers","contributors_url":"https://api.github.com/repos/tfoleyNV/slang/contributors","subscribers_url":"https://api.github.com/repos/tfoleyNV/slang/subscribers","subscription_url":"https://api.github.com/repos/tfoleyNV/slang/subscription","commits_url":"https://api.github.com/repos/tfoleyNV/slang/commits{/sha}","git_commits_url":"https://api.github.com/repos/tfoleyNV/slang/git/commits{/sha}","comments_url":"https://api.github.com/repos/tfoleyNV/slang/comments{/number}","issue_comment_url":"https://api.github.com/repos/tfoleyNV/slang/issues/comments{/number}","contents_url":"https://api.github.com/repos/tfoleyNV/slang/contents/{+path}","compare_url":"https://api.github.com/repos/tfoleyNV/slang/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tfoleyNV/slang/merges","archive_url":"https://api.github.com/repos/tfoleyNV/slang/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tfoleyNV/slang/downloads","issues_url":"https://api.github.com/repos/tfoleyNV/slang/issues{/number}","pulls_url":"https://api.github.com/repos/tfoleyNV/slang/pulls{/number}","milestones_url":"https://api.github.com/repos/tfoleyNV/slang/milestones{/number}","notifications_url":"https://api.github.com/repos/tfoleyNV/slang/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tfoleyNV/slang/labels{/name}","releases_url":"https://api.github.com/repos/tfoleyNV/slang/releases{/id}","deployments_url":"https://api.github.com/repos/tfoleyNV/slang/deployments","created_at":"2017-06-12T15:36:58Z","updated_at":"2017-06-12T15:37:01Z","pushed_at":"2017-11-14T18:58:11Z","git_url":"git://github.com/tfoleyNV/slang.git","ssh_url":"git@github.com:tfoleyNV/slang.git","clone_url":"https://github.com/tfoleyNV/slang.git","svn_url":"https://github.com/tfoleyNV/slang","homepage":null,"size":2954,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"shader-slang:master","ref":"master","sha":"7c4ad877dcd353b9431011f0fc98aad315366c6c","user":{"login":"shader-slang","id":29205606,"avatar_url":"https://avatars1.githubusercontent.com/u/29205606?v=4","gravatar_id":"","url":"https://api.github.com/users/shader-slang","html_url":"https://github.com/shader-slang","followers_url":"https://api.github.com/users/shader-slang/followers","following_url":"https://api.github.com/users/shader-slang/following{/other_user}","gists_url":"https://api.github.com/users/shader-slang/gists{/gist_id}","starred_url":"https://api.github.com/users/shader-slang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shader-slang/subscriptions","organizations_url":"https://api.github.com/users/shader-slang/orgs","repos_url":"https://api.github.com/users/shader-slang/repos","events_url":"https://api.github.com/users/shader-slang/events{/privacy}","received_events_url":"https://api.github.com/users/shader-slang/received_events","type":"Organization","site_admin":false},"repo":{"id":93882897,"name":"slang","full_name":"shader-slang/slang","owner":{"login":"shader-slang","id":29205606,"avatar_url":"https://avatars1.githubusercontent.com/u/29205606?v=4","gravatar_id":"","url":"https://api.github.com/users/shader-slang","html_url":"https://github.com/shader-slang","followers_url":"https://api.github.com/users/shader-slang/followers","following_url":"https://api.github.com/users/shader-slang/following{/other_user}","gists_url":"https://api.github.com/users/shader-slang/gists{/gist_id}","starred_url":"https://api.github.com/users/shader-slang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shader-slang/subscriptions","organizations_url":"https://api.github.com/users/shader-slang/orgs","repos_url":"https://api.github.com/users/shader-slang/repos","events_url":"https://api.github.com/users/shader-slang/events{/privacy}","received_events_url":"https://api.github.com/users/shader-slang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/shader-slang/slang","description":"Making it easier to work with shaders","fork":false,"url":"https://api.github.com/repos/shader-slang/slang","forks_url":"https://api.github.com/repos/shader-slang/slang/forks","keys_url":"https://api.github.com/repos/shader-slang/slang/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shader-slang/slang/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shader-slang/slang/teams","hooks_url":"https://api.github.com/repos/shader-slang/slang/hooks","issue_events_url":"https://api.github.com/repos/shader-slang/slang/issues/events{/number}","events_url":"https://api.github.com/repos/shader-slang/slang/events","assignees_url":"https://api.github.com/repos/shader-slang/slang/assignees{/user}","branches_url":"https://api.github.com/repos/shader-slang/slang/branches{/branch}","tags_url":"https://api.github.com/repos/shader-slang/slang/tags","blobs_url":"https://api.github.com/repos/shader-slang/slang/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shader-slang/slang/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shader-slang/slang/git/refs{/sha}","trees_url":"https://api.github.com/repos/shader-slang/slang/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shader-slang/slang/statuses/{sha}","languages_url":"https://api.github.com/repos/shader-slang/slang/languages","stargazers_url":"https://api.github.com/repos/shader-slang/slang/stargazers","contributors_url":"https://api.github.com/repos/shader-slang/slang/contributors","subscribers_url":"https://api.github.com/repos/shader-slang/slang/subscribers","subscription_url":"https://api.github.com/repos/shader-slang/slang/subscription","commits_url":"https://api.github.com/repos/shader-slang/slang/commits{/sha}","git_commits_url":"https://api.github.com/repos/shader-slang/slang/git/commits{/sha}","comments_url":"https://api.github.com/repos/shader-slang/slang/comments{/number}","issue_comment_url":"https://api.github.com/repos/shader-slang/slang/issues/comments{/number}","contents_url":"https://api.github.com/repos/shader-slang/slang/contents/{+path}","compare_url":"https://api.github.com/repos/shader-slang/slang/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shader-slang/slang/merges","archive_url":"https://api.github.com/repos/shader-slang/slang/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shader-slang/slang/downloads","issues_url":"https://api.github.com/repos/shader-slang/slang/issues{/number}","pulls_url":"https://api.github.com/repos/shader-slang/slang/pulls{/number}","milestones_url":"https://api.github.com/repos/shader-slang/slang/milestones{/number}","notifications_url":"https://api.github.com/repos/shader-slang/slang/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shader-slang/slang/labels{/name}","releases_url":"https://api.github.com/repos/shader-slang/slang/releases{/id}","deployments_url":"https://api.github.com/repos/shader-slang/slang/deployments","created_at":"2017-06-09T17:42:49Z","updated_at":"2017-11-13T18:46:22Z","pushed_at":"2017-11-14T18:58:12Z","git_url":"git://github.com/shader-slang/slang.git","ssh_url":"git@github.com:shader-slang/slang.git","clone_url":"https://github.com/shader-slang/slang.git","svn_url":"https://github.com/shader-slang/slang","homepage":null,"size":2986,"stargazers_count":60,"watchers_count":60,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"archived":false,"open_issues_count":48,"forks":4,"open_issues":48,"watchers":60,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/shader-slang/slang/pulls/278"},"html":{"href":"https://github.com/shader-slang/slang/pull/278"},"issue":{"href":"https://api.github.com/repos/shader-slang/slang/issues/278"},"comments":{"href":"https://api.github.com/repos/shader-slang/slang/issues/278/comments"},"review_comments":{"href":"https://api.github.com/repos/shader-slang/slang/pulls/278/comments"},"review_comment":{"href":"https://api.github.com/repos/shader-slang/slang/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/shader-slang/slang/pulls/278/commits"},"statuses":{"href":"https://api.github.com/repos/shader-slang/slang/statuses/7fddac35c8593bb37b8485f363c3929637db8ab4"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"tfoleyNV"}}