Title: [RFC] Split oparg type from the opcode enum · Issue #6746 · RustPython/RustPython · GitHub
Open Graph Title: [RFC] Split oparg type from the opcode enum · Issue #6746 · RustPython/RustPython
X Title: [RFC] Split oparg type from the opcode enum · Issue #6746 · RustPython/RustPython
Description: Summary Introduce a new AnyOparg enum & make Instruction + PseudoInstruction enums to not hold the oparg type. Detailed Explanation The current Instruction enum couples the opcode and its oparg type together. In practice, this creates fr...
Open Graph Description: Summary Introduce a new AnyOparg enum & make Instruction + PseudoInstruction enums to not hold the oparg type. Detailed Explanation The current Instruction enum couples the opcode and its oparg typ...
X Description: Summary Introduce a new AnyOparg enum & make Instruction + PseudoInstruction enums to not hold the oparg type. Detailed Explanation The current Instruction enum couples the opcode and its oparg...
Opengraph URL: https://github.com/RustPython/RustPython/issues/6746
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[RFC] Split oparg type from the opcode enum","articleBody":"## Summary\n\nIntroduce a new `AnyOparg` enum \u0026 make `Instruction` + `PseudoInstruction` enums to not hold the oparg type.\n\n## Detailed Explanation\n\nThe current `Instruction` enum couples the opcode and its oparg type together. In practice, this creates friction and many boilerplate code that can be avoided.\n\n### Suggested API\nNew pure `Opcode` enum that will have only the mapping between the opcode name and it's ID, like this:\n```rust\nenum Opcode {\n Nop = 0,\n IsOp = 1,\n BinaryOp = 2,\n ...\n}\n```\n\nA new `AnyOparg` enum that will have all oparg types as it's variants:\n```rust\nenum AnyOparg {\n NameIdx(oparg::NameIdx),\n IntristicFunction1(oparg::IntristicFunction1),\n Invert(oparg::Invert),\n ...\n}\n```\n\nAn `Instruction` struct that is like a typed version of the `CodeUnit` struct:\n```rust\nstruct Instruction {\n opcode: AnyOpcode,\n oparg: AnyOparg,\n}\n\nimpl Instruction {\n pub fn new\u003cT: Into\u003cAnyOpcode\u003e\u003e(opcode: T, oparg: Option\u003ci32\u003e) -\u003e Result\u003cSelf, MarshalError\u003e {\n let oparg = match opcode.into() {\n AnyOpcode::Real(Opcode::Nop) =\u003e None,\n AnyOpcode::Real(Opcode::IsOp) =\u003e Some(oparg::Invert::try_from(oparg.unwrap())?),\n ...\n };\n\n Ok(Self { opcode: opcode.into(), oparg: oparg.map(Into::into) })\n }\n}\n```\n\n## Drawbacks, Rationale, and Alternatives\n### Drawbacks\n- Will require a serious refactoring to the code\n\n### Rational\n- Reduce boilerplate code (use `num_enum` crate for example).\n- Easier to auto-generate the opcodes (and their IDs) in the future.\n- Simplify `opcode -\u003e oparg` mapping.\n\n## Unresolved Questions\n\nPerformance implifications?\n\nImplementation \u0026 refactoring efforts?\n\n","author":{"url":"https://github.com/ShaharNaveh","@type":"Person","name":"ShaharNaveh"},"datePublished":"2026-01-16T14:03:16.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/6746/RustPython/issues/6746"}
| 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:d66a5e73-36b9-8ab1-0093-665edff8c166 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B77E:DDF37:9C1EB9:DFAE5B:696FB09A |
| html-safe-nonce | 75efdfdb71afd41fb1716953bf29caf92f239366733d6f337ea7a2706148ee96 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNzdFOkRERjM3OjlDMUVCOTpERkFFNUI6Njk2RkIwOUEiLCJ2aXNpdG9yX2lkIjoiODA5NDA4ODkzMDIwNzQ0NTE0NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e45cbca2ea6071837e884c88e22896df46894b5163f26b33b303b945973bc6d6 |
| hovercard-subject-tag | issue:3822182991 |
| 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/RustPython/RustPython/6746/issue_layout |
| twitter:image | https://opengraph.githubassets.com/40ae75f28f44ea0a6e19f44e790187f6490998a175fde2de2d6a4d2e77499efe/RustPython/RustPython/issues/6746 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/40ae75f28f44ea0a6e19f44e790187f6490998a175fde2de2d6a4d2e77499efe/RustPython/RustPython/issues/6746 |
| og:image:alt | Summary Introduce a new AnyOparg enum & make Instruction + PseudoInstruction enums to not hold the oparg type. Detailed Explanation The current Instruction enum couples the opcode and its oparg typ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ShaharNaveh |
| hostname | github.com |
| expected-hostname | github.com |
| None | d146dfd2c89f9048de9fd6d73ec4ffcf201cc2c89880fcf1c73ff73970d46e64 |
| turbo-cache-control | no-preview |
| go-import | github.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git |
| octolytics-dimension-user_id | 39710557 |
| octolytics-dimension-user_login | RustPython |
| octolytics-dimension-repository_id | 135201145 |
| octolytics-dimension-repository_nwo | RustPython/RustPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 135201145 |
| octolytics-dimension-repository_network_root_nwo | RustPython/RustPython |
| 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 | 1866f0fdabd6ce28d22bf272fe23b56a9d475be6 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width