Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ vfs-notify = { path = "./crates/vfs-notify", version = "0.0.0" }
vfs = { path = "./crates/vfs", version = "0.0.0" }
edition = { path = "./crates/edition", version = "0.0.0" }

ra-ap-rustc_lexer = { version = "0.137", default-features = false }
ra-ap-rustc_parse_format = { version = "0.137", default-features = false }
ra-ap-rustc_index = { version = "0.137", default-features = false }
ra-ap-rustc_abi = { version = "0.137", default-features = false }
ra-ap-rustc_pattern_analysis = { version = "0.137", default-features = false }
ra-ap-rustc_ast_ir = { version = "0.137", default-features = false }
ra-ap-rustc_type_ir = { version = "0.137", default-features = false }
ra-ap-rustc_next_trait_solver = { version = "0.137", default-features = false }
ra-ap-rustc_lexer = { version = "0.139", default-features = false }
ra-ap-rustc_parse_format = { version = "0.139", default-features = false }
ra-ap-rustc_index = { version = "0.139", default-features = false }
ra-ap-rustc_abi = { version = "0.139", default-features = false }
ra-ap-rustc_pattern_analysis = { version = "0.139", default-features = false }
ra-ap-rustc_ast_ir = { version = "0.139", default-features = false }
ra-ap-rustc_type_ir = { version = "0.139", default-features = false }
ra-ap-rustc_next_trait_solver = { version = "0.139", default-features = false }

# local crates that aren't published to crates.io. These should not have versions.

Expand Down
20 changes: 9 additions & 11 deletions crates/hir-ty/src/consteval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod tests;

use base_db::Crate;
use hir_def::{
ConstId, EnumVariantId, StaticId,
ConstId, EnumVariantId, GeneralConstId, StaticId,
expr_store::Body,
hir::{Expr, ExprId},
type_ref::LiteralConstRef,
Expand All @@ -21,8 +21,8 @@ use crate::{
infer::InferenceContext,
mir::{MirEvalError, MirLowerError},
next_solver::{
Const, ConstBytes, ConstKind, DbInterner, ErrorGuaranteed, GenericArg, GenericArgs,
SolverDefId, Ty, ValueConst,
Const, ConstBytes, ConstKind, DbInterner, ErrorGuaranteed, GenericArg, GenericArgs, Ty,
ValueConst,
},
};

Expand Down Expand Up @@ -139,17 +139,16 @@ pub fn try_const_usize<'db>(db: &'db dyn HirDatabase, c: Const<'db>) -> Option<u
ConstKind::Infer(_) => None,
ConstKind::Bound(_, _) => None,
ConstKind::Placeholder(_) => None,
ConstKind::Unevaluated(unevaluated_const) => match unevaluated_const.def {
SolverDefId::ConstId(id) => {
ConstKind::Unevaluated(unevaluated_const) => match unevaluated_const.def.0 {
GeneralConstId::ConstId(id) => {
let subst = unevaluated_const.args;
let ec = db.const_eval(id, subst, None).ok()?;
try_const_usize(db, ec)
}
SolverDefId::StaticId(id) => {
GeneralConstId::StaticId(id) => {
let ec = db.const_eval_static(id).ok()?;
try_const_usize(db, ec)
}
_ => unreachable!(),
},
ConstKind::Value(val) => Some(u128::from_le_bytes(pad16(&val.value.inner().memory, false))),
ConstKind::Error(_) => None,
Expand All @@ -163,17 +162,16 @@ pub fn try_const_isize<'db>(db: &'db dyn HirDatabase, c: &Const<'db>) -> Option<
ConstKind::Infer(_) => None,
ConstKind::Bound(_, _) => None,
ConstKind::Placeholder(_) => None,
ConstKind::Unevaluated(unevaluated_const) => match unevaluated_const.def {
SolverDefId::ConstId(id) => {
ConstKind::Unevaluated(unevaluated_const) => match unevaluated_const.def.0 {
GeneralConstId::ConstId(id) => {
let subst = unevaluated_const.args;
let ec = db.const_eval(id, subst, None).ok()?;
try_const_isize(db, &ec)
}
SolverDefId::StaticId(id) => {
GeneralConstId::StaticId(id) => {
let ec = db.const_eval_static(id).ok()?;
try_const_isize(db, &ec)
}
_ => unreachable!(),
},
ConstKind::Value(val) => Some(i128::from_le_bytes(pad16(&val.value.inner().memory, true))),
ConstKind::Error(_) => None,
Expand Down
9 changes: 2 additions & 7 deletions crates/hir-ty/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use std::{
use base_db::Crate;
use either::Either;
use hir_def::{
FindPathConfig, GeneralConstId, GenericDefId, HasModule, LocalFieldId, Lookup, ModuleDefId,
ModuleId, TraitId,
FindPathConfig, GenericDefId, HasModule, LocalFieldId, Lookup, ModuleDefId, ModuleId, TraitId,
db::DefDatabase,
expr_store::{ExpressionStore, path::Path},
find_path::{self, PrefixKind},
Expand Down Expand Up @@ -700,11 +699,7 @@ impl<'db> HirDisplay<'db> for Const<'db> {
const_bytes.ty,
),
ConstKind::Unevaluated(unev) => {
let c = match unev.def {
SolverDefId::ConstId(id) => GeneralConstId::ConstId(id),
SolverDefId::StaticId(id) => GeneralConstId::StaticId(id),
_ => unreachable!(),
};
let c = unev.def.0;
write!(f, "{}", c.name(f.db))?;
hir_fmt_generics(f, unev.args.as_slice(), c.generic_def(f.db), None)?;
Ok(())
Expand Down
18 changes: 2 additions & 16 deletions crates/hir-ty/src/infer/unify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_hash::FxHashSet;
use rustc_type_ir::{
TyVid, TypeFoldable, TypeVisitableExt, UpcastFrom,
inherent::{Const as _, GenericArg as _, IntoKind, SliceLike, Ty as _},
solve::{Certainty, GoalSource},
solve::Certainty,
};
use smallvec::SmallVec;
use triomphe::Arc;
Expand Down Expand Up @@ -62,21 +62,7 @@ impl<'a, 'db> ProofTreeVisitor<'db> for NestedObligationsForSelfTy<'a, 'db> {

let db = self.ctx.interner();
let goal = inspect_goal.goal();
if self.ctx.predicate_has_self_ty(goal.predicate, self.self_ty)
// We do not push the instantiated forms of goals as it would cause any
// aliases referencing bound vars to go from having escaping bound vars to
// being able to be normalized to an inference variable.
//
// This is mostly just a hack as arbitrary nested goals could still contain
// such aliases while having a different `GoalSource`. Closure signature inference
// however can't really handle *every* higher ranked `Fn` goal also being present
// in the form of `?c: Fn<(<?x as Trait<'!a>>::Assoc)`.
//
// This also just better matches the behaviour of the old solver where we do not
// encounter instantiated forms of goals, only nested goals that referred to bound
// vars from instantiated goals.
&& !matches!(inspect_goal.source(), GoalSource::InstantiateHigherRanked)
{
if self.ctx.predicate_has_self_ty(goal.predicate, self.self_ty) {
self.obligations_for_self_ty.push(Obligation::new(
db,
self.root_cause.clone(),
Expand Down
8 changes: 4 additions & 4 deletions crates/hir-ty/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use base_db::Crate;
use either::Either;
use hir_def::{
AdtId, AssocItemId, CallableDefId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId,
FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, ItemContainerId, LifetimeParamId,
LocalFieldId, Lookup, StaticId, StructId, TypeAliasId, TypeOrConstParamId, TypeParamId,
UnionId, VariantId,
FunctionId, GeneralConstId, GenericDefId, GenericParamId, HasModule, ImplId, ItemContainerId,
LifetimeParamId, LocalFieldId, Lookup, StaticId, StructId, TypeAliasId, TypeOrConstParamId,
TypeParamId, UnionId, VariantId,
builtin_type::BuiltinType,
expr_store::{ExpressionStore, HygieneId, path::Path},
hir::generics::{
Expand Down Expand Up @@ -335,7 +335,7 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> {
Some(Const::new(
self.interner,
rustc_type_ir::ConstKind::Unevaluated(UnevaluatedConst::new(
SolverDefId::ConstId(c),
GeneralConstId::ConstId(c).into(),
args,
)),
))
Expand Down
10 changes: 3 additions & 7 deletions crates/hir-ty/src/mir/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ use crate::{
layout::{Layout, LayoutError, RustcEnumVariantIdx},
method_resolution::{is_dyn_method, lookup_impl_const},
next_solver::{
Const, ConstBytes, ConstKind, DbInterner, ErrorGuaranteed, GenericArgs, Region,
SolverDefId, Ty, TyKind, TypingMode, UnevaluatedConst, ValueConst,
Const, ConstBytes, ConstKind, DbInterner, ErrorGuaranteed, GenericArgs, Region, Ty, TyKind,
TypingMode, UnevaluatedConst, ValueConst,
infer::{DbInternerInferExt, InferCtxt, traits::ObligationCause},
obligation_ctxt::ObligationCtxt,
},
Expand Down Expand Up @@ -1917,11 +1917,7 @@ impl<'db> Evaluator<'db> {
let value = match konst.kind() {
ConstKind::Value(value) => value,
ConstKind::Unevaluated(UnevaluatedConst { def: const_id, args: subst }) => 'b: {
let mut id = match const_id {
SolverDefId::ConstId(it) => GeneralConstId::from(it),
SolverDefId::StaticId(it) => it.into(),
_ => unreachable!("unevaluated consts should be consts or statics"),
};
let mut id = const_id.0;
let mut subst = subst;
if let hir_def::GeneralConstId::ConstId(c) = id {
let (c, s) = lookup_impl_const(&self.infcx, self.trait_env.clone(), c, subst);
Expand Down
49 changes: 49 additions & 0 deletions crates/hir-ty/src/next_solver/def_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,55 @@ declare_id_wrapper!(CoroutineIdWrapper, InternedCoroutineId);
declare_id_wrapper!(AdtIdWrapper, AdtId);
declare_id_wrapper!(ImplIdWrapper, ImplId);

#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct GeneralConstIdWrapper(pub GeneralConstId);

impl std::fmt::Debug for GeneralConstIdWrapper {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Debug::fmt(&self.0, f)
}
}
impl From<GeneralConstIdWrapper> for GeneralConstId {
#[inline]
fn from(value: GeneralConstIdWrapper) -> GeneralConstId {
value.0
}
}
impl From<GeneralConstId> for GeneralConstIdWrapper {
#[inline]
fn from(value: GeneralConstId) -> GeneralConstIdWrapper {
Self(value)
}
}
impl From<GeneralConstIdWrapper> for SolverDefId {
#[inline]
fn from(value: GeneralConstIdWrapper) -> SolverDefId {
match value.0 {
GeneralConstId::ConstId(id) => SolverDefId::ConstId(id),
GeneralConstId::StaticId(id) => SolverDefId::StaticId(id),
}
}
}
impl TryFrom<SolverDefId> for GeneralConstIdWrapper {
type Error = ();
#[inline]
fn try_from(value: SolverDefId) -> Result<Self, Self::Error> {
match value {
SolverDefId::ConstId(it) => Ok(Self(it.into())),
SolverDefId::StaticId(it) => Ok(Self(it.into())),
_ => Err(()),
}
}
}
impl<'db> inherent::DefId<DbInterner<'db>> for GeneralConstIdWrapper {
fn as_local(self) -> Option<SolverDefId> {
Some(self.into())
}
fn is_local(self) -> bool {
true
}
}

#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct CallableIdWrapper(pub CallableDefId);

Expand Down
Loading