mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-27 18:26:19 +00:00
Salsify the crate graph
I.e. make it not one giant input but multiple, for incrementality and decreased memory usage for Salsa 3 reasons.
This commit is contained in:
parent
44f18c3d05
commit
c94e9efbef
108 changed files with 3630 additions and 2512 deletions
|
|
@ -11,7 +11,7 @@ use tracing::debug;
|
|||
use chalk_ir::{cast::Caster, fold::shift::Shift, CanonicalVarKinds};
|
||||
use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait};
|
||||
|
||||
use base_db::CrateId;
|
||||
use base_db::Crate;
|
||||
use hir_def::{
|
||||
data::{adt::StructFlags, TraitFlags},
|
||||
hir::Movability,
|
||||
|
|
@ -523,7 +523,7 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
|
|||
|
||||
impl ChalkContext<'_> {
|
||||
fn edition(&self) -> Edition {
|
||||
self.db.crate_graph()[self.krate].edition
|
||||
self.krate.data(self.db).edition
|
||||
}
|
||||
|
||||
fn for_trait_impls(
|
||||
|
|
@ -593,7 +593,7 @@ impl chalk_ir::UnificationDatabase<Interner> for &dyn HirDatabase {
|
|||
|
||||
pub(crate) fn program_clauses_for_chalk_env_query(
|
||||
db: &dyn HirDatabase,
|
||||
krate: CrateId,
|
||||
krate: Crate,
|
||||
block: Option<BlockId>,
|
||||
environment: chalk_ir::Environment<Interner>,
|
||||
) -> chalk_ir::ProgramClauses<Interner> {
|
||||
|
|
@ -665,7 +665,7 @@ pub(crate) fn associated_ty_data_query(
|
|||
|
||||
pub(crate) fn trait_datum_query(
|
||||
db: &dyn HirDatabase,
|
||||
krate: CrateId,
|
||||
krate: Crate,
|
||||
trait_id: TraitId,
|
||||
) -> Arc<TraitDatum> {
|
||||
debug!("trait_datum {:?}", trait_id);
|
||||
|
|
@ -750,7 +750,7 @@ fn lang_item_from_well_known_trait(trait_: WellKnownTrait) -> LangItem {
|
|||
|
||||
pub(crate) fn adt_datum_query(
|
||||
db: &dyn HirDatabase,
|
||||
krate: CrateId,
|
||||
krate: Crate,
|
||||
chalk_ir::AdtId(adt_id): AdtId,
|
||||
) -> Arc<AdtDatum> {
|
||||
debug!("adt_datum {:?}", adt_id);
|
||||
|
|
@ -824,7 +824,7 @@ pub(crate) fn adt_datum_query(
|
|||
|
||||
pub(crate) fn impl_datum_query(
|
||||
db: &dyn HirDatabase,
|
||||
krate: CrateId,
|
||||
krate: Crate,
|
||||
impl_id: ImplId,
|
||||
) -> Arc<ImplDatum> {
|
||||
let _p = tracing::info_span!("impl_datum_query").entered();
|
||||
|
|
@ -833,11 +833,7 @@ pub(crate) fn impl_datum_query(
|
|||
impl_def_datum(db, krate, impl_)
|
||||
}
|
||||
|
||||
fn impl_def_datum(
|
||||
db: &dyn HirDatabase,
|
||||
krate: CrateId,
|
||||
impl_id: hir_def::ImplId,
|
||||
) -> Arc<ImplDatum> {
|
||||
fn impl_def_datum(db: &dyn HirDatabase, krate: Crate, impl_id: hir_def::ImplId) -> Arc<ImplDatum> {
|
||||
let trait_ref = db
|
||||
.impl_trait(impl_id)
|
||||
// ImplIds for impls where the trait ref can't be resolved should never reach Chalk
|
||||
|
|
@ -887,7 +883,7 @@ fn impl_def_datum(
|
|||
|
||||
pub(crate) fn associated_ty_value_query(
|
||||
db: &dyn HirDatabase,
|
||||
krate: CrateId,
|
||||
krate: Crate,
|
||||
id: AssociatedTyValueId,
|
||||
) -> Arc<AssociatedTyValue> {
|
||||
let type_alias: TypeAliasAsValue = from_chalk(db, id);
|
||||
|
|
@ -896,7 +892,7 @@ pub(crate) fn associated_ty_value_query(
|
|||
|
||||
fn type_alias_associated_ty_value(
|
||||
db: &dyn HirDatabase,
|
||||
_krate: CrateId,
|
||||
_krate: Crate,
|
||||
type_alias: TypeAliasId,
|
||||
) -> Arc<AssociatedTyValue> {
|
||||
let type_alias_data = db.type_alias_data(type_alias);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
//! Constant evaluation details
|
||||
|
||||
use base_db::CrateId;
|
||||
use base_db::Crate;
|
||||
use chalk_ir::{cast::Cast, BoundVar, DebruijnIndex};
|
||||
use hir_def::{
|
||||
expr_store::{Body, HygieneId},
|
||||
|
|
@ -162,7 +162,7 @@ pub fn intern_const_ref(
|
|||
db: &dyn HirDatabase,
|
||||
value: &LiteralConstRef,
|
||||
ty: Ty,
|
||||
krate: CrateId,
|
||||
krate: Crate,
|
||||
) -> Const {
|
||||
let layout = db.layout_of_ty(ty.clone(), TraitEnvironment::empty(krate));
|
||||
let bytes = match value {
|
||||
|
|
@ -185,7 +185,7 @@ pub fn intern_const_ref(
|
|||
}
|
||||
|
||||
/// Interns a possibly-unknown target usize
|
||||
pub fn usize_const(db: &dyn HirDatabase, value: Option<u128>, krate: CrateId) -> Const {
|
||||
pub fn usize_const(db: &dyn HirDatabase, value: Option<u128>, krate: Crate) -> Const {
|
||||
intern_const_ref(
|
||||
db,
|
||||
&value.map_or(LiteralConstRef::Unknown, LiteralConstRef::UInt),
|
||||
|
|
|
|||
|
|
@ -101,10 +101,7 @@ fn check_answer(
|
|||
fn pretty_print_err(e: ConstEvalError, db: TestDB) -> String {
|
||||
let mut err = String::new();
|
||||
let span_formatter = |file, range| format!("{file:?} {range:?}");
|
||||
let display_target = DisplayTarget::from_crate(
|
||||
&db,
|
||||
*db.crate_graph().crates_in_topological_order().last().unwrap(),
|
||||
);
|
||||
let display_target = DisplayTarget::from_crate(&db, *db.all_crates().last().unwrap());
|
||||
match e {
|
||||
ConstEvalError::MirLowerError(e) => {
|
||||
e.pretty_print(&mut err, &db, span_formatter, display_target)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
use std::sync;
|
||||
|
||||
use base_db::{impl_intern_key, CrateId, Upcast};
|
||||
use base_db::{impl_intern_key, Crate, Upcast};
|
||||
use hir_def::{
|
||||
db::DefDatabase, hir::ExprId, layout::TargetDataLayout, AdtId, BlockId, CallableDefId,
|
||||
ConstParamId, DefWithBodyId, EnumVariantId, FunctionId, GeneralConstId, GenericDefId, ImplId,
|
||||
|
|
@ -103,8 +103,8 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> + std::fmt::Debug {
|
|||
#[salsa::cycle(crate::layout::layout_of_ty_recover)]
|
||||
fn layout_of_ty(&self, ty: Ty, env: Arc<TraitEnvironment>) -> Result<Arc<Layout>, LayoutError>;
|
||||
|
||||
#[salsa::invoke(crate::layout::target_data_layout_query)]
|
||||
fn target_data_layout(&self, krate: CrateId) -> Result<Arc<TargetDataLayout>, Arc<str>>;
|
||||
#[salsa::invoke_actual(crate::layout::target_data_layout_query)]
|
||||
fn target_data_layout(&self, krate: Crate) -> Result<Arc<TargetDataLayout>, Arc<str>>;
|
||||
|
||||
#[salsa::invoke_actual(crate::dyn_compatibility::dyn_compatibility_of_trait_query)]
|
||||
fn dyn_compatibility_of_trait(&self, trait_: TraitId) -> Option<DynCompatibilityViolation>;
|
||||
|
|
@ -196,8 +196,8 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> + std::fmt::Debug {
|
|||
#[salsa::invoke_actual(crate::lower::generic_defaults_query)]
|
||||
fn generic_defaults(&self, def: GenericDefId) -> GenericDefaults;
|
||||
|
||||
#[salsa::invoke(InherentImpls::inherent_impls_in_crate_query)]
|
||||
fn inherent_impls_in_crate(&self, krate: CrateId) -> Arc<InherentImpls>;
|
||||
#[salsa::invoke_actual(InherentImpls::inherent_impls_in_crate_query)]
|
||||
fn inherent_impls_in_crate(&self, krate: Crate) -> Arc<InherentImpls>;
|
||||
|
||||
#[salsa::invoke_actual(InherentImpls::inherent_impls_in_block_query)]
|
||||
fn inherent_impls_in_block(&self, block: BlockId) -> Option<Arc<InherentImpls>>;
|
||||
|
|
@ -209,18 +209,18 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> + std::fmt::Debug {
|
|||
#[salsa::invoke(crate::method_resolution::incoherent_inherent_impl_crates)]
|
||||
fn incoherent_inherent_impl_crates(
|
||||
&self,
|
||||
krate: CrateId,
|
||||
krate: Crate,
|
||||
fp: TyFingerprint,
|
||||
) -> SmallVec<[CrateId; 2]>;
|
||||
) -> SmallVec<[Crate; 2]>;
|
||||
|
||||
#[salsa::invoke(TraitImpls::trait_impls_in_crate_query)]
|
||||
fn trait_impls_in_crate(&self, krate: CrateId) -> Arc<TraitImpls>;
|
||||
#[salsa::invoke_actual(TraitImpls::trait_impls_in_crate_query)]
|
||||
fn trait_impls_in_crate(&self, krate: Crate) -> Arc<TraitImpls>;
|
||||
|
||||
#[salsa::invoke_actual(TraitImpls::trait_impls_in_block_query)]
|
||||
fn trait_impls_in_block(&self, block: BlockId) -> Option<Arc<TraitImpls>>;
|
||||
|
||||
#[salsa::invoke(TraitImpls::trait_impls_in_deps_query)]
|
||||
fn trait_impls_in_deps(&self, krate: CrateId) -> Arc<[Arc<TraitImpls>]>;
|
||||
#[salsa::invoke_actual(TraitImpls::trait_impls_in_deps_query)]
|
||||
fn trait_impls_in_deps(&self, krate: Crate) -> Arc<[Arc<TraitImpls>]>;
|
||||
|
||||
// Interned IDs for Chalk integration
|
||||
#[salsa::interned]
|
||||
|
|
@ -253,23 +253,16 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> + std::fmt::Debug {
|
|||
#[salsa::invoke(chalk_db::trait_datum_query)]
|
||||
fn trait_datum(
|
||||
&self,
|
||||
krate: CrateId,
|
||||
krate: Crate,
|
||||
trait_id: chalk_db::TraitId,
|
||||
) -> sync::Arc<chalk_db::TraitDatum>;
|
||||
|
||||
#[salsa::invoke(chalk_db::adt_datum_query)]
|
||||
fn adt_datum(
|
||||
&self,
|
||||
krate: CrateId,
|
||||
struct_id: chalk_db::AdtId,
|
||||
) -> sync::Arc<chalk_db::AdtDatum>;
|
||||
fn adt_datum(&self, krate: Crate, struct_id: chalk_db::AdtId) -> sync::Arc<chalk_db::AdtDatum>;
|
||||
|
||||
#[salsa::invoke(chalk_db::impl_datum_query)]
|
||||
fn impl_datum(
|
||||
&self,
|
||||
krate: CrateId,
|
||||
impl_id: chalk_db::ImplId,
|
||||
) -> sync::Arc<chalk_db::ImplDatum>;
|
||||
fn impl_datum(&self, krate: Crate, impl_id: chalk_db::ImplId)
|
||||
-> sync::Arc<chalk_db::ImplDatum>;
|
||||
|
||||
#[salsa::invoke(chalk_db::fn_def_datum_query)]
|
||||
fn fn_def_datum(&self, fn_def_id: FnDefId) -> sync::Arc<chalk_db::FnDefDatum>;
|
||||
|
|
@ -287,7 +280,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> + std::fmt::Debug {
|
|||
#[salsa::invoke(chalk_db::associated_ty_value_query)]
|
||||
fn associated_ty_value(
|
||||
&self,
|
||||
krate: CrateId,
|
||||
krate: Crate,
|
||||
id: chalk_db::AssociatedTyValueId,
|
||||
) -> sync::Arc<chalk_db::AssociatedTyValue>;
|
||||
|
||||
|
|
@ -302,7 +295,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> + std::fmt::Debug {
|
|||
#[salsa::invoke(crate::traits::trait_solve_query)]
|
||||
fn trait_solve(
|
||||
&self,
|
||||
krate: CrateId,
|
||||
krate: Crate,
|
||||
block: Option<BlockId>,
|
||||
goal: crate::Canonical<crate::InEnvironment<crate::Goal>>,
|
||||
) -> Option<crate::Solution>;
|
||||
|
|
@ -310,7 +303,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> + std::fmt::Debug {
|
|||
#[salsa::invoke(chalk_db::program_clauses_for_chalk_env_query)]
|
||||
fn program_clauses_for_chalk_env(
|
||||
&self,
|
||||
krate: CrateId,
|
||||
krate: Crate,
|
||||
block: Option<BlockId>,
|
||||
env: chalk_ir::Environment<Interner>,
|
||||
) -> chalk_ir::ProgramClauses<Interner>;
|
||||
|
|
|
|||
|
|
@ -288,7 +288,7 @@ impl<'a> DeclValidator<'a> {
|
|||
|
||||
fn edition(&self, id: impl HasModule) -> span::Edition {
|
||||
let krate = id.krate(self.db.upcast());
|
||||
self.db.crate_graph()[krate].edition
|
||||
krate.data(self.db).edition
|
||||
}
|
||||
|
||||
fn validate_struct(&mut self, struct_id: StructId) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use std::fmt;
|
||||
|
||||
use base_db::CrateId;
|
||||
use base_db::Crate;
|
||||
use chalk_solve::rust_ir::AdtKind;
|
||||
use either::Either;
|
||||
use hir_def::{
|
||||
|
|
@ -630,7 +630,7 @@ fn missing_match_arms<'p>(
|
|||
scrut_ty: &Ty,
|
||||
witnesses: Vec<WitnessPat<'p>>,
|
||||
arms_is_empty: bool,
|
||||
krate: CrateId,
|
||||
krate: Crate,
|
||||
) -> String {
|
||||
struct DisplayWitness<'a, 'p>(&'a WitnessPat<'p>, &'a MatchCheckCtx<'p>, DisplayTarget);
|
||||
impl fmt::Display for DisplayWitness<'_, '_> {
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ impl<'a> UnsafeVisitor<'a> {
|
|||
DefWithBodyId::FunctionId(func) => TargetFeatures::from_attrs(&db.attrs(func.into())),
|
||||
_ => TargetFeatures::default(),
|
||||
};
|
||||
let edition = db.crate_graph()[resolver.module().krate()].edition;
|
||||
let edition = resolver.module().krate().data(db).edition;
|
||||
Self {
|
||||
db,
|
||||
infer,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use std::{
|
|||
mem,
|
||||
};
|
||||
|
||||
use base_db::CrateId;
|
||||
use base_db::Crate;
|
||||
use chalk_ir::{BoundVar, Safety, TyKind};
|
||||
use either::Either;
|
||||
use hir_def::{
|
||||
|
|
@ -339,7 +339,7 @@ pub trait HirDisplay {
|
|||
}
|
||||
|
||||
impl HirFormatter<'_> {
|
||||
pub fn krate(&self) -> CrateId {
|
||||
pub fn krate(&self) -> Crate {
|
||||
self.display_target.krate
|
||||
}
|
||||
|
||||
|
|
@ -408,13 +408,13 @@ impl HirFormatter<'_> {
|
|||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct DisplayTarget {
|
||||
krate: CrateId,
|
||||
krate: Crate,
|
||||
pub edition: Edition,
|
||||
}
|
||||
|
||||
impl DisplayTarget {
|
||||
pub fn from_crate(db: &dyn HirDatabase, krate: CrateId) -> Self {
|
||||
let edition = db.crate_graph()[krate].edition;
|
||||
pub fn from_crate(db: &dyn HirDatabase, krate: Crate) -> Self {
|
||||
let edition = krate.data(db).edition;
|
||||
Self { krate, edition }
|
||||
}
|
||||
}
|
||||
|
|
@ -1711,7 +1711,7 @@ fn fn_traits(db: &dyn DefDatabase, trait_: TraitId) -> impl Iterator<Item = Trai
|
|||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub enum SizedByDefault {
|
||||
NotSized,
|
||||
Sized { anchor: CrateId },
|
||||
Sized { anchor: Crate },
|
||||
}
|
||||
|
||||
impl SizedByDefault {
|
||||
|
|
@ -2266,8 +2266,8 @@ impl HirDisplayWithTypesMap for Path {
|
|||
// Resolve `$crate` to the crate's display name.
|
||||
// FIXME: should use the dependency name instead if available, but that depends on
|
||||
// the crate invoking `HirDisplay`
|
||||
let crate_graph = f.db.crate_graph();
|
||||
let name = crate_graph[*id]
|
||||
let crate_data = id.extra_data(f.db);
|
||||
let name = crate_data
|
||||
.display_name
|
||||
.as_ref()
|
||||
.map(|name| name.canonical_name())
|
||||
|
|
|
|||
|
|
@ -307,7 +307,7 @@ impl CapturedItem {
|
|||
}
|
||||
}
|
||||
}
|
||||
if is_raw_identifier(&result, db.crate_graph()[owner.module(db.upcast()).krate()].edition) {
|
||||
if is_raw_identifier(&result, owner.module(db.upcast()).krate().data(db).edition) {
|
||||
result.insert_str(0, "r#");
|
||||
}
|
||||
result
|
||||
|
|
@ -316,7 +316,7 @@ impl CapturedItem {
|
|||
pub fn display_place_source_code(&self, owner: DefWithBodyId, db: &dyn HirDatabase) -> String {
|
||||
let body = db.body(owner);
|
||||
let krate = owner.krate(db.upcast());
|
||||
let edition = db.crate_graph()[krate].edition;
|
||||
let edition = krate.data(db).edition;
|
||||
let mut result = body[self.place.local].name.display(db.upcast(), edition).to_string();
|
||||
for proj in &self.place.projections {
|
||||
match proj {
|
||||
|
|
@ -368,7 +368,7 @@ impl CapturedItem {
|
|||
pub fn display_place(&self, owner: DefWithBodyId, db: &dyn HirDatabase) -> String {
|
||||
let body = db.body(owner);
|
||||
let krate = owner.krate(db.upcast());
|
||||
let edition = db.crate_graph()[krate].edition;
|
||||
let edition = krate.data(db).edition;
|
||||
let mut result = body[self.place.local].name.display(db.upcast(), edition).to_string();
|
||||
let mut field_need_paren = false;
|
||||
for proj in &self.place.projections {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
//! Target dependent parameters needed for layouts
|
||||
|
||||
use base_db::CrateId;
|
||||
use base_db::Crate;
|
||||
use hir_def::layout::TargetDataLayout;
|
||||
use rustc_abi::{AlignFromBytesError, TargetDataLayoutErrors};
|
||||
use triomphe::Arc;
|
||||
|
|
@ -9,9 +9,9 @@ use crate::db::HirDatabase;
|
|||
|
||||
pub fn target_data_layout_query(
|
||||
db: &dyn HirDatabase,
|
||||
krate: CrateId,
|
||||
krate: Crate,
|
||||
) -> Result<Arc<TargetDataLayout>, Arc<str>> {
|
||||
match &db.crate_workspace_data()[&krate].data_layout {
|
||||
match &krate.workspace_data(db).data_layout {
|
||||
Ok(it) => match TargetDataLayout::parse_from_llvm_datalayout_string(it) {
|
||||
Ok(it) => Ok(Arc::new(it)),
|
||||
Err(e) => {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use std::{
|
|||
ops::{self, Not as _},
|
||||
};
|
||||
|
||||
use base_db::CrateId;
|
||||
use base_db::Crate;
|
||||
use chalk_ir::{
|
||||
cast::Cast,
|
||||
fold::{Shift, TypeFoldable},
|
||||
|
|
@ -801,7 +801,7 @@ impl<'a> TyLoweringContext<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn lower_impl_trait(&mut self, bounds: &[TypeBound], krate: CrateId) -> ImplTrait {
|
||||
fn lower_impl_trait(&mut self, bounds: &[TypeBound], krate: Crate) -> ImplTrait {
|
||||
cov_mark::hit!(lower_rpit);
|
||||
let self_ty = TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)).intern(Interner);
|
||||
let predicates = self.with_shifted_in(DebruijnIndex::ONE, |ctx| {
|
||||
|
|
@ -1863,8 +1863,11 @@ pub(crate) fn const_or_path_to_chalk<'g>(
|
|||
.unwrap_or_else(|| unknown_const(expected_ty))
|
||||
}
|
||||
&ConstRef::Complex(it) => {
|
||||
let crate_data = &db.crate_graph()[resolver.krate()];
|
||||
if crate_data.env.get("__ra_is_test_fixture").is_none() && crate_data.origin.is_local()
|
||||
let krate = resolver.krate();
|
||||
// Keep the `&&` this way, because it's better to access the crate data, as we access it for
|
||||
// a bunch of other things nevertheless.
|
||||
if krate.data(db).origin.is_local()
|
||||
&& krate.env(db).get("__ra_is_test_fixture").is_none()
|
||||
{
|
||||
// FIXME: current `InTypeConstId` is very unstable, so we only use it in non local crate
|
||||
// that are unlikely to be edited.
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
use std::ops::ControlFlow;
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
use base_db::CrateId;
|
||||
use base_db::Crate;
|
||||
use chalk_ir::{cast::Cast, UniverseIndex, WithKind};
|
||||
use hir_def::{
|
||||
data::{adt::StructFlags, ImplData, TraitFlags},
|
||||
|
|
@ -148,7 +148,7 @@ pub struct TraitImpls {
|
|||
}
|
||||
|
||||
impl TraitImpls {
|
||||
pub(crate) fn trait_impls_in_crate_query(db: &dyn HirDatabase, krate: CrateId) -> Arc<Self> {
|
||||
pub(crate) fn trait_impls_in_crate_query(db: &dyn HirDatabase, krate: Crate) -> Arc<Self> {
|
||||
let _p = tracing::info_span!("trait_impls_in_crate_query", ?krate).entered();
|
||||
let mut impls = FxHashMap::default();
|
||||
|
||||
|
|
@ -175,13 +175,11 @@ impl TraitImpls {
|
|||
|
||||
pub(crate) fn trait_impls_in_deps_query(
|
||||
db: &dyn HirDatabase,
|
||||
krate: CrateId,
|
||||
krate: Crate,
|
||||
) -> Arc<[Arc<Self>]> {
|
||||
let _p = tracing::info_span!("trait_impls_in_deps_query", ?krate).entered();
|
||||
let crate_graph = db.crate_graph();
|
||||
|
||||
Arc::from_iter(
|
||||
crate_graph.transitive_deps(krate).map(|krate| db.trait_impls_in_crate(krate)),
|
||||
db.transitive_deps(krate).into_iter().map(|krate| db.trait_impls_in_crate(krate)),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -282,7 +280,7 @@ pub struct InherentImpls {
|
|||
}
|
||||
|
||||
impl InherentImpls {
|
||||
pub(crate) fn inherent_impls_in_crate_query(db: &dyn HirDatabase, krate: CrateId) -> Arc<Self> {
|
||||
pub(crate) fn inherent_impls_in_crate_query(db: &dyn HirDatabase, krate: Crate) -> Arc<Self> {
|
||||
let _p = tracing::info_span!("inherent_impls_in_crate_query", ?krate).entered();
|
||||
let mut impls = Self { map: FxHashMap::default(), invalid_impls: Vec::default() };
|
||||
|
||||
|
|
@ -367,16 +365,15 @@ impl InherentImpls {
|
|||
|
||||
pub(crate) fn incoherent_inherent_impl_crates(
|
||||
db: &dyn HirDatabase,
|
||||
krate: CrateId,
|
||||
krate: Crate,
|
||||
fp: TyFingerprint,
|
||||
) -> SmallVec<[CrateId; 2]> {
|
||||
) -> SmallVec<[Crate; 2]> {
|
||||
let _p = tracing::info_span!("incoherent_inherent_impl_crates").entered();
|
||||
let mut res = SmallVec::new();
|
||||
let crate_graph = db.crate_graph();
|
||||
|
||||
// should pass crate for finger print and do reverse deps
|
||||
|
||||
for krate in crate_graph.transitive_deps(krate) {
|
||||
for krate in db.transitive_deps(krate) {
|
||||
let impls = db.inherent_impls_in_crate(krate);
|
||||
if impls.map.get(&fp).is_some_and(|v| !v.is_empty()) {
|
||||
res.push(krate);
|
||||
|
|
@ -386,11 +383,7 @@ pub(crate) fn incoherent_inherent_impl_crates(
|
|||
res
|
||||
}
|
||||
|
||||
pub fn def_crates(
|
||||
db: &dyn HirDatabase,
|
||||
ty: &Ty,
|
||||
cur_crate: CrateId,
|
||||
) -> Option<SmallVec<[CrateId; 2]>> {
|
||||
pub fn def_crates(db: &dyn HirDatabase, ty: &Ty, cur_crate: Crate) -> Option<SmallVec<[Crate; 2]>> {
|
||||
match ty.kind(Interner) {
|
||||
&TyKind::Adt(AdtId(def_id), _) => {
|
||||
let rustc_has_incoherent_inherent_impls = match def_id {
|
||||
|
|
@ -1226,7 +1219,7 @@ fn iterate_trait_method_candidates(
|
|||
{
|
||||
// FIXME: this should really be using the edition of the method name's span, in case it
|
||||
// comes from a macro
|
||||
if !db.crate_graph()[krate].edition.at_least_2021() {
|
||||
if !krate.data(db).edition.at_least_2021() {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
@ -1239,7 +1232,7 @@ fn iterate_trait_method_candidates(
|
|||
{
|
||||
// FIXME: this should really be using the edition of the method name's span, in case it
|
||||
// comes from a macro
|
||||
if !db.crate_graph()[krate].edition.at_least_2024() {
|
||||
if !krate.data(db).edition.at_least_2024() {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use crate::{
|
|||
CallableDefId, ClosureId, Const, ConstScalar, InferenceResult, Interner, MemoryMap,
|
||||
Substitution, TraitEnvironment, Ty, TyExt, TyKind,
|
||||
};
|
||||
use base_db::CrateId;
|
||||
use base_db::Crate;
|
||||
use chalk_ir::Mutability;
|
||||
use either::Either;
|
||||
use hir_def::{
|
||||
|
|
@ -143,7 +143,7 @@ impl<V, T> ProjectionElem<V, T> {
|
|||
mut base: Ty,
|
||||
db: &dyn HirDatabase,
|
||||
closure_field: impl FnOnce(ClosureId, &Substitution, usize) -> Ty,
|
||||
krate: CrateId,
|
||||
krate: Crate,
|
||||
) -> Ty {
|
||||
// we only bail on mir building when there are type mismatches
|
||||
// but error types may pop up resulting in us still attempting to build the mir
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use std::{borrow::Cow, cell::RefCell, fmt::Write, iter, mem, ops::Range};
|
||||
|
||||
use base_db::CrateId;
|
||||
use base_db::Crate;
|
||||
use chalk_ir::{cast::Cast, Mutability};
|
||||
use either::Either;
|
||||
use hir_def::{
|
||||
|
|
@ -186,7 +186,7 @@ pub struct Evaluator<'a> {
|
|||
cached_fn_trait_func: Option<FunctionId>,
|
||||
cached_fn_mut_trait_func: Option<FunctionId>,
|
||||
cached_fn_once_trait_func: Option<FunctionId>,
|
||||
crate_id: CrateId,
|
||||
crate_id: Crate,
|
||||
// FIXME: This is a workaround, see the comment on `interpret_mir`
|
||||
assert_placeholder_ty_is_unused: bool,
|
||||
/// A general limit on execution, to prevent non terminating programs from breaking r-a main process
|
||||
|
|
@ -2785,7 +2785,7 @@ impl Evaluator<'_> {
|
|||
let db = self.db.upcast();
|
||||
let loc = variant.lookup(db);
|
||||
let enum_loc = loc.parent.lookup(db);
|
||||
let edition = self.db.crate_graph()[self.crate_id].edition;
|
||||
let edition = self.crate_id.data(self.db).edition;
|
||||
let name = format!(
|
||||
"{}::{}",
|
||||
enum_loc.id.item_tree(db)[enum_loc.id.value].name.display(db.upcast(), edition),
|
||||
|
|
|
|||
|
|
@ -569,7 +569,7 @@ impl Evaluator<'_> {
|
|||
}
|
||||
String::from_utf8_lossy(&name_buf)
|
||||
};
|
||||
let value = self.db.crate_graph()[self.crate_id].env.get(&name);
|
||||
let value = self.crate_id.env(self.db).get(&name);
|
||||
match value {
|
||||
None => {
|
||||
// Write null as fail
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use std::{fmt::Write, iter, mem};
|
||||
|
||||
use base_db::{salsa::Cycle, CrateId};
|
||||
use base_db::{salsa::Cycle, Crate};
|
||||
use chalk_ir::{BoundVar, ConstData, DebruijnIndex, TyKind};
|
||||
use hir_def::{
|
||||
data::adt::{StructKind, VariantData},
|
||||
|
|
@ -1920,10 +1920,10 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
|||
}
|
||||
|
||||
fn edition(&self) -> Edition {
|
||||
self.db.crate_graph()[self.krate()].edition
|
||||
self.krate().data(self.db).edition
|
||||
}
|
||||
|
||||
fn krate(&self) -> CrateId {
|
||||
fn krate(&self) -> Crate {
|
||||
self.owner.krate(self.db.upcast())
|
||||
}
|
||||
|
||||
|
|
@ -2121,7 +2121,7 @@ pub fn mir_body_for_closure_query(
|
|||
|
||||
pub fn mir_body_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Result<Arc<MirBody>> {
|
||||
let krate = def.krate(db.upcast());
|
||||
let edition = db.crate_graph()[krate].edition;
|
||||
let edition = krate.data(db).edition;
|
||||
let detail = match def {
|
||||
DefWithBodyId::FunctionId(it) => {
|
||||
db.function_data(it).name.display(db.upcast(), edition).to_string()
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
use std::{fmt, panic, sync::Mutex};
|
||||
|
||||
use base_db::{
|
||||
FileSourceRootInput, FileText, RootQueryDb, SourceDatabase, SourceRoot, SourceRootId,
|
||||
SourceRootInput, Upcast,
|
||||
CrateGraphBuilder, CratesMap, FileSourceRootInput, FileText, RootQueryDb, SourceDatabase,
|
||||
SourceRoot, SourceRootId, SourceRootInput, Upcast,
|
||||
};
|
||||
|
||||
use hir_def::{db::DefDatabase, ModuleId};
|
||||
|
|
@ -21,6 +21,7 @@ use triomphe::Arc;
|
|||
pub(crate) struct TestDB {
|
||||
storage: salsa::Storage<Self>,
|
||||
files: Arc<base_db::Files>,
|
||||
crates_map: Arc<CratesMap>,
|
||||
events: Arc<Mutex<Option<Vec<salsa::Event>>>>,
|
||||
}
|
||||
|
||||
|
|
@ -30,8 +31,12 @@ impl Default for TestDB {
|
|||
storage: Default::default(),
|
||||
events: Default::default(),
|
||||
files: Default::default(),
|
||||
crates_map: Default::default(),
|
||||
};
|
||||
this.set_expand_proc_attr_macros_with_durability(true, Durability::HIGH);
|
||||
// This needs to be here otherwise `CrateGraphBuilder` panics.
|
||||
this.set_all_crates(Arc::new(Box::new([])));
|
||||
CrateGraphBuilder::default().set_in_db(&mut this);
|
||||
this
|
||||
}
|
||||
}
|
||||
|
|
@ -115,6 +120,10 @@ impl SourceDatabase for TestDB {
|
|||
let files = Arc::clone(&self.files);
|
||||
files.set_file_source_root_with_durability(self, id, source_root_id, durability);
|
||||
}
|
||||
|
||||
fn crates_map(&self) -> Arc<CratesMap> {
|
||||
self.crates_map.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[salsa::db]
|
||||
|
|
@ -151,8 +160,7 @@ impl TestDB {
|
|||
&self,
|
||||
) -> FxHashMap<EditionedFileId, Vec<(TextRange, String)>> {
|
||||
let mut files = Vec::new();
|
||||
let crate_graph = self.crate_graph();
|
||||
for krate in crate_graph.iter() {
|
||||
for &krate in self.all_crates().iter() {
|
||||
let crate_def_map = self.crate_def_map(krate);
|
||||
for (module_id, _) in crate_def_map.modules() {
|
||||
let file_id = crate_def_map[module_id].origin.file_id();
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ mod type_alias_impl_traits;
|
|||
use std::env;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use base_db::{CrateId, SourceDatabase};
|
||||
use base_db::{Crate, SourceDatabase};
|
||||
use expect_test::Expect;
|
||||
use hir_def::{
|
||||
db::DefDatabase,
|
||||
|
|
@ -124,7 +124,7 @@ fn check_impl(
|
|||
}
|
||||
assert!(had_annotations || allow_none, "no `//^` annotations found");
|
||||
|
||||
let mut defs: Vec<(DefWithBodyId, CrateId)> = Vec::new();
|
||||
let mut defs: Vec<(DefWithBodyId, Crate)> = Vec::new();
|
||||
for file_id in files {
|
||||
let module = db.module_for_file_opt(file_id);
|
||||
let module = match module {
|
||||
|
|
@ -302,7 +302,7 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
|
|||
let mut infer_def = |inference_result: Arc<InferenceResult>,
|
||||
body: Arc<Body>,
|
||||
body_source_map: Arc<BodySourceMap>,
|
||||
krate: CrateId| {
|
||||
krate: Crate| {
|
||||
let display_target = DisplayTarget::from_crate(&db, krate);
|
||||
let mut types: Vec<(InFile<SyntaxNode>, &Ty)> = Vec::new();
|
||||
let mut mismatches: Vec<(InFile<SyntaxNode>, &TypeMismatch)> = Vec::new();
|
||||
|
|
@ -391,7 +391,7 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
|
|||
let module = db.module_for_file(file_id);
|
||||
let def_map = module.def_map(&db);
|
||||
|
||||
let mut defs: Vec<(DefWithBodyId, CrateId)> = Vec::new();
|
||||
let mut defs: Vec<(DefWithBodyId, Crate)> = Vec::new();
|
||||
visit_module(&db, &def_map, module.local_id, &mut |it| {
|
||||
let def = match it {
|
||||
ModuleDefId::FunctionId(it) => it.into(),
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use chalk_ir::{fold::TypeFoldable, DebruijnIndex, GoalData};
|
|||
use chalk_recursive::Cache;
|
||||
use chalk_solve::{logging_db::LoggingRustIrDatabase, rust_ir, Solver};
|
||||
|
||||
use base_db::CrateId;
|
||||
use base_db::Crate;
|
||||
use hir_def::{
|
||||
lang_item::{LangItem, LangItemTarget},
|
||||
BlockId, TraitId,
|
||||
|
|
@ -30,7 +30,7 @@ const CHALK_SOLVER_FUEL: i32 = 1000;
|
|||
#[derive(Debug, Copy, Clone)]
|
||||
pub(crate) struct ChalkContext<'a> {
|
||||
pub(crate) db: &'a dyn HirDatabase,
|
||||
pub(crate) krate: CrateId,
|
||||
pub(crate) krate: Crate,
|
||||
pub(crate) block: Option<BlockId>,
|
||||
}
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ fn create_chalk_solver() -> chalk_recursive::RecursiveSolver<Interner> {
|
|||
/// we assume that `T: Default`.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TraitEnvironment {
|
||||
pub krate: CrateId,
|
||||
pub krate: Crate,
|
||||
pub block: Option<BlockId>,
|
||||
// FIXME make this a BTreeMap
|
||||
traits_from_clauses: Box<[(Ty, TraitId)]>,
|
||||
|
|
@ -56,7 +56,7 @@ pub struct TraitEnvironment {
|
|||
}
|
||||
|
||||
impl TraitEnvironment {
|
||||
pub fn empty(krate: CrateId) -> Arc<Self> {
|
||||
pub fn empty(krate: Crate) -> Arc<Self> {
|
||||
Arc::new(TraitEnvironment {
|
||||
krate,
|
||||
block: None,
|
||||
|
|
@ -66,7 +66,7 @@ impl TraitEnvironment {
|
|||
}
|
||||
|
||||
pub fn new(
|
||||
krate: CrateId,
|
||||
krate: Crate,
|
||||
block: Option<BlockId>,
|
||||
traits_from_clauses: Box<[(Ty, TraitId)]>,
|
||||
env: chalk_ir::Environment<Interner>,
|
||||
|
|
@ -109,7 +109,7 @@ pub(crate) fn normalize_projection_query(
|
|||
/// Solve a trait goal using Chalk.
|
||||
pub(crate) fn trait_solve_query(
|
||||
db: &dyn HirDatabase,
|
||||
krate: CrateId,
|
||||
krate: Crate,
|
||||
block: Option<BlockId>,
|
||||
goal: Canonical<InEnvironment<Goal>>,
|
||||
) -> Option<Solution> {
|
||||
|
|
@ -148,7 +148,7 @@ pub(crate) fn trait_solve_query(
|
|||
|
||||
fn solve(
|
||||
db: &dyn HirDatabase,
|
||||
krate: CrateId,
|
||||
krate: Crate,
|
||||
block: Option<BlockId>,
|
||||
goal: &chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<Interner>>>,
|
||||
) -> Option<chalk_solve::Solution<Interner>> {
|
||||
|
|
@ -294,7 +294,7 @@ impl FnTrait {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_id(self, db: &dyn HirDatabase, krate: CrateId) -> Option<TraitId> {
|
||||
pub fn get_id(self, db: &dyn HirDatabase, krate: Crate) -> Option<TraitId> {
|
||||
let target = db.lang_item(krate, self.lang_item())?;
|
||||
match target {
|
||||
LangItemTarget::Trait(t) => Some(t),
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
use std::{hash::Hash, iter};
|
||||
|
||||
use base_db::CrateId;
|
||||
use base_db::Crate;
|
||||
use chalk_ir::{
|
||||
fold::{FallibleTypeFolder, Shift},
|
||||
DebruijnIndex,
|
||||
|
|
@ -34,10 +34,7 @@ use crate::{
|
|||
TraitRefExt, Ty, WhereClause,
|
||||
};
|
||||
|
||||
pub(crate) fn fn_traits(
|
||||
db: &dyn DefDatabase,
|
||||
krate: CrateId,
|
||||
) -> impl Iterator<Item = TraitId> + '_ {
|
||||
pub(crate) fn fn_traits(db: &dyn DefDatabase, krate: Crate) -> impl Iterator<Item = TraitId> + '_ {
|
||||
[LangItem::Fn, LangItem::FnMut, LangItem::FnOnce]
|
||||
.into_iter()
|
||||
.filter_map(move |lang| db.lang_item(krate, lang))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue