-
Notifications
You must be signed in to change notification settings - Fork 210
mir: newtype peeling #1199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
mir: newtype peeling #1199
Conversation
2d964be to
f59fb0a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
e1082af to
54e0716
Compare
|
@codex review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements "newtype peeling" in the MIR (Mid-level Intermediate Representation) layer, which recursively replaces single-field structs with their underlying field values while preserving type information. The optimization reduces memory allocations by treating transparent newtype wrappers (like struct Wei { inner: u256 }) as their inner type at runtime.
Key changes include:
- A new
repr.rsmodule centralizing runtime representation queries with recursive newtype unwrapping - A canonicalization transform pass (
canonicalize_transparent_newtypes) that rewrites transparent-newtype projections - Extension of
StorageMapto include aconst SALTparameter for type-level discrimination between storage maps - Updates to expression lowering, match lowering, and effect argument handling to support transparent cast operations
Reviewed changes
Copilot reviewed 57 out of 57 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
crates/mir/src/repr.rs |
New module defining canonical representation categories with transparent newtype peeling logic |
crates/mir/src/transform.rs |
Adds canonicalize_transparent_newtypes pass to flatten transparent cast chains and rewrite place projections |
crates/mir/src/lower/mod.rs |
Integrates new canonicalization pass and refactors representation queries to use centralized logic |
crates/mir/src/lower/prepass.rs |
Extends const expression handling to support const generic parameters in type positions |
crates/mir/src/lower/expr.rs |
Major refactoring of expression lowering to handle transparent casts, effect arguments, and assignment to transparent newtype fields |
crates/mir/src/lower/match_lowering.rs |
Adds transparent cast handling for non-reference scrutinee projections in match expressions |
crates/mir/src/lower/aggregates.rs |
Simplifies record literal lowering for transparent newtypes |
crates/mir/src/monomorphize.rs |
Adds const type parameter substitution in monomorphization |
crates/mir/src/ir.rs |
Extracts try_value_address_space_in helper for reuse in transform pass |
library/std/src/evm/storage_map.fe |
Breaks API: adds required const SALT parameter to StorageMap for collision prevention |
| Test fixtures | Updates MIR/codegen snapshots and adds new test cases for newtype scenarios |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Codex Review: Didn't find any major issues. Another round soon, please! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This (recursively) replaces single-field structs with their field, while retaining the original type information from the. Result is many fewer memory allocations, and free "newtype" wrapper structs like
struct Wei { inner: u256 }.