Skip to content

Chore/move more types to ir#152706

Draft
Jamesbarford wants to merge 7 commits intorust-lang:mainfrom
Jamesbarford:chore/move-more-types-to-ir
Draft

Chore/move more types to ir#152706
Jamesbarford wants to merge 7 commits intorust-lang:mainfrom
Jamesbarford:chore/move-more-types-to-ir

Conversation

@Jamesbarford
Copy link
Contributor

r? ghost

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Feb 16, 2026
@Jamesbarford Jamesbarford force-pushed the chore/move-more-types-to-ir branch from 3ef4cf0 to c64839d Compare February 16, 2026 12:35
@rust-log-analyzer

This comment has been minimized.

@lcnr lcnr self-assigned this Feb 16, 2026
where
F: FnOnce(&mut Self) -> R;
pub trait TyEncoder<'tcx>: ir_codec::TyEncoder<'tcx, Interner = TyCtxt<'tcx>> {}
impl<'tcx, T> TyEncoder<'tcx> for T where T: ir_codec::TyEncoder<'tcx, Interner = TyCtxt<'tcx>> {}
Copy link
Contributor

Choose a reason for hiding this comment

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

why does this trait have to be moved? This is surprising to me

Might be good to write in the PR description what you're moving and why.

As in, sth like

  • moving Ty
  • also uses other types X which now need to be moved
  • has function which relies on tcx, add method fn XXX to trait Interner

feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
)]
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
Copy link
Contributor

Choose a reason for hiding this comment

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

?

#[rustc_diagnostic_item = "Ty"]
#[rustc_pass_by_value]
#[rustc_has_incoherent_inherent_impls]
pub struct Ty<I: Interner>(pub I::Interned<WithCachedTypeInfo<TyKind<I>>>);
Copy link
Contributor

Choose a reason for hiding this comment

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

should be in a mod ty or mod sty to mirror rustc_middle

#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
#[rustc_diagnostic_item = "Ty"]
#[rustc_pass_by_value]
#[rustc_has_incoherent_inherent_impls]
Copy link
Contributor

Choose a reason for hiding this comment

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

dubious :3 i guess that's a way to simply the migration. Removing this before merge/add a TODO rn

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I was experimenting with things. This in my opinion is 'cheating', I'll remove it

#[inline]
pub fn interned(self) -> I::Interned<WithCachedTypeInfo<TyKind<I>>> {
self.0
}
Copy link
Contributor

Choose a reason for hiding this comment

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

where is this used?

}

#[inline]
#[allow(rustc::pass_by_value)]
Copy link
Contributor

Choose a reason for hiding this comment

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

why by ref?


impl<I: Interner> TypeSuperVisitable<I> for Ty<I>
where
I::Interned<WithCachedTypeInfo<TyKind<I>>>: Deref<Target = WithCachedTypeInfo<TyKind<I>>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

should be item bound of I::Interned, same with all other where-bounds here

I::Region: TypeFoldable<I> + TypeVisitable<I>,
I::Term: From<Ty<I>>,
I::Tys: TypeFoldable<I> + TypeVisitable<I>,
I::Interned<WithCachedTypeInfo<TyKind<I>>>:
Copy link
Contributor

Choose a reason for hiding this comment

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

all item bounds of Interned

/// This offset is also chosen so that the first byte is never < 0x80.
pub const SHORTHAND_OFFSET: usize = 0x80;

pub trait TyEncoder<'tcx>: SpanEncoder {
Copy link
Contributor

Choose a reason for hiding this comment

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

this feels rustc specific and is not used by r-a afaik, so I'd prefer keeping this in rustc_middle for now

}

pub trait Interned<T>: Clone + Copy + Hash + PartialEq + Eq + Debug {
fn new_unchecked(t: &T) -> Self;
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 where is that used, surprising that we'd ever want to use this in rustc_next_trait_solver

+ Hash
+ Eq
+ PartialEq
+ Deref<Target = T>;
Copy link
Contributor

Choose a reason for hiding this comment

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

should be a super trait bounds of a single Interned trait

#![cfg_attr(feature = "nightly", rustc_diagnostic_item = "type_ir")]
// tidy-alphabetical-start
#![allow(rustc::direct_use_of_rustc_type_ir)]
#![allow(rustc::pass_by_value)]
Copy link
Contributor

Choose a reason for hiding this comment

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

please don't

Copy link
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.

changes to rustc_next_trait_solver look as expected

don't need to change rust-analyzer for now as they don't directly depend on rustc. We need ot change it to test that it's correct, but I'd wait on actually getting rustc to work for this

View changes since this review

@Jamesbarford Jamesbarford force-pushed the chore/move-more-types-to-ir branch from c64839d to 9b563d7 Compare February 26, 2026 09:28
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

BlobDecoder, BytePos, ByteSymbol, DUMMY_SP, Pos, RemapPathScopeComponents, SpanData,
SpanDecoder, Symbol, SyntaxContext, kw,
};
use rustc_type_ir::codec::TyDecoder;
Copy link
Contributor

Choose a reason for hiding this comment

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

TyDecoder should stay in rustc_middle 🤔

def_id: DefId,
args: Self::GenericArgs,
) -> Ty<'tcx> {
Ty::new_coroutine_witness_for_coroutine(self, def_id, args)
Copy link
Contributor

Choose a reason for hiding this comment

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

why method on Interner insetead of Ty?

}

fn ty_discriminant_ty(self, ty: Ty<'tcx>) -> Ty<'tcx> {
ty.discriminant_ty(self)
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

Comment on lines +746 to +748
fn u8_type(self) -> Ty<'tcx> {
self.types.u8
}
Copy link
Contributor

Choose a reason for hiding this comment

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

can you, potentially in an earlier PR so that we can test it for perf, stop using self.types.X and instead use Ty::new_uint(..). This should inline to the same thing and means whether we have a precomputed interned type for u8 is not handled by the interner

use rustc_macros::{Lift, extension};
use rustc_session::cstore::{ExternCrate, ExternCrateSource};
use rustc_span::{Ident, RemapPathScopeComponents, Symbol, kw, sym};
use rustc_type_ir::inherent::{GenericArgs as _, IntoKind as _};
Copy link
Contributor

Choose a reason for hiding this comment

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

why? we should never import these traits 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe it is due to have implemented IntoKind on Ty to expose the kind() method but then not made a pub fn kind(&self) pass-through method that previously existed. I would think once I've implemented the pass-through I can remove this. As for GenericArgs, it could possibly a similar reason

tcx,
trait_def_id,
[self_ty, Ty::new_tup(tcx, args)],
[self_ty, ty::Ty::new_tup(tcx, args)],
Copy link
Contributor

Choose a reason for hiding this comment

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

this should lint 🤔 as we want people to consistently use Ty and import it from rustc_middle::ty. We should have some #[cfg_if("nightly", rustc_diagnostic_item = "Ty")] attribute on Ty

write!(p, ")")?;

if !sig.output().is_unit() {
if !matches!(sig.output().kind(), ty::Tuple(tys) if tys.is_empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

:<

type GenericArgsSlice: Copy + Debug + Hash + Eq + SliceLike<Item = Self::GenericArg>;
type GenericArg: GenericArg<Self>;
type Term: Term<Self>;
type Term: Term<Self> + From<Ty<Self>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

From<Ty<Self>> should be super-trait of Term instead

@rustbot rustbot added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Mar 2, 2026
@Jamesbarford Jamesbarford force-pushed the chore/move-more-types-to-ir branch from 4bb23fa to f89feb9 Compare March 2, 2026 16:24
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
/dev/sda15      105M  6.2M   99M   6% /boot/efi
tmpfs           1.6G   12K  1.6G   1% /run/user/1001
================================================================================

Sufficient disk space available (94917476KB >= 52428800KB). Skipping cleanup.
##[group]Run echo "[CI_PR_NUMBER=$num]"
echo "[CI_PR_NUMBER=$num]"
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
---

error: unknown start of token: `
   --> compiler/rustc_type_ir/src/inherent.rs:602:54
    |
602 | ||||||| parent of 9b563d7d339 (Moved over methods to `rustc_type_ir` and added helper functions to)
    |                                                      ^
    |
help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not
    |
602 - ||||||| parent of 9b563d7d339 (Moved over methods to `rustc_type_ir` and added helper functions to)
602 + ||||||| parent of 9b563d7d339 (Moved over methods to 'rustc_type_ir` and added helper functions to)
    |

error: unknown start of token: `
   --> compiler/rustc_type_ir/src/inherent.rs:602:68
    |
602 | ||||||| parent of 9b563d7d339 (Moved over methods to `rustc_type_ir` and added helper functions to)
    |                                                                    ^
    |
help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not
    |
602 - ||||||| parent of 9b563d7d339 (Moved over methods to `rustc_type_ir` and added helper functions to)
602 + ||||||| parent of 9b563d7d339 (Moved over methods to `rustc_type_ir' and added helper functions to)
    |

error: unknown start of token: `
   --> compiler/rustc_type_ir/src/inherent.rs:611:44
    |
611 | >>>>>>> 9b563d7d339 (Moved over methods to `rustc_type_ir` and added helper functions to)
    |                                            ^
    |
help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not
    |
611 - >>>>>>> 9b563d7d339 (Moved over methods to `rustc_type_ir` and added helper functions to)
611 + >>>>>>> 9b563d7d339 (Moved over methods to 'rustc_type_ir` and added helper functions to)
    |

error: unknown start of token: `
   --> compiler/rustc_type_ir/src/inherent.rs:611:58
    |
611 | >>>>>>> 9b563d7d339 (Moved over methods to `rustc_type_ir` and added helper functions to)
    |                                                          ^
    |
help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not
    |
611 - >>>>>>> 9b563d7d339 (Moved over methods to `rustc_type_ir` and added helper functions to)
611 + >>>>>>> 9b563d7d339 (Moved over methods to `rustc_type_ir' and added helper functions to)
    |

error: unknown start of token: `
   --> compiler/rustc_type_ir/src/inherent.rs:628:76
    |
628 | ||||||| parent of 50840285187 (Start moving over implementation details of `Ty` to `rustc_type_ir`,)
    |                                                                            ^
    |
help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not
    |
628 - ||||||| parent of 50840285187 (Start moving over implementation details of `Ty` to `rustc_type_ir`,)
628 + ||||||| parent of 50840285187 (Start moving over implementation details of 'Ty` to `rustc_type_ir`,)
    |

error: unknown start of token: `
   --> compiler/rustc_type_ir/src/inherent.rs:628:79
    |
628 | ||||||| parent of 50840285187 (Start moving over implementation details of `Ty` to `rustc_type_ir`,)
    |                                                                               ^
    |
help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not
    |
628 - ||||||| parent of 50840285187 (Start moving over implementation details of `Ty` to `rustc_type_ir`,)
628 + ||||||| parent of 50840285187 (Start moving over implementation details of `Ty' to `rustc_type_ir`,)
    |

error: unknown start of token: `
   --> compiler/rustc_type_ir/src/inherent.rs:628:84
    |
628 | ||||||| parent of 50840285187 (Start moving over implementation details of `Ty` to `rustc_type_ir`,)
    |                                                                                    ^
    |
help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not
    |
628 - ||||||| parent of 50840285187 (Start moving over implementation details of `Ty` to `rustc_type_ir`,)
628 + ||||||| parent of 50840285187 (Start moving over implementation details of `Ty` to 'rustc_type_ir`,)
    |

