{"action":"created","comment":{"url":"https://api.github.com/repos/p4lang/p4c/pulls/comments/243462587","pull_request_review_id":187240339,"id":243462587,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0MzQ2MjU4Nw==","diff_hunk":"@@ -819,93 +820,100 @@ header H {\n }\n ...\n H h;\n+\n+// Fixed-length size of H\n header H_0 {\n    bit<8> len;\n }\n-header H_1 {\n-   varbit<64> data;\n-}\n \n H_0 h_0;\n-H_1 h_1;\n-pkt.extract(h_0);\n-pkt.extract(h_1, h_0.len);\n-h.setValid();\n-h.len = h_0.len;\n-h.data = h_1.data;\n+h_0 = pkt.lookahead<H_0>();\n+pkt.extract(h, h_0.len);\n \n */\n class FixExtracts final : public Transform {\n     ProgramStructure* structure;\n \n-    /// Newly-introduced types for each extract.\n-    std::vector<const IR::Type_Header*> typeDecls;\n+    struct HeaderSplit {\n+        /// Fixed-size part of a header type (computed for each extract).\n+        const IR::Type_Header* fixedHeaderType;\n+        /// Expression computing the length of the variable-size header.\n+        const IR::Expression* headerLength;\n+    };\n+\n     /// All newly-introduced types.\n-    // The following contains IR::Type_Header, but it is easier\n+    // The following vector contains only IR::Type_Header, but it is easier\n     // to append if the elements are Node.\n     IR::Vector<IR::Node>               allTypeDecls;\n     /// All newly-introduced variables, for each parser.\n     IR::IndexedVector<IR::Declaration> varDecls;\n-    /// Map each newly created header with a varbit field\n-    /// to an expression that denotes its length.\n-    std::map<const IR::Type_Header*, const IR::Expression*> lengths;\n-\n-    /// If a header type contains varbit fields split it into several\n-    /// header types, each of which starts with a varbit field.  The\n-    /// types are inserted in the typeDecls list.\n-    void splitHeaderType(const IR::Type_Header* type) {\n+    /// Maps each original header type name to the fixed part of it.\n+    std::map<cstring, HeaderSplit*> fixedPart;\n+\n+    /// If a header type contains a varbit field then create a new\n+    /// header type containing only the fields prior to the varbit.\n+    /// Returns nullptr otherwise.\n+    HeaderSplit* splitHeaderType(const IR::Type_Header* type) {\n+        auto fixed = ::get(fixedPart, type->name.name);\n+        if (fixed != nullptr)\n+            return fixed;\n+\n+        const IR::Expression* headerLength = nullptr;\n+        const IR::Type_Header* fixedHeaderType = nullptr;\n         IR::IndexedVector<IR::StructField> fields;\n-        const IR::Expression* length = nullptr;\n+\n         for (auto f : type->fields) {\n             if (f->type->is<IR::Type_Varbits>()) {\n                 cstring hname = structure->makeUniqueName(type->name);\n-                auto htype = new IR::Type_Header(IR::ID(hname), fields);\n-                if (length != nullptr)\n-                    lengths.emplace(htype, length);\n-                typeDecls.push_back(htype);\n-                fields.clear();\n+                if (fixedHeaderType != nullptr)\n+                    ::error(\"%1%: header types with multiple varbit fields are not supported\",\n+                            type);\n+                fixedHeaderType = new IR::Type_Header(IR::ID(hname), fields);\n                 auto anno = f->getAnnotation(IR::Annotation::lengthAnnotation);\n                 BUG_CHECK(anno != nullptr, \"No length annotation on varbit field\", f);\n                 BUG_CHECK(anno->expr.size() == 1, \"Expected exactly 1 argument\", anno->expr);\n-                length = anno->expr.at(0);\n+                headerLength = anno->expr.at(0);\n                 f = new IR::StructField(f->srcInfo, f->name, f->type);  // lose the annotation\n             }\n-            fields.push_back(f);\n+            if (fixedHeaderType == nullptr)","path":"frontends/p4/fromv1.0/converters.cpp","position":95,"original_position":95,"commit_id":"6b92ac7db5e349835cd7caa81568e32198aea7ea","original_commit_id":"6b92ac7db5e349835cd7caa81568e32198aea7ea","user":{"login":"mbudiu-vmw","id":19397042,"node_id":"MDQ6VXNlcjE5Mzk3MDQy","avatar_url":"https://avatars1.githubusercontent.com/u/19397042?v=4","gravatar_id":"","url":"https://api.github.com/users/mbudiu-vmw","html_url":"https://github.com/mbudiu-vmw","followers_url":"https://api.github.com/users/mbudiu-vmw/followers","following_url":"https://api.github.com/users/mbudiu-vmw/following{/other_user}","gists_url":"https://api.github.com/users/mbudiu-vmw/gists{/gist_id}","starred_url":"https://api.github.com/users/mbudiu-vmw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbudiu-vmw/subscriptions","organizations_url":"https://api.github.com/users/mbudiu-vmw/orgs","repos_url":"https://api.github.com/users/mbudiu-vmw/repos","events_url":"https://api.github.com/users/mbudiu-vmw/events{/privacy}","received_events_url":"https://api.github.com/users/mbudiu-vmw/received_events","type":"User","site_admin":false},"body":"We only add to the list of headers the ones before the varbit field. All the other ones are ignored.\r\nIf there is a second varbit field you will get an error.\r\n","created_at":"2018-12-21T00:51:13Z","updated_at":"2018-12-21T00:51:14Z","html_url":"https://github.com/p4lang/p4c/pull/1635#discussion_r243462587","pull_request_url":"https://api.github.com/repos/p4lang/p4c/pulls/1635","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/p4lang/p4c/pulls/comments/243462587"},"html":{"href":"https://github.com/p4lang/p4c/pull/1635#discussion_r243462587"},"pull_request":{"href":"https://api.github.com/repos/p4lang/p4c/pulls/1635"}},"in_reply_to_id":243385494},"pull_request":{"url":"https://api.github.com/repos/p4lang/p4c/pulls/1635","id":239339288,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM5MzM5Mjg4","html_url":"https://github.com/p4lang/p4c/pull/1635","diff_url":"https://github.com/p4lang/p4c/pull/1635.diff","patch_url":"https://github.com/p4lang/p4c/pull/1635.patch","issue_url":"https://api.github.com/repos/p4lang/p4c/issues/1635","number":1635,"state":"open","locked":false,"title":"Improved translation of P4-14 header stacks with varbits (fixes #576)","user":{"login":"mbudiu-vmw","id":19397042,"node_id":"MDQ6VXNlcjE5Mzk3MDQy","avatar_url":"https://avatars1.githubusercontent.com/u/19397042?v=4","gravatar_id":"","url":"https://api.github.com/users/mbudiu-vmw","html_url":"https://github.com/mbudiu-vmw","followers_url":"https://api.github.com/users/mbudiu-vmw/followers","following_url":"https://api.github.com/users/mbudiu-vmw/following{/other_user}","gists_url":"https://api.github.com/users/mbudiu-vmw/gists{/gist_id}","starred_url":"https://api.github.com/users/mbudiu-vmw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbudiu-vmw/subscriptions","organizations_url":"https://api.github.com/users/mbudiu-vmw/orgs","repos_url":"https://api.github.com/users/mbudiu-vmw/repos","events_url":"https://api.github.com/users/mbudiu-vmw/events{/privacy}","received_events_url":"https://api.github.com/users/mbudiu-vmw/received_events","type":"User","site_admin":false},"body":"This is about translating P4-14 header stacks into P4-16. The translation was incorrect for stacks with varbits. We now handle correctly headers that contain one varbit field. \r\nInstead of splitting a header into multiple headers, we read the fixed-sized part of a header using lookahead, and use it to compute the length, which is then used to read the whole header using an extract. The previous translation was not handling correctly the next/last stack fields.\r\nFixes #576.\r\n(This also generates better code.)","created_at":"2018-12-18T01:43:58Z","updated_at":"2018-12-21T00:51:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"688828ae098824b680af67f60af62d6927785550","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/p4lang/p4c/pulls/1635/commits","review_comments_url":"https://api.github.com/repos/p4lang/p4c/pulls/1635/comments","review_comment_url":"https://api.github.com/repos/p4lang/p4c/pulls/comments{/number}","comments_url":"https://api.github.com/repos/p4lang/p4c/issues/1635/comments","statuses_url":"https://api.github.com/repos/p4lang/p4c/statuses/6b92ac7db5e349835cd7caa81568e32198aea7ea","head":{"label":"mbudiu-vmw:issue576","ref":"issue576","sha":"6b92ac7db5e349835cd7caa81568e32198aea7ea","user":{"login":"mbudiu-vmw","id":19397042,"node_id":"MDQ6VXNlcjE5Mzk3MDQy","avatar_url":"https://avatars1.githubusercontent.com/u/19397042?v=4","gravatar_id":"","url":"https://api.github.com/users/mbudiu-vmw","html_url":"https://github.com/mbudiu-vmw","followers_url":"https://api.github.com/users/mbudiu-vmw/followers","following_url":"https://api.github.com/users/mbudiu-vmw/following{/other_user}","gists_url":"https://api.github.com/users/mbudiu-vmw/gists{/gist_id}","starred_url":"https://api.github.com/users/mbudiu-vmw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbudiu-vmw/subscriptions","organizations_url":"https://api.github.com/users/mbudiu-vmw/orgs","repos_url":"https://api.github.com/users/mbudiu-vmw/repos","events_url":"https://api.github.com/users/mbudiu-vmw/events{/privacy}","received_events_url":"https://api.github.com/users/mbudiu-vmw/received_events","type":"User","site_admin":false},"repo":{"id":76977246,"node_id":"MDEwOlJlcG9zaXRvcnk3Njk3NzI0Ng==","name":"p4c-clone","full_name":"mbudiu-vmw/p4c-clone","private":false,"owner":{"login":"mbudiu-vmw","id":19397042,"node_id":"MDQ6VXNlcjE5Mzk3MDQy","avatar_url":"https://avatars1.githubusercontent.com/u/19397042?v=4","gravatar_id":"","url":"https://api.github.com/users/mbudiu-vmw","html_url":"https://github.com/mbudiu-vmw","followers_url":"https://api.github.com/users/mbudiu-vmw/followers","following_url":"https://api.github.com/users/mbudiu-vmw/following{/other_user}","gists_url":"https://api.github.com/users/mbudiu-vmw/gists{/gist_id}","starred_url":"https://api.github.com/users/mbudiu-vmw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbudiu-vmw/subscriptions","organizations_url":"https://api.github.com/users/mbudiu-vmw/orgs","repos_url":"https://api.github.com/users/mbudiu-vmw/repos","events_url":"https://api.github.com/users/mbudiu-vmw/events{/privacy}","received_events_url":"https://api.github.com/users/mbudiu-vmw/received_events","type":"User","site_admin":false},"html_url":"https://github.com/mbudiu-vmw/p4c-clone","description":"P4_16 prototype compiler","fork":true,"url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone","forks_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/forks","keys_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/teams","hooks_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/hooks","issue_events_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/issues/events{/number}","events_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/events","assignees_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/assignees{/user}","branches_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/branches{/branch}","tags_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/tags","blobs_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/git/refs{/sha}","trees_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/statuses/{sha}","languages_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/languages","stargazers_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/stargazers","contributors_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/contributors","subscribers_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/subscribers","subscription_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/subscription","commits_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/commits{/sha}","git_commits_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/git/commits{/sha}","comments_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/comments{/number}","issue_comment_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/issues/comments{/number}","contents_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/contents/{+path}","compare_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/merges","archive_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/downloads","issues_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/issues{/number}","pulls_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/pulls{/number}","milestones_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/milestones{/number}","notifications_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/labels{/name}","releases_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/releases{/id}","deployments_url":"https://api.github.com/repos/mbudiu-vmw/p4c-clone/deployments","created_at":"2016-12-20T17:24:35Z","updated_at":"2018-10-23T22:41:40Z","pushed_at":"2018-12-20T16:21:01Z","git_url":"git://github.com/mbudiu-vmw/p4c-clone.git","ssh_url":"git@github.com:mbudiu-vmw/p4c-clone.git","clone_url":"https://github.com/mbudiu-vmw/p4c-clone.git","svn_url":"https://github.com/mbudiu-vmw/p4c-clone","homepage":"","size":40211,"stargazers_count":0,"watchers_count":0,"language":"P4","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"p4lang:master","ref":"master","sha":"17187c725106159aa530f00a6de67753ecdfc620","user":{"login":"p4lang","id":10765181,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEwNzY1MTgx","avatar_url":"https://avatars1.githubusercontent.com/u/10765181?v=4","gravatar_id":"","url":"https://api.github.com/users/p4lang","html_url":"https://github.com/p4lang","followers_url":"https://api.github.com/users/p4lang/followers","following_url":"https://api.github.com/users/p4lang/following{/other_user}","gists_url":"https://api.github.com/users/p4lang/gists{/gist_id}","starred_url":"https://api.github.com/users/p4lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/p4lang/subscriptions","organizations_url":"https://api.github.com/users/p4lang/orgs","repos_url":"https://api.github.com/users/p4lang/repos","events_url":"https://api.github.com/users/p4lang/events{/privacy}","received_events_url":"https://api.github.com/users/p4lang/received_events","type":"Organization","site_admin":false},"repo":{"id":55433859,"node_id":"MDEwOlJlcG9zaXRvcnk1NTQzMzg1OQ==","name":"p4c","full_name":"p4lang/p4c","private":false,"owner":{"login":"p4lang","id":10765181,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEwNzY1MTgx","avatar_url":"https://avatars1.githubusercontent.com/u/10765181?v=4","gravatar_id":"","url":"https://api.github.com/users/p4lang","html_url":"https://github.com/p4lang","followers_url":"https://api.github.com/users/p4lang/followers","following_url":"https://api.github.com/users/p4lang/following{/other_user}","gists_url":"https://api.github.com/users/p4lang/gists{/gist_id}","starred_url":"https://api.github.com/users/p4lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/p4lang/subscriptions","organizations_url":"https://api.github.com/users/p4lang/orgs","repos_url":"https://api.github.com/users/p4lang/repos","events_url":"https://api.github.com/users/p4lang/events{/privacy}","received_events_url":"https://api.github.com/users/p4lang/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/p4lang/p4c","description":"P4_16 prototype compiler","fork":false,"url":"https://api.github.com/repos/p4lang/p4c","forks_url":"https://api.github.com/repos/p4lang/p4c/forks","keys_url":"https://api.github.com/repos/p4lang/p4c/keys{/key_id}","collaborators_url":"https://api.github.com/repos/p4lang/p4c/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/p4lang/p4c/teams","hooks_url":"https://api.github.com/repos/p4lang/p4c/hooks","issue_events_url":"https://api.github.com/repos/p4lang/p4c/issues/events{/number}","events_url":"https://api.github.com/repos/p4lang/p4c/events","assignees_url":"https://api.github.com/repos/p4lang/p4c/assignees{/user}","branches_url":"https://api.github.com/repos/p4lang/p4c/branches{/branch}","tags_url":"https://api.github.com/repos/p4lang/p4c/tags","blobs_url":"https://api.github.com/repos/p4lang/p4c/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/p4lang/p4c/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/p4lang/p4c/git/refs{/sha}","trees_url":"https://api.github.com/repos/p4lang/p4c/git/trees{/sha}","statuses_url":"https://api.github.com/repos/p4lang/p4c/statuses/{sha}","languages_url":"https://api.github.com/repos/p4lang/p4c/languages","stargazers_url":"https://api.github.com/repos/p4lang/p4c/stargazers","contributors_url":"https://api.github.com/repos/p4lang/p4c/contributors","subscribers_url":"https://api.github.com/repos/p4lang/p4c/subscribers","subscription_url":"https://api.github.com/repos/p4lang/p4c/subscription","commits_url":"https://api.github.com/repos/p4lang/p4c/commits{/sha}","git_commits_url":"https://api.github.com/repos/p4lang/p4c/git/commits{/sha}","comments_url":"https://api.github.com/repos/p4lang/p4c/comments{/number}","issue_comment_url":"https://api.github.com/repos/p4lang/p4c/issues/comments{/number}","contents_url":"https://api.github.com/repos/p4lang/p4c/contents/{+path}","compare_url":"https://api.github.com/repos/p4lang/p4c/compare/{base}...{head}","merges_url":"https://api.github.com/repos/p4lang/p4c/merges","archive_url":"https://api.github.com/repos/p4lang/p4c/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/p4lang/p4c/downloads","issues_url":"https://api.github.com/repos/p4lang/p4c/issues{/number}","pulls_url":"https://api.github.com/repos/p4lang/p4c/pulls{/number}","milestones_url":"https://api.github.com/repos/p4lang/p4c/milestones{/number}","notifications_url":"https://api.github.com/repos/p4lang/p4c/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/p4lang/p4c/labels{/name}","releases_url":"https://api.github.com/repos/p4lang/p4c/releases{/id}","deployments_url":"https://api.github.com/repos/p4lang/p4c/deployments","created_at":"2016-04-04T18:12:32Z","updated_at":"2018-12-20T18:14:24Z","pushed_at":"2018-12-20T22:57:55Z","git_url":"git://github.com/p4lang/p4c.git","ssh_url":"git@github.com:p4lang/p4c.git","clone_url":"https://github.com/p4lang/p4c.git","svn_url":"https://github.com/p4lang/p4c","homepage":"","size":74868,"stargazers_count":156,"watchers_count":156,"language":"P4","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":97,"mirror_url":null,"archived":false,"open_issues_count":82,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":97,"open_issues":82,"watchers":156,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/p4lang/p4c/pulls/1635"},"html":{"href":"https://github.com/p4lang/p4c/pull/1635"},"issue":{"href":"https://api.github.com/repos/p4lang/p4c/issues/1635"},"comments":{"href":"https://api.github.com/repos/p4lang/p4c/issues/1635/comments"},"review_comments":{"href":"https://api.github.com/repos/p4lang/p4c/pulls/1635/comments"},"review_comment":{"href":"https://api.github.com/repos/p4lang/p4c/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/p4lang/p4c/pulls/1635/commits"},"statuses":{"href":"https://api.github.com/repos/p4lang/p4c/statuses/6b92ac7db5e349835cd7caa81568e32198aea7ea"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"mbudiu-vmw"}}