Skip to content

Chore/move more types to ir#152706

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

Chore/move more types to ir#152706
Jamesbarford wants to merge 8 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

This comment has been minimized.

@Jamesbarford Jamesbarford force-pushed the chore/move-more-types-to-ir branch from f89feb9 to 0780eb0 Compare March 3, 2026 10:13
@rust-log-analyzer

This comment has been minimized.

@Jamesbarford Jamesbarford force-pushed the chore/move-more-types-to-ir branch from 207dc41 to bc41000 Compare March 3, 2026 10:54
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-20 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 (95818632KB >= 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}
---
set -ex

# Run a subset of tests. Used to run tests in parallel in multiple jobs.

# When this job partition is run as part of PR CI, skip tidy to allow revealing more failures. The
# dedicated `tidy` job failing won't block other PR CI jobs from completing, and so tidy failures
# shouldn't inhibit revealing other failures in PR CI jobs.
if [ "$PR_CI_JOB" == "1" ]; then
  echo "PR_CI_JOB set; skipping tidy"
  SKIP_TIDY="--skip tidy"
fi

../x.py --stage 2 test \
  ${SKIP_TIDY:+$SKIP_TIDY} \
  --skip compiler \
  --skip src
#!/bin/bash

set -ex

# Run a subset of tests. Used to run tests in parallel in multiple jobs.

# When this job partition is run as part of PR CI, skip tidy to allow revealing more failures. The
# dedicated `tidy` job failing won't block other PR CI jobs from completing, and so tidy failures
# shouldn't inhibit revealing other failures in PR CI jobs.
if [ "$PR_CI_JOB" == "1" ]; then
  echo "PR_CI_JOB set; skipping tidy"
  SKIP_TIDY="--skip tidy"
fi

../x.py --stage 2 test \
  ${SKIP_TIDY:+$SKIP_TIDY} \
  --skip tests \
  --skip coverage-map \
  --skip coverage-run \
  --skip library \
  --skip tidyselftest
---

error[E0106]: missing lifetime specifier
   --> compiler/rustc_type_ir/src/interner.rs:467:46
    |
467 |     fn get_ty_var(self, id: usize) -> Option<&Ty<Self>>;
    |                                              ^ expected named lifetime parameter
    |
    = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`
    |
467 |     fn get_ty_var(self, id: usize) -> Option<&'static Ty<Self>>;
    |                                               +++++++
help: instead, you are more likely to want to return an owned value
    |
467 -     fn get_ty_var(self, id: usize) -> Option<&Ty<Self>>;
467 +     fn get_ty_var(self, id: usize) -> Option<Ty<Self>>;
    |

error[E0106]: missing lifetime specifier
   --> compiler/rustc_type_ir/src/interner.rs:469:48
    |
469 |     fn get_fresh_ty(self, id: usize) -> Option<&Ty<Self>>;
    |                                                ^ expected named lifetime parameter
    |
    = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`
    |
469 |     fn get_fresh_ty(self, id: usize) -> Option<&'static Ty<Self>>;
    |                                                 +++++++
help: instead, you are more likely to want to return an owned value
    |
469 -     fn get_fresh_ty(self, id: usize) -> Option<&Ty<Self>>;
469 +     fn get_fresh_ty(self, id: usize) -> Option<Ty<Self>>;
    |

error[E0106]: missing lifetime specifier
   --> compiler/rustc_type_ir/src/interner.rs:471:52
    |
471 |     fn get_fresh_ty_int(self, id: usize) -> Option<&Ty<Self>>;
    |                                                    ^ expected named lifetime parameter
    |
    = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`
    |
471 |     fn get_fresh_ty_int(self, id: usize) -> Option<&'static Ty<Self>>;
    |                                                     +++++++
help: instead, you are more likely to want to return an owned value
    |
471 -     fn get_fresh_ty_int(self, id: usize) -> Option<&Ty<Self>>;
471 +     fn get_fresh_ty_int(self, id: usize) -> Option<Ty<Self>>;
    |

error[E0106]: missing lifetime specifier
   --> compiler/rustc_type_ir/src/interner.rs:473:54
    |
473 |     fn get_fresh_ty_float(self, id: usize) -> Option<&Ty<Self>>;
    |                                                      ^ expected named lifetime parameter
    |
    = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`
    |
473 |     fn get_fresh_ty_float(self, id: usize) -> Option<&'static Ty<Self>>;
    |                                                       +++++++
help: instead, you are more likely to want to return an owned value
    |
473 -     fn get_fresh_ty_float(self, id: usize) -> Option<&Ty<Self>>;
473 +     fn get_fresh_ty_float(self, id: usize) -> Option<Ty<Self>>;
    |

error[E0106]: missing lifetime specifier
   --> compiler/rustc_type_ir/src/interner.rs:475:53
    |
475 |     fn get_anon_bound_ty(self, id: usize) -> Option<&Vec<Ty<Self>>>;
    |                                                     ^ expected named lifetime parameter
    |
    = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`
    |
475 |     fn get_anon_bound_ty(self, id: usize) -> Option<&'static Vec<Ty<Self>>>;
    |                                                      +++++++
help: instead, you are more likely to want to return an owned value
    |
475 -     fn get_anon_bound_ty(self, id: usize) -> Option<&Vec<Ty<Self>>>;
475 +     fn get_anon_bound_ty(self, id: usize) -> Option<Vec<Ty<Self>>>;
    |

error[E0106]: missing lifetime specifier
   --> compiler/rustc_type_ir/src/interner.rs:477:63
    |
477 |     fn get_anon_canonical_bound_ty(self, id: usize) -> Option<&Ty<Self>>;
    |                                                               ^ expected named lifetime parameter
    |
    = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`
    |
477 |     fn get_anon_canonical_bound_ty(self, id: usize) -> Option<&'static Ty<Self>>;
    |                                                                +++++++
help: instead, you are more likely to want to return an owned value
    |
477 -     fn get_anon_canonical_bound_ty(self, id: usize) -> Option<&Ty<Self>>;
477 +     fn get_anon_canonical_bound_ty(self, id: usize) -> Option<Ty<Self>>;
    |

error[E0425]: cannot find type `Mutability` in this scope
   --> compiler/rustc_type_ir/src/inherent.rs:102:46
    |
102 |     fn new_ptr(interner: I, ty: Self, mutbl: Mutability) -> Self;
    |                                              ^^^^^^^^^^ not found in this scope
    |
help: consider importing one of these enums
    |
  6 + use crate::Mutability;
    |
  6 + use rustc_ast_ir::Mutability;
    |

error[E0425]: cannot find type `Mutability` in this scope
   --> compiler/rustc_type_ir/src/inherent.rs:104:65
    |
104 |     fn new_ref(interner: I, region: I::Region, ty: Self, mutbl: Mutability) -> Self;
    |                                                                 ^^^^^^^^^^ not found in this scope
    |
help: consider importing one of these enums
    |
  6 + use crate::Mutability;
    |
  6 + use rustc_ast_ir::Mutability;
    |

error[E0425]: cannot find value `index` in this scope
    --> compiler/rustc_type_ir/src/binder.rs:1673:61
     |
1673 |             && let Some(inner) = interner.get_anon_bound_ty(index.as_usize())
     |                                                             ^^^^^ not found in this scope
     |
help: consider importing one of these constants
     |
   1 + use crate::binder::sym::index;

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