mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Deduplicate layout_of_adt
This commit is contained in:
parent
eeaefa4b9d
commit
9912b803bc
@ -94,11 +94,11 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
|
|||||||
|
|
||||||
#[salsa::invoke(crate::layout::layout_of_adt_query)]
|
#[salsa::invoke(crate::layout::layout_of_adt_query)]
|
||||||
#[salsa::cycle(cycle_result = crate::layout::layout_of_adt_cycle_result)]
|
#[salsa::cycle(cycle_result = crate::layout::layout_of_adt_cycle_result)]
|
||||||
fn layout_of_adt(
|
fn layout_of_adt<'db>(
|
||||||
&self,
|
&'db self,
|
||||||
def: AdtId,
|
def: AdtId,
|
||||||
subst: Substitution,
|
args: crate::next_solver::GenericArgs<'db>,
|
||||||
env: Arc<TraitEnvironment>,
|
trait_env: Arc<TraitEnvironment>,
|
||||||
) -> Result<Arc<Layout>, LayoutError>;
|
) -> Result<Arc<Layout>, LayoutError>;
|
||||||
|
|
||||||
#[salsa::invoke(crate::layout::layout_of_ty_query)]
|
#[salsa::invoke(crate::layout::layout_of_ty_query)]
|
||||||
@ -300,15 +300,6 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
|
|||||||
|
|
||||||
// next trait solver
|
// next trait solver
|
||||||
|
|
||||||
#[salsa::invoke(crate::layout::layout_of_adt_ns_query)]
|
|
||||||
#[salsa::cycle(cycle_result = crate::layout::layout_of_adt_ns_cycle_result)]
|
|
||||||
fn layout_of_adt_ns<'db>(
|
|
||||||
&'db self,
|
|
||||||
def: AdtId,
|
|
||||||
args: crate::next_solver::GenericArgs<'db>,
|
|
||||||
trait_env: Arc<TraitEnvironment>,
|
|
||||||
) -> Result<Arc<Layout>, LayoutError>;
|
|
||||||
|
|
||||||
#[salsa::invoke(crate::layout::layout_of_ty_ns_query)]
|
#[salsa::invoke(crate::layout::layout_of_ty_ns_query)]
|
||||||
#[salsa::cycle(cycle_result = crate::layout::layout_of_ty_ns_cycle_result)]
|
#[salsa::cycle(cycle_result = crate::layout::layout_of_ty_ns_cycle_result)]
|
||||||
fn layout_of_ty_ns<'db>(
|
fn layout_of_ty_ns<'db>(
|
||||||
|
@ -944,7 +944,7 @@ fn render_const_scalar_inner(
|
|||||||
SolverDefId::AdtId(def) => def,
|
SolverDefId::AdtId(def) => def,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
let Ok(layout) = f.db.layout_of_adt_ns(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>");
|
||||||
};
|
};
|
||||||
match def {
|
match def {
|
||||||
|
@ -31,11 +31,8 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) use self::adt::{layout_of_adt_cycle_result, layout_of_adt_ns_cycle_result};
|
pub(crate) use self::adt::layout_of_adt_cycle_result;
|
||||||
pub use self::{
|
pub use self::{adt::layout_of_adt_query, target::target_data_layout_query};
|
||||||
adt::{layout_of_adt_ns_query, layout_of_adt_query},
|
|
||||||
target::target_data_layout_query,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub(crate) mod adt;
|
pub(crate) mod adt;
|
||||||
pub(crate) mod target;
|
pub(crate) mod target;
|
||||||
@ -197,7 +194,7 @@ pub fn layout_of_ty_ns_query<'db>(
|
|||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
return db.layout_of_adt_ns(def.inner().id, args, trait_env);
|
return db.layout_of_adt(def.inner().id, args, trait_env);
|
||||||
}
|
}
|
||||||
TyKind::Bool => Layout::scalar(
|
TyKind::Bool => Layout::scalar(
|
||||||
dl,
|
dl,
|
||||||
|
@ -13,23 +13,13 @@ use smallvec::SmallVec;
|
|||||||
use triomphe::Arc;
|
use triomphe::Arc;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Substitution, TraitEnvironment,
|
TraitEnvironment,
|
||||||
db::HirDatabase,
|
db::HirDatabase,
|
||||||
layout::{Layout, LayoutCx, LayoutError, field_ty},
|
layout::{Layout, LayoutCx, LayoutError, field_ty},
|
||||||
next_solver::{DbInterner, GenericArgs, mapping::ChalkToNextSolver},
|
next_solver::GenericArgs,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn layout_of_adt_query(
|
pub fn layout_of_adt_query<'db>(
|
||||||
db: &dyn HirDatabase,
|
|
||||||
def: AdtId,
|
|
||||||
subst: Substitution,
|
|
||||||
trait_env: Arc<TraitEnvironment>,
|
|
||||||
) -> Result<Arc<Layout>, LayoutError> {
|
|
||||||
let interner = DbInterner::new_with(db, Some(trait_env.krate), trait_env.block);
|
|
||||||
db.layout_of_adt_ns(def, subst.to_nextsolver(interner), trait_env)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn layout_of_adt_ns_query<'db>(
|
|
||||||
db: &'db dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
def: AdtId,
|
def: AdtId,
|
||||||
args: GenericArgs<'db>,
|
args: GenericArgs<'db>,
|
||||||
@ -105,16 +95,7 @@ pub fn layout_of_adt_ns_query<'db>(
|
|||||||
Ok(Arc::new(result))
|
Ok(Arc::new(result))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn layout_of_adt_cycle_result(
|
pub(crate) fn layout_of_adt_cycle_result<'db>(
|
||||||
_: &dyn HirDatabase,
|
|
||||||
_: AdtId,
|
|
||||||
_: Substitution,
|
|
||||||
_: Arc<TraitEnvironment>,
|
|
||||||
) -> Result<Arc<Layout>, LayoutError> {
|
|
||||||
Err(LayoutError::RecursiveTypeWithoutIndirection)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn layout_of_adt_ns_cycle_result<'db>(
|
|
||||||
_: &'db dyn HirDatabase,
|
_: &'db dyn HirDatabase,
|
||||||
_def: AdtId,
|
_def: AdtId,
|
||||||
_args: GenericArgs<'db>,
|
_args: GenericArgs<'db>,
|
||||||
|
@ -1818,7 +1818,7 @@ impl Adt {
|
|||||||
pub fn layout(self, db: &dyn HirDatabase) -> Result<Layout, LayoutError> {
|
pub fn layout(self, db: &dyn HirDatabase) -> Result<Layout, LayoutError> {
|
||||||
let env = db.trait_environment(self.into());
|
let env = db.trait_environment(self.into());
|
||||||
let interner = DbInterner::new_with(db, Some(env.krate), env.block);
|
let interner = DbInterner::new_with(db, Some(env.krate), env.block);
|
||||||
db.layout_of_adt_ns(
|
db.layout_of_adt(
|
||||||
self.into(),
|
self.into(),
|
||||||
TyBuilder::adt(db, self.into())
|
TyBuilder::adt(db, self.into())
|
||||||
.fill_with_defaults(db, || TyKind::Error.intern(Interner))
|
.fill_with_defaults(db, || TyKind::Error.intern(Interner))
|
||||||
|
@ -10,15 +10,17 @@ use std::{
|
|||||||
|
|
||||||
use cfg::{CfgAtom, CfgDiff};
|
use cfg::{CfgAtom, CfgDiff};
|
||||||
use hir::{
|
use hir::{
|
||||||
Adt, AssocItem, Crate, DefWithBody, HasSource, HirDisplay, ImportPathConfig, ModuleDef, Name,
|
Adt, AssocItem, Crate, DefWithBody, HasCrate, HasSource, HirDisplay, ImportPathConfig,
|
||||||
|
ModuleDef, Name,
|
||||||
db::{DefDatabase, ExpandDatabase, HirDatabase},
|
db::{DefDatabase, ExpandDatabase, HirDatabase},
|
||||||
|
next_solver::{DbInterner, GenericArgs},
|
||||||
};
|
};
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
SyntheticSyntax,
|
SyntheticSyntax,
|
||||||
expr_store::BodySourceMap,
|
expr_store::BodySourceMap,
|
||||||
hir::{ExprId, PatId},
|
hir::{ExprId, PatId},
|
||||||
};
|
};
|
||||||
use hir_ty::{Interner, Substitution, TyExt, TypeFlags};
|
use hir_ty::{Interner, TyExt, TypeFlags};
|
||||||
use ide::{
|
use ide::{
|
||||||
Analysis, AnalysisHost, AnnotationConfig, DiagnosticsConfig, Edition, InlayFieldsToResolve,
|
Analysis, AnalysisHost, AnnotationConfig, DiagnosticsConfig, Edition, InlayFieldsToResolve,
|
||||||
InlayHintsConfig, LineCol, RootDatabase,
|
InlayHintsConfig, LineCol, RootDatabase,
|
||||||
@ -361,6 +363,7 @@ impl flags::AnalysisStats {
|
|||||||
let mut all = 0;
|
let mut all = 0;
|
||||||
let mut fail = 0;
|
let mut fail = 0;
|
||||||
for &a in adts {
|
for &a in adts {
|
||||||
|
let interner = DbInterner::new_with(db, Some(a.krate(db).base()), None);
|
||||||
let generic_params = db.generic_params(a.into());
|
let generic_params = db.generic_params(a.into());
|
||||||
if generic_params.iter_type_or_consts().next().is_some()
|
if generic_params.iter_type_or_consts().next().is_some()
|
||||||
|| generic_params.iter_lt().next().is_some()
|
|| generic_params.iter_lt().next().is_some()
|
||||||
@ -371,7 +374,7 @@ impl flags::AnalysisStats {
|
|||||||
all += 1;
|
all += 1;
|
||||||
let Err(e) = db.layout_of_adt(
|
let Err(e) = db.layout_of_adt(
|
||||||
hir_def::AdtId::from(a),
|
hir_def::AdtId::from(a),
|
||||||
Substitution::empty(Interner),
|
GenericArgs::new_from_iter(interner, []),
|
||||||
db.trait_environment(a.into()),
|
db.trait_environment(a.into()),
|
||||||
) else {
|
) else {
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user