error: unknown start of token: `
   --> compiler/rustc_type_ir/src/inherent.rs:628:98
    |
628 | ||||||| parent of 50840285187 (Start moving over implementation details of `Ty` to `rustc_type_ir`,)
    |                                                                                                  ^
    |
help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not
    |
628 - ||||||| parent of 50840285187 (Start moving over implementation details of `Ty` to `rustc_type_ir`,)
628 + ||||||| parent of 50840285187 (Start moving over implementation details of `Ty` to `rustc_type_ir',)
    |

error: unknown start of token: `
   --> compiler/rustc_type_ir/src/inherent.rs:631:66
    |
631 | >>>>>>> 50840285187 (Start moving over implementation details of `Ty` to `rustc_type_ir`,)
    |                                                                  ^
    |
help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not
    |
631 - >>>>>>> 50840285187 (Start moving over implementation details of `Ty` to `rustc_type_ir`,)
631 + >>>>>>> 50840285187 (Start moving over implementation details of 'Ty` to `rustc_type_ir`,)
    |

error: unknown start of token: `
   --> compiler/rustc_type_ir/src/inherent.rs:631:69
    |
631 | >>>>>>> 50840285187 (Start moving over implementation details of `Ty` to `rustc_type_ir`,)
    |                                                                     ^
    |
help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not
    |
631 - >>>>>>> 50840285187 (Start moving over implementation details of `Ty` to `rustc_type_ir`,)
631 + >>>>>>> 50840285187 (Start moving over implementation details of `Ty' to `rustc_type_ir`,)
    |

error: unknown start of token: `
   --> compiler/rustc_type_ir/src/inherent.rs:631:74
    |
631 | >>>>>>> 50840285187 (Start moving over implementation details of `Ty` to `rustc_type_ir`,)
    |                                                                          ^
    |
help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not
    |
631 - >>>>>>> 50840285187 (Start moving over implementation details of `Ty` to `rustc_type_ir`,)
631 + >>>>>>> 50840285187 (Start moving over implementation details of `Ty` to 'rustc_type_ir`,)
    |

error: unknown start of token: `
   --> compiler/rustc_type_ir/src/inherent.rs:631:88
    |
631 | >>>>>>> 50840285187 (Start moving over implementation details of `Ty` to `rustc_type_ir`,)
    |                                                                                        ^
    |
help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not
    |
631 - >>>>>>> 50840285187 (Start moving over implementation details of `Ty` to `rustc_type_ir`,)
631 + >>>>>>> 50840285187 (Start moving over implementation details of `Ty` to `rustc_type_ir',)
    |

error: encountered diff marker
   --> compiler/rustc_type_ir/src/inherent.rs:15:1
    |
 15 | <<<<<<< HEAD
    | ^^^^^^^ between this marker and `|||||||` is the code that you are merging into
...
602 | ||||||| parent of 9b563d7d339 (Moved over methods to `rustc_type_ir` and added helper functions to)
    | ------- between this marker and `=======` is the base code (what the two refs diverged from)
603 | =======
    | ------- between this marker and `>>>>>>>` is the incoming code
...
611 | >>>>>>> 9b563d7d339 (Moved over methods to `rustc_type_ir` and added helper functions to)
    | ^^^^^^^ this marker concludes the conflict region
    |
    = note: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
            to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
    = help: if you are in a merge, the top section is the code you already had checked out and the bottom section is the new code
            if you are in a rebase, the top section is the code being rebased onto and the bottom section is the code you had checked out which is being rebased
    = note: for an explanation on these markers from the `git` documentation, visit <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>

[RUSTC-TIMING] rustc_type_ir test:false 0.020
warning: `rustc_type_ir` (lib) generated 1 warning
error: could not compile `rustc_type_ir` (lib) due to 13 previous errors; 1 warning emitted
warning: build failed, waiting for other jobs to finish...

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

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer 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.

4 participants