Skip to content

Conversation

@sbillig
Copy link
Collaborator

@sbillig sbillig commented Dec 31, 2025

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 }.

@sbillig sbillig closed this Dec 31, 2025
@sbillig sbillig reopened this Dec 31, 2025
@sbillig sbillig marked this pull request as ready for review December 31, 2025 17:15
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

@sbillig sbillig mentioned this pull request Jan 1, 2026
8 tasks
@sbillig
Copy link
Collaborator Author

sbillig commented Jan 1, 2026

@codex review

Copy link

Copilot AI left a 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.rs module centralizing runtime representation queries with recursive newtype unwrapping
  • A canonicalization transform pass (canonicalize_transparent_newtypes) that rewrites transparent-newtype projections
  • Extension of StorageMap to include a const SALT parameter 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.

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Another round soon, please!

ℹ️ 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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant