Skip to content

ty::Alias refactor#154758

Merged
rust-bors[bot] merged 7 commits intorust-lang:mainfrom
WaffleLapkin:aliassss
Apr 7, 2026
Merged

ty::Alias refactor#154758
rust-bors[bot] merged 7 commits intorust-lang:mainfrom
WaffleLapkin:aliassss

Conversation

@WaffleLapkin
Copy link
Copy Markdown
Member

@WaffleLapkin WaffleLapkin commented Apr 3, 2026

View all comments

This PR changes the following alias-related types from this:

pub enum AliasTyKind {
    Projection,
    Inherent,
    Opaque,
    Free,
}

pub struct AliasTy<I: Interner> {
    pub args: I::GenericArgs,
    pub def_id: I::DefId,
}

pub enum TyKind<I: Interner> {
    ...
    Alias(AliasTyKind, AliasTy<I>),
}

Into this:

pub enum AliasTyKind<I: Interner> {
    Projection { def_id: I::DefId },
    Inherent { def_id: I::DefId },
    Opaque { def_id: I::DefId },
    Free { def_id: I::DefId },
}

pub struct AliasTy<I: Interner> {
    pub args: I::GenericArgs,
    pub kind: AliasTyKind<I>,
}

pub enum TyKind<I: Interner> {
    ...
    Alias(AliasTy<I>),
}

... and then does a thousand other changes to accommodate for this change everywhere.

This brings us closer to being able to have AliasTyKinds which don't require a DefId (and thus can be more easily created, etc). Although notably we depend on both AliasTyKind -> DefId and DefId -> AliasTyKind conversions in a bunch of places still.

r? lcnr


A lot of these changes were done either by search & replace (via ast-grep) or on auto pilot, so I'm not quite sure I didn't mess up somewhere, but at least tests pass...

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 3, 2026

Some changes occurred in exhaustiveness checking

cc @Nadrieril

Some changes occurred in need_type_info.rs

cc @lcnr

changes to the core type system

cc @lcnr

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

changes to the core type system

cc @lcnr

This PR changes rustc_public

cc @oli-obk, @celinval, @ouz-a, @makai410

HIR ty lowering was modified

cc @fmease

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Apr 3, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

Copy link
Copy Markdown
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

winning!

Let's add a refactor tracking issue for future cleanups:

replace all the <name> @ ty::AliasTy { matches with just using args: <name>_args instead

I think similarly, the assert on AliasTy is less valuable now that we go through AliasTyKind, so maybe remove the assert, third field, and make matches nicer again

let's also look at def_id: did and do a rename to make that unnecessary in a future PR.

Ideally we don't have new_from_def_id or a alias_ty_kind_from_def_id but instead call e.g. new_projection directly, also future work

I also expect that most uses of AliasTyKind::def_id should be made unnecessary via a larger rewrite of the code

is_impl_trait should be renamed to is_opaque

there are uses of tcx.mk_ty_from_kind which should be a more specific constructor method

please rebase -> perf -> r=me if the impact is as expected from the size change test

View changes since this review

Comment on lines +39 to +40
/// During codegen, `interner.type_of(def_id)` can be used to get the type of the
/// underlying type if the type is an opaque.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that comment feels wrong here

should be on Opaque

also vibes: I prefer keeping comments on the variant if there's just a single field, otherwise the formatting is kinda /

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it more on the variant, but changed anyway.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I fixed the docs, can you double check?

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 6, 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.

@WaffleLapkin
Copy link
Copy Markdown
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Apr 6, 2026
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 6, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 6, 2026

☀️ Try build successful (CI)
Build commit: 5340284 (5340284638d1148f25eaeb7e354eb90237024842, parent: 5a0d572cd1bbe1e3f75d64b32d86dbd277ce4b89)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (5340284): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

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.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@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.3% [0.1%, 0.5%] 15
Improvements ✅
(primary)
-0.1% [-0.1%, -0.1%] 1
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.2%] 4
All ❌✅ (primary) -0.1% [-0.1%, -0.1%] 1

Max RSS (memory usage)

