{"action":"created","comment":{"url":"https://api.github.com/repos/haypo/bytecode/pulls/comments/88664857","pull_request_review_id":9232470,"id":88664857,"diff_hunk":"@@ -268,11 +269,17 @@ def lineno(self):\n     def lineno(self, lineno):\n         self._set(self._name, self._arg, lineno)\n \n+    @property\n+    def stack_effect(self):\n+        # All opcodes whose arguments are not represented by integers have\n+        # a stack_effect indepent of their argument.\n+        arg = (self._arg if isinstance(self._arg, int) else\n+               0 if self._opcode >= _opcode.HAVE_ARGUMENT else None)","path":"bytecode/instr.py","position":15,"original_position":15,"commit_id":"3829d71b534d35e3075d957f7d41fe35cd3deda9","original_commit_id":"3829d71b534d35e3075d957f7d41fe35cd3deda9","user":{"login":"MatthieuDartiailh","id":4481740,"avatar_url":"https://avatars.githubusercontent.com/u/4481740?v=3","gravatar_id":"","url":"https://api.github.com/users/MatthieuDartiailh","html_url":"https://github.com/MatthieuDartiailh","followers_url":"https://api.github.com/users/MatthieuDartiailh/followers","following_url":"https://api.github.com/users/MatthieuDartiailh/following{/other_user}","gists_url":"https://api.github.com/users/MatthieuDartiailh/gists{/gist_id}","starred_url":"https://api.github.com/users/MatthieuDartiailh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MatthieuDartiailh/subscriptions","organizations_url":"https://api.github.com/users/MatthieuDartiailh/orgs","repos_url":"https://api.github.com/users/MatthieuDartiailh/repos","events_url":"https://api.github.com/users/MatthieuDartiailh/events{/privacy}","received_events_url":"https://api.github.com/users/MatthieuDartiailh/received_events","type":"User","site_admin":false},"body":"My point is that the computation can always be carried out even on Instr, as all instruction whose arguments is not an int does not have a stack effect depending on the argument. Furthermore as the stack depth calculation is done on a cfg we cannot force to only have ConcreteInstr. Another way would be to have a ConcreteCFG but I really do not like this idea.","created_at":"2016-11-18T14:22:22Z","updated_at":"2016-11-18T14:22:22Z","html_url":"https://github.com/haypo/bytecode/pull/8#discussion_r88664857","pull_request_url":"https://api.github.com/repos/haypo/bytecode/pulls/8","_links":{"self":{"href":"https://api.github.com/repos/haypo/bytecode/pulls/comments/88664857"},"html":{"href":"https://github.com/haypo/bytecode/pull/8#discussion_r88664857"},"pull_request":{"href":"https://api.github.com/repos/haypo/bytecode/pulls/8"}}},"pull_request":{"url":"https://api.github.com/repos/haypo/bytecode/pulls/8","id":93847177,"html_url":"https://github.com/haypo/bytecode/pull/8","diff_url":"https://github.com/haypo/bytecode/pull/8.diff","patch_url":"https://github.com/haypo/bytecode/pull/8.patch","issue_url":"https://api.github.com/repos/haypo/bytecode/issues/8","number":8,"state":"open","locked":false,"title":"Stack depth computation based on cfg analysis","user":{"login":"MatthieuDartiailh","id":4481740,"avatar_url":"https://avatars.githubusercontent.com/u/4481740?v=3","gravatar_id":"","url":"https://api.github.com/users/MatthieuDartiailh","html_url":"https://github.com/MatthieuDartiailh","followers_url":"https://api.github.com/users/MatthieuDartiailh/followers","following_url":"https://api.github.com/users/MatthieuDartiailh/following{/other_user}","gists_url":"https://api.github.com/users/MatthieuDartiailh/gists{/gist_id}","starred_url":"https://api.github.com/users/MatthieuDartiailh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MatthieuDartiailh/subscriptions","organizations_url":"https://api.github.com/users/MatthieuDartiailh/orgs","repos_url":"https://api.github.com/users/MatthieuDartiailh/repos","events_url":"https://api.github.com/users/MatthieuDartiailh/events{/privacy}","received_events_url":"https://api.github.com/users/MatthieuDartiailh/received_events","type":"User","site_admin":false},"body":"This is a new version of the stack depth computation based on CPython implementation using the control flow graph of the code. It has several advantages compared to the previous implementation:\r\n- it is shorter and easier to read\r\n- it is very close to CPython own implementation (https://hg.python.org/cpython/file/tip/Python/compile.c#l4883) as I basically copy-pasted and adapted the C code\r\n- It is very general as the implementation is identical between CPython 2.7 and 3.6 up to some cosmetic change\r\nHowever it is likely to be slow.\r\nI added some tests comparing to CPython results. Actually one of them is broken : test_nested_try_except_else_finally. I am not yet sure but I suspect it is a bug in the cfg building.\r\n\r\nI made stack_effect a property of Instr and added some argument analysis as dis.stack_effect is quite picky on the argument even if it is not involved in the computation. As a side node, adding a Python 2.7 implementation of stack effect will be, I believe, the only modification required to support Python 2.7","created_at":"2016-11-15T21:01:18Z","updated_at":"2016-11-18T14:22:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"006c8b58b2d9ea6492bc93a7b93dd5b75de04ab4","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/haypo/bytecode/pulls/8/commits","review_comments_url":"https://api.github.com/repos/haypo/bytecode/pulls/8/comments","review_comment_url":"https://api.github.com/repos/haypo/bytecode/pulls/comments{/number}","comments_url":"https://api.github.com/repos/haypo/bytecode/issues/8/comments","statuses_url":"https://api.github.com/repos/haypo/bytecode/statuses/3829d71b534d35e3075d957f7d41fe35cd3deda9","head":{"label":"MatthieuDartiailh:stack_depth_cfg","ref":"stack_depth_cfg","sha":"3829d71b534d35e3075d957f7d41fe35cd3deda9","user":{"login":"MatthieuDartiailh","id":4481740,"avatar_url":"https://avatars.githubusercontent.com/u/4481740?v=3","gravatar_id":"","url":"https://api.github.com/users/MatthieuDartiailh","html_url":"https://github.com/MatthieuDartiailh","followers_url":"https://api.github.com/users/MatthieuDartiailh/followers","following_url":"https://api.github.com/users/MatthieuDartiailh/following{/other_user}","gists_url":"https://api.github.com/users/MatthieuDartiailh/gists{/gist_id}","starred_url":"https://api.github.com/users/MatthieuDartiailh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MatthieuDartiailh/subscriptions","organizations_url":"https://api.github.com/users/MatthieuDartiailh/orgs","repos_url":"https://api.github.com/users/MatthieuDartiailh/repos","events_url":"https://api.github.com/users/MatthieuDartiailh/events{/privacy}","received_events_url":"https://api.github.com/users/MatthieuDartiailh/received_events","type":"User","site_admin":false},"repo":{"id":72933704,"name":"bytecode","full_name":"MatthieuDartiailh/bytecode","owner":{"login":"MatthieuDartiailh","id":4481740,"avatar_url":"https://avatars.githubusercontent.com/u/4481740?v=3","gravatar_id":"","url":"https://api.github.com/users/MatthieuDartiailh","html_url":"https://github.com/MatthieuDartiailh","followers_url":"https://api.github.com/users/MatthieuDartiailh/followers","following_url":"https://api.github.com/users/MatthieuDartiailh/following{/other_user}","gists_url":"https://api.github.com/users/MatthieuDartiailh/gists{/gist_id}","starred_url":"https://api.github.com/users/MatthieuDartiailh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MatthieuDartiailh/subscriptions","organizations_url":"https://api.github.com/users/MatthieuDartiailh/orgs","repos_url":"https://api.github.com/users/MatthieuDartiailh/repos","events_url":"https://api.github.com/users/MatthieuDartiailh/events{/privacy}","received_events_url":"https://api.github.com/users/MatthieuDartiailh/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/MatthieuDartiailh/bytecode","description":"Python module to modify bytecode","fork":true,"url":"https://api.github.com/repos/MatthieuDartiailh/bytecode","forks_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/forks","keys_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/teams","hooks_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/hooks","issue_events_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/issues/events{/number}","events_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/events","assignees_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/assignees{/user}","branches_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/branches{/branch}","tags_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/tags","blobs_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/git/refs{/sha}","trees_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/statuses/{sha}","languages_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/languages","stargazers_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/stargazers","contributors_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/contributors","subscribers_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/subscribers","subscription_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/subscription","commits_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/commits{/sha}","git_commits_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/git/commits{/sha}","comments_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/comments{/number}","issue_comment_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/issues/comments{/number}","contents_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/contents/{+path}","compare_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/merges","archive_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/downloads","issues_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/issues{/number}","pulls_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/pulls{/number}","milestones_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/milestones{/number}","notifications_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/labels{/name}","releases_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/releases{/id}","deployments_url":"https://api.github.com/repos/MatthieuDartiailh/bytecode/deployments","created_at":"2016-11-05T15:09:39Z","updated_at":"2016-11-05T15:09:41Z","pushed_at":"2016-11-17T09:42:32Z","git_url":"git://github.com/MatthieuDartiailh/bytecode.git","ssh_url":"git@github.com:MatthieuDartiailh/bytecode.git","clone_url":"https://github.com/MatthieuDartiailh/bytecode.git","svn_url":"https://github.com/MatthieuDartiailh/bytecode","homepage":null,"size":326,"stargazers_count":0,"watchers_count":0,"language":"Python","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":"haypo:master","ref":"master","sha":"e9cc95996a7efe676ebe5ffd8a51a162faeb4952","user":{"login":"haypo","id":194129,"avatar_url":"https://avatars.githubusercontent.com/u/194129?v=3","gravatar_id":"","url":"https://api.github.com/users/haypo","html_url":"https://github.com/haypo","followers_url":"https://api.github.com/users/haypo/followers","following_url":"https://api.github.com/users/haypo/following{/other_user}","gists_url":"https://api.github.com/users/haypo/gists{/gist_id}","starred_url":"https://api.github.com/users/haypo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haypo/subscriptions","organizations_url":"https://api.github.com/users/haypo/orgs","repos_url":"https://api.github.com/users/haypo/repos","events_url":"https://api.github.com/users/haypo/events{/privacy}","received_events_url":"https://api.github.com/users/haypo/received_events","type":"User","site_admin":false},"repo":{"id":52368046,"name":"bytecode","full_name":"haypo/bytecode","owner":{"login":"haypo","id":194129,"avatar_url":"https://avatars.githubusercontent.com/u/194129?v=3","gravatar_id":"","url":"https://api.github.com/users/haypo","html_url":"https://github.com/haypo","followers_url":"https://api.github.com/users/haypo/followers","following_url":"https://api.github.com/users/haypo/following{/other_user}","gists_url":"https://api.github.com/users/haypo/gists{/gist_id}","starred_url":"https://api.github.com/users/haypo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haypo/subscriptions","organizations_url":"https://api.github.com/users/haypo/orgs","repos_url":"https://api.github.com/users/haypo/repos","events_url":"https://api.github.com/users/haypo/events{/privacy}","received_events_url":"https://api.github.com/users/haypo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/haypo/bytecode","description":"Python module to modify bytecode","fork":false,"url":"https://api.github.com/repos/haypo/bytecode","forks_url":"https://api.github.com/repos/haypo/bytecode/forks","keys_url":"https://api.github.com/repos/haypo/bytecode/keys{/key_id}","collaborators_url":"https://api.github.com/repos/haypo/bytecode/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/haypo/bytecode/teams","hooks_url":"https://api.github.com/repos/haypo/bytecode/hooks","issue_events_url":"https://api.github.com/repos/haypo/bytecode/issues/events{/number}","events_url":"https://api.github.com/repos/haypo/bytecode/events","assignees_url":"https://api.github.com/repos/haypo/bytecode/assignees{/user}","branches_url":"https://api.github.com/repos/haypo/bytecode/branches{/branch}","tags_url":"https://api.github.com/repos/haypo/bytecode/tags","blobs_url":"https://api.github.com/repos/haypo/bytecode/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/haypo/bytecode/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/haypo/bytecode/git/refs{/sha}","trees_url":"https://api.github.com/repos/haypo/bytecode/git/trees{/sha}","statuses_url":"https://api.github.com/repos/haypo/bytecode/statuses/{sha}","languages_url":"https://api.github.com/repos/haypo/bytecode/languages","stargazers_url":"https://api.github.com/repos/haypo/bytecode/stargazers","contributors_url":"https://api.github.com/repos/haypo/bytecode/contributors","subscribers_url":"https://api.github.com/repos/haypo/bytecode/subscribers","subscription_url":"https://api.github.com/repos/haypo/bytecode/subscription","commits_url":"https://api.github.com/repos/haypo/bytecode/commits{/sha}","git_commits_url":"https://api.github.com/repos/haypo/bytecode/git/commits{/sha}","comments_url":"https://api.github.com/repos/haypo/bytecode/comments{/number}","issue_comment_url":"https://api.github.com/repos/haypo/bytecode/issues/comments{/number}","contents_url":"https://api.github.com/repos/haypo/bytecode/contents/{+path}","compare_url":"https://api.github.com/repos/haypo/bytecode/compare/{base}...{head}","merges_url":"https://api.github.com/repos/haypo/bytecode/merges","archive_url":"https://api.github.com/repos/haypo/bytecode/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/haypo/bytecode/downloads","issues_url":"https://api.github.com/repos/haypo/bytecode/issues{/number}","pulls_url":"https://api.github.com/repos/haypo/bytecode/pulls{/number}","milestones_url":"https://api.github.com/repos/haypo/bytecode/milestones{/number}","notifications_url":"https://api.github.com/repos/haypo/bytecode/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/haypo/bytecode/labels{/name}","releases_url":"https://api.github.com/repos/haypo/bytecode/releases{/id}","deployments_url":"https://api.github.com/repos/haypo/bytecode/deployments","created_at":"2016-02-23T15:14:29Z","updated_at":"2016-11-18T08:36:32Z","pushed_at":"2016-11-17T09:42:32Z","git_url":"git://github.com/haypo/bytecode.git","ssh_url":"git@github.com:haypo/bytecode.git","clone_url":"https://github.com/haypo/bytecode.git","svn_url":"https://github.com/haypo/bytecode","homepage":null,"size":283,"stargazers_count":19,"watchers_count":19,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":4,"forks":6,"open_issues":4,"watchers":19,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/haypo/bytecode/pulls/8"},"html":{"href":"https://github.com/haypo/bytecode/pull/8"},"issue":{"href":"https://api.github.com/repos/haypo/bytecode/issues/8"},"comments":{"href":"https://api.github.com/repos/haypo/bytecode/issues/8/comments"},"review_comments":{"href":"https://api.github.com/repos/haypo/bytecode/pulls/8/comments"},"review_comment":{"href":"https://api.github.com/repos/haypo/bytecode/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/haypo/bytecode/pulls/8/commits"},"statuses":{"href":"https://api.github.com/repos/haypo/bytecode/statuses/3829d71b534d35e3075d957f7d41fe35cd3deda9"}}}}
{"actor":{"display_login":"MatthieuDartiailh"}}