Skip to content
Open
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
21 changes: 3 additions & 18 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ debug = 2

# ungrammar = { path = "lib/ungrammar" }

# salsa = { path = "../salsa" }
# salsa-macros = { path = "../salsa/components/salsa-macros" }
# salsa-macro-rules = { path = "../salsa/components/salsa-macro-rules" }
salsa = { path = "../salsa" }
salsa-macros = { path = "../salsa/components/salsa-macros" }
salsa-macro-rules = { path = "../salsa/components/salsa-macro-rules" }

[workspace.dependencies]
# local crates
Expand Down
14 changes: 7 additions & 7 deletions crates/hir-ty/src/autoderef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ impl<'db> AutoderefCtx<'db> for DefaultAutoderefCtx<'_, 'db> {
}
}

pub(crate) struct InferenceContextAutoderefCtx<'a, 'b, 'db>(&'a mut InferenceContext<'b, 'db>);
impl<'db> AutoderefCtx<'db> for InferenceContextAutoderefCtx<'_, '_, 'db> {
pub(crate) struct InferenceContextAutoderefCtx<'a, 'db>(&'a mut InferenceContext<'db>);
impl<'db> AutoderefCtx<'db> for InferenceContextAutoderefCtx<'_, 'db> {
#[inline]
fn infcx(&self) -> &InferCtxt<'db> {
&self.0.table.infer_ctxt
Expand Down Expand Up @@ -160,8 +160,8 @@ pub(crate) struct GeneralAutoderef<'db, Ctx, Steps = Vec<(Ty<'db>, AutoderefKind

pub(crate) type Autoderef<'a, 'db, Steps = Vec<(Ty<'db>, AutoderefKind)>> =
GeneralAutoderef<'db, DefaultAutoderefCtx<'a, 'db>, Steps>;
pub(crate) type InferenceContextAutoderef<'a, 'b, 'db, Steps = Vec<(Ty<'db>, AutoderefKind)>> =
GeneralAutoderef<'db, InferenceContextAutoderefCtx<'a, 'b, 'db>, Steps>;
pub(crate) type InferenceContextAutoderef<'a, 'db, Steps = Vec<(Ty<'db>, AutoderefKind)>> =
GeneralAutoderef<'db, InferenceContextAutoderefCtx<'a, 'db>, Steps>;

impl<'db, Ctx, Steps> Iterator for GeneralAutoderef<'db, Ctx, Steps>
where
Expand Down Expand Up @@ -239,18 +239,18 @@ impl<'a, 'db> Autoderef<'a, 'db> {
}
}

impl<'a, 'b, 'db> InferenceContextAutoderef<'a, 'b, 'db> {
impl<'a, 'db> InferenceContextAutoderef<'a, 'db> {
#[inline]
pub(crate) fn new_from_inference_context(
ctx: &'a mut InferenceContext<'b, 'db>,
ctx: &'a mut InferenceContext<'db>,
base_ty: Ty<'db>,
span: Span,
) -> Self {
Self::new_impl(InferenceContextAutoderefCtx(ctx), base_ty, span)
}

#[inline]
pub(crate) fn ctx(&mut self) -> &mut InferenceContext<'b, 'db> {
pub(crate) fn ctx(&mut self) -> &mut InferenceContext<'db> {
self.ctx.0
}
}
Expand Down
83 changes: 42 additions & 41 deletions crates/hir-ty/src/consteval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use rustc_abi::Size;
use rustc_apfloat::Float;
use rustc_ast_ir::Mutability;
use rustc_type_ir::inherent::{Const as _, GenericArgs as _, IntoKind, Ty as _};
use salsa::Update;
use stdx::never;

use crate::{
Expand All @@ -35,13 +36,13 @@ use crate::{

use super::mir::interpret_mir;

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ConstEvalError {
MirLowerError(MirLowerError),
MirEvalError(MirEvalError),
#[derive(Debug, Clone, PartialEq, Eq, Update)]
pub enum ConstEvalError<'db> {
MirLowerError(MirLowerError<'db>),
MirEvalError(MirEvalError<'db>),
}

impl ConstEvalError {
impl ConstEvalError<'_> {
pub fn pretty_print(
&self,
f: &mut String,
Expand All @@ -60,17 +61,17 @@ impl ConstEvalError {
}
}

impl From<MirLowerError> for ConstEvalError {
fn from(value: MirLowerError) -> Self {
impl<'db> From<MirLowerError<'db>> for ConstEvalError<'db> {
fn from(value: MirLowerError<'db>) -> Self {
match value {
MirLowerError::ConstEvalError(_, e) => *e,
_ => ConstEvalError::MirLowerError(value),
}
}
}

impl From<MirEvalError> for ConstEvalError {
fn from(value: MirEvalError) -> Self {
impl<'db> From<MirEvalError<'db>> for ConstEvalError<'db> {
fn from(value: MirEvalError<'db>) -> Self {
ConstEvalError::MirEvalError(value)
}
}
Expand Down Expand Up @@ -405,10 +406,10 @@ pub(crate) fn create_anon_const<'a, 'db>(
}
}

pub(crate) fn const_eval_discriminant_variant(
db: &dyn HirDatabase,
pub(crate) fn const_eval_discriminant_variant<'db>(
db: &'db dyn HirDatabase,
variant_id: EnumVariantId,
) -> Result<i128, ConstEvalError> {
) -> Result<i128, ConstEvalError<'db>> {
let interner = DbInterner::new_no_crate(db);
let def = variant_id.into();
let body = Body::of(db, def);
Expand Down Expand Up @@ -441,11 +442,11 @@ pub(crate) fn const_eval_discriminant_variant(
Ok(c)
}

pub(crate) fn const_eval_discriminant_cycle_result(
_: &dyn HirDatabase,
pub(crate) fn const_eval_discriminant_cycle_result<'db>(
_: &'db dyn HirDatabase,
_: salsa::Id,
_: EnumVariantId,
) -> Result<i128, ConstEvalError> {
) -> Result<i128, ConstEvalError<'db>> {
Err(ConstEvalError::MirLowerError(MirLowerError::Loop))
}

Expand All @@ -454,58 +455,58 @@ pub(crate) fn const_eval<'db>(
def: ConstId,
subst: GenericArgs<'db>,
trait_env: Option<ParamEnvAndCrate<'db>>,
) -> Result<Allocation<'db>, ConstEvalError> {
) -> Result<Allocation<'db>, ConstEvalError<'db>> {
return match const_eval_query(db, def, subst.store(), trait_env.map(|env| env.store())) {
Ok(konst) => Ok(konst.as_ref()),
Err(err) => Err(err.clone()),
};

#[salsa::tracked(returns(ref), cycle_result = const_eval_cycle_result)]
pub(crate) fn const_eval_query(
db: &dyn HirDatabase,
pub(crate) fn const_eval_query<'db>(
db: &'db dyn HirDatabase,
def: ConstId,
subst: StoredGenericArgs,
trait_env: Option<StoredParamEnvAndCrate>,
) -> Result<StoredAllocation, ConstEvalError> {
) -> Result<StoredAllocation, ConstEvalError<'db>> {
let body = db.monomorphized_mir_body(
def.into(),
subst,
ParamEnvAndCrate { param_env: db.trait_environment(def.into()), krate: def.krate(db) }
.store(),
)?;
let c = interpret_mir(db, body, false, trait_env.as_ref().map(|env| env.as_ref()))?.0?;
let c = interpret_mir(db, body, false, trait_env.as_ref().map(|env| env.as_ref(db)))?.0?;
Ok(c.store())
}

pub(crate) fn const_eval_cycle_result(
_: &dyn HirDatabase,
pub(crate) fn const_eval_cycle_result<'db>(
_: &'db dyn HirDatabase,
_: salsa::Id,
_: ConstId,
_: StoredGenericArgs,
_: Option<StoredParamEnvAndCrate>,
) -> Result<StoredAllocation, ConstEvalError> {
) -> Result<StoredAllocation, ConstEvalError<'db>> {
Err(ConstEvalError::MirLowerError(MirLowerError::Loop))
}
}

pub(crate) fn anon_const_eval<'db>(
db: &'db dyn HirDatabase,
def: AnonConstId,
def: AnonConstId<'db>,
subst: GenericArgs<'db>,
trait_env: Option<ParamEnvAndCrate<'db>>,
) -> Result<Allocation<'db>, ConstEvalError> {
) -> Result<Allocation<'db>, ConstEvalError<'db>> {
return match anon_const_eval_query(db, def, subst.store(), trait_env.map(|env| env.store())) {
Ok(konst) => Ok(konst.as_ref()),
Err(err) => Err(err.clone()),
};

#[salsa::tracked(returns(ref), cycle_result = anon_const_eval_cycle_result)]
pub(crate) fn anon_const_eval_query(
db: &dyn HirDatabase,
def: AnonConstId,
pub(crate) fn anon_const_eval_query<'db>(
db: &'db dyn HirDatabase,
def: AnonConstId<'db>,
subst: StoredGenericArgs,
trait_env: Option<StoredParamEnvAndCrate>,
) -> Result<StoredAllocation, ConstEvalError> {
) -> Result<StoredAllocation, ConstEvalError<'db>> {
let body = db.monomorphized_mir_body(
def.into(),
subst,
Expand All @@ -515,35 +516,35 @@ pub(crate) fn anon_const_eval<'db>(
}
.store(),
)?;
let c = interpret_mir(db, body, false, trait_env.as_ref().map(|env| env.as_ref()))?.0?;
let c = interpret_mir(db, body, false, trait_env.as_ref().map(|env| env.as_ref(db)))?.0?;
Ok(c.store())
}

pub(crate) fn anon_const_eval_cycle_result(
_: &dyn HirDatabase,
pub(crate) fn anon_const_eval_cycle_result<'db>(
_: &'db dyn HirDatabase,
_: salsa::Id,
_: AnonConstId,
_: AnonConstId<'db>,
_: StoredGenericArgs,
_: Option<StoredParamEnvAndCrate>,
) -> Result<StoredAllocation, ConstEvalError> {
) -> Result<StoredAllocation, ConstEvalError<'db>> {
Err(ConstEvalError::MirLowerError(MirLowerError::Loop))
}
}

pub(crate) fn const_eval_static<'db>(
db: &'db dyn HirDatabase,
def: StaticId,
) -> Result<Allocation<'db>, ConstEvalError> {
) -> Result<Allocation<'db>, ConstEvalError<'db>> {
return match const_eval_static_query(db, def) {
Ok(konst) => Ok(konst.as_ref()),
Err(err) => Err(err.clone()),
};

#[salsa::tracked(returns(ref), cycle_result = const_eval_static_cycle_result)]
pub(crate) fn const_eval_static_query(
db: &dyn HirDatabase,
pub(crate) fn const_eval_static_query<'db>(
db: &'db dyn HirDatabase,
def: StaticId,
) -> Result<StoredAllocation, ConstEvalError> {
) -> Result<StoredAllocation, ConstEvalError<'db>> {
let interner = DbInterner::new_no_crate(db);
let body = db.monomorphized_mir_body(
def.into(),
Expand All @@ -555,11 +556,11 @@ pub(crate) fn const_eval_static<'db>(
Ok(c.store())
}

pub(crate) fn const_eval_static_cycle_result(
_: &dyn HirDatabase,
pub(crate) fn const_eval_static_cycle_result<'db>(
_: &'db dyn HirDatabase,
_: salsa::Id,
_: StaticId,
) -> Result<StoredAllocation, ConstEvalError> {
) -> Result<StoredAllocation, ConstEvalError<'db>> {
Err(ConstEvalError::MirLowerError(MirLowerError::Loop))
}
}
8 changes: 4 additions & 4 deletions crates/hir-ty/src/consteval/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use super::{

mod intrinsics;

fn simplify(e: ConstEvalError) -> ConstEvalError {
fn simplify(e: ConstEvalError<'_>) -> ConstEvalError<'_> {
match e {
ConstEvalError::MirEvalError(MirEvalError::InFunction(e, _)) => {
simplify(ConstEvalError::MirEvalError(*e))
Expand All @@ -38,7 +38,7 @@ fn simplify(e: ConstEvalError) -> ConstEvalError {
#[track_caller]
fn check_fail(
#[rust_analyzer::rust_fixture] ra_fixture: &str,
error: impl FnOnce(ConstEvalError) -> bool,
error: impl FnOnce(ConstEvalError<'_>) -> bool,
) {
let (db, file_id) = TestDB::with_single_file(ra_fixture);
crate::attach_db(&db, || match eval_goal(&db, file_id) {
Expand Down Expand Up @@ -101,7 +101,7 @@ fn check_answer(
});
}

fn pretty_print_err(e: ConstEvalError, db: &TestDB) -> String {
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 =
Expand All @@ -118,7 +118,7 @@ fn pretty_print_err(e: ConstEvalError, db: &TestDB) -> String {
err
}

fn eval_goal(db: &TestDB, file_id: EditionedFileId) -> Result<Allocation<'_>, ConstEvalError> {
fn eval_goal(db: &TestDB, file_id: EditionedFileId) -> Result<Allocation<'_>, ConstEvalError<'_>> {
let _tracing = setup_tracing();
let interner = DbInterner::new_no_crate(db);
let module_id = db.module_for_file(file_id.file_id(db));
Expand Down
Loading
Loading