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
10 changes: 5 additions & 5 deletions crates/hir-ty/src/autoderef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ const AUTODEREF_RECURSION_LIMIT: usize = 20;
/// - the yielded types don't contain inference variables (but may contain `TyKind::Error`).
/// - a type won't be yielded more than once; in other words, the returned iterator will stop if it
/// detects a cycle in the deref chain.
pub fn autoderef(
db: &dyn HirDatabase,
env: Arc<TraitEnvironment>,
pub fn autoderef<'db>(
db: &'db dyn HirDatabase,
env: Arc<TraitEnvironment<'db>>,
ty: crate::Canonical<crate::Ty>,
) -> impl Iterator<Item = crate::Ty> {
) -> impl Iterator<Item = crate::Ty> + use<> {
let mut table = InferenceTable::new(db, env);
let interner = table.interner;
let ty = table.instantiate_canonical(ty);
Expand Down Expand Up @@ -298,7 +298,7 @@ fn structurally_normalize_ty<'db>(
) -> Option<(Ty<'db>, PredicateObligations<'db>)> {
let mut ocx = ObligationCtxt::new(&table.infer_ctxt);
let Ok(normalized_ty) =
ocx.structurally_normalize_ty(&ObligationCause::misc(), table.param_env, ty)
ocx.structurally_normalize_ty(&ObligationCause::misc(), table.trait_env.env, ty)
else {
// We shouldn't have errors here in the old solver, except for
// evaluate/fulfill mismatches, but that's not a reason for an ICE.
Expand Down
14 changes: 11 additions & 3 deletions crates/hir-ty/src/chalk_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ use crate::{
AdtId, AliasEq, AliasTy, Binders, CallableDefId, CallableSig, Canonical, CanonicalVarKinds,
ClosureId, DynTy, FnPointer, ImplTraitId, InEnvironment, Interner, Lifetime, ProjectionTy,
QuantifiedWhereClause, Substitution, ToChalk, TraitRef, Ty, TyBuilder, TyKind, TypeFlags,
WhereClause, db::HirDatabase, from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id,
from_placeholder_idx, generics::generics, to_chalk_trait_id, utils::ClosureSubst,
WhereClause,
db::HirDatabase,
from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id, from_placeholder_idx,
generics::generics,
next_solver::{DbInterner, mapping::NextSolverToChalk},
to_chalk_trait_id,
utils::ClosureSubst,
};

pub trait TyExt {
Expand Down Expand Up @@ -372,7 +377,10 @@ impl TyExt for Ty {
let trait_ref = TyBuilder::trait_ref(db, copy_trait).push(self).build();
let env = db.trait_environment_for_body(owner);
let goal = Canonical {
value: InEnvironment::new(&env.env, trait_ref.cast(Interner)),
value: InEnvironment::new(
&env.env.to_chalk(DbInterner::new_with(db, Some(env.krate), env.block)),
trait_ref.cast(Interner),
),
binders: CanonicalVarKinds::empty(Interner),
};
!db.trait_solve(crate_id, None, goal).no_solution()
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-ty/src/consteval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ pub(crate) fn const_eval_cycle_result(
_: &dyn HirDatabase,
_: GeneralConstId,
_: Substitution,
_: Option<Arc<TraitEnvironment>>,
_: Option<Arc<TraitEnvironment<'_>>>,
) -> Result<Const, ConstEvalError> {
Err(ConstEvalError::MirLowerError(MirLowerError::Loop))
}
Expand All @@ -252,7 +252,7 @@ pub(crate) fn const_eval_query(
db: &dyn HirDatabase,
def: GeneralConstId,
subst: Substitution,
trait_env: Option<Arc<TraitEnvironment>>,
trait_env: Option<Arc<TraitEnvironment<'_>>>,
) -> Result<Const, ConstEvalError> {
let body = match def {
GeneralConstId::ConstId(c) => {
Expand Down
25 changes: 13 additions & 12 deletions crates/hir-ty/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
&self,
def: DefWithBodyId,
subst: Substitution,
env: Arc<TraitEnvironment>,
env: Arc<TraitEnvironment<'_>>,
) -> Result<Arc<MirBody>, MirLowerError>;

#[salsa::invoke(crate::mir::monomorphized_mir_body_for_closure_query)]
fn monomorphized_mir_body_for_closure(
&self,
def: InternedClosureId,
subst: Substitution,
env: Arc<TraitEnvironment>,
env: Arc<TraitEnvironment<'_>>,
) -> Result<Arc<MirBody>, MirLowerError>;

#[salsa::invoke(crate::mir::borrowck_query)]
Expand All @@ -70,7 +70,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
&self,
def: GeneralConstId,
subst: Substitution,
trait_env: Option<Arc<TraitEnvironment>>,
trait_env: Option<Arc<TraitEnvironment<'_>>>,
) -> Result<Const, ConstEvalError>;

#[salsa::invoke(crate::consteval::const_eval_static_query)]
Expand All @@ -84,7 +84,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
#[salsa::invoke(crate::method_resolution::lookup_impl_method_query)]
fn lookup_impl_method(
&self,
env: Arc<TraitEnvironment>,
env: Arc<TraitEnvironment<'_>>,
func: FunctionId,
fn_subst: Substitution,
) -> (FunctionId, Substitution);
Expand All @@ -97,15 +97,15 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
&'db self,
def: AdtId,
args: crate::next_solver::GenericArgs<'db>,
trait_env: Arc<TraitEnvironment>,
trait_env: Arc<TraitEnvironment<'db>>,
) -> Result<Arc<Layout>, LayoutError>;

#[salsa::invoke(crate::layout::layout_of_ty_query)]
#[salsa::cycle(cycle_result = crate::layout::layout_of_ty_cycle_result)]
fn layout_of_ty<'db>(
&'db self,
ty: crate::next_solver::Ty<'db>,
env: Arc<TraitEnvironment>,
env: Arc<TraitEnvironment<'db>>,
) -> Result<Arc<Layout>, LayoutError>;

#[salsa::invoke(crate::layout::target_data_layout_query)]
Expand Down Expand Up @@ -182,12 +182,13 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
#[salsa::invoke(crate::lower::generic_predicates_query)]
fn generic_predicates(&self, def: GenericDefId) -> GenericPredicates;

#[salsa::invoke(crate::lower::trait_environment_for_body_query)]
#[salsa::invoke(crate::lower_nextsolver::trait_environment_for_body_query)]
#[salsa::transparent]
fn trait_environment_for_body(&self, def: DefWithBodyId) -> Arc<TraitEnvironment>;
fn trait_environment_for_body<'db>(&'db self, def: DefWithBodyId)
-> Arc<TraitEnvironment<'db>>;

#[salsa::invoke(crate::lower::trait_environment_query)]
fn trait_environment(&self, def: GenericDefId) -> Arc<TraitEnvironment>;
#[salsa::invoke(crate::lower_nextsolver::trait_environment_query)]
fn trait_environment<'db>(&'db self, def: GenericDefId) -> Arc<TraitEnvironment<'db>>;

#[salsa::invoke(crate::lower::generic_defaults_with_diagnostics_query)]
#[salsa::cycle(cycle_result = crate::lower::generic_defaults_with_diagnostics_cycle_result)]
Expand Down Expand Up @@ -258,7 +259,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
fn normalize_projection(
&self,
projection: crate::ProjectionTy,
env: Arc<TraitEnvironment>,
env: Arc<TraitEnvironment<'_>>,
) -> Ty;

#[salsa::invoke(crate::traits::trait_solve_query)]
Expand All @@ -272,7 +273,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {

#[salsa::invoke(crate::drop::has_drop_glue)]
#[salsa::cycle(cycle_result = crate::drop::has_drop_glue_cycle_result)]
fn has_drop_glue(&self, ty: Ty, env: Arc<TraitEnvironment>) -> DropGlue;
fn has_drop_glue(&self, ty: Ty, env: Arc<TraitEnvironment<'_>>) -> DropGlue;

// next trait solver

Expand Down
8 changes: 4 additions & 4 deletions crates/hir-ty/src/diagnostics/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ impl BodyValidationDiagnostic {
}
}

struct ExprValidator {
struct ExprValidator<'db> {
owner: DefWithBodyId,
body: Arc<Body>,
infer: Arc<InferenceResult>,
env: Arc<TraitEnvironment>,
env: Arc<TraitEnvironment<'db>>,
diagnostics: Vec<BodyValidationDiagnostic>,
validate_lints: bool,
}

impl ExprValidator {
fn validate_body(&mut self, db: &dyn HirDatabase) {
impl<'db> ExprValidator<'db> {
fn validate_body(&mut self, db: &'db dyn HirDatabase) {
let mut filter_map_next_checker = None;
// we'll pass &mut self while iterating over body.exprs, so they need to be disjoint
let body = Arc::clone(&self.body);
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ pub(crate) struct MatchCheckCtx<'db> {
body: DefWithBodyId,
pub(crate) db: &'db dyn HirDatabase,
exhaustive_patterns: bool,
env: Arc<TraitEnvironment>,
env: Arc<TraitEnvironment<'db>>,
}

impl<'db> MatchCheckCtx<'db> {
pub(crate) fn new(
module: ModuleId,
body: DefWithBodyId,
db: &'db dyn HirDatabase,
env: Arc<TraitEnvironment>,
env: Arc<TraitEnvironment<'db>>,
) -> Self {
let def_map = module.crate_def_map(db);
let exhaustive_patterns = def_map.is_unstable_feature_enabled(&sym::exhaustive_patterns);
Expand Down
15 changes: 6 additions & 9 deletions crates/hir-ty/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,19 +792,16 @@ fn render_const_scalar_ns(
let trait_env = TraitEnvironment::empty(f.krate());
let interner = DbInterner::new_with(f.db, Some(trait_env.krate), trait_env.block);
let infcx = interner.infer_ctxt().build(rustc_type_ir::TypingMode::PostAnalysis);
let ty = infcx
.at(&ObligationCause::new(), trait_env.env.to_nextsolver(interner))
.deeply_normalize(ty)
.unwrap_or(ty);
let ty = infcx.at(&ObligationCause::new(), trait_env.env).deeply_normalize(ty).unwrap_or(ty);
render_const_scalar_inner(f, b, memory_map, ty, trait_env)
}

fn render_const_scalar_inner(
fn render_const_scalar_inner<'db>(
f: &mut HirFormatter<'_>,
b: &[u8],
memory_map: &MemoryMap<'_>,
ty: crate::next_solver::Ty<'_>,
trait_env: Arc<TraitEnvironment>,
ty: crate::next_solver::Ty<'db>,
trait_env: Arc<TraitEnvironment<'db>>,
) -> Result<(), HirDisplayError> {
use rustc_type_ir::TyKind;
match ty.kind() {
Expand Down Expand Up @@ -1068,11 +1065,11 @@ fn render_const_scalar_inner(
}
}

fn render_variant_after_name(
fn render_variant_after_name<'db>(
data: &VariantFields,
f: &mut HirFormatter<'_>,
field_types: &ArenaMap<LocalFieldId, Binders<Ty>>,
trait_env: Arc<TraitEnvironment>,
trait_env: Arc<TraitEnvironment<'db>>,
layout: &Layout,
args: GenericArgs<'_>,
b: &[u8],
Expand Down
19 changes: 14 additions & 5 deletions crates/hir-ty/src/drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use hir_def::signatures::StructFlags;
use stdx::never;
use triomphe::Arc;

use crate::next_solver::DbInterner;
use crate::next_solver::mapping::NextSolverToChalk;
use crate::{
AliasTy, Canonical, CanonicalVarKinds, ConcreteConst, ConstScalar, ConstValue, InEnvironment,
Interner, ProjectionTy, TraitEnvironment, Ty, TyBuilder, TyKind, db::HirDatabase,
Expand Down Expand Up @@ -43,7 +45,11 @@ pub enum DropGlue {
HasDropGlue,
}

pub(crate) fn has_drop_glue(db: &dyn HirDatabase, ty: Ty, env: Arc<TraitEnvironment>) -> DropGlue {
pub(crate) fn has_drop_glue(
db: &dyn HirDatabase,
ty: Ty,
env: Arc<TraitEnvironment<'_>>,
) -> DropGlue {
match ty.kind(Interner) {
TyKind::Adt(adt, subst) => {
if has_destructor(db, adt.0) {
Expand Down Expand Up @@ -165,7 +171,7 @@ pub(crate) fn has_drop_glue(db: &dyn HirDatabase, ty: Ty, env: Arc<TraitEnvironm

fn projection_has_drop_glue(
db: &dyn HirDatabase,
env: Arc<TraitEnvironment>,
env: Arc<TraitEnvironment<'_>>,
projection: ProjectionTy,
ty: Ty,
) -> DropGlue {
Expand All @@ -178,13 +184,16 @@ fn projection_has_drop_glue(
}
}

fn is_copy(db: &dyn HirDatabase, ty: Ty, env: Arc<TraitEnvironment>) -> bool {
fn is_copy(db: &dyn HirDatabase, ty: Ty, env: Arc<TraitEnvironment<'_>>) -> bool {
let Some(copy_trait) = LangItem::Copy.resolve_trait(db, env.krate) else {
return false;
};
let trait_ref = TyBuilder::trait_ref(db, copy_trait).push(ty).build();
let goal = Canonical {
value: InEnvironment::new(&env.env, trait_ref.cast(Interner)),
value: InEnvironment::new(
&env.env.to_chalk(DbInterner::new_with(db, Some(env.krate), env.block)),
trait_ref.cast(Interner),
),
binders: CanonicalVarKinds::empty(Interner),
};
db.trait_solve(env.krate, env.block, goal).certain()
Expand All @@ -193,7 +202,7 @@ fn is_copy(db: &dyn HirDatabase, ty: Ty, env: Arc<TraitEnvironment>) -> bool {
pub(crate) fn has_drop_glue_cycle_result(
_db: &dyn HirDatabase,
_ty: Ty,
_env: Arc<TraitEnvironment>,
_env: Arc<TraitEnvironment<'_>>,
) -> DropGlue {
DropGlue::None
}
2 changes: 1 addition & 1 deletion crates/hir-ty/src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub(crate) fn infer_cycle_result(_: &dyn HirDatabase, _: DefWithBodyId) -> Arc<I
/// This is appropriate to use only after type-check: it assumes
/// that normalization will succeed, for example.
#[tracing::instrument(level = "debug", skip(db))]
pub(crate) fn normalize(db: &dyn HirDatabase, trait_env: Arc<TraitEnvironment>, ty: Ty) -> Ty {
pub(crate) fn normalize(db: &dyn HirDatabase, trait_env: Arc<TraitEnvironment<'_>>, ty: Ty) -> Ty {
// FIXME: TypeFlags::HAS_CT_PROJECTION is not implemented in chalk, so TypeFlags::HAS_PROJECTION only
// works for the type case, so we check array unconditionally. Remove the array part
// when the bug in chalk becomes fixed.
Expand Down
6 changes: 3 additions & 3 deletions crates/hir-ty/src/infer/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl<'db> InferenceContext<'db> {
_ = self
.table
.infer_ctxt
.at(&ObligationCause::new(), self.table.param_env)
.at(&ObligationCause::new(), self.table.trait_env.env)
.eq(DefineOpaqueTypes::Yes, inferred_fnptr_sig, generalized_fnptr_sig)
.map(|infer_ok| self.table.register_infer_ok(infer_ok));

Expand Down Expand Up @@ -703,15 +703,15 @@ impl<'db> InferenceContext<'db> {
let cause = ObligationCause::new();
let InferOk { value: (), obligations } = table
.infer_ctxt
.at(&cause, table.param_env)
.at(&cause, table.trait_env.env)
.eq(DefineOpaqueTypes::Yes, expected_ty, supplied_ty)?;
all_obligations.extend(obligations);
}

let supplied_output_ty = supplied_sig.output();
let cause = ObligationCause::new();
let InferOk { value: (), obligations } =
table.infer_ctxt.at(&cause, table.param_env).eq(
table.infer_ctxt.at(&cause, table.trait_env.env).eq(
DefineOpaqueTypes::Yes,
expected_sigs.liberated_sig.output(),
supplied_output_ty,
Expand Down
Loading
Loading