Skip to content

Conversation

@Zalathar
Copy link
Member

@Zalathar Zalathar commented Jan 8, 2026

This PR removes the AscribeUserType and ExpandedConstant variants from thir::PatKind, and replaces them with an Option<Box<PatExtra>> field attached to every thir::Pat.

Why remove these variants?

Unlike other THIR pattern kinds, these variants are mere “wrappers” that exist to attach some additional information to an underlying pattern node.

There are several places where code that consumes THIR patterns needs to carefully “unpeel” any wrapper nodes, in order to match on the underlying pattern. This is clunky, and easy to forget to do, especially since it's not always obvious where the wrapper nodes can and can't appear.

Attaching the data to an optional per-node field makes it easier for consuming code to simply ignore the extra data when it is not relevant.

(One downside is that it is now easier to accidentally ignore the extra data when it is relevant, but I think that's generally a favourable tradeoff.)

Impact

After this change, THIR pattern trees should be “logically identical” to the previous THIR pattern trees, in the sense that information that was carried by wrapper nodes should now be directly attached to the non-wrapper nodes that were being wrapped. Types and spans associated with THIR pattern nodes should (hopefully!) still be accurate.

There should be no change to the output of THIR-based checks or MIR building.

@rustbot
Copy link
Collaborator

rustbot commented Jan 8, 2026

Some changes occurred in exhaustiveness checking

cc @Nadrieril

Some changes occurred in match lowering

cc @Nadrieril

Some changes occurred in match checking

cc @Nadrieril

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 8, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 8, 2026

r? @davidtwco

rustbot has assigned @davidtwco.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@Zalathar
Copy link
Member Author

Zalathar commented Jan 8, 2026

I don't expect any measurable perf impact, but let's check.

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Jan 8, 2026
THIR patterns: Replace `AscribeUserType` and `ExpandedConstant` wrappers with per-node data
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 8, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 8, 2026

☀️ Try build successful (CI)
Build commit: aaf4488 (aaf4488e6255bbdeeff8e4c003177b5941dddfa0, parent: fecb335cbad3d84ef3da39191ba094e6c726a5b4)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (aaf4488): comparison URL.

Overall result: ❌✅ regressions and improvements - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.4% [-1.4%, -1.4%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 0.2%, secondary 2.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.0% [2.0%, 2.0%] 1
Regressions ❌
(secondary)
2.6% [2.6%, 2.6%] 1
Improvements ✅
(primary)
-1.6% [-1.6%, -1.6%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [-1.6%, 2.0%] 2

Cycles

Results (primary 3.0%, secondary -3.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
3.0% [2.3%, 3.6%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.1% [-3.4%, -2.9%] 2
All ❌✅ (primary) 3.0% [2.3%, 3.6%] 2

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 473.64s -> 475.633s (0.42%)
Artifact size: 390.86 MiB -> 390.86 MiB (-0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 8, 2026
@Zalathar
Copy link
Member Author

Zalathar commented Jan 8, 2026

Perf changes look like the usual noise to me.

@bors rollup=maybe

@rustbot
Copy link
Collaborator

rustbot commented Jan 9, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@Nadrieril
Copy link
Member

Nice, those wrappers were indeed a hassle to deal with.

r? me

@bors r+

@rust-bors rust-bors bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jan 10, 2026
@rust-bors rust-bors bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 10, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 10, 2026

📌 Commit 8516c64 has been approved by Nadrieril

It is now in the queue for this repository.

Zalathar added a commit to Zalathar/rust that referenced this pull request Jan 10, 2026
THIR patterns: Replace `AscribeUserType` and `ExpandedConstant` wrappers with per-node data

This PR removes the `AscribeUserType` and `ExpandedConstant` variants from `thir::PatKind`, and replaces them with an `Option<Box<PatExtra>>` field attached to every `thir::Pat`.

### Why remove these variants?

Unlike other THIR pattern kinds, these variants are mere “wrappers” that exist to attach some additional information to an underlying pattern node.

There are several places where code that consumes THIR patterns needs to carefully “unpeel” any wrapper nodes, in order to match on the underlying pattern. This is clunky, and easy to forget to do, especially since it's not always obvious where the wrapper nodes can and can't appear.

Attaching the data to an optional per-node field makes it easier for consuming code to simply ignore the extra data when it is not relevant.

(One downside is that it is now easier to accidentally ignore the extra data when it *is* relevant, but I think that's generally a favourable tradeoff.)

### Impact

After this change, THIR pattern trees should be “logically identical” to the previous THIR pattern trees, in the sense that information that was carried by wrapper nodes should now be directly attached to the non-wrapper nodes that were being wrapped. Types and spans associated with THIR pattern nodes should (hopefully!) still be accurate.

There should be no change to the output of THIR-based checks or MIR building.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 10, 2026
THIR patterns: Replace `AscribeUserType` and `ExpandedConstant` wrappers with per-node data

This PR removes the `AscribeUserType` and `ExpandedConstant` variants from `thir::PatKind`, and replaces them with an `Option<Box<PatExtra>>` field attached to every `thir::Pat`.

### Why remove these variants?

Unlike other THIR pattern kinds, these variants are mere “wrappers” that exist to attach some additional information to an underlying pattern node.

There are several places where code that consumes THIR patterns needs to carefully “unpeel” any wrapper nodes, in order to match on the underlying pattern. This is clunky, and easy to forget to do, especially since it's not always obvious where the wrapper nodes can and can't appear.

Attaching the data to an optional per-node field makes it easier for consuming code to simply ignore the extra data when it is not relevant.

(One downside is that it is now easier to accidentally ignore the extra data when it *is* relevant, but I think that's generally a favourable tradeoff.)

### Impact

After this change, THIR pattern trees should be “logically identical” to the previous THIR pattern trees, in the sense that information that was carried by wrapper nodes should now be directly attached to the non-wrapper nodes that were being wrapped. Types and spans associated with THIR pattern nodes should (hopefully!) still be accurate.

There should be no change to the output of THIR-based checks or MIR building.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 10, 2026
THIR patterns: Replace `AscribeUserType` and `ExpandedConstant` wrappers with per-node data

This PR removes the `AscribeUserType` and `ExpandedConstant` variants from `thir::PatKind`, and replaces them with an `Option<Box<PatExtra>>` field attached to every `thir::Pat`.

### Why remove these variants?

Unlike other THIR pattern kinds, these variants are mere “wrappers” that exist to attach some additional information to an underlying pattern node.

There are several places where code that consumes THIR patterns needs to carefully “unpeel” any wrapper nodes, in order to match on the underlying pattern. This is clunky, and easy to forget to do, especially since it's not always obvious where the wrapper nodes can and can't appear.

Attaching the data to an optional per-node field makes it easier for consuming code to simply ignore the extra data when it is not relevant.

(One downside is that it is now easier to accidentally ignore the extra data when it *is* relevant, but I think that's generally a favourable tradeoff.)

### Impact

After this change, THIR pattern trees should be “logically identical” to the previous THIR pattern trees, in the sense that information that was carried by wrapper nodes should now be directly attached to the non-wrapper nodes that were being wrapped. Types and spans associated with THIR pattern nodes should (hopefully!) still be accurate.

There should be no change to the output of THIR-based checks or MIR building.
rust-bors bot added a commit that referenced this pull request Jan 11, 2026
Rollup of 11 pull requests

Successful merges:

 - #148196 (Implement create_dir_all() to operate iteratively instead of recursively)
 - #150494 ( Fix dso_local for external statics with linkage)
 - #150788 (THIR patterns: Replace `AscribeUserType` and `ExpandedConstant` wrappers with per-node data)
 - #150799 (Fix ICE: can't type-check body of DefId  for issue #148729)
 - #150804 (Remove std_detect_file_io and std_detect_dlsym_getauxval features)
 - #150852 (std: sys: fs: uefi: Implement File::write)
 - #150871 (Use f64 NaN in documentation instead of sqrt(-1.0))
 - #150878 (Emit an error for linking staticlibs on BPF)
 - #150911 (Add missing documentation for globs feature)
 - #150913 (compiler: Forward attributes to eii-expanded macros)
 - #150916 (Once again, reorganize the EII tests a bit)

r? @ghost
rust-bors bot added a commit that referenced this pull request Jan 11, 2026
Rollup of 12 pull requests

Successful merges:

 - #150947 (alloctests: Don't run the longer partial-sort tests under Miri)
 - #148196 (Implement create_dir_all() to operate iteratively instead of recursively)
 - #150494 ( Fix dso_local for external statics with linkage)
 - #150788 (THIR patterns: Replace `AscribeUserType` and `ExpandedConstant` wrappers with per-node data)
 - #150799 (Fix ICE: can't type-check body of DefId  for issue #148729)
 - #150804 (Remove std_detect_file_io and std_detect_dlsym_getauxval features)
 - #150852 (std: sys: fs: uefi: Implement File::write)
 - #150871 (Use f64 NaN in documentation instead of sqrt(-1.0))
 - #150878 (Emit an error for linking staticlibs on BPF)
 - #150911 (Add missing documentation for globs feature)
 - #150913 (compiler: Forward attributes to eii-expanded macros)
 - #150916 (Once again, reorganize the EII tests a bit)

r? @ghost
@rust-bors rust-bors bot merged commit 8a5c66e into rust-lang:main Jan 11, 2026
11 checks passed
@rustbot rustbot added this to the 1.94.0 milestone Jan 11, 2026
rust-timer added a commit that referenced this pull request Jan 11, 2026
Rollup merge of #150788 - thir-pat, r=Nadrieril

THIR patterns: Replace `AscribeUserType` and `ExpandedConstant` wrappers with per-node data

This PR removes the `AscribeUserType` and `ExpandedConstant` variants from `thir::PatKind`, and replaces them with an `Option<Box<PatExtra>>` field attached to every `thir::Pat`.

### Why remove these variants?

Unlike other THIR pattern kinds, these variants are mere “wrappers” that exist to attach some additional information to an underlying pattern node.

There are several places where code that consumes THIR patterns needs to carefully “unpeel” any wrapper nodes, in order to match on the underlying pattern. This is clunky, and easy to forget to do, especially since it's not always obvious where the wrapper nodes can and can't appear.

Attaching the data to an optional per-node field makes it easier for consuming code to simply ignore the extra data when it is not relevant.

(One downside is that it is now easier to accidentally ignore the extra data when it *is* relevant, but I think that's generally a favourable tradeoff.)

### Impact

After this change, THIR pattern trees should be “logically identical” to the previous THIR pattern trees, in the sense that information that was carried by wrapper nodes should now be directly attached to the non-wrapper nodes that were being wrapped. Types and spans associated with THIR pattern nodes should (hopefully!) still be accurate.

There should be no change to the output of THIR-based checks or MIR building.
@Zalathar Zalathar deleted the thir-pat branch January 11, 2026 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants