Merge pull request #20645 from ChayimFriedman2/update-rustc

internal: Upgrade rustc crates
This commit is contained in:
Shoyu Vanilla (Flint) 2025-09-10 01:45:46 +00:00 committed by GitHub
commit cd529a48f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 472 additions and 334 deletions

45
Cargo.lock generated
View file

@ -1863,9 +1863,9 @@ dependencies = [
[[package]] [[package]]
name = "ra-ap-rustc_abi" name = "ra-ap-rustc_abi"
version = "0.126.0" version = "0.128.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c6789d94fb3e6e30d62f55e99a321ba63484a8bb3b4ead338687c9ddc282d28" checksum = "8da95e732b424802b1f043ab4007c78a0fc515ab249587abbea4634bf5fdce9a"
dependencies = [ dependencies = [
"bitflags 2.9.1", "bitflags 2.9.1",
"ra-ap-rustc_hashes", "ra-ap-rustc_hashes",
@ -1875,24 +1875,24 @@ dependencies = [
[[package]] [[package]]
name = "ra-ap-rustc_ast_ir" name = "ra-ap-rustc_ast_ir"
version = "0.126.0" version = "0.128.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aaab80bda0f05e9842e3afb7779b0bad0a4b54e0f7ba6deb5705dcf86482811d" checksum = "3838d9d7a3a5cdc511cfb6ad78740ce532f75a2366d3fc3b9853ea1b5c872779"
[[package]] [[package]]
name = "ra-ap-rustc_hashes" name = "ra-ap-rustc_hashes"
version = "0.126.0" version = "0.128.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64bd405e538102b5f699241794b2eefee39d5414c0e4bc72435e91430c51f905" checksum = "bdc8995d268d3bb4ece910f575ea5a063d6003e193ec155d15703b65882d53fb"
dependencies = [ dependencies = [
"rustc-stable-hash", "rustc-stable-hash",
] ]
[[package]] [[package]]
name = "ra-ap-rustc_index" name = "ra-ap-rustc_index"
version = "0.126.0" version = "0.128.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "521621e271aa03b8433dad5981838278d6cfd7d2d8c9f4eb6d427f1d671f90fc" checksum = "ed0ccdf6e5627c6c3e54e571e52ce0bc8b94d5f0b94b7460269ca68a4706be69"
dependencies = [ dependencies = [
"ra-ap-rustc_index_macros", "ra-ap-rustc_index_macros",
"smallvec", "smallvec",
@ -1900,9 +1900,9 @@ dependencies = [
[[package]] [[package]]
name = "ra-ap-rustc_index_macros" name = "ra-ap-rustc_index_macros"
version = "0.126.0" version = "0.128.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "245e30f2e1fef258913cc548b36f575549c8af31cbc4649929d21deda96ceeb7" checksum = "bd28f42362b5c9fb9b8766c3189df02a402b13363600c6885e11027889f03ee6"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1911,9 +1911,9 @@ dependencies = [
[[package]] [[package]]
name = "ra-ap-rustc_lexer" name = "ra-ap-rustc_lexer"
version = "0.126.0" version = "0.128.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a82681f924500e888c860e60ed99e9bf702a219a69374f59116c4261525a2157" checksum = "f1c31a82f091b910a27ee53a86a9af28a2df10c3484e2f1bbfe70633aa84dee9"
dependencies = [ dependencies = [
"memchr", "memchr",
"unicode-properties", "unicode-properties",
@ -1922,9 +1922,9 @@ dependencies = [
[[package]] [[package]]
name = "ra-ap-rustc_next_trait_solver" name = "ra-ap-rustc_next_trait_solver"
version = "0.126.0" version = "0.128.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c9ce51f2431fbdc7fabd2d957522b6e27f41f68ec2af74b52a6f4116352ce1a" checksum = "f8cac6c2b5a8924209d4ca682cbc507252c58a664911e0ef463c112882ba6f72"
dependencies = [ dependencies = [
"derive-where", "derive-where",
"ra-ap-rustc_index", "ra-ap-rustc_index",
@ -1935,9 +1935,9 @@ dependencies = [
[[package]] [[package]]
name = "ra-ap-rustc_parse_format" name = "ra-ap-rustc_parse_format"
version = "0.126.0" version = "0.128.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adc85ef3fdb6c084bde84857d8948dc66b752129dc8417a8614ce490e99a143f" checksum = "a085a1cf902dcca8abbc537faaef154bbccbbb51850f779ce5484ae3782b5d8f"
dependencies = [ dependencies = [
"ra-ap-rustc_lexer", "ra-ap-rustc_lexer",
"rustc-literal-escaper 0.0.5", "rustc-literal-escaper 0.0.5",
@ -1945,9 +1945,9 @@ dependencies = [
[[package]] [[package]]
name = "ra-ap-rustc_pattern_analysis" name = "ra-ap-rustc_pattern_analysis"
version = "0.126.0" version = "0.128.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3cd81eccf33d9528905d4e5abaa254b3129a6405d6c5f123fed9b73a3d217f35" checksum = "8ba32e3985367bc34856b41c7604133649d4a367eb5d7bdf50623025731459d8"
dependencies = [ dependencies = [
"ra-ap-rustc_index", "ra-ap-rustc_index",
"rustc-hash 2.1.1", "rustc-hash 2.1.1",
@ -1958,10 +1958,11 @@ dependencies = [
[[package]] [[package]]
name = "ra-ap-rustc_type_ir" name = "ra-ap-rustc_type_ir"
version = "0.126.0" version = "0.128.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11cb0da02853698d9c89e1d1c01657b9969752befd56365e8899d4310e52b373" checksum = "9c9911d72f75d85d21fe88374d7bcec94f2200feffb7234108a24cc3da7c3591"
dependencies = [ dependencies = [
"arrayvec",
"bitflags 2.9.1", "bitflags 2.9.1",
"derive-where", "derive-where",
"ena", "ena",
@ -1977,9 +1978,9 @@ dependencies = [
[[package]] [[package]]
name = "ra-ap-rustc_type_ir_macros" name = "ra-ap-rustc_type_ir_macros"
version = "0.126.0" version = "0.128.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffc93adeb52c483ede13bee6680466458218243ab479c04fb71bb53925a6e0ff" checksum = "22f539b87991683ce17cc52e62600fdf2b4a8af43952db30387edc1a576d3b43"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

View file

@ -89,14 +89,14 @@ vfs-notify = { path = "./crates/vfs-notify", version = "0.0.0" }
vfs = { path = "./crates/vfs", version = "0.0.0" } vfs = { path = "./crates/vfs", version = "0.0.0" }
edition = { path = "./crates/edition", version = "0.0.0" } edition = { path = "./crates/edition", version = "0.0.0" }
ra-ap-rustc_lexer = { version = "0.126", default-features = false } ra-ap-rustc_lexer = { version = "0.128", default-features = false }
ra-ap-rustc_parse_format = { version = "0.126", default-features = false } ra-ap-rustc_parse_format = { version = "0.128", default-features = false }
ra-ap-rustc_index = { version = "0.126", default-features = false } ra-ap-rustc_index = { version = "0.128", default-features = false }
ra-ap-rustc_abi = { version = "0.126", default-features = false } ra-ap-rustc_abi = { version = "0.128", default-features = false }
ra-ap-rustc_pattern_analysis = { version = "0.126", default-features = false } ra-ap-rustc_pattern_analysis = { version = "0.128", default-features = false }
ra-ap-rustc_ast_ir = { version = "0.126", default-features = false } ra-ap-rustc_ast_ir = { version = "0.128", default-features = false }
ra-ap-rustc_type_ir = { version = "0.126", default-features = false } ra-ap-rustc_type_ir = { version = "0.128", default-features = false }
ra-ap-rustc_next_trait_solver = { version = "0.126", default-features = false } ra-ap-rustc_next_trait_solver = { version = "0.128", default-features = false }
# local crates that aren't published to crates.io. These should not have versions. # local crates that aren't published to crates.io. These should not have versions.

View file

@ -84,6 +84,15 @@ impl LangItemTarget {
_ => None, _ => None,
} }
} }
pub fn as_adt(self) -> Option<AdtId> {
match self {
LangItemTarget::Union(it) => Some(it.into()),
LangItemTarget::EnumId(it) => Some(it.into()),
LangItemTarget::Struct(it) => Some(it.into()),
_ => None,
}
}
} }
/// Salsa query. This will look for lang items in a specific crate. /// Salsa query. This will look for lang items in a specific crate.
@ -289,6 +298,10 @@ impl LangItem {
lang_item(db, start_crate, self).and_then(|t| t.as_trait()) lang_item(db, start_crate, self).and_then(|t| t.as_trait())
} }
pub fn resolve_adt(self, db: &dyn DefDatabase, start_crate: Crate) -> Option<AdtId> {
lang_item(db, start_crate, self).and_then(|t| t.as_adt())
}
pub fn resolve_enum(self, db: &dyn DefDatabase, start_crate: Crate) -> Option<EnumId> { pub fn resolve_enum(self, db: &dyn DefDatabase, start_crate: Crate) -> Option<EnumId> {
lang_item(db, start_crate, self).and_then(|t| t.as_enum()) lang_item(db, start_crate, self).and_then(|t| t.as_enum())
} }

View file

@ -59,7 +59,7 @@ use crate::{
lt_from_placeholder_idx, lt_from_placeholder_idx,
mir::pad16, mir::pad16,
next_solver::{ next_solver::{
BoundExistentialPredicate, Ctor, DbInterner, GenericArgs, SolverDefId, BoundExistentialPredicate, DbInterner, GenericArgs, SolverDefId,
mapping::{ mapping::{
ChalkToNextSolver, convert_args_for_result, convert_const_for_result, ChalkToNextSolver, convert_args_for_result, convert_const_for_result,
convert_region_for_result, convert_ty_for_result, convert_region_for_result, convert_ty_for_result,
@ -911,14 +911,13 @@ fn render_const_scalar_inner(
f.write_str("&")?; f.write_str("&")?;
render_const_scalar_ns(f, bytes, memory_map, t) render_const_scalar_ns(f, bytes, memory_map, t)
} }
TyKind::Adt(adt, _) if b.len() == 2 * size_of::<usize>() => match adt.def_id() { TyKind::Adt(adt, _) if b.len() == 2 * size_of::<usize>() => match adt.def_id().0 {
SolverDefId::AdtId(hir_def::AdtId::StructId(s)) => { hir_def::AdtId::StructId(s) => {
let data = f.db.struct_signature(s); let data = f.db.struct_signature(s);
write!(f, "&{}", data.name.display(f.db, f.edition()))?; write!(f, "&{}", data.name.display(f.db, f.edition()))?;
Ok(()) Ok(())
} }
SolverDefId::AdtId(_) => f.write_str("<unsized-enum-or-union>"), _ => f.write_str("<unsized-enum-or-union>"),
_ => unreachable!(),
}, },
_ => { _ => {
let addr = usize::from_le_bytes(match b.try_into() { let addr = usize::from_le_bytes(match b.try_into() {
@ -966,10 +965,7 @@ fn render_const_scalar_inner(
f.write_str(")") f.write_str(")")
} }
TyKind::Adt(def, args) => { TyKind::Adt(def, args) => {
let def = match def.def_id() { let def = def.def_id().0;
SolverDefId::AdtId(def) => def,
_ => unreachable!(),
};
let Ok(layout) = f.db.layout_of_adt(def, args, trait_env.clone()) else { let Ok(layout) = f.db.layout_of_adt(def, args, trait_env.clone()) else {
return f.write_str("<layout-error>"); return f.write_str("<layout-error>");
}; };
@ -1300,12 +1296,7 @@ impl<'db> HirDisplay for crate::next_solver::Ty<'db> {
sig.hir_fmt(f)?; sig.hir_fmt(f)?;
} }
TyKind::FnDef(def, args) => { TyKind::FnDef(def, args) => {
let def = match def { let def = def.0;
SolverDefId::FunctionId(id) => CallableDefId::FunctionId(id),
SolverDefId::Ctor(Ctor::Enum(e)) => CallableDefId::EnumVariantId(e),
SolverDefId::Ctor(Ctor::Struct(s)) => CallableDefId::StructId(s),
_ => unreachable!(),
};
let sig = db let sig = db
.callable_item_signature(def) .callable_item_signature(def)
.substitute(Interner, &convert_args_for_result(interner, args.as_slice())); .substitute(Interner, &convert_args_for_result(interner, args.as_slice()));
@ -1406,10 +1397,7 @@ impl<'db> HirDisplay for crate::next_solver::Ty<'db> {
} }
} }
TyKind::Adt(def, parameters) => { TyKind::Adt(def, parameters) => {
let def_id = match def.def_id() { let def_id = def.def_id().0;
SolverDefId::AdtId(id) => id,
_ => unreachable!(),
};
f.start_location_link(def_id.into()); f.start_location_link(def_id.into());
match f.display_kind { match f.display_kind {
DisplayKind::Diagnostics | DisplayKind::Test => { DisplayKind::Diagnostics | DisplayKind::Test => {
@ -1448,7 +1436,7 @@ impl<'db> HirDisplay for crate::next_solver::Ty<'db> {
hir_fmt_generics( hir_fmt_generics(
f, f,
convert_args_for_result(interner, parameters.as_slice()).as_slice(Interner), convert_args_for_result(interner, parameters.as_slice()).as_slice(Interner),
def.def_id().try_into().ok(), Some(def.def_id().0.into()),
None, None,
)?; )?;
} }
@ -1466,13 +1454,9 @@ impl<'db> HirDisplay for crate::next_solver::Ty<'db> {
projection_ty.hir_fmt(f)?; projection_ty.hir_fmt(f)?;
} }
TyKind::Foreign(type_alias) => { TyKind::Foreign(alias) => {
let alias = match type_alias { let type_alias = db.type_alias_signature(alias.0);
SolverDefId::TypeAliasId(id) => id, f.start_location_link(alias.0.into());
_ => unreachable!(),
};
let type_alias = db.type_alias_signature(alias);
f.start_location_link(alias.into());
write!(f, "{}", type_alias.name.display(f.db, f.edition()))?; write!(f, "{}", type_alias.name.display(f.db, f.edition()))?;
f.end_location_link(); f.end_location_link();
} }
@ -1549,10 +1533,7 @@ impl<'db> HirDisplay for crate::next_solver::Ty<'db> {
} }
} }
TyKind::Closure(id, substs) => { TyKind::Closure(id, substs) => {
let id = match id { let id = id.0;
SolverDefId::InternedClosureId(id) => id,
_ => unreachable!(),
};
let substs = convert_args_for_result(interner, substs.as_slice()); let substs = convert_args_for_result(interner, substs.as_slice());
if f.display_kind.is_source_code() { if f.display_kind.is_source_code() {
if !f.display_kind.allows_opaque() { if !f.display_kind.allows_opaque() {

View file

@ -25,7 +25,7 @@ use crate::{
consteval_nextsolver::try_const_usize, consteval_nextsolver::try_const_usize,
db::HirDatabase, db::HirDatabase,
next_solver::{ next_solver::{
DbInterner, GenericArgs, ParamEnv, SolverDefId, Ty, TyKind, TypingMode, DbInterner, GenericArgs, ParamEnv, Ty, TyKind, TypingMode,
infer::{DbInternerInferExt, traits::ObligationCause}, infer::{DbInternerInferExt, traits::ObligationCause},
mapping::{ChalkToNextSolver, convert_args_for_result}, mapping::{ChalkToNextSolver, convert_args_for_result},
project::solve_normalize::deeply_normalize, project::solve_normalize::deeply_normalize,
@ -323,14 +323,10 @@ pub fn layout_of_ty_query<'db>(
ptr.valid_range_mut().start = 1; ptr.valid_range_mut().start = 1;
Layout::scalar(dl, ptr) Layout::scalar(dl, ptr)
} }
TyKind::Closure(c, args) => { TyKind::Closure(id, args) => {
let id = match c { let def = db.lookup_intern_closure(id.0);
SolverDefId::InternedClosureId(id) => id,
_ => unreachable!(),
};
let def = db.lookup_intern_closure(id);
let infer = db.infer(def.0); let infer = db.infer(def.0);
let (captures, _) = infer.closure_info(&id.into()); let (captures, _) = infer.closure_info(&id.0.into());
let fields = captures let fields = captures
.iter() .iter()
.map(|it| { .map(|it| {

View file

@ -163,10 +163,7 @@ impl TyFingerprint {
rustc_ast_ir::Mutability::Mut => TyFingerprint::RawPtr(Mutability::Mut), rustc_ast_ir::Mutability::Mut => TyFingerprint::RawPtr(Mutability::Mut),
rustc_ast_ir::Mutability::Not => TyFingerprint::RawPtr(Mutability::Not), rustc_ast_ir::Mutability::Not => TyFingerprint::RawPtr(Mutability::Not),
}, },
TyKind::Foreign(def) => { TyKind::Foreign(def) => TyFingerprint::ForeignType(crate::to_foreign_def_id(def.0)),
let SolverDefId::TypeAliasId(def) = def else { unreachable!() };
TyFingerprint::ForeignType(crate::to_foreign_def_id(def))
}
TyKind::Dynamic(bounds, _, _) => { TyKind::Dynamic(bounds, _, _) => {
let trait_ref = bounds let trait_ref = bounds
.as_slice() .as_slice()

View file

@ -42,7 +42,7 @@ use crate::{
layout::{Layout, LayoutError, RustcEnumVariantIdx}, layout::{Layout, LayoutError, RustcEnumVariantIdx},
method_resolution::{is_dyn_method, lookup_impl_const}, method_resolution::{is_dyn_method, lookup_impl_const},
next_solver::{ next_solver::{
Ctor, DbInterner, SolverDefId, DbInterner,
mapping::{ChalkToNextSolver, convert_args_for_result, convert_ty_for_result}, mapping::{ChalkToNextSolver, convert_args_for_result, convert_ty_for_result},
}, },
static_lifetime, static_lifetime,
@ -2366,8 +2366,8 @@ impl<'db> Evaluator<'db> {
let new_id = self.vtable_map.id(ty); let new_id = self.vtable_map.id(ty);
self.write_memory(addr, &new_id.to_le_bytes())?; self.write_memory(addr, &new_id.to_le_bytes())?;
} }
TyKind::Adt(id, args) => match id.def_id() { TyKind::Adt(id, args) => match id.def_id().0 {
SolverDefId::AdtId(AdtId::StructId(s)) => { AdtId::StructId(s) => {
for (i, (_, ty)) in self.db.field_types_ns(s.into()).iter().enumerate() { for (i, (_, ty)) in self.db.field_types_ns(s.into()).iter().enumerate() {
let offset = layout.fields.offset(i).bytes_usize(); let offset = layout.fields.offset(i).bytes_usize();
let ty = ty.instantiate(interner, args); let ty = ty.instantiate(interner, args);
@ -2380,8 +2380,8 @@ impl<'db> Evaluator<'db> {
)?; )?;
} }
} }
SolverDefId::AdtId(AdtId::UnionId(_)) => (), AdtId::UnionId(_) => (),
SolverDefId::AdtId(AdtId::EnumId(e)) => { AdtId::EnumId(e) => {
if let Some((ev, layout)) = detect_variant_from_bytes( if let Some((ev, layout)) = detect_variant_from_bytes(
&layout, &layout,
self.db, self.db,
@ -2402,7 +2402,6 @@ impl<'db> Evaluator<'db> {
} }
} }
} }
_ => unreachable!(),
}, },
TyKind::Tuple(tys) => { TyKind::Tuple(tys) => {
for (id, ty) in tys.iter().enumerate() { for (id, ty) in tys.iter().enumerate() {
@ -2472,38 +2471,24 @@ impl<'db> Evaluator<'db> {
let interner = DbInterner::new_with(self.db, None, None); let interner = DbInterner::new_with(self.db, None, None);
use rustc_type_ir::TyKind; use rustc_type_ir::TyKind;
match next_ty.kind() { match next_ty.kind() {
TyKind::FnDef(def, generic_args) => { TyKind::FnDef(def, generic_args) => self.exec_fn_def(
let def = match def { def.0,
SolverDefId::FunctionId(id) => CallableDefId::FunctionId(id),
SolverDefId::Ctor(Ctor::Struct(s)) => CallableDefId::StructId(s),
SolverDefId::Ctor(Ctor::Enum(e)) => CallableDefId::EnumVariantId(e),
_ => unreachable!(),
};
self.exec_fn_def(
def,
&convert_args_for_result(interner, generic_args.as_slice()), &convert_args_for_result(interner, generic_args.as_slice()),
destination, destination,
args, args,
locals, locals,
target_bb, target_bb,
span, span,
) ),
} TyKind::Closure(id, generic_args) => self.exec_closure(
TyKind::Closure(id, generic_args) => { id.0.into(),
let id = match id {
SolverDefId::InternedClosureId(id) => id,
_ => unreachable!(),
};
self.exec_closure(
id.into(),
bytes.slice(0..0), bytes.slice(0..0),
&convert_args_for_result(interner, generic_args.as_slice()), &convert_args_for_result(interner, generic_args.as_slice()),
destination, destination,
args, args,
locals, locals,
span, span,
) ),
}
_ => Err(MirEvalError::InternalError("function pointer to non function".into())), _ => Err(MirEvalError::InternalError("function pointer to non function".into())),
} }
} }

View file

@ -1,8 +1,8 @@
//! Definition of `SolverDefId` //! Definition of `SolverDefId`
use hir_def::{ use hir_def::{
AdtId, ConstId, EnumId, EnumVariantId, FunctionId, GenericDefId, ImplId, StaticId, StructId, AdtId, CallableDefId, ConstId, EnumId, EnumVariantId, FunctionId, GenericDefId, ImplId,
TraitId, TypeAliasId, UnionId, StaticId, StructId, TraitId, TypeAliasId, UnionId,
}; };
use rustc_type_ir::inherent; use rustc_type_ir::inherent;
use stdx::impl_from; use stdx::impl_from;
@ -42,7 +42,8 @@ impl_from!(
TypeAliasId, TypeAliasId,
InternedClosureId, InternedClosureId,
InternedCoroutineId, InternedCoroutineId,
InternedOpaqueTyId InternedOpaqueTyId,
Ctor
for SolverDefId for SolverDefId
); );
@ -145,3 +146,59 @@ macro_rules! declare_id_wrapper {
} }
declare_id_wrapper!(TraitIdWrapper, TraitId); declare_id_wrapper!(TraitIdWrapper, TraitId);
declare_id_wrapper!(TypeAliasIdWrapper, TypeAliasId);
declare_id_wrapper!(ClosureIdWrapper, InternedClosureId);
declare_id_wrapper!(CoroutineIdWrapper, InternedCoroutineId);
declare_id_wrapper!(AdtIdWrapper, AdtId);
declare_id_wrapper!(ImplIdWrapper, ImplId);
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct CallableIdWrapper(pub CallableDefId);
impl std::fmt::Debug for CallableIdWrapper {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Debug::fmt(&self.0, f)
}
}
impl From<CallableIdWrapper> for CallableDefId {
#[inline]
fn from(value: CallableIdWrapper) -> CallableDefId {
value.0
}
}
impl From<CallableDefId> for CallableIdWrapper {
#[inline]
fn from(value: CallableDefId) -> CallableIdWrapper {
Self(value)
}
}
impl From<CallableIdWrapper> for SolverDefId {
#[inline]
fn from(value: CallableIdWrapper) -> SolverDefId {
match value.0 {
CallableDefId::FunctionId(it) => it.into(),
CallableDefId::StructId(it) => Ctor::Struct(it).into(),
CallableDefId::EnumVariantId(it) => Ctor::Enum(it).into(),
}
}
}
impl TryFrom<SolverDefId> for CallableIdWrapper {
type Error = ();
#[inline]
fn try_from(value: SolverDefId) -> Result<Self, Self::Error> {
match value {
SolverDefId::FunctionId(it) => Ok(Self(it.into())),
SolverDefId::Ctor(Ctor::Struct(it)) => Ok(Self(it.into())),
SolverDefId::Ctor(Ctor::Enum(it)) => Ok(Self(it.into())),
_ => Err(()),
}
}
}
impl<'db> inherent::DefId<DbInterner<'db>> for CallableIdWrapper {
fn as_local(self) -> Option<SolverDefId> {
Some(self.into())
}
fn is_local(self) -> bool {
true
}
}

View file

@ -10,9 +10,8 @@ use rustc_index::Idx;
use rustc_type_ir::InferTy::{self, FloatVar, IntVar, TyVar}; use rustc_type_ir::InferTy::{self, FloatVar, IntVar, TyVar};
use rustc_type_ir::inherent::{Const as _, IntoKind as _, Region as _, SliceLike, Ty as _}; use rustc_type_ir::inherent::{Const as _, IntoKind as _, Region as _, SliceLike, Ty as _};
use rustc_type_ir::{ use rustc_type_ir::{
BoundVar, CanonicalQueryInput, CanonicalTyVarKind, DebruijnIndex, Flags, InferConst, BoundVar, CanonicalQueryInput, DebruijnIndex, Flags, InferConst, RegionKind, TyVid, TypeFlags,
RegionKind, TypeFlags, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, UniverseIndex,
UniverseIndex,
}; };
use smallvec::SmallVec; use smallvec::SmallVec;
use tracing::debug; use tracing::debug;
@ -316,6 +315,13 @@ struct Canonicalizer<'cx, 'db> {
// Note that indices is only used once `var_values` is big enough to be // Note that indices is only used once `var_values` is big enough to be
// heap-allocated. // heap-allocated.
indices: FxHashMap<GenericArg<'db>, BoundVar>, indices: FxHashMap<GenericArg<'db>, BoundVar>,
/// Maps each `sub_unification_table_root_var` to the index of the first
/// variable which used it.
///
/// This means in case two type variables have the same sub relations root,
/// we set the `sub_root` of the second variable to the position of the first.
/// Otherwise the `sub_root` of each type variable is just its own position.
sub_root_lookup_table: FxHashMap<TyVid, usize>,
canonicalize_mode: &'cx dyn CanonicalizeMode, canonicalize_mode: &'cx dyn CanonicalizeMode,
needs_canonical_flags: TypeFlags, needs_canonical_flags: TypeFlags,
@ -384,10 +390,9 @@ impl<'cx, 'db> TypeFolder<DbInterner<'db>> for Canonicalizer<'cx, 'db> {
// FIXME: perf problem described in #55921. // FIXME: perf problem described in #55921.
ui = UniverseIndex::ROOT; ui = UniverseIndex::ROOT;
} }
self.canonicalize_ty_var(
CanonicalVarKind::Ty(CanonicalTyVarKind::General(ui)), let sub_root = self.get_or_insert_sub_root(vid);
t, self.canonicalize_ty_var(CanonicalVarKind::Ty { ui, sub_root }, t)
)
} }
} }
} }
@ -397,7 +402,7 @@ impl<'cx, 'db> TypeFolder<DbInterner<'db>> for Canonicalizer<'cx, 'db> {
if nt != t { if nt != t {
self.fold_ty(nt) self.fold_ty(nt)
} else { } else {
self.canonicalize_ty_var(CanonicalVarKind::Ty(CanonicalTyVarKind::Int), t) self.canonicalize_ty_var(CanonicalVarKind::Int, t)
} }
} }
TyKind::Infer(FloatVar(vid)) => { TyKind::Infer(FloatVar(vid)) => {
@ -405,7 +410,7 @@ impl<'cx, 'db> TypeFolder<DbInterner<'db>> for Canonicalizer<'cx, 'db> {
if nt != t { if nt != t {
self.fold_ty(nt) self.fold_ty(nt)
} else { } else {
self.canonicalize_ty_var(CanonicalVarKind::Ty(CanonicalTyVarKind::Float), t) self.canonicalize_ty_var(CanonicalVarKind::Float, t)
} }
} }
@ -579,6 +584,7 @@ impl<'cx, 'db> Canonicalizer<'cx, 'db> {
variables: SmallVec::from_slice(base.variables.as_slice()), variables: SmallVec::from_slice(base.variables.as_slice()),
query_state, query_state,
indices: FxHashMap::default(), indices: FxHashMap::default(),
sub_root_lookup_table: Default::default(),
binder_index: DebruijnIndex::ZERO, binder_index: DebruijnIndex::ZERO,
}; };
if canonicalizer.query_state.var_values.spilled() { if canonicalizer.query_state.var_values.spilled() {
@ -673,6 +679,13 @@ impl<'cx, 'db> Canonicalizer<'cx, 'db> {
} }
} }
fn get_or_insert_sub_root(&mut self, vid: TyVid) -> BoundVar {
let root_vid = self.infcx.sub_unification_table_root_var(vid);
let idx =
*self.sub_root_lookup_table.entry(root_vid).or_insert_with(|| self.variables.len());
BoundVar::from(idx)
}
/// Replaces the universe indexes used in `var_values` with their index in /// Replaces the universe indexes used in `var_values` with their index in
/// `query_state.universe_map`. This minimizes the maximum universe used in /// `query_state.universe_map`. This minimizes the maximum universe used in
/// the canonicalized value. /// the canonicalized value.
@ -692,9 +705,9 @@ impl<'cx, 'db> Canonicalizer<'cx, 'db> {
self.variables self.variables
.iter() .iter()
.map(|v| match *v { .map(|v| match *v {
CanonicalVarKind::Ty(CanonicalTyVarKind::Int | CanonicalTyVarKind::Float) => *v, CanonicalVarKind::Int | CanonicalVarKind::Float => *v,
CanonicalVarKind::Ty(CanonicalTyVarKind::General(u)) => { CanonicalVarKind::Ty { ui, sub_root } => {
CanonicalVarKind::Ty(CanonicalTyVarKind::General(reverse_universe_map[&u])) CanonicalVarKind::Ty { ui: reverse_universe_map[&ui], sub_root }
} }
CanonicalVarKind::Region(u) => CanonicalVarKind::Region(reverse_universe_map[&u]), CanonicalVarKind::Region(u) => CanonicalVarKind::Region(reverse_universe_map[&u]),
CanonicalVarKind::Const(u) => CanonicalVarKind::Const(reverse_universe_map[&u]), CanonicalVarKind::Const(u) => CanonicalVarKind::Const(reverse_universe_map[&u]),

View file

@ -32,9 +32,10 @@ use crate::next_solver::{
}; };
use instantiate::CanonicalExt; use instantiate::CanonicalExt;
use rustc_index::IndexVec; use rustc_index::IndexVec;
use rustc_type_ir::inherent::IntoKind;
use rustc_type_ir::{ use rustc_type_ir::{
AliasRelationDirection, AliasTyKind, CanonicalTyVarKind, CanonicalVarKind, InferTy, AliasRelationDirection, AliasTyKind, CanonicalVarKind, InferTy, TypeFoldable, UniverseIndex,
TypeFoldable, UniverseIndex, Upcast, Variance, Upcast, Variance,
inherent::{SliceLike, Ty as _}, inherent::{SliceLike, Ty as _},
relate::{ relate::{
Relate, TypeRelation, VarianceDiagInfo, Relate, TypeRelation, VarianceDiagInfo,
@ -78,27 +79,13 @@ impl<'db> InferCtxt<'db> {
.chain((1..=canonical.max_universe.as_u32()).map(|_| self.create_next_universe())) .chain((1..=canonical.max_universe.as_u32()).map(|_| self.create_next_universe()))
.collect(); .collect();
let canonical_inference_vars = let var_values = CanonicalVarValues::instantiate(
self.instantiate_canonical_vars(canonical.variables, |ui| universes[ui]); self.interner,
let result = canonical.instantiate(self.interner, &canonical_inference_vars); canonical.variables,
(result, canonical_inference_vars) |var_values, info| self.instantiate_canonical_var(info, var_values, |ui| universes[ui]),
} );
let result = canonical.instantiate(self.interner, &var_values);
/// Given the "infos" about the canonical variables from some (result, var_values)
/// canonical, creates fresh variables with the same
/// characteristics (see `instantiate_canonical_var` for
/// details). You can then use `instantiate` to instantiate the
/// canonical variable with these inference variables.
fn instantiate_canonical_vars(
&self,
variables: CanonicalVars<'db>,
universe_map: impl Fn(UniverseIndex) -> UniverseIndex,
) -> CanonicalVarValues<'db> {
CanonicalVarValues {
var_values: self.interner.mk_args_from_iter(
variables.iter().map(|info| self.instantiate_canonical_var(info, &universe_map)),
),
}
} }
/// Given the "info" about a canonical variable, creates a fresh /// Given the "info" about a canonical variable, creates a fresh
@ -112,21 +99,27 @@ impl<'db> InferCtxt<'db> {
pub fn instantiate_canonical_var( pub fn instantiate_canonical_var(
&self, &self,
cv_info: CanonicalVarKind<DbInterner<'db>>, cv_info: CanonicalVarKind<DbInterner<'db>>,
previous_var_values: &[GenericArg<'db>],
universe_map: impl Fn(UniverseIndex) -> UniverseIndex, universe_map: impl Fn(UniverseIndex) -> UniverseIndex,
) -> GenericArg<'db> { ) -> GenericArg<'db> {
match cv_info { match cv_info {
CanonicalVarKind::Ty(ty_kind) => { CanonicalVarKind::Ty { ui, sub_root } => {
let ty = match ty_kind { let vid = self.next_ty_var_id_in_universe(universe_map(ui));
CanonicalTyVarKind::General(ui) => { // If this inference variable is related to an earlier variable
self.next_ty_var_in_universe(universe_map(ui)) // via subtyping, we need to add that info to the inference context.
if let Some(prev) = previous_var_values.get(sub_root.as_usize()) {
if let TyKind::Infer(InferTy::TyVar(sub_root)) = prev.expect_ty().kind() {
self.sub_unify_ty_vids_raw(vid, sub_root);
} else {
unreachable!()
}
}
Ty::new_var(self.interner, vid).into()
} }
CanonicalTyVarKind::Int => self.next_int_var(), CanonicalVarKind::Int => self.next_int_var().into(),
CanonicalTyVarKind::Float => self.next_float_var(), CanonicalVarKind::Float => self.next_float_var().into(),
};
ty.into()
}
CanonicalVarKind::PlaceholderTy(PlaceholderTy { universe, bound }) => { CanonicalVarKind::PlaceholderTy(PlaceholderTy { universe, bound }) => {
let universe_mapped = universe_map(universe); let universe_mapped = universe_map(universe);

View file

@ -313,4 +313,12 @@ impl<'db> rustc_type_ir::InferCtxtLike for InferCtxt<'db> {
fn reset_opaque_types(&self) { fn reset_opaque_types(&self) {
let _ = self.take_opaque_types(); let _ = self.take_opaque_types();
} }
fn sub_unification_table_root_var(&self, var: rustc_type_ir::TyVid) -> rustc_type_ir::TyVid {
self.sub_unification_table_root_var(var)
}
fn sub_unify_ty_vids_raw(&self, a: rustc_type_ir::TyVid, b: rustc_type_ir::TyVid) {
self.sub_unify_ty_vids_raw(a, b);
}
} }

View file

@ -1019,6 +1019,14 @@ impl<'db> InferCtxt<'db> {
} }
} }
} }
fn sub_unification_table_root_var(&self, var: rustc_type_ir::TyVid) -> rustc_type_ir::TyVid {
self.inner.borrow_mut().type_variables().sub_unification_table_root_var(var)
}
fn sub_unify_ty_vids_raw(&self, a: rustc_type_ir::TyVid, b: rustc_type_ir::TyVid) {
self.inner.borrow_mut().type_variables().sub_unify(a, b);
}
} }
/// Helper for [InferCtxt::ty_or_const_infer_var_changed] (see comment on that), currently /// Helper for [InferCtxt::ty_or_const_infer_var_changed] (see comment on that), currently

View file

@ -25,7 +25,7 @@ pub struct Snapshot {
pub(crate) enum UndoLog<'db> { pub(crate) enum UndoLog<'db> {
DuplicateOpaqueType, DuplicateOpaqueType,
OpaqueTypes(OpaqueTypeKey<'db>, Option<OpaqueHiddenType<'db>>), OpaqueTypes(OpaqueTypeKey<'db>, Option<OpaqueHiddenType<'db>>),
TypeVariables(sv::UndoLog<ut::Delegate<type_variable::TyVidEqKey<'db>>>), TypeVariables(type_variable::UndoLog<'db>),
ConstUnificationTable(sv::UndoLog<ut::Delegate<ConstVidKey<'db>>>), ConstUnificationTable(sv::UndoLog<ut::Delegate<ConstVidKey<'db>>>),
IntUnificationTable(sv::UndoLog<ut::Delegate<IntVid>>), IntUnificationTable(sv::UndoLog<ut::Delegate<IntVid>>),
FloatUnificationTable(sv::UndoLog<ut::Delegate<FloatVid>>), FloatUnificationTable(sv::UndoLog<ut::Delegate<FloatVid>>),
@ -51,6 +51,8 @@ impl_from! {
RegionConstraintCollector(region_constraints::UndoLog<'db>), RegionConstraintCollector(region_constraints::UndoLog<'db>),
TypeVariables(sv::UndoLog<ut::Delegate<type_variable::TyVidEqKey<'db>>>), TypeVariables(sv::UndoLog<ut::Delegate<type_variable::TyVidEqKey<'db>>>),
TypeVariables(sv::UndoLog<ut::Delegate<type_variable::TyVidSubKey>>),
TypeVariables(type_variable::UndoLog<'db>),
IntUnificationTable(sv::UndoLog<ut::Delegate<IntVid>>), IntUnificationTable(sv::UndoLog<ut::Delegate<IntVid>>),
FloatUnificationTable(sv::UndoLog<ut::Delegate<FloatVid>>), FloatUnificationTable(sv::UndoLog<ut::Delegate<FloatVid>>),

View file

@ -17,12 +17,48 @@ use crate::next_solver::SolverDefId;
use crate::next_solver::Ty; use crate::next_solver::Ty;
use crate::next_solver::infer::InferCtxtUndoLogs; use crate::next_solver::infer::InferCtxtUndoLogs;
/// Represents a single undo-able action that affects a type inference variable.
#[derive(Clone)]
pub(crate) enum UndoLog<'tcx> {
EqRelation(sv::UndoLog<ut::Delegate<TyVidEqKey<'tcx>>>),
SubRelation(sv::UndoLog<ut::Delegate<TyVidSubKey>>),
}
/// Convert from a specific kind of undo to the more general UndoLog
impl<'db> From<sv::UndoLog<ut::Delegate<TyVidEqKey<'db>>>> for UndoLog<'db> {
fn from(l: sv::UndoLog<ut::Delegate<TyVidEqKey<'db>>>) -> Self {
UndoLog::EqRelation(l)
}
}
/// Convert from a specific kind of undo to the more general UndoLog
impl<'db> From<sv::UndoLog<ut::Delegate<TyVidSubKey>>> for UndoLog<'db> {
fn from(l: sv::UndoLog<ut::Delegate<TyVidSubKey>>) -> Self {
UndoLog::SubRelation(l)
}
}
impl<'db> Rollback<sv::UndoLog<ut::Delegate<TyVidEqKey<'db>>>> for TypeVariableStorage<'db> { impl<'db> Rollback<sv::UndoLog<ut::Delegate<TyVidEqKey<'db>>>> for TypeVariableStorage<'db> {
fn reverse(&mut self, undo: sv::UndoLog<ut::Delegate<TyVidEqKey<'db>>>) { fn reverse(&mut self, undo: sv::UndoLog<ut::Delegate<TyVidEqKey<'db>>>) {
self.eq_relations.reverse(undo) self.eq_relations.reverse(undo)
} }
} }
impl<'tcx> Rollback<sv::UndoLog<ut::Delegate<TyVidSubKey>>> for TypeVariableStorage<'tcx> {
fn reverse(&mut self, undo: sv::UndoLog<ut::Delegate<TyVidSubKey>>) {
self.sub_unification_table.reverse(undo)
}
}
impl<'tcx> Rollback<UndoLog<'tcx>> for TypeVariableStorage<'tcx> {
fn reverse(&mut self, undo: UndoLog<'tcx>) {
match undo {
UndoLog::EqRelation(undo) => self.eq_relations.reverse(undo),
UndoLog::SubRelation(undo) => self.sub_unification_table.reverse(undo),
}
}
}
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub(crate) struct TypeVariableStorage<'db> { pub(crate) struct TypeVariableStorage<'db> {
/// The origins of each type variable. /// The origins of each type variable.
@ -31,6 +67,25 @@ pub(crate) struct TypeVariableStorage<'db> {
/// constraint `?X == ?Y`. This table also stores, for each key, /// constraint `?X == ?Y`. This table also stores, for each key,
/// the known value. /// the known value.
eq_relations: ut::UnificationTableStorage<TyVidEqKey<'db>>, eq_relations: ut::UnificationTableStorage<TyVidEqKey<'db>>,
/// Only used by `-Znext-solver` and for diagnostics. Tracks whether
/// type variables are related via subtyping at all, ignoring which of
/// the two is the subtype.
///
/// When reporting ambiguity errors, we sometimes want to
/// treat all inference vars which are subtypes of each
/// others as if they are equal. For this case we compute
/// the transitive closure of our subtype obligations here.
///
/// E.g. when encountering ambiguity errors, we want to suggest
/// specifying some method argument or to add a type annotation
/// to a local variable. Because subtyping cannot change the
/// shape of a type, it's fine if the cause of the ambiguity error
/// is only related to the suggested variable via subtyping.
///
/// Even for something like `let x = returns_arg(); x.method();` the
/// type of `x` is only a supertype of the argument of `returns_arg`. We
/// still want to suggest specifying the type of the argument.
sub_unification_table: ut::UnificationTableStorage<TyVidSubKey>,
} }
pub(crate) struct TypeVariableTable<'a, 'db> { pub(crate) struct TypeVariableTable<'a, 'db> {
@ -112,6 +167,17 @@ impl<'db> TypeVariableTable<'_, 'db> {
debug_assert!(self.probe(a).is_unknown()); debug_assert!(self.probe(a).is_unknown());
debug_assert!(self.probe(b).is_unknown()); debug_assert!(self.probe(b).is_unknown());
self.eq_relations().union(a, b); self.eq_relations().union(a, b);
self.sub_unification_table().union(a, b);
}
/// Records that `a` and `b` are related via subtyping. We don't track
/// which of the two is the subtype.
///
/// Precondition: neither `a` nor `b` are known.
pub(crate) fn sub_unify(&mut self, a: TyVid, b: TyVid) {
debug_assert!(self.probe(a).is_unknown());
debug_assert!(self.probe(b).is_unknown());
self.sub_unification_table().union(a, b);
} }
/// Instantiates `vid` with the type `ty`. /// Instantiates `vid` with the type `ty`.
@ -141,6 +207,10 @@ impl<'db> TypeVariableTable<'_, 'db> {
/// for improving error messages. /// for improving error messages.
pub(crate) fn new_var(&mut self, universe: UniverseIndex, origin: TypeVariableOrigin) -> TyVid { pub(crate) fn new_var(&mut self, universe: UniverseIndex, origin: TypeVariableOrigin) -> TyVid {
let eq_key = self.eq_relations().new_key(TypeVariableValue::Unknown { universe }); let eq_key = self.eq_relations().new_key(TypeVariableValue::Unknown { universe });
let sub_key = self.sub_unification_table().new_key(());
debug_assert_eq!(eq_key.vid, sub_key.vid);
let index = self.storage.values.push(TypeVariableData { origin }); let index = self.storage.values.push(TypeVariableData { origin });
debug_assert_eq!(eq_key.vid, index); debug_assert_eq!(eq_key.vid, index);
@ -163,6 +233,18 @@ impl<'db> TypeVariableTable<'_, 'db> {
self.eq_relations().find(vid).vid self.eq_relations().find(vid).vid
} }
/// Returns the "root" variable of `vid` in the `sub_unification_table`
/// equivalence table. All type variables that have been are related via
/// equality or subtyping will yield the same root variable (per the
/// union-find algorithm), so `sub_unification_table_root_var(a)
/// == sub_unification_table_root_var(b)` implies that:
/// ```text
/// exists X. (a <: X || X <: a) && (b <: X || X <: b)
/// ```
pub(crate) fn sub_unification_table_root_var(&mut self, vid: TyVid) -> TyVid {
self.sub_unification_table().find(vid).vid
}
/// Retrieves the type to which `vid` has been instantiated, if /// Retrieves the type to which `vid` has been instantiated, if
/// any. /// any.
pub(crate) fn probe(&mut self, vid: TyVid) -> TypeVariableValue<'db> { pub(crate) fn probe(&mut self, vid: TyVid) -> TypeVariableValue<'db> {
@ -180,6 +262,11 @@ impl<'db> TypeVariableTable<'_, 'db> {
self.storage.eq_relations.with_log(self.undo_log) self.storage.eq_relations.with_log(self.undo_log)
} }
#[inline]
fn sub_unification_table(&mut self) -> super::UnificationTable<'_, 'db, TyVidSubKey> {
self.storage.sub_unification_table.with_log(self.undo_log)
}
/// Returns indices of all variables that are not yet /// Returns indices of all variables that are not yet
/// instantiated. /// instantiated.
pub(crate) fn unresolved_variables(&mut self) -> Vec<TyVid> { pub(crate) fn unresolved_variables(&mut self) -> Vec<TyVid> {
@ -228,6 +315,36 @@ impl<'db> ut::UnifyKey for TyVidEqKey<'db> {
fn tag() -> &'static str { fn tag() -> &'static str {
"TyVidEqKey" "TyVidEqKey"
} }
fn order_roots(a: Self, _: &Self::Value, b: Self, _: &Self::Value) -> Option<(Self, Self)> {
if a.vid.as_u32() < b.vid.as_u32() { Some((a, b)) } else { Some((b, a)) }
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub(crate) struct TyVidSubKey {
vid: TyVid,
}
impl From<TyVid> for TyVidSubKey {
#[inline] // make this function eligible for inlining - it is quite hot.
fn from(vid: TyVid) -> Self {
TyVidSubKey { vid }
}
}
impl ut::UnifyKey for TyVidSubKey {
type Value = ();
#[inline]
fn index(&self) -> u32 {
self.vid.as_u32()
}
#[inline]
fn from_index(i: u32) -> TyVidSubKey {
TyVidSubKey { vid: TyVid::from_u32(i) }
}
fn tag() -> &'static str {
"TyVidSubKey"
}
} }
impl<'db> ut::UnifyValue for TypeVariableValue<'db> { impl<'db> ut::UnifyValue for TypeVariableValue<'db> {

View file

@ -139,6 +139,9 @@ impl<'db> UnifyKey for ConstVidKey<'db> {
fn tag() -> &'static str { fn tag() -> &'static str {
"ConstVidKey" "ConstVidKey"
} }
fn order_roots(a: Self, _: &Self::Value, b: Self, _: &Self::Value) -> Option<(Self, Self)> {
if a.vid.as_u32() < b.vid.as_u32() { Some((a, b)) } else { Some((b, a)) }
}
} }
impl<'db> UnifyValue for ConstVariableValue<'db> { impl<'db> UnifyValue for ConstVariableValue<'db> {

View file

@ -19,7 +19,7 @@ use rustc_type_ir::error::TypeError;
use rustc_type_ir::inherent::{ use rustc_type_ir::inherent::{
AdtDef as _, GenericArgs as _, GenericsOf, IntoKind, SliceLike as _, Span as _, AdtDef as _, GenericArgs as _, GenericsOf, IntoKind, SliceLike as _, Span as _,
}; };
use rustc_type_ir::lang_items::{SolverLangItem, SolverTraitLangItem}; use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem};
use rustc_type_ir::solve::SizedTraitKind; use rustc_type_ir::solve::SizedTraitKind;
use rustc_type_ir::{ use rustc_type_ir::{
AliasTerm, AliasTermKind, AliasTy, AliasTyKind, EarlyBinder, FlagComputation, Flags, AliasTerm, AliasTermKind, AliasTy, AliasTyKind, EarlyBinder, FlagComputation, Flags,
@ -47,8 +47,9 @@ use crate::method_resolution::{ALL_FLOAT_FPS, ALL_INT_FPS, TyFingerprint};
use crate::next_solver::infer::InferCtxt; use crate::next_solver::infer::InferCtxt;
use crate::next_solver::util::{ContainsTypeErrors, explicit_item_bounds, for_trait_impls}; use crate::next_solver::util::{ContainsTypeErrors, explicit_item_bounds, for_trait_impls};
use crate::next_solver::{ use crate::next_solver::{
BoundConst, CanonicalVarKind, FxIndexMap, InternedWrapperNoDebug, RegionAssumptions, AdtIdWrapper, BoundConst, CallableIdWrapper, CanonicalVarKind, ClosureIdWrapper,
SolverContext, SolverDefIds, TraitIdWrapper, CoroutineIdWrapper, FxIndexMap, ImplIdWrapper, InternedWrapperNoDebug, RegionAssumptions,
SolverContext, SolverDefIds, TraitIdWrapper, TypeAliasIdWrapper,
}; };
use crate::{ConstScalar, FnAbi, Interner, db::HirDatabase}; use crate::{ConstScalar, FnAbi, Interner, db::HirDatabase};
@ -609,8 +610,8 @@ impl AdtDef {
} }
impl<'db> inherent::AdtDef<DbInterner<'db>> for AdtDef { impl<'db> inherent::AdtDef<DbInterner<'db>> for AdtDef {
fn def_id(self) -> <DbInterner<'db> as rustc_type_ir::Interner>::DefId { fn def_id(self) -> AdtIdWrapper {
SolverDefId::AdtId(self.inner().id) self.inner().id.into()
} }
fn is_struct(self) -> bool { fn is_struct(self) -> bool {
@ -889,6 +890,13 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
type LocalDefId = SolverDefId; type LocalDefId = SolverDefId;
type LocalDefIds = SolverDefIds; type LocalDefIds = SolverDefIds;
type TraitId = TraitIdWrapper; type TraitId = TraitIdWrapper;
type ForeignId = TypeAliasIdWrapper;
type FunctionId = CallableIdWrapper;
type ClosureId = ClosureIdWrapper;
type CoroutineClosureId = CoroutineIdWrapper;
type CoroutineId = CoroutineIdWrapper;
type AdtId = AdtIdWrapper;
type ImplId = ImplIdWrapper;
type Span = Span; type Span = Span;
type GenericArgs = GenericArgs<'db>; type GenericArgs = GenericArgs<'db>;
@ -1103,12 +1111,8 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
self.db().ty_ns(def_id) self.db().ty_ns(def_id)
} }
fn adt_def(self, adt_def_id: Self::DefId) -> Self::AdtDef { fn adt_def(self, def_id: Self::AdtId) -> Self::AdtDef {
let def_id = match adt_def_id { AdtDef::new(def_id.0, self)
SolverDefId::AdtId(adt_id) => adt_id,
_ => panic!("Invalid DefId passed to adt_def"),
};
AdtDef::new(def_id, self)
} }
fn alias_ty_kind(self, alias: rustc_type_ir::AliasTy<Self>) -> AliasTyKind { fn alias_ty_kind(self, alias: rustc_type_ir::AliasTy<Self>) -> AliasTyKind {
@ -1219,24 +1223,16 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
fn fn_sig( fn fn_sig(
self, self,
def_id: Self::DefId, def_id: Self::FunctionId,
) -> EarlyBinder<Self, rustc_type_ir::Binder<Self, rustc_type_ir::FnSig<Self>>> { ) -> EarlyBinder<Self, rustc_type_ir::Binder<Self, rustc_type_ir::FnSig<Self>>> {
let id = match def_id { self.db().callable_item_signature_ns(def_id.0)
SolverDefId::FunctionId(id) => CallableDefId::FunctionId(id),
SolverDefId::Ctor(ctor) => match ctor {
super::Ctor::Struct(struct_id) => CallableDefId::StructId(struct_id),
super::Ctor::Enum(enum_variant_id) => CallableDefId::EnumVariantId(enum_variant_id),
},
def => unreachable!("{:?}", def),
};
self.db().callable_item_signature_ns(id)
} }
fn coroutine_movability(self, def_id: Self::DefId) -> rustc_ast_ir::Movability { fn coroutine_movability(self, def_id: Self::CoroutineId) -> rustc_ast_ir::Movability {
unimplemented!() unimplemented!()
} }
fn coroutine_for_closure(self, def_id: Self::DefId) -> Self::DefId { fn coroutine_for_closure(self, def_id: Self::CoroutineId) -> Self::CoroutineId {
unimplemented!() unimplemented!()
} }
@ -1361,13 +1357,9 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
fn impl_super_outlives( fn impl_super_outlives(
self, self,
impl_def_id: Self::DefId, impl_id: Self::ImplId,
) -> EarlyBinder<Self, impl IntoIterator<Item = Self::Clause>> { ) -> EarlyBinder<Self, impl IntoIterator<Item = Self::Clause>> {
let impl_id = match impl_def_id { let trait_ref = self.db().impl_trait_ns(impl_id.0).expect("expected an impl of trait");
SolverDefId::ImplId(id) => id,
_ => unreachable!(),
};
let trait_ref = self.db().impl_trait_ns(impl_id).expect("expected an impl of trait");
trait_ref.map_bound(|trait_ref| { trait_ref.map_bound(|trait_ref| {
let clause: Clause<'_> = trait_ref.upcast(self); let clause: Clause<'_> = trait_ref.upcast(self);
Clauses::new_from_iter( Clauses::new_from_iter(
@ -1392,7 +1384,7 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
EarlyBinder::bind([unimplemented!()]) EarlyBinder::bind([unimplemented!()])
} }
fn has_target_features(self, def_id: Self::DefId) -> bool { fn has_target_features(self, def_id: Self::FunctionId) -> bool {
false false
} }
@ -1407,8 +1399,6 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
SolverLangItem::DynMetadata => LangItem::DynMetadata, SolverLangItem::DynMetadata => LangItem::DynMetadata,
SolverLangItem::FutureOutput => LangItem::FutureOutput, SolverLangItem::FutureOutput => LangItem::FutureOutput,
SolverLangItem::Metadata => LangItem::Metadata, SolverLangItem::Metadata => LangItem::Metadata,
SolverLangItem::Option => LangItem::Option,
SolverLangItem::Poll => LangItem::Poll,
}; };
let target = hir_def::lang_item::lang_item( let target = hir_def::lang_item::lang_item(
self.db(), self.db(),
@ -1468,24 +1458,33 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
.into() .into()
} }
#[allow(clippy::match_like_matches_macro)] fn require_adt_lang_item(self, lang_item: SolverAdtLangItem) -> AdtIdWrapper {
fn is_lang_item(self, def_id: Self::DefId, lang_item: SolverLangItem) -> bool { let lang_item = match lang_item {
use SolverLangItem::*; SolverAdtLangItem::Option => LangItem::Option,
SolverAdtLangItem::Poll => LangItem::Poll,
};
lang_item
.resolve_adt(self.db(), self.krate.expect("Must have self.krate"))
.unwrap_or_else(|| panic!("Lang item {lang_item:?} required but not found."))
.into()
}
// FIXME: derive PartialEq on SolverLangItem fn is_lang_item(self, def_id: Self::DefId, lang_item: SolverLangItem) -> bool {
self.as_lang_item(def_id) self.as_lang_item(def_id)
.map_or(false, |l| std::mem::discriminant(&l) == std::mem::discriminant(&lang_item)) .map_or(false, |l| std::mem::discriminant(&l) == std::mem::discriminant(&lang_item))
} }
#[allow(clippy::match_like_matches_macro)]
fn is_trait_lang_item(self, def_id: Self::TraitId, lang_item: SolverTraitLangItem) -> bool { fn is_trait_lang_item(self, def_id: Self::TraitId, lang_item: SolverTraitLangItem) -> bool {
use SolverTraitLangItem::*;
// FIXME: derive PartialEq on SolverTraitLangItem
self.as_trait_lang_item(def_id) self.as_trait_lang_item(def_id)
.map_or(false, |l| std::mem::discriminant(&l) == std::mem::discriminant(&lang_item)) .map_or(false, |l| std::mem::discriminant(&l) == std::mem::discriminant(&lang_item))
} }
fn is_adt_lang_item(self, def_id: Self::AdtId, lang_item: SolverAdtLangItem) -> bool {
// FIXME: derive PartialEq on SolverTraitLangItem
self.as_adt_lang_item(def_id)
.map_or(false, |l| std::mem::discriminant(&l) == std::mem::discriminant(&lang_item))
}
fn as_lang_item(self, def_id: Self::DefId) -> Option<SolverLangItem> { fn as_lang_item(self, def_id: Self::DefId) -> Option<SolverLangItem> {
let def_id: AttrDefId = match def_id { let def_id: AttrDefId = match def_id {
SolverDefId::TraitId(id) => id.into(), SolverDefId::TraitId(id) => id.into(),
@ -1505,9 +1504,7 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
DynMetadata, DynMetadata,
CoroutineReturn, CoroutineReturn,
CoroutineYield, CoroutineYield,
Poll,
FutureOutput, FutureOutput,
Option,
AsyncFnOnceOutput, AsyncFnOnceOutput,
CallRefFuture, CallRefFuture,
CallOnceFuture, CallOnceFuture,
@ -1556,6 +1553,19 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
) )
} }
fn as_adt_lang_item(self, def_id: Self::AdtId) -> Option<SolverAdtLangItem> {
let def_id: AttrDefId = def_id.0.into();
let lang_item = self.db().lang_attr(def_id)?;
as_lang_item!(
SolverAdtLangItem, lang_item;
ignore = {}
Option,
Poll,
)
}
fn associated_type_def_ids(self, def_id: Self::DefId) -> impl IntoIterator<Item = Self::DefId> { fn associated_type_def_ids(self, def_id: Self::DefId) -> impl IntoIterator<Item = Self::DefId> {
let trait_ = match def_id { let trait_ = match def_id {
SolverDefId::TraitId(id) => id, SolverDefId::TraitId(id) => id,
@ -1568,7 +1578,7 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
self, self,
trait_: Self::TraitId, trait_: Self::TraitId,
self_ty: Self::Ty, self_ty: Self::Ty,
mut f: impl FnMut(Self::DefId), mut f: impl FnMut(Self::ImplId),
) { ) {
let trait_ = trait_.0; let trait_ = trait_.0;
let self_ty_fp = TyFingerprint::for_trait_impl_ns(&self_ty); let self_ty_fp = TyFingerprint::for_trait_impl_ns(&self_ty);
@ -1595,7 +1605,7 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
continue; continue;
} }
f(SolverDefId::ImplId(i)); f(i.into());
} }
ControlFlow::Continue(()) ControlFlow::Continue(())
}, },
@ -1618,7 +1628,7 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
continue; continue;
} }
f(SolverDefId::ImplId(i)); f(i.into());
} }
} }
ControlFlow::Continue(()) ControlFlow::Continue(())
@ -1632,7 +1642,7 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
true true
} }
fn impl_is_default(self, impl_def_id: Self::DefId) -> bool { fn impl_is_default(self, impl_def_id: Self::ImplId) -> bool {
// FIXME // FIXME
false false
} }
@ -1640,26 +1650,16 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
#[tracing::instrument(skip(self), ret)] #[tracing::instrument(skip(self), ret)]
fn impl_trait_ref( fn impl_trait_ref(
self, self,
impl_def_id: Self::DefId, impl_id: Self::ImplId,
) -> EarlyBinder<Self, rustc_type_ir::TraitRef<Self>> { ) -> EarlyBinder<Self, rustc_type_ir::TraitRef<Self>> {
let impl_id = match impl_def_id {
SolverDefId::ImplId(id) => id,
_ => panic!("Unexpected SolverDefId in impl_trait_ref"),
};
let db = self.db(); let db = self.db();
db.impl_trait_ns(impl_id.0)
db.impl_trait_ns(impl_id)
// ImplIds for impls where the trait ref can't be resolved should never reach trait solving // ImplIds for impls where the trait ref can't be resolved should never reach trait solving
.expect("invalid impl passed to trait solver") .expect("invalid impl passed to trait solver")
} }
fn impl_polarity(self, impl_def_id: Self::DefId) -> rustc_type_ir::ImplPolarity { fn impl_polarity(self, impl_id: Self::ImplId) -> rustc_type_ir::ImplPolarity {
let impl_id = match impl_def_id { let impl_data = self.db().impl_signature(impl_id.0);
SolverDefId::ImplId(id) => id,
_ => unreachable!(),
};
let impl_data = self.db().impl_signature(impl_id);
if impl_data.flags.contains(ImplFlags::NEGATIVE) { if impl_data.flags.contains(ImplFlags::NEGATIVE) {
ImplPolarity::Negative ImplPolarity::Negative
} else { } else {
@ -1701,33 +1701,29 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
panic!("Bug encountered in next-trait-solver.") panic!("Bug encountered in next-trait-solver.")
} }
fn is_general_coroutine(self, coroutine_def_id: Self::DefId) -> bool { fn is_general_coroutine(self, coroutine_def_id: Self::CoroutineId) -> bool {
// FIXME(next-solver) // FIXME(next-solver)
true true
} }
fn coroutine_is_async(self, coroutine_def_id: Self::DefId) -> bool { fn coroutine_is_async(self, coroutine_def_id: Self::CoroutineId) -> bool {
// FIXME(next-solver) // FIXME(next-solver)
true true
} }
fn coroutine_is_gen(self, coroutine_def_id: Self::DefId) -> bool { fn coroutine_is_gen(self, coroutine_def_id: Self::CoroutineId) -> bool {
// FIXME(next-solver) // FIXME(next-solver)
false false
} }
fn coroutine_is_async_gen(self, coroutine_def_id: Self::DefId) -> bool { fn coroutine_is_async_gen(self, coroutine_def_id: Self::CoroutineId) -> bool {
// FIXME(next-solver) // FIXME(next-solver)
false false
} }
fn unsizing_params_for_adt(self, adt_def_id: Self::DefId) -> Self::UnsizingParams { fn unsizing_params_for_adt(self, id: Self::AdtId) -> Self::UnsizingParams {
let id = match adt_def_id { let def = AdtDef::new(id.0, self);
SolverDefId::AdtId(id) => id, let num_params = self.generics_of(id.into()).count();
_ => unreachable!(),
};
let def = AdtDef::new(id, self);
let num_params = self.generics_of(adt_def_id).count();
let maybe_unsizing_param_idx = |arg: GenericArg<'db>| match arg.kind() { let maybe_unsizing_param_idx = |arg: GenericArg<'db>| match arg.kind() {
GenericArgKind::Type(ty) => match ty.kind() { GenericArgKind::Type(ty) => match ty.kind() {
@ -1835,15 +1831,15 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
EarlyBinder::bind([]) EarlyBinder::bind([])
} }
fn fn_is_const(self, def_id: Self::DefId) -> bool { fn fn_is_const(self, id: Self::FunctionId) -> bool {
let id = match def_id { let id = match id.0 {
SolverDefId::FunctionId(id) => id, CallableDefId::FunctionId(id) => id,
_ => unreachable!(), _ => return false,
}; };
self.db().function_signature(id).flags.contains(FnFlags::CONST) self.db().function_signature(id).flags.contains(FnFlags::CONST)
} }
fn impl_is_const(self, def_id: Self::DefId) -> bool { fn impl_is_const(self, def_id: Self::ImplId) -> bool {
false false
} }
@ -1877,7 +1873,7 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
fn coroutine_hidden_types( fn coroutine_hidden_types(
self, self,
def_id: Self::DefId, def_id: Self::CoroutineId,
) -> EarlyBinder<Self, rustc_type_ir::Binder<Self, rustc_type_ir::CoroutineWitnessTypes<Self>>> ) -> EarlyBinder<Self, rustc_type_ir::Binder<Self, rustc_type_ir::CoroutineWitnessTypes<Self>>>
{ {
// FIXME(next-solver) // FIXME(next-solver)
@ -1896,11 +1892,11 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
self.db().trait_signature(trait_.0).flags.contains(TraitFlags::UNSAFE) self.db().trait_signature(trait_.0).flags.contains(TraitFlags::UNSAFE)
} }
fn impl_self_is_guaranteed_unsized(self, def_id: Self::DefId) -> bool { fn impl_self_is_guaranteed_unsized(self, def_id: Self::ImplId) -> bool {
false false
} }
fn impl_specializes(self, impl_def_id: Self::DefId, victim_def_id: Self::DefId) -> bool { fn impl_specializes(self, impl_def_id: Self::ImplId, victim_def_id: Self::ImplId) -> bool {
false false
} }
@ -2020,6 +2016,12 @@ macro_rules! TrivialTypeTraversalImpls {
TrivialTypeTraversalImpls! { TrivialTypeTraversalImpls! {
SolverDefId, SolverDefId,
TraitIdWrapper, TraitIdWrapper,
TypeAliasIdWrapper,
CallableIdWrapper,
ClosureIdWrapper,
CoroutineIdWrapper,
AdtIdWrapper,
ImplIdWrapper,
Pattern<'db>, Pattern<'db>,
Safety, Safety,
FnAbi, FnAbi,

View file

@ -243,12 +243,10 @@ impl<'db> ChalkToNextSolver<'db, Ty<'db>> for chalk_ir::Ty<Interner> {
} }
chalk_ir::TyKind::FnDef(fn_def_id, substitution) => { chalk_ir::TyKind::FnDef(fn_def_id, substitution) => {
let def_id = CallableDefId::from_chalk(interner.db(), *fn_def_id); let def_id = CallableDefId::from_chalk(interner.db(), *fn_def_id);
let id: SolverDefId = match def_id { rustc_type_ir::TyKind::FnDef(
CallableDefId::FunctionId(id) => id.into(), def_id.into(),
CallableDefId::StructId(id) => SolverDefId::Ctor(Ctor::Struct(id)), substitution.to_nextsolver(interner),
CallableDefId::EnumVariantId(id) => SolverDefId::Ctor(Ctor::Enum(id)), )
};
rustc_type_ir::TyKind::FnDef(id, substitution.to_nextsolver(interner))
} }
chalk_ir::TyKind::Str => rustc_type_ir::TyKind::Str, chalk_ir::TyKind::Str => rustc_type_ir::TyKind::Str,
chalk_ir::TyKind::Never => rustc_type_ir::TyKind::Never, chalk_ir::TyKind::Never => rustc_type_ir::TyKind::Never,
@ -271,7 +269,7 @@ impl<'db> ChalkToNextSolver<'db, Ty<'db>> for chalk_ir::Ty<Interner> {
) )
} }
chalk_ir::TyKind::Foreign(foreign_def_id) => rustc_type_ir::TyKind::Foreign( chalk_ir::TyKind::Foreign(foreign_def_id) => rustc_type_ir::TyKind::Foreign(
SolverDefId::TypeAliasId(crate::from_foreign_def_id(*foreign_def_id)), crate::from_foreign_def_id(*foreign_def_id).into(),
), ),
chalk_ir::TyKind::Error => rustc_type_ir::TyKind::Error(ErrorGuaranteed), chalk_ir::TyKind::Error => rustc_type_ir::TyKind::Error(ErrorGuaranteed),
chalk_ir::TyKind::Dyn(dyn_ty) => { chalk_ir::TyKind::Dyn(dyn_ty) => {
@ -734,15 +732,13 @@ impl<'db, T: HasInterner<Interner = Interner> + ChalkToNextSolver<'db, U>, U>
interner, interner,
self.binders.iter(Interner).map(|k| match &k.kind { self.binders.iter(Interner).map(|k| match &k.kind {
chalk_ir::VariableKind::Ty(ty_variable_kind) => match ty_variable_kind { chalk_ir::VariableKind::Ty(ty_variable_kind) => match ty_variable_kind {
TyVariableKind::General => rustc_type_ir::CanonicalVarKind::Ty( // FIXME(next-solver): the info is incorrect, but we have no way to store the information in Chalk.
rustc_type_ir::CanonicalTyVarKind::General(UniverseIndex::ROOT), TyVariableKind::General => rustc_type_ir::CanonicalVarKind::Ty {
), ui: UniverseIndex::ROOT,
TyVariableKind::Integer => { sub_root: BoundVar::from_u32(0),
rustc_type_ir::CanonicalVarKind::Ty(rustc_type_ir::CanonicalTyVarKind::Int) },
} TyVariableKind::Integer => rustc_type_ir::CanonicalVarKind::Int,
TyVariableKind::Float => rustc_type_ir::CanonicalVarKind::Ty( TyVariableKind::Float => rustc_type_ir::CanonicalVarKind::Float,
rustc_type_ir::CanonicalTyVarKind::Float,
),
}, },
chalk_ir::VariableKind::Lifetime => { chalk_ir::VariableKind::Lifetime => {
rustc_type_ir::CanonicalVarKind::Region(UniverseIndex::ROOT) rustc_type_ir::CanonicalVarKind::Region(UniverseIndex::ROOT)
@ -767,24 +763,20 @@ impl<'db, T: NextSolverToChalk<'db, U>, U: HasInterner<Interner = Interner>>
let binders = chalk_ir::CanonicalVarKinds::from_iter( let binders = chalk_ir::CanonicalVarKinds::from_iter(
Interner, Interner,
self.variables.iter().map(|v| match v { self.variables.iter().map(|v| match v {
rustc_type_ir::CanonicalVarKind::Ty( rustc_type_ir::CanonicalVarKind::Ty { ui, sub_root: _ } => {
rustc_type_ir::CanonicalTyVarKind::General(ui), chalk_ir::CanonicalVarKind::new(
) => chalk_ir::CanonicalVarKind::new(
chalk_ir::VariableKind::Ty(TyVariableKind::General), chalk_ir::VariableKind::Ty(TyVariableKind::General),
chalk_ir::UniverseIndex { counter: ui.as_usize() }, chalk_ir::UniverseIndex { counter: ui.as_usize() },
), )
rustc_type_ir::CanonicalVarKind::Ty(rustc_type_ir::CanonicalTyVarKind::Int) => { }
chalk_ir::CanonicalVarKind::new( rustc_type_ir::CanonicalVarKind::Int => chalk_ir::CanonicalVarKind::new(
chalk_ir::VariableKind::Ty(TyVariableKind::Integer), chalk_ir::VariableKind::Ty(TyVariableKind::Integer),
chalk_ir::UniverseIndex::root(), chalk_ir::UniverseIndex::root(),
) ),
} rustc_type_ir::CanonicalVarKind::Float => chalk_ir::CanonicalVarKind::new(
rustc_type_ir::CanonicalVarKind::Ty(rustc_type_ir::CanonicalTyVarKind::Float) => {
chalk_ir::CanonicalVarKind::new(
chalk_ir::VariableKind::Ty(TyVariableKind::Float), chalk_ir::VariableKind::Ty(TyVariableKind::Float),
chalk_ir::UniverseIndex::root(), chalk_ir::UniverseIndex::root(),
) ),
}
rustc_type_ir::CanonicalVarKind::Region(ui) => chalk_ir::CanonicalVarKind::new( rustc_type_ir::CanonicalVarKind::Region(ui) => chalk_ir::CanonicalVarKind::new(
chalk_ir::VariableKind::Lifetime, chalk_ir::VariableKind::Lifetime,
chalk_ir::UniverseIndex { counter: ui.as_usize() }, chalk_ir::UniverseIndex { counter: ui.as_usize() },
@ -1520,13 +1512,7 @@ pub(crate) fn convert_ty_for_result<'db>(interner: DbInterner<'db>, ty: Ty<'db>)
TyKind::Slice(ty) TyKind::Slice(ty)
} }
rustc_type_ir::TyKind::Foreign(foreign) => { rustc_type_ir::TyKind::Foreign(foreign) => TyKind::Foreign(to_foreign_def_id(foreign.0)),
let def_id = match foreign {
SolverDefId::TypeAliasId(id) => id,
_ => unreachable!(),
};
TyKind::Foreign(to_foreign_def_id(def_id))
}
rustc_type_ir::TyKind::Pat(_, _) => unimplemented!(), rustc_type_ir::TyKind::Pat(_, _) => unimplemented!(),
rustc_type_ir::TyKind::RawPtr(ty, mutability) => { rustc_type_ir::TyKind::RawPtr(ty, mutability) => {
let mutability = match mutability { let mutability = match mutability {
@ -1537,40 +1523,22 @@ pub(crate) fn convert_ty_for_result<'db>(interner: DbInterner<'db>, ty: Ty<'db>)
TyKind::Raw(mutability, ty) TyKind::Raw(mutability, ty)
} }
rustc_type_ir::TyKind::FnDef(def_id, args) => { rustc_type_ir::TyKind::FnDef(def_id, args) => {
let id = match def_id {
SolverDefId::FunctionId(id) => CallableDefId::FunctionId(id),
SolverDefId::Ctor(Ctor::Struct(id)) => CallableDefId::StructId(id),
SolverDefId::Ctor(Ctor::Enum(id)) => CallableDefId::EnumVariantId(id),
_ => unreachable!(),
};
let subst = convert_args_for_result(interner, args.as_slice()); let subst = convert_args_for_result(interner, args.as_slice());
TyKind::FnDef(id.to_chalk(interner.db()), subst) TyKind::FnDef(def_id.0.to_chalk(interner.db()), subst)
} }
rustc_type_ir::TyKind::Closure(def_id, args) => { rustc_type_ir::TyKind::Closure(def_id, args) => {
let id = match def_id {
SolverDefId::InternedClosureId(id) => id,
_ => unreachable!(),
};
let subst = convert_args_for_result(interner, args.as_slice()); let subst = convert_args_for_result(interner, args.as_slice());
TyKind::Closure(id.into(), subst) TyKind::Closure(def_id.0.into(), subst)
} }
rustc_type_ir::TyKind::CoroutineClosure(_, _) => unimplemented!(), rustc_type_ir::TyKind::CoroutineClosure(_, _) => unimplemented!(),
rustc_type_ir::TyKind::Coroutine(def_id, args) => { rustc_type_ir::TyKind::Coroutine(def_id, args) => {
let id = match def_id {
SolverDefId::InternedCoroutineId(id) => id,
_ => unreachable!(),
};
let subst = convert_args_for_result(interner, args.as_slice()); let subst = convert_args_for_result(interner, args.as_slice());
TyKind::Coroutine(id.into(), subst) TyKind::Coroutine(def_id.0.into(), subst)
} }
rustc_type_ir::TyKind::CoroutineWitness(def_id, args) => { rustc_type_ir::TyKind::CoroutineWitness(def_id, args) => {
let id = match def_id {
SolverDefId::InternedCoroutineId(id) => id,
_ => unreachable!(),
};
let subst = convert_args_for_result(interner, args.as_slice()); let subst = convert_args_for_result(interner, args.as_slice());
TyKind::CoroutineWitness(id.into(), subst) TyKind::CoroutineWitness(def_id.0.into(), subst)
} }
rustc_type_ir::TyKind::UnsafeBinder(_) => unimplemented!(), rustc_type_ir::TyKind::UnsafeBinder(_) => unimplemented!(),

View file

@ -10,6 +10,7 @@ use rustc_type_ir::{
}; };
use crate::next_solver::mapping::NextSolverToChalk; use crate::next_solver::mapping::NextSolverToChalk;
use crate::next_solver::{CanonicalVarKind, ImplIdWrapper};
use crate::{ use crate::{
TraitRefExt, TraitRefExt,
db::HirDatabase, db::HirDatabase,
@ -117,13 +118,14 @@ impl<'db> SolverDelegate for SolverContext<'db> {
canonical.instantiate(self.cx(), &values) canonical.instantiate(self.cx(), &values)
} }
fn instantiate_canonical_var_with_infer( fn instantiate_canonical_var(
&self, &self,
cv_info: rustc_type_ir::CanonicalVarKind<Self::Interner>, kind: CanonicalVarKind<'db>,
_span: <Self::Interner as rustc_type_ir::Interner>::Span, span: <Self::Interner as Interner>::Span,
var_values: &[GenericArg<'db>],
universe_map: impl Fn(rustc_type_ir::UniverseIndex) -> rustc_type_ir::UniverseIndex, universe_map: impl Fn(rustc_type_ir::UniverseIndex) -> rustc_type_ir::UniverseIndex,
) -> <Self::Interner as rustc_type_ir::Interner>::GenericArg { ) -> GenericArg<'db> {
self.0.instantiate_canonical_var(cv_info, universe_map) self.0.instantiate_canonical_var(kind, var_values, universe_map)
} }
fn add_item_bounds_for_hidden_type( fn add_item_bounds_for_hidden_type(
@ -146,12 +148,8 @@ impl<'db> SolverDelegate for SolverContext<'db> {
&self, &self,
goal_trait_ref: rustc_type_ir::TraitRef<Self::Interner>, goal_trait_ref: rustc_type_ir::TraitRef<Self::Interner>,
trait_assoc_def_id: <Self::Interner as rustc_type_ir::Interner>::DefId, trait_assoc_def_id: <Self::Interner as rustc_type_ir::Interner>::DefId,
impl_def_id: <Self::Interner as rustc_type_ir::Interner>::DefId, impl_id: ImplIdWrapper,
) -> Result<Option<<Self::Interner as rustc_type_ir::Interner>::DefId>, ErrorGuaranteed> { ) -> Result<Option<<Self::Interner as rustc_type_ir::Interner>::DefId>, ErrorGuaranteed> {
let impl_id = match impl_def_id {
SolverDefId::ImplId(id) => id,
_ => panic!("Unexpected SolverDefId"),
};
let trait_assoc_id = match trait_assoc_def_id { let trait_assoc_id = match trait_assoc_def_id {
SolverDefId::TypeAliasId(id) => id, SolverDefId::TypeAliasId(id) => id,
_ => panic!("Unexpected SolverDefId"), _ => panic!("Unexpected SolverDefId"),
@ -160,7 +158,7 @@ impl<'db> SolverDelegate for SolverContext<'db> {
.0 .0
.interner .interner
.db() .db()
.impl_trait(impl_id) .impl_trait(impl_id.0)
// ImplIds for impls where the trait ref can't be resolved should never reach solver // ImplIds for impls where the trait ref can't be resolved should never reach solver
.expect("invalid impl passed to next-solver") .expect("invalid impl passed to next-solver")
.into_value_and_skipped_binders() .into_value_and_skipped_binders()
@ -168,7 +166,7 @@ impl<'db> SolverDelegate for SolverContext<'db> {
let trait_ = trait_ref.hir_trait_id(); let trait_ = trait_ref.hir_trait_id();
let trait_data = trait_.trait_items(self.0.interner.db()); let trait_data = trait_.trait_items(self.0.interner.db());
let id = let id =
impl_id.impl_items(self.0.interner.db()).items.iter().find_map(|item| -> Option<_> { impl_id.0.impl_items(self.0.interner.db()).items.iter().find_map(|item| -> Option<_> {
match item { match item {
(_, AssocItemId::TypeAliasId(type_alias)) => { (_, AssocItemId::TypeAliasId(type_alias)) => {
let name = &self.0.interner.db().type_alias_signature(*type_alias).name; let name = &self.0.interner.db().type_alias_signature(*type_alias).name;

View file

@ -20,7 +20,9 @@ use rustc_type_ir::{
use salsa::plumbing::{AsId, FromId}; use salsa::plumbing::{AsId, FromId};
use smallvec::SmallVec; use smallvec::SmallVec;
use crate::next_solver::GenericArg; use crate::next_solver::{
CallableIdWrapper, ClosureIdWrapper, CoroutineIdWrapper, GenericArg, TypeAliasIdWrapper,
};
use crate::{ use crate::{
db::HirDatabase, db::HirDatabase,
interner::InternedWrapperNoDebug, interner::InternedWrapperNoDebug,
@ -599,10 +601,7 @@ impl<'db> rustc_type_ir::inherent::Ty<DbInterner<'db>> for Ty<'db> {
Ty::new(interner, TyKind::Adt(adt_def, args)) Ty::new(interner, TyKind::Adt(adt_def, args))
} }
fn new_foreign( fn new_foreign(interner: DbInterner<'db>, def_id: TypeAliasIdWrapper) -> Self {
interner: DbInterner<'db>,
def_id: <DbInterner<'db> as rustc_type_ir::Interner>::DefId,
) -> Self {
Ty::new(interner, TyKind::Foreign(def_id)) Ty::new(interner, TyKind::Foreign(def_id))
} }
@ -617,7 +616,7 @@ impl<'db> rustc_type_ir::inherent::Ty<DbInterner<'db>> for Ty<'db> {
fn new_coroutine( fn new_coroutine(
interner: DbInterner<'db>, interner: DbInterner<'db>,
def_id: <DbInterner<'db> as rustc_type_ir::Interner>::DefId, def_id: CoroutineIdWrapper,
args: <DbInterner<'db> as rustc_type_ir::Interner>::GenericArgs, args: <DbInterner<'db> as rustc_type_ir::Interner>::GenericArgs,
) -> Self { ) -> Self {
Ty::new(interner, TyKind::Coroutine(def_id, args)) Ty::new(interner, TyKind::Coroutine(def_id, args))
@ -625,7 +624,7 @@ impl<'db> rustc_type_ir::inherent::Ty<DbInterner<'db>> for Ty<'db> {
fn new_coroutine_closure( fn new_coroutine_closure(
interner: DbInterner<'db>, interner: DbInterner<'db>,
def_id: <DbInterner<'db> as rustc_type_ir::Interner>::DefId, def_id: CoroutineIdWrapper,
args: <DbInterner<'db> as rustc_type_ir::Interner>::GenericArgs, args: <DbInterner<'db> as rustc_type_ir::Interner>::GenericArgs,
) -> Self { ) -> Self {
Ty::new(interner, TyKind::CoroutineClosure(def_id, args)) Ty::new(interner, TyKind::CoroutineClosure(def_id, args))
@ -633,7 +632,7 @@ impl<'db> rustc_type_ir::inherent::Ty<DbInterner<'db>> for Ty<'db> {
fn new_closure( fn new_closure(
interner: DbInterner<'db>, interner: DbInterner<'db>,
def_id: <DbInterner<'db> as rustc_type_ir::Interner>::DefId, def_id: ClosureIdWrapper,
args: <DbInterner<'db> as rustc_type_ir::Interner>::GenericArgs, args: <DbInterner<'db> as rustc_type_ir::Interner>::GenericArgs,
) -> Self { ) -> Self {
Ty::new(interner, TyKind::Closure(def_id, args)) Ty::new(interner, TyKind::Closure(def_id, args))
@ -641,7 +640,7 @@ impl<'db> rustc_type_ir::inherent::Ty<DbInterner<'db>> for Ty<'db> {
fn new_coroutine_witness( fn new_coroutine_witness(
interner: DbInterner<'db>, interner: DbInterner<'db>,
def_id: <DbInterner<'db> as rustc_type_ir::Interner>::DefId, def_id: CoroutineIdWrapper,
args: <DbInterner<'db> as rustc_type_ir::Interner>::GenericArgs, args: <DbInterner<'db> as rustc_type_ir::Interner>::GenericArgs,
) -> Self { ) -> Self {
Ty::new(interner, TyKind::CoroutineWitness(def_id, args)) Ty::new(interner, TyKind::CoroutineWitness(def_id, args))
@ -649,7 +648,7 @@ impl<'db> rustc_type_ir::inherent::Ty<DbInterner<'db>> for Ty<'db> {
fn new_coroutine_witness_for_coroutine( fn new_coroutine_witness_for_coroutine(
interner: DbInterner<'db>, interner: DbInterner<'db>,
def_id: <DbInterner<'db> as rustc_type_ir::Interner>::DefId, def_id: CoroutineIdWrapper,
coroutine_args: <DbInterner<'db> as rustc_type_ir::Interner>::GenericArgs, coroutine_args: <DbInterner<'db> as rustc_type_ir::Interner>::GenericArgs,
) -> Self { ) -> Self {
// HACK: Coroutine witness types are lifetime erased, so they // HACK: Coroutine witness types are lifetime erased, so they
@ -714,7 +713,7 @@ impl<'db> rustc_type_ir::inherent::Ty<DbInterner<'db>> for Ty<'db> {
fn new_fn_def( fn new_fn_def(
interner: DbInterner<'db>, interner: DbInterner<'db>,
def_id: <DbInterner<'db> as rustc_type_ir::Interner>::DefId, def_id: CallableIdWrapper,
args: <DbInterner<'db> as rustc_type_ir::Interner>::GenericArgs, args: <DbInterner<'db> as rustc_type_ir::Interner>::GenericArgs,
) -> Self { ) -> Self {
Ty::new(interner, TyKind::FnDef(def_id, args)) Ty::new(interner, TyKind::FnDef(def_id, args))

View file

@ -532,17 +532,14 @@ pub(crate) fn mini_canonicalize<'db, T: TypeFoldable<DbInterner<'db>>>(
max_universe: UniverseIndex::from_u32(1), max_universe: UniverseIndex::from_u32(1),
variables: CanonicalVars::new_from_iter( variables: CanonicalVars::new_from_iter(
context.cx(), context.cx(),
vars.iter().map(|(k, v)| match (*k).kind() { vars.iter().enumerate().map(|(idx, (k, v))| match (*k).kind() {
GenericArgKind::Type(ty) => match ty.kind() { GenericArgKind::Type(ty) => match ty.kind() {
TyKind::Int(..) | TyKind::Uint(..) => { TyKind::Int(..) | TyKind::Uint(..) => rustc_type_ir::CanonicalVarKind::Int,
rustc_type_ir::CanonicalVarKind::Ty(rustc_type_ir::CanonicalTyVarKind::Int) TyKind::Float(..) => rustc_type_ir::CanonicalVarKind::Float,
} _ => rustc_type_ir::CanonicalVarKind::Ty {
TyKind::Float(..) => rustc_type_ir::CanonicalVarKind::Ty( ui: UniverseIndex::ZERO,
rustc_type_ir::CanonicalTyVarKind::Float, sub_root: BoundVar::from_usize(idx),
), },
_ => rustc_type_ir::CanonicalVarKind::Ty(
rustc_type_ir::CanonicalTyVarKind::General(UniverseIndex::ZERO),
),
}, },
GenericArgKind::Lifetime(_) => { GenericArgKind::Lifetime(_) => {
rustc_type_ir::CanonicalVarKind::Region(UniverseIndex::ZERO) rustc_type_ir::CanonicalVarKind::Region(UniverseIndex::ZERO)