Title: Incorrect output due to Tier 2 `_LOAD_CONST_INLINE` · Issue #117051 · python/cpython · GitHub
Open Graph Title: Incorrect output due to Tier 2 `_LOAD_CONST_INLINE` · Issue #117051 · python/cpython
X Title: Incorrect output due to Tier 2 `_LOAD_CONST_INLINE` · Issue #117051 · python/cpython
Description: Bug report I've constructed a sneaky way to break the remove_globals() optimization, by executing a code object in two different globals dicts. (Credit goes to @brandtbucher who started the conversation about this topic, though this part...
Open Graph Description: Bug report I've constructed a sneaky way to break the remove_globals() optimization, by executing a code object in two different globals dicts. (Credit goes to @brandtbucher who started the convers...
X Description: Bug report I've constructed a sneaky way to break the remove_globals() optimization, by executing a code object in two different globals dicts. (Credit goes to @brandtbucher who started the con...
Opengraph URL: https://github.com/python/cpython/issues/117051
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect output due to Tier 2 `_LOAD_CONST_INLINE`","articleBody":"# Bug report\r\n\r\nI've constructed a sneaky way to break the `remove_globals()` optimization, by executing a code object in two different globals dicts. (Credit goes to @brandtbucher who [started](https://github.com/python/cpython/issues/117045#issuecomment-2008283808) the conversation about this topic, though [this particular example](https://github.com/python/cpython/issues/117045#issuecomment-2008371267) is mine.)\r\n\r\nTake this code:\r\n```py\r\nsrc = \"\"\"\r\ndef f():\r\n global x\r\n def inner(i):\r\n a = 1\r\n for _ in range(100):\r\n a = x + i\r\n return a\r\n return inner\r\n\r\nfunc = f()\r\n\"\"\"\r\n\r\nco = compile(src, __file__, \"exec\")\r\n\r\nns1 = {\"x\": 1000}\r\neval(co, ns1)\r\nfunc1 = ns1[\"func\"]\r\nfor i in range(1000):\r\n x = func1(i)\r\nprint(x)\r\n\r\nns2 = {\"x\": 2000}\r\neval(co, ns2)\r\nfunc2 = ns2[\"func\"]\r\nfor i in range(1000):\r\n x = func2(i)\r\nprint(x)\r\n```\r\n\r\nThis *should* print\r\n```\r\n1999\r\n2999\r\n```\r\n(try it with Python 3.12, or Python 3.13 **without JIT or `-Xuops`**).\r\n\r\nHowever with current main (**EDIT:** when using JIT or `-Xuops`) it prints\r\n```\r\n1999\r\n1999\r\n```\r\n:-(","author":{"url":"https://github.com/gvanrossum","@type":"Person","name":"gvanrossum"},"datePublished":"2024-03-20T00:09:31.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/117051/cpython/issues/117051"}
| 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:fbac02e3-b070-208f-a19c-2bdf5fbb388a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DB86:550E0:B9E789:F7AE92:6A56AC62 |
| html-safe-nonce | fc94ab8798d6593daf8e49b0606516023bb0dfa4c02bcaf31108e9ad431d1c2a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQjg2OjU1MEUwOkI5RTc4OTpGN0FFOTI6NkE1NkFDNjIiLCJ2aXNpdG9yX2lkIjoiNzI1MTE1NTgwODYxMjk1NzE0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 4ebb8853779819685c90a2e592396b9f3d8bc362ff001093cc19efaa01834f56 |
| hovercard-subject-tag | issue:2196304876 |
| 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/117051/issue_layout |
| twitter:image | https://opengraph.githubassets.com/39f1ab69c621973add5cc00508b71e17991072d0e68840942f35faecfc007094/python/cpython/issues/117051 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/39f1ab69c621973add5cc00508b71e17991072d0e68840942f35faecfc007094/python/cpython/issues/117051 |
| og:image:alt | Bug report I've constructed a sneaky way to break the remove_globals() optimization, by executing a code object in two different globals dicts. (Credit goes to @brandtbucher who started the convers... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gvanrossum |
| hostname | github.com |
| expected-hostname | github.com |
| None | 13efe7fe8ecc41eda1078cbde8206041ed92bc54e29bcb737e9353dd9c407aad |
| 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 | 5466ebe023a0abf876a1e6c5d7602ee8f5e6a02b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width