mirror of
https://github.com/rust-lang/rust.git
synced 2026-06-01 22:18:23 +03:00
Merge pull request #21104 from Veykril/veykril/push-plqyyxsxvtyr
minor: Use `const_eval_static` query for statics
This commit is contained in:
@@ -460,6 +460,61 @@ pub struct Crate {
|
||||
pub env: Env,
|
||||
}
|
||||
|
||||
impl Crate {
|
||||
/// Returns an iterator over all transitive dependencies of the given crate,
|
||||
/// including the crate itself.
|
||||
///
|
||||
/// **Warning**: do not use this query in `hir-*` crates! It kills incrementality across crate metadata modifications.
|
||||
pub fn transitive_deps(self, db: &dyn salsa::Database) -> Box<[Crate]> {
|
||||
// There is a bit of duplication here and in `CrateGraphBuilder` in the same method, but it's not terrible
|
||||
// and removing that is a bit difficult.
|
||||
let mut worklist = vec![self];
|
||||
let mut deps_seen = FxHashSet::default();
|
||||
let mut deps = Vec::new();
|
||||
|
||||
while let Some(krate) = worklist.pop() {
|
||||
if !deps_seen.insert(krate) {
|
||||
continue;
|
||||
}
|
||||
deps.push(krate);
|
||||
|
||||
worklist.extend(krate.data(db).dependencies.iter().map(|dep| dep.crate_id));
|
||||
}
|
||||
deps.into_boxed_slice()
|
||||
}
|
||||
|
||||
/// Returns all transitive reverse dependencies of the given crate,
|
||||
/// including the crate itself.
|
||||
///
|
||||
/// **Warning**: do not use this query in `hir-*` crates! It kills incrementality across crate metadata modifications.
|
||||
pub fn transitive_rev_deps(self, db: &dyn RootQueryDb) -> Box<[Crate]> {
|
||||
let mut worklist = vec![self];
|
||||
let mut rev_deps = FxHashSet::default();
|
||||
rev_deps.insert(self);
|
||||
|
||||
let mut inverted_graph = FxHashMap::<_, Vec<_>>::default();
|
||||
db.all_crates().iter().for_each(|&krate| {
|
||||
krate
|
||||
.data(db)
|
||||
.dependencies
|
||||
.iter()
|
||||
.for_each(|dep| inverted_graph.entry(dep.crate_id).or_default().push(krate))
|
||||
});
|
||||
|
||||
while let Some(krate) = worklist.pop() {
|
||||
if let Some(crate_rev_deps) = inverted_graph.get(&krate) {
|
||||
crate_rev_deps
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|&rev_dep| rev_deps.insert(rev_dep))
|
||||
.for_each(|rev_dep| worklist.push(rev_dep));
|
||||
}
|
||||
}
|
||||
|
||||
rev_deps.into_iter().collect::<Box<_>>()
|
||||
}
|
||||
}
|
||||
|
||||
/// The mapping from [`UniqueCrateData`] to their [`Crate`] input.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct CratesMap(DashMap<UniqueCrateData, Crate, BuildHasherDefault<FxHasher>>);
|
||||
@@ -802,33 +857,6 @@ pub fn shrink_to_fit(&mut self) {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn transitive_rev_deps(db: &dyn RootQueryDb, of: Crate) -> FxHashSet<Crate> {
|
||||
let mut worklist = vec![of];
|
||||
let mut rev_deps = FxHashSet::default();
|
||||
rev_deps.insert(of);
|
||||
|
||||
let mut inverted_graph = FxHashMap::<_, Vec<_>>::default();
|
||||
db.all_crates().iter().for_each(|&krate| {
|
||||
krate
|
||||
.data(db)
|
||||
.dependencies
|
||||
.iter()
|
||||
.for_each(|dep| inverted_graph.entry(dep.crate_id).or_default().push(krate))
|
||||
});
|
||||
|
||||
while let Some(krate) = worklist.pop() {
|
||||
if let Some(crate_rev_deps) = inverted_graph.get(&krate) {
|
||||
crate_rev_deps
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|&rev_dep| rev_deps.insert(rev_dep))
|
||||
.for_each(|rev_dep| worklist.push(rev_dep));
|
||||
}
|
||||
}
|
||||
|
||||
rev_deps
|
||||
}
|
||||
|
||||
impl BuiltCrateData {
|
||||
pub fn root_file_id(&self, db: &dyn salsa::Database) -> EditionedFileId {
|
||||
EditionedFileId::new(db, self.root_file_id, self.edition)
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
};
|
||||
use dashmap::{DashMap, mapref::entry::Entry};
|
||||
pub use query_group::{self};
|
||||
use rustc_hash::{FxHashSet, FxHasher};
|
||||
use rustc_hash::FxHasher;
|
||||
use salsa::{Durability, Setter};
|
||||
pub use semver::{BuildMetadata, Prerelease, Version, VersionReq};
|
||||
use span::Edition;
|
||||
@@ -256,38 +256,6 @@ pub trait RootQueryDb: SourceDatabase + salsa::Database {
|
||||
/// **Warning**: do not use this query in `hir-*` crates! It kills incrementality across crate metadata modifications.
|
||||
#[salsa::input]
|
||||
fn all_crates(&self) -> Arc<Box<[Crate]>>;
|
||||
|
||||
/// Returns an iterator over all transitive dependencies of the given crate,
|
||||
/// including the crate itself.
|
||||
///
|
||||
/// **Warning**: do not use this query in `hir-*` crates! It kills incrementality across crate metadata modifications.
|
||||
#[salsa::transparent]
|
||||
fn transitive_deps(&self, crate_id: Crate) -> FxHashSet<Crate>;
|
||||
|
||||
/// Returns all transitive reverse dependencies of the given crate,
|
||||
/// including the crate itself.
|
||||
///
|
||||
/// **Warning**: do not use this query in `hir-*` crates! It kills incrementality across crate metadata modifications.
|
||||
#[salsa::invoke(input::transitive_rev_deps)]
|
||||
#[salsa::transparent]
|
||||
fn transitive_rev_deps(&self, of: Crate) -> FxHashSet<Crate>;
|
||||
}
|
||||
|
||||
fn transitive_deps(db: &dyn SourceDatabase, crate_id: Crate) -> FxHashSet<Crate> {
|
||||
// There is a bit of duplication here and in `CrateGraphBuilder` in the same method, but it's not terrible
|
||||
// and removing that is a bit difficult.
|
||||
let mut worklist = vec![crate_id];
|
||||
let mut deps = FxHashSet::default();
|
||||
|
||||
while let Some(krate) = worklist.pop() {
|
||||
if !deps.insert(krate) {
|
||||
continue;
|
||||
}
|
||||
|
||||
worklist.extend(krate.data(db).dependencies.iter().map(|dep| dep.crate_id));
|
||||
}
|
||||
|
||||
deps
|
||||
}
|
||||
|
||||
#[salsa_macros::db]
|
||||
|
||||
@@ -273,10 +273,9 @@ fn fields_attrs_source_map(
|
||||
|
||||
// endregion:visibilities
|
||||
|
||||
#[salsa::invoke(crate::lang_item::notable_traits_in_deps)]
|
||||
fn notable_traits_in_deps(&self, krate: Crate) -> Arc<[Arc<[TraitId]>]>;
|
||||
#[salsa::invoke(crate::lang_item::crate_notable_traits)]
|
||||
fn crate_notable_traits(&self, krate: Crate) -> Option<Arc<[TraitId]>>;
|
||||
#[salsa::transparent]
|
||||
fn crate_notable_traits(&self, krate: Crate) -> Option<&[TraitId]>;
|
||||
|
||||
#[salsa::invoke(crate_supports_no_std)]
|
||||
fn crate_supports_no_std(&self, crate_id: Crate) -> bool;
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
use hir_expand::name::Name;
|
||||
use intern::{Symbol, sym};
|
||||
use rustc_hash::FxHashMap;
|
||||
use triomphe::Arc;
|
||||
|
||||
use crate::{
|
||||
AdtId, AssocItemId, AttrDefId, Crate, EnumId, EnumVariantId, FunctionId, ImplId, ModuleDefId,
|
||||
@@ -223,16 +222,8 @@ pub(crate) fn lang_attr(db: &dyn DefDatabase, item: AttrDefId) -> Option<LangIte
|
||||
db.attrs(item).lang_item()
|
||||
}
|
||||
|
||||
pub(crate) fn notable_traits_in_deps(db: &dyn DefDatabase, krate: Crate) -> Arc<[Arc<[TraitId]>]> {
|
||||
let _p = tracing::info_span!("notable_traits_in_deps", ?krate).entered();
|
||||
Arc::from_iter(
|
||||
db.transitive_deps(krate).into_iter().filter_map(|krate| db.crate_notable_traits(krate)),
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn crate_notable_traits(db: &dyn DefDatabase, krate: Crate) -> Option<Arc<[TraitId]>> {
|
||||
let _p = tracing::info_span!("crate_notable_traits", ?krate).entered();
|
||||
|
||||
#[salsa::tracked(returns(as_deref))]
|
||||
pub(crate) fn crate_notable_traits(db: &dyn DefDatabase, krate: Crate) -> Option<Box<[TraitId]>> {
|
||||
let mut traits = Vec::new();
|
||||
|
||||
let crate_def_map = crate_def_map(db, krate);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
use base_db::Crate;
|
||||
use hir_def::{
|
||||
EnumVariantId, GeneralConstId, HasModule, StaticId,
|
||||
ConstId, EnumVariantId, StaticId,
|
||||
expr_store::Body,
|
||||
hir::{Expr, ExprId},
|
||||
type_ref::LiteralConstRef,
|
||||
@@ -139,16 +139,18 @@ 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) => {
|
||||
let c = match unevaluated_const.def {
|
||||
SolverDefId::ConstId(id) => GeneralConstId::ConstId(id),
|
||||
SolverDefId::StaticId(id) => GeneralConstId::StaticId(id),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let subst = unevaluated_const.args;
|
||||
let ec = db.const_eval(c, subst, None).ok()?;
|
||||
try_const_usize(db, ec)
|
||||
}
|
||||
ConstKind::Unevaluated(unevaluated_const) => match unevaluated_const.def {
|
||||
SolverDefId::ConstId(id) => {
|
||||
let subst = unevaluated_const.args;
|
||||
let ec = db.const_eval(id, subst, None).ok()?;
|
||||
try_const_usize(db, ec)
|
||||
}
|
||||
SolverDefId::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,
|
||||
ConstKind::Expr(_) => None,
|
||||
@@ -161,16 +163,18 @@ 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) => {
|
||||
let c = match unevaluated_const.def {
|
||||
SolverDefId::ConstId(id) => GeneralConstId::ConstId(id),
|
||||
SolverDefId::StaticId(id) => GeneralConstId::StaticId(id),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let subst = unevaluated_const.args;
|
||||
let ec = db.const_eval(c, subst, None).ok()?;
|
||||
try_const_isize(db, &ec)
|
||||
}
|
||||
ConstKind::Unevaluated(unevaluated_const) => match unevaluated_const.def {
|
||||
SolverDefId::ConstId(id) => {
|
||||
let subst = unevaluated_const.args;
|
||||
let ec = db.const_eval(id, subst, None).ok()?;
|
||||
try_const_isize(db, &ec)
|
||||
}
|
||||
SolverDefId::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,
|
||||
ConstKind::Expr(_) => None,
|
||||
@@ -254,7 +258,7 @@ fn has_closure(body: &Body, expr: ExprId) -> bool {
|
||||
|
||||
pub(crate) fn const_eval_cycle_result<'db>(
|
||||
_: &'db dyn HirDatabase,
|
||||
_: GeneralConstId,
|
||||
_: ConstId,
|
||||
_: GenericArgs<'db>,
|
||||
_: Option<Arc<TraitEnvironment<'db>>>,
|
||||
) -> Result<Const<'db>, ConstEvalError<'db>> {
|
||||
@@ -277,19 +281,11 @@ pub(crate) fn const_eval_discriminant_cycle_result<'db>(
|
||||
|
||||
pub(crate) fn const_eval_query<'db>(
|
||||
db: &'db dyn HirDatabase,
|
||||
def: GeneralConstId,
|
||||
def: ConstId,
|
||||
subst: GenericArgs<'db>,
|
||||
trait_env: Option<Arc<TraitEnvironment<'db>>>,
|
||||
) -> Result<Const<'db>, ConstEvalError<'db>> {
|
||||
let body = match def {
|
||||
GeneralConstId::ConstId(c) => {
|
||||
db.monomorphized_mir_body(c.into(), subst, db.trait_environment(c.into()))?
|
||||
}
|
||||
GeneralConstId::StaticId(s) => {
|
||||
let krate = s.module(db).krate();
|
||||
db.monomorphized_mir_body(s.into(), subst, TraitEnvironment::empty(krate))?
|
||||
}
|
||||
};
|
||||
let body = db.monomorphized_mir_body(def.into(), subst, db.trait_environment(def.into()))?;
|
||||
let c = interpret_mir(db, body, false, trait_env)?.0?;
|
||||
Ok(c)
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ fn eval_goal(db: &TestDB, file_id: EditionedFileId) -> Result<Const<'_>, ConstEv
|
||||
_ => None,
|
||||
})
|
||||
.expect("No const named GOAL found in the test");
|
||||
db.const_eval(const_id.into(), GenericArgs::new_from_iter(interner, []), None)
|
||||
db.const_eval(const_id, GenericArgs::new_from_iter(interner, []), None)
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
use base_db::{Crate, target::TargetLoadError};
|
||||
use hir_def::{
|
||||
AdtId, CallableDefId, ConstParamId, DefWithBodyId, EnumVariantId, FunctionId, GeneralConstId,
|
||||
GenericDefId, ImplId, LifetimeParamId, LocalFieldId, StaticId, TraitId, TypeAliasId,
|
||||
TypeOrConstParamId, VariantId, db::DefDatabase, hir::ExprId, layout::TargetDataLayout,
|
||||
AdtId, CallableDefId, ConstId, ConstParamId, DefWithBodyId, EnumVariantId, FunctionId,
|
||||
GenericDefId, ImplId, LifetimeParamId, LocalFieldId, StaticId, TraitId, TypeAliasId, VariantId,
|
||||
db::DefDatabase, hir::ExprId, layout::TargetDataLayout,
|
||||
};
|
||||
use la_arena::ArenaMap;
|
||||
use salsa::plumbing::AsId;
|
||||
@@ -29,6 +29,8 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
|
||||
|
||||
// region:mir
|
||||
|
||||
// FXME: Collapse `mir_body_for_closure` into `mir_body`
|
||||
// and `monomorphized_mir_body_for_closure` into `monomorphized_mir_body`
|
||||
#[salsa::invoke(crate::mir::mir_body_query)]
|
||||
#[salsa::cycle(cycle_result = crate::mir::mir_body_cycle_result)]
|
||||
fn mir_body<'db>(
|
||||
@@ -70,7 +72,7 @@ fn borrowck<'db>(
|
||||
#[salsa::cycle(cycle_result = crate::consteval::const_eval_cycle_result)]
|
||||
fn const_eval<'db>(
|
||||
&'db self,
|
||||
def: GeneralConstId,
|
||||
def: ConstId,
|
||||
subst: GenericArgs<'db>,
|
||||
trait_env: Option<Arc<TraitEnvironment<'db>>>,
|
||||
) -> Result<Const<'db>, ConstEvalError<'db>>;
|
||||
@@ -232,13 +234,6 @@ fn hir_database_is_dyn_compatible() {
|
||||
fn _assert_dyn_compatible(_: &dyn HirDatabase) {}
|
||||
}
|
||||
|
||||
#[salsa_macros::interned(no_lifetime, debug, revisions = usize::MAX)]
|
||||
#[derive(PartialOrd, Ord)]
|
||||
pub struct InternedTypeOrConstParamId {
|
||||
/// This stores the param and its index.
|
||||
pub loc: (TypeOrConstParamId, u32),
|
||||
}
|
||||
|
||||
#[salsa_macros::interned(no_lifetime, debug, revisions = usize::MAX)]
|
||||
#[derive(PartialOrd, Ord)]
|
||||
pub struct InternedLifetimeParamId {
|
||||
|
||||
@@ -28,10 +28,10 @@ fn has_destructor(db: &dyn HirDatabase, adt: AdtId) -> bool {
|
||||
};
|
||||
let impls = match module.containing_block() {
|
||||
Some(block) => match TraitImpls::for_block(db, block) {
|
||||
Some(it) => it,
|
||||
Some(it) => &**it,
|
||||
None => return false,
|
||||
},
|
||||
None => &**TraitImpls::for_crate(db, module.krate()),
|
||||
None => TraitImpls::for_crate(db, module.krate()),
|
||||
};
|
||||
!impls.for_trait_and_self_ty(drop_trait, &SimplifiedType::Adt(adt.into())).is_empty()
|
||||
}
|
||||
|
||||
@@ -687,7 +687,7 @@ pub fn for_block(db: &dyn HirDatabase, block: BlockId) -> Option<Box<Self>> {
|
||||
|
||||
#[salsa::tracked(returns(ref))]
|
||||
pub fn for_crate_and_deps(db: &dyn HirDatabase, krate: Crate) -> Box<[Arc<Self>]> {
|
||||
db.transitive_deps(krate).iter().map(|&dep| Self::for_crate(db, dep).clone()).collect()
|
||||
krate.transitive_deps(db).iter().map(|&dep| Self::for_crate(db, dep).clone()).collect()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1917,24 +1917,32 @@ fn allocate_const_in_heap(
|
||||
let value = match konst.kind() {
|
||||
ConstKind::Value(value) => value,
|
||||
ConstKind::Unevaluated(UnevaluatedConst { def: const_id, args: subst }) => 'b: {
|
||||
let mut const_id = match const_id {
|
||||
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 subst = subst;
|
||||
if let hir_def::GeneralConstId::ConstId(c) = const_id {
|
||||
if let hir_def::GeneralConstId::ConstId(c) = id {
|
||||
let (c, s) = lookup_impl_const(&self.infcx, self.trait_env.clone(), c, subst);
|
||||
const_id = hir_def::GeneralConstId::ConstId(c);
|
||||
id = hir_def::GeneralConstId::ConstId(c);
|
||||
subst = s;
|
||||
}
|
||||
result_owner = self
|
||||
.db
|
||||
.const_eval(const_id, subst, Some(self.trait_env.clone()))
|
||||
.map_err(|e| {
|
||||
let name = const_id.name(self.db);
|
||||
MirEvalError::ConstEvalError(name, Box::new(e))
|
||||
})?;
|
||||
result_owner = match id {
|
||||
GeneralConstId::ConstId(const_id) => self
|
||||
.db
|
||||
.const_eval(const_id, subst, Some(self.trait_env.clone()))
|
||||
.map_err(|e| {
|
||||
let name = id.name(self.db);
|
||||
MirEvalError::ConstEvalError(name, Box::new(e))
|
||||
})?,
|
||||
GeneralConstId::StaticId(static_id) => {
|
||||
self.db.const_eval_static(static_id).map_err(|e| {
|
||||
let name = id.name(self.db);
|
||||
MirEvalError::ConstEvalError(name, Box::new(e))
|
||||
})?
|
||||
}
|
||||
};
|
||||
if let ConstKind::Value(value) = result_owner.kind() {
|
||||
break 'b value;
|
||||
}
|
||||
|
||||
@@ -1532,10 +1532,20 @@ fn lower_const_to_operand(
|
||||
UnevaluatedConst { def: const_id.into(), args: subst },
|
||||
)
|
||||
} else {
|
||||
let name = const_id.name(self.db);
|
||||
self.db
|
||||
.const_eval(const_id, subst, None)
|
||||
.map_err(|e| MirLowerError::ConstEvalError(name.into(), Box::new(e)))?
|
||||
match const_id {
|
||||
id @ GeneralConstId::ConstId(const_id) => {
|
||||
self.db.const_eval(const_id, subst, None).map_err(|e| {
|
||||
let name = id.name(self.db);
|
||||
MirLowerError::ConstEvalError(name.into(), Box::new(e))
|
||||
})?
|
||||
}
|
||||
GeneralConstId::StaticId(static_id) => {
|
||||
self.db.const_eval_static(static_id).map_err(|e| {
|
||||
let name = const_id.name(self.db);
|
||||
MirLowerError::ConstEvalError(name.into(), Box::new(e))
|
||||
})?
|
||||
}
|
||||
}
|
||||
};
|
||||
let ty = self
|
||||
.db
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
generics::Generics,
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, TypeVisitable, TypeFoldable)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, TypeVisitable, TypeFoldable, salsa::Supertype)]
|
||||
pub enum GenericArg<'db> {
|
||||
Ty(Ty<'db>),
|
||||
Lifetime(Region<'db>),
|
||||
@@ -196,6 +196,11 @@ pub fn for_item<F>(
|
||||
{
|
||||
let defs = interner.generics_of(def_id);
|
||||
let count = defs.count();
|
||||
|
||||
if count == 0 {
|
||||
return Default::default();
|
||||
}
|
||||
|
||||
let mut args = SmallVec::with_capacity(count);
|
||||
Self::fill_item(&mut args, interner, defs, &mut mk_kind);
|
||||
interner.mk_args(&args)
|
||||
|
||||
@@ -214,6 +214,10 @@ fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
}
|
||||
|
||||
impl<'db> $name<'db> {
|
||||
pub fn empty(interner: DbInterner<'db>) -> Self {
|
||||
$name::new_(interner.db(), smallvec::SmallVec::new())
|
||||
}
|
||||
|
||||
pub fn new_from_iter(
|
||||
interner: DbInterner<'db>,
|
||||
data: impl IntoIterator<Item = $ty<'db>>,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Defining `SolverContext` for next-trait-solver.
|
||||
|
||||
use hir_def::{AssocItemId, GeneralConstId};
|
||||
use hir_def::AssocItemId;
|
||||
use rustc_next_trait_solver::delegate::SolverDelegate;
|
||||
use rustc_type_ir::{
|
||||
AliasTyKind, GenericArgKind, InferCtxtLike, Interner, PredicatePolarity, TypeFlags,
|
||||
@@ -233,14 +233,18 @@ fn evaluate_const(
|
||||
_param_env: ParamEnv<'db>,
|
||||
uv: rustc_type_ir::UnevaluatedConst<Self::Interner>,
|
||||
) -> Option<<Self::Interner as rustc_type_ir::Interner>::Const> {
|
||||
let c = match uv.def {
|
||||
SolverDefId::ConstId(c) => GeneralConstId::ConstId(c),
|
||||
SolverDefId::StaticId(c) => GeneralConstId::StaticId(c),
|
||||
match uv.def {
|
||||
SolverDefId::ConstId(c) => {
|
||||
let subst = uv.args;
|
||||
let ec = self.cx().db.const_eval(c, subst, None).ok()?;
|
||||
Some(ec)
|
||||
}
|
||||
SolverDefId::StaticId(c) => {
|
||||
let ec = self.cx().db.const_eval_static(c).ok()?;
|
||||
Some(ec)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let subst = uv.args;
|
||||
let ec = self.cx().db.const_eval(c, subst, None).ok()?;
|
||||
Some(ec)
|
||||
}
|
||||
}
|
||||
|
||||
fn compute_goal_fast_path(
|
||||
|
||||
@@ -247,7 +247,15 @@ pub fn transitive_reverse_dependencies(
|
||||
self,
|
||||
db: &dyn HirDatabase,
|
||||
) -> impl Iterator<Item = Crate> {
|
||||
db.transitive_rev_deps(self.id).into_iter().map(|id| Crate { id })
|
||||
self.id.transitive_rev_deps(db).into_iter().map(|id| Crate { id })
|
||||
}
|
||||
|
||||
pub fn notable_traits_in_deps(self, db: &dyn HirDatabase) -> impl Iterator<Item = &TraitId> {
|
||||
self.id
|
||||
.transitive_deps(db)
|
||||
.into_iter()
|
||||
.filter_map(|krate| db.crate_notable_traits(krate))
|
||||
.flatten()
|
||||
}
|
||||
|
||||
pub fn root_module(self) -> Module {
|
||||
@@ -2798,7 +2806,7 @@ pub fn ty(self, db: &dyn HirDatabase) -> Type<'_> {
|
||||
pub fn eval(self, db: &dyn HirDatabase) -> Result<EvaluatedConst<'_>, ConstEvalError<'_>> {
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let ty = db.value_ty(self.id.into()).unwrap().instantiate_identity();
|
||||
db.const_eval(self.id.into(), GenericArgs::new_from_iter(interner, []), None)
|
||||
db.const_eval(self.id, GenericArgs::new_from_iter(interner, []), None)
|
||||
.map(|it| EvaluatedConst { const_: it, def: self.id.into(), ty })
|
||||
}
|
||||
}
|
||||
@@ -2877,10 +2885,12 @@ pub fn extern_block(self, db: &dyn HirDatabase) -> Option<ExternBlock> {
|
||||
|
||||
/// Evaluate the static initializer.
|
||||
pub fn eval(self, db: &dyn HirDatabase) -> Result<EvaluatedConst<'_>, ConstEvalError<'_>> {
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let ty = db.value_ty(self.id.into()).unwrap().instantiate_identity();
|
||||
db.const_eval(self.id.into(), GenericArgs::new_from_iter(interner, []), None)
|
||||
.map(|it| EvaluatedConst { const_: it, def: self.id.into(), ty })
|
||||
db.const_eval_static(self.id).map(|it| EvaluatedConst {
|
||||
const_: it,
|
||||
def: self.id.into(),
|
||||
ty,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4444,7 +4454,7 @@ pub fn all_for_trait(db: &dyn HirDatabase, trait_: Trait) -> Vec<Impl> {
|
||||
let mut handle_impls = |impls: &TraitImpls| {
|
||||
impls.for_trait(trait_.id, |impls| all.extend(impls.iter().copied().map(Impl::from)));
|
||||
};
|
||||
for krate in db.transitive_rev_deps(module.krate()) {
|
||||
for krate in module.krate().transitive_rev_deps(db) {
|
||||
handle_impls(TraitImpls::for_crate(db, krate));
|
||||
}
|
||||
if let Some(block) = module.containing_block()
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
use either::Either;
|
||||
use hir::{
|
||||
DisplayTarget, GenericDef, GenericSubstitution, HasCrate, HasSource, LangItem, Semantics,
|
||||
db::DefDatabase,
|
||||
};
|
||||
use ide_db::{
|
||||
FileRange, FxIndexSet, MiniCore, Ranker, RootDatabase,
|
||||
@@ -522,9 +521,8 @@ fn notable_traits<'db>(
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
db.notable_traits_in_deps(ty.krate(db).into())
|
||||
.iter()
|
||||
.flat_map(|it| &**it)
|
||||
ty.krate(db)
|
||||
.notable_traits_in_deps(db)
|
||||
.filter_map(move |&trait_| {
|
||||
let trait_ = trait_.into();
|
||||
ty.impls_trait(db, trait_, &[]).then(|| {
|
||||
|
||||
@@ -642,7 +642,7 @@ pub fn crates_for(&self, file_id: FileId) -> Cancellable<Vec<Crate>> {
|
||||
|
||||
/// Returns crates that this file belongs to.
|
||||
pub fn transitive_rev_deps(&self, crate_id: Crate) -> Cancellable<Vec<Crate>> {
|
||||
self.with_db(|db| Vec::from_iter(db.transitive_rev_deps(crate_id)))
|
||||
self.with_db(|db| Vec::from_iter(crate_id.transitive_rev_deps(db)))
|
||||
}
|
||||
|
||||
/// Returns crates that this file *might* belong to.
|
||||
|
||||
Reference in New Issue
Block a user