Title: Move const folding to the peephole optimizer · Issue #126835 · python/cpython · GitHub
Open Graph Title: Move const folding to the peephole optimizer · Issue #126835 · python/cpython
X Title: Move const folding to the peephole optimizer · Issue #126835 · python/cpython
Description: Feature or enhancement Proposal: For additional context see #126830 (comment). Flow graph optimizer has more information and can do better job. The problem is that we need to convert from UNARY_OP(-, CONST(1)) to CONST(-1), still before ...
Open Graph Description: Feature or enhancement Proposal: For additional context see #126830 (comment). Flow graph optimizer has more information and can do better job. The problem is that we need to convert from UNARY_OP(...
X Description: Feature or enhancement Proposal: For additional context see #126830 (comment). Flow graph optimizer has more information and can do better job. The problem is that we need to convert from UNARY_OP(...
Opengraph URL: https://github.com/python/cpython/issues/126835
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Move const folding to the peephole optimizer","articleBody":"# Feature or enhancement\n\n### Proposal:\n\nFor additional context see https://github.com/python/cpython/pull/126830#issuecomment-2476525196.\n\nFlow graph optimizer has more information and can do better job.\n\nThe problem is that we need to convert from `UNARY_OP(-, CONST(1))` to `CONST(-1)`, still before the code generation phase, because this leads to a few problems, one of which is shown below.\n```python\nx = 1\n\nmatch x:\n case -0:\n y = 0\n```\n\n```\neclips4@nixos ~/p/p/cpython (remove-ast-optimizer)\u003e ./python example.py\n File \"/home/eclips4/programming/programming-languages/cpython/example.py\", line 4\n case -0:\n ^^\nSyntaxError: patterns may only match literals and attribute lookups\n```\n\n\ncc @markshannon \n\n\n\n### Has this already been discussed elsewhere?\n\nNo response given\n\n### Links to previous discussion of this feature:\n\n_No response_\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-128802\n* gh-129426\n* gh-129550\n* gh-129568\n* gh-129634\n* gh-129703\n* gh-129963\n* gh-130016\n* gh-130032\n* gh-130109\n* gh-130769\n* gh-131054\n* gh-131826\n* gh-131830\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/Eclips4","@type":"Person","name":"Eclips4"},"datePublished":"2024-11-14T18:08:07.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":122},"url":"https://github.com/126835/cpython/issues/126835"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c4c97742-bd9c-27ac-c955-9af63f9f6985 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D3D4:3A6082:23C3CFC:2EB305D:696B5AE1 |
| html-safe-nonce | 7d3467d6b15091dd5a59417f6898e26f7c4e4b4bf94bd43e3ebab0c96f9f02dc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEM0Q0OjNBNjA4MjoyM0MzQ0ZDOjJFQjMwNUQ6Njk2QjVBRTEiLCJ2aXNpdG9yX2lkIjoiODc5OTI2MTUyNDQzMDExNzYwMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3455d9a62998b4a10949d256b1ce715bce6da75043d8686b6edab7b27b17fbba |
| hovercard-subject-tag | issue:2659638853 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/126835/issue_layout |
| twitter:image | https://opengraph.githubassets.com/219e0e8c6ad3277b548d9920421eb8d71b248eedf0aa6a45a045b76684ce9223/python/cpython/issues/126835 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/219e0e8c6ad3277b548d9920421eb8d71b248eedf0aa6a45a045b76684ce9223/python/cpython/issues/126835 |
| og:image:alt | Feature or enhancement Proposal: For additional context see #126830 (comment). Flow graph optimizer has more information and can do better job. The problem is that we need to convert from UNARY_OP(... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Eclips4 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width