Results (primary 1.6%, secondary 0.3%)

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

mean range count
Regressions ❌
(primary)
1.6% [0.5%, 4.4%] 5
Regressions ❌
(secondary)
1.2% [1.0%, 2.0%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.3% [-4.3%, -4.3%] 1
All ❌✅ (primary) 1.6% [0.5%, 4.4%] 5

Cycles

Results (secondary -0.9%)

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

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.4% [1.8%, 3.0%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-7.6% [-10.5%, -4.7%] 2
All ❌✅ (primary) - - 0

Binary size

Results (primary 0.0%, secondary 0.0%)

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

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

Bootstrap: 488.486s -> 488.964s (0.10%)
Artifact size: 395.12 MiB -> 395.18 MiB (0.01%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Apr 6, 2026
Copy link
Copy Markdown
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me after removing the new_from_args file

View changes since this review

@lcnr
Copy link
Copy Markdown
Contributor

lcnr commented Apr 7, 2026

@bors rollup=never

Add `#[track_caller]` to some functions which can panic b/c of the
caller's wrong index (this helped me debug some mistakes I did while
refactoring `ty::Alias`)
@WaffleLapkin
Copy link
Copy Markdown
Member Author

@bors r=lcnr

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 7, 2026

📌 Commit 6ab50d5 has been approved by lcnr

It is now in the queue for this repository.

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

This comment has been minimized.

@rust-bors rust-bors bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 7, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 7, 2026

☀️ Test successful - CI
Approved by: lcnr
Duration: 3h 34m 55s
Pushing c3bd628 to main...

@rust-bors rust-bors bot merged commit c3bd628 into rust-lang:main Apr 7, 2026
12 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Apr 7, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 49b6ac0 (parent) -> c3bd628 (this PR)

Test differences

Show 98 test diffs

98 doctest diffs were found. These are ignored, as they are noisy.

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard c3bd6289f65fa7210c50bdeeb0ed4541caa33d2d --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-apple-various: 1h 34m -> 1h 54m (+21.5%)
  2. dist-x86_64-apple: 2h 10m -> 1h 47m (-17.2%)
  3. aarch64-apple: 3h -> 3h 28m (+15.9%)
  4. dist-aarch64-msvc: 1h 34m -> 1h 46m (+12.7%)
  5. dist-aarch64-apple: 1h 52m -> 2h 4m (+10.7%)
  6. pr-check-2: 41m 15s -> 44m 42s (+8.4%)
  7. x86_64-msvc-ext1: 2h 5m -> 2h 15m (+8.2%)
  8. dist-x86_64-netbsd: 1h 27m -> 1h 20m (-7.9%)
  9. x86_64-msvc-ext2: 1h 57m -> 1h 48m (-7.9%)
  10. dist-aarch64-llvm-mingw: 1h 32m -> 1h 39m (+7.7%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (c3bd628): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

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.3% [0.1%, 0.5%] 14
Improvements ✅
(primary)
-0.2% [-0.2%, -0.1%] 2
Improvements ✅
(secondary)
-0.2% [-0.3%, -0.2%] 5
All ❌✅ (primary) -0.2% [-0.2%, -0.1%] 2

Max RSS (memory usage)

Results (primary 1.0%, secondary 1.3%)

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

mean range count
Regressions ❌
(primary)
1.0% [0.9%, 1.1%] 2
Regressions ❌
(secondary)
2.4% [0.9%, 4.2%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.1% [-2.1%, -2.1%] 1
All ❌✅ (primary) 1.0% [0.9%, 1.1%] 2

Cycles

Results (secondary 1.4%)

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

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

Binary size

Results (primary 0.1%, secondary 0.1%)

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

mean range count
Regressions ❌
(primary)
0.1% [0.0%, 0.1%] 63
Regressions ❌
(secondary)
0.1% [0.0%, 0.1%] 24
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [0.0%, 0.1%] 63

Bootstrap: 487.434s -> 487.084s (-0.07%)
Artifact size: 395.10 MiB -> 395.18 MiB (0.02%)

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

Labels

merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants