Skip to content

Commit 57c019a

Browse files
Adapt for new cycle handling changing in Salsa
1 parent db72e2f commit 57c019a

File tree

15 files changed

+133
-339
lines changed

15 files changed

+133
-339
lines changed

crates/hir-def/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ impl_from!(
619619

620620
/// A constant, which might appears as a const item, an anonymous const block in expressions
621621
/// or patterns, or as a constant in types with const generics.
622-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
622+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, salsa::Supertype)]
623623
pub enum GeneralConstId {
624624
ConstId(ConstId),
625625
StaticId(StaticId),

crates/hir-ty/src/consteval.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use hir_def::{
1010
type_ref::LiteralConstRef,
1111
};
1212
use hir_expand::Lookup;
13-
use salsa::Cycle;
1413
use stdx::never;
1514
use triomphe::Arc;
1615

@@ -220,27 +219,24 @@ pub fn try_const_isize(db: &dyn HirDatabase, c: &Const) -> Option<i128> {
220219
}
221220
}
222221

223-
pub(crate) fn const_eval_recover(
222+
pub(crate) fn const_eval_cycle_result(
224223
_: &dyn HirDatabase,
225-
_: &Cycle,
226224
_: GeneralConstId,
227225
_: Substitution,
228226
_: Option<Arc<TraitEnvironment>>,
229227
) -> Result<Const, ConstEvalError> {
230228
Err(ConstEvalError::MirLowerError(MirLowerError::Loop))
231229
}
232230

233-
pub(crate) fn const_eval_static_recover(
231+
pub(crate) fn const_eval_static_cycle_result(
234232
_: &dyn HirDatabase,
235-
_: &Cycle,
236233
_: StaticId,
237234
) -> Result<Const, ConstEvalError> {
238235
Err(ConstEvalError::MirLowerError(MirLowerError::Loop))
239236
}
240237

241-
pub(crate) fn const_eval_discriminant_recover(
238+
pub(crate) fn const_eval_discriminant_cycle_result(
242239
_: &dyn HirDatabase,
243-
_: &Cycle,
244240
_: EnumVariantId,
245241
) -> Result<i128, ConstEvalError> {
246242
Err(ConstEvalError::MirLowerError(MirLowerError::Loop))

crates/hir-ty/src/db.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
3636
// region:mir
3737

3838
#[salsa::invoke(crate::mir::mir_body_query)]
39-
#[salsa::cycle(crate::mir::mir_body_recover)]
39+
#[salsa::cycle(cycle_result = crate::mir::mir_body_cycle_result)]
4040
fn mir_body(&self, def: DefWithBodyId) -> Result<Arc<MirBody>, MirLowerError>;
4141

4242
#[salsa::invoke(crate::mir::mir_body_for_closure_query)]
4343
fn mir_body_for_closure(&self, def: InternedClosureId) -> Result<Arc<MirBody>, MirLowerError>;
4444

4545
#[salsa::invoke(crate::mir::monomorphized_mir_body_query)]
46-
#[salsa::cycle(crate::mir::monomorphized_mir_body_recover)]
46+
#[salsa::cycle(cycle_result = crate::mir::monomorphized_mir_body_cycle_result)]
4747
fn monomorphized_mir_body(
4848
&self,
4949
def: DefWithBodyId,
@@ -64,7 +64,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
6464
fn borrowck(&self, def: DefWithBodyId) -> Result<Arc<[BorrowckResult]>, MirLowerError>;
6565

6666
#[salsa::invoke(crate::consteval::const_eval_query)]
67-
#[salsa::cycle(crate::consteval::const_eval_recover)]
67+
#[salsa::cycle(cycle_result = crate::consteval::const_eval_cycle_result)]
6868
fn const_eval(
6969
&self,
7070
def: GeneralConstId,
@@ -73,11 +73,11 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
7373
) -> Result<Const, ConstEvalError>;
7474

7575
#[salsa::invoke(crate::consteval::const_eval_static_query)]
76-
#[salsa::cycle(crate::consteval::const_eval_static_recover)]
76+
#[salsa::cycle(cycle_result = crate::consteval::const_eval_static_cycle_result)]
7777
fn const_eval_static(&self, def: StaticId) -> Result<Const, ConstEvalError>;
7878

7979
#[salsa::invoke(crate::consteval::const_eval_discriminant_variant)]
80-
#[salsa::cycle(crate::consteval::const_eval_discriminant_recover)]
80+
#[salsa::cycle(cycle_result = crate::consteval::const_eval_discriminant_cycle_result)]
8181
fn const_eval_discriminant(&self, def: EnumVariantId) -> Result<i128, ConstEvalError>;
8282

8383
#[salsa::invoke(crate::method_resolution::lookup_impl_method_query)]
@@ -91,7 +91,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
9191
// endregion:mir
9292

9393
#[salsa::invoke(crate::layout::layout_of_adt_query)]
94-
#[salsa::cycle(crate::layout::layout_of_adt_recover)]
94+
#[salsa::cycle(cycle_result = crate::layout::layout_of_adt_cycle_result)]
9595
fn layout_of_adt(
9696
&self,
9797
def: AdtId,
@@ -100,7 +100,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
100100
) -> Result<Arc<Layout>, LayoutError>;
101101

102102
#[salsa::invoke(crate::layout::layout_of_ty_query)]
103-
#[salsa::cycle(crate::layout::layout_of_ty_recover)]
103+
#[salsa::cycle(cycle_result = crate::layout::layout_of_ty_cycle_result)]
104104
fn layout_of_ty(&self, ty: Ty, env: Arc<TraitEnvironment>) -> Result<Arc<Layout>, LayoutError>;
105105

106106
#[salsa::invoke(crate::layout::target_data_layout_query)]
@@ -113,8 +113,8 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
113113
#[salsa::transparent]
114114
fn ty(&self, def: TyDefId) -> Binders<Ty>;
115115

116-
#[salsa::cycle(crate::lower::type_for_type_alias_with_diagnostics_query_recover)]
117116
#[salsa::invoke(crate::lower::type_for_type_alias_with_diagnostics_query)]
117+
#[salsa::cycle(cycle_result = crate::lower::type_for_type_alias_with_diagnostics_cycle_result)]
118118
fn type_for_type_alias_with_diagnostics(&self, def: TypeAliasId) -> (Binders<Ty>, Diagnostics);
119119

120120
/// Returns the type of the value of the given constant, or `None` if the `ValueTyDefId` is
@@ -123,7 +123,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
123123
fn value_ty(&self, def: ValueTyDefId) -> Option<Binders<Ty>>;
124124

125125
#[salsa::invoke(crate::lower::impl_self_ty_with_diagnostics_query)]
126-
#[salsa::cycle(crate::lower::impl_self_ty_with_diagnostics_recover)]
126+
#[salsa::cycle(cycle_result = crate::lower::impl_self_ty_with_diagnostics_cycle_result)]
127127
fn impl_self_ty_with_diagnostics(&self, def: ImplId) -> (Binders<Ty>, Diagnostics);
128128

129129
#[salsa::invoke(crate::lower::impl_self_ty_query)]
@@ -165,7 +165,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
165165
fn type_alias_impl_traits(&self, def: TypeAliasId) -> Option<Arc<Binders<ImplTraits>>>;
166166

167167
#[salsa::invoke(crate::lower::generic_predicates_for_param_query)]
168-
#[salsa::cycle(crate::lower::generic_predicates_for_param_recover)]
168+
#[salsa::cycle(cycle_result = crate::lower::generic_predicates_for_param_cycle_result)]
169169
fn generic_predicates_for_param(
170170
&self,
171171
def: GenericDefId,
@@ -194,7 +194,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
194194
fn trait_environment(&self, def: GenericDefId) -> Arc<TraitEnvironment>;
195195

196196
#[salsa::invoke(crate::lower::generic_defaults_with_diagnostics_query)]
197-
#[salsa::cycle(crate::lower::generic_defaults_with_diagnostics_recover)]
197+
#[salsa::cycle(cycle_result = crate::lower::generic_defaults_with_diagnostics_cycle_result)]
198198
fn generic_defaults_with_diagnostics(
199199
&self,
200200
def: GenericDefId,
@@ -282,7 +282,10 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
282282
fn adt_variance(&self, adt_id: AdtId) -> chalk_db::Variances;
283283

284284
#[salsa::invoke(crate::variance::variances_of)]
285-
#[salsa::cycle(crate::variance::variances_of_cycle)]
285+
#[salsa::cycle(
286+
cycle_fn = crate::variance::variances_of_cycle_fn,
287+
cycle_initial = crate::variance::variances_of_cycle_initial,
288+
)]
286289
fn variances_of(&self, def: GenericDefId) -> Option<Arc<[crate::variance::Variance]>>;
287290

288291
#[salsa::invoke(chalk_db::associated_ty_value_query)]
@@ -317,7 +320,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
317320
) -> chalk_ir::ProgramClauses<Interner>;
318321

319322
#[salsa::invoke(crate::drop::has_drop_glue)]
320-
#[salsa::cycle(crate::drop::has_drop_glue_recover)]
323+
#[salsa::cycle(cycle_result = crate::drop::has_drop_glue_cycle_result)]
321324
fn has_drop_glue(&self, ty: Ty, env: Arc<TraitEnvironment>) -> DropGlue;
322325
}
323326

crates/hir-ty/src/drop.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,8 @@ fn is_copy(db: &dyn HirDatabase, ty: Ty, env: Arc<TraitEnvironment>) -> bool {
193193
db.trait_solve(env.krate, env.block, goal).is_some()
194194
}
195195

196-
pub(crate) fn has_drop_glue_recover(
196+
pub(crate) fn has_drop_glue_cycle_result(
197197
_db: &dyn HirDatabase,
198-
_cycle: &salsa::Cycle,
199198
_ty: Ty,
200199
_env: Arc<TraitEnvironment>,
201200
) -> DropGlue {

crates/hir-ty/src/layout.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use hir_def::{
1313
use la_arena::{Idx, RawIdx};
1414
use rustc_abi::AddressSpace;
1515
use rustc_index::IndexVec;
16-
use salsa::Cycle;
1716

1817
use triomphe::Arc;
1918

@@ -25,7 +24,7 @@ use crate::{
2524
utils::ClosureSubst,
2625
};
2726

28-
pub(crate) use self::adt::layout_of_adt_recover;
27+
pub(crate) use self::adt::layout_of_adt_cycle_result;
2928
pub use self::{adt::layout_of_adt_query, target::target_data_layout_query};
3029

3130
mod adt;
@@ -365,9 +364,8 @@ pub fn layout_of_ty_query(
365364
Ok(Arc::new(result))
366365
}
367366

368-
pub(crate) fn layout_of_ty_recover(
367+
pub(crate) fn layout_of_ty_cycle_result(
369368
_: &dyn HirDatabase,
370-
_: &Cycle,
371369
_: Ty,
372370
_: Arc<TraitEnvironment>,
373371
) -> Result<Arc<Layout>, LayoutError> {

crates/hir-ty/src/layout/adt.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use hir_def::{
99
};
1010
use intern::sym;
1111
use rustc_index::IndexVec;
12-
use salsa::Cycle;
1312
use smallvec::SmallVec;
1413
use triomphe::Arc;
1514

@@ -131,9 +130,8 @@ fn layout_scalar_valid_range(db: &dyn HirDatabase, def: AdtId) -> (Bound<u128>,
131130
(get(sym::rustc_layout_scalar_valid_range_start), get(sym::rustc_layout_scalar_valid_range_end))
132131
}
133132

134-
pub(crate) fn layout_of_adt_recover(
133+
pub(crate) fn layout_of_adt_cycle_result(
135134
_: &dyn HirDatabase,
136-
_: &Cycle,
137135
_: AdtId,
138136
_: Substitution,
139137
_: Arc<TraitEnvironment>,

crates/hir-ty/src/lower.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ use hir_expand::name::Name;
4545
use la_arena::{Arena, ArenaMap};
4646
use rustc_hash::FxHashSet;
4747
use rustc_pattern_analysis::Captures;
48-
use salsa::Cycle;
4948
use stdx::{impl_from, never};
5049
use triomphe::{Arc, ThinArc};
5150

@@ -961,9 +960,8 @@ pub(crate) fn generic_predicates_for_param_query(
961960
GenericPredicates(predicates.is_empty().not().then(|| predicates.into()))
962961
}
963962

964-
pub(crate) fn generic_predicates_for_param_recover(
963+
pub(crate) fn generic_predicates_for_param_cycle_result(
965964
_db: &dyn HirDatabase,
966-
_cycle: &salsa::Cycle,
967965
_def: GenericDefId,
968966
_param_id: TypeOrConstParamId,
969967
_assoc_name: Option<Name>,
@@ -1264,9 +1262,8 @@ pub(crate) fn generic_defaults_with_diagnostics_query(
12641262
}
12651263
}
12661264

1267-
pub(crate) fn generic_defaults_with_diagnostics_recover(
1265+
pub(crate) fn generic_defaults_with_diagnostics_cycle_result(
12681266
_db: &dyn HirDatabase,
1269-
_cycle: &Cycle,
12701267
_def: GenericDefId,
12711268
) -> (GenericDefaults, Diagnostics) {
12721269
(GenericDefaults(None), None)
@@ -1402,16 +1399,12 @@ fn type_for_enum_variant_constructor(
14021399
}
14031400
}
14041401

1405-
#[salsa::tracked(recovery_fn = type_for_adt_recovery)]
1402+
#[salsa::tracked(cycle_result = type_for_adt_cycle_result)]
14061403
fn type_for_adt_tracked(db: &dyn HirDatabase, adt: AdtId) -> Binders<Ty> {
14071404
type_for_adt(db, adt)
14081405
}
14091406

1410-
pub(crate) fn type_for_adt_recovery(
1411-
db: &dyn HirDatabase,
1412-
_cycle: &salsa::Cycle,
1413-
adt: AdtId,
1414-
) -> Binders<Ty> {
1407+
fn type_for_adt_cycle_result(db: &dyn HirDatabase, adt: AdtId) -> Binders<Ty> {
14151408
let generics = generics(db, adt.into());
14161409
make_binders(db, &generics, TyKind::Error.intern(Interner))
14171410
}
@@ -1449,9 +1442,8 @@ pub(crate) fn type_for_type_alias_with_diagnostics_query(
14491442
(make_binders(db, &generics, inner), diags)
14501443
}
14511444

1452-
pub(crate) fn type_for_type_alias_with_diagnostics_query_recover(
1445+
pub(crate) fn type_for_type_alias_with_diagnostics_cycle_result(
14531446
db: &dyn HirDatabase,
1454-
_cycle: &salsa::Cycle,
14551447
adt: TypeAliasId,
14561448
) -> (Binders<Ty>, Diagnostics) {
14571449
let generics = generics(db, adt.into());
@@ -1555,12 +1547,11 @@ pub(crate) fn const_param_ty_with_diagnostics_query(
15551547
(ty, create_diagnostics(ctx.diagnostics))
15561548
}
15571549

1558-
pub(crate) fn impl_self_ty_with_diagnostics_recover(
1550+
pub(crate) fn impl_self_ty_with_diagnostics_cycle_result(
15591551
db: &dyn HirDatabase,
1560-
_cycle: &salsa::Cycle,
15611552
impl_id: ImplId,
15621553
) -> (Binders<Ty>, Diagnostics) {
1563-
let generics = generics(db, (impl_id).into());
1554+
let generics = generics(db, impl_id.into());
15641555
(make_binders(db, &generics, TyKind::Error.intern(Interner)), None)
15651556
}
15661557

crates/hir-ty/src/mir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ use rustc_hash::FxHashMap;
4141
use smallvec::{SmallVec, smallvec};
4242
use stdx::{impl_from, never};
4343

44-
pub(crate) use lower::mir_body_recover;
45-
pub(crate) use monomorphization::monomorphized_mir_body_recover;
44+
pub(crate) use lower::mir_body_cycle_result;
45+
pub(crate) use monomorphization::monomorphized_mir_body_cycle_result;
4646

4747
use super::consteval::{intern_const_scalar, try_const_usize};
4848

crates/hir-ty/src/mir/lower.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::{fmt::Write, iter, mem};
44

5-
use base_db::{Crate, salsa::Cycle};
5+
use base_db::Crate;
66
use chalk_ir::{BoundVar, ConstData, DebruijnIndex, TyKind};
77
use hir_def::{
88
AdtId, DefWithBodyId, EnumVariantId, GeneralConstId, HasModule, ItemContainerId, LocalFieldId,
@@ -2145,9 +2145,8 @@ pub fn mir_body_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Result<Arc<Mi
21452145
Ok(Arc::new(result))
21462146
}
21472147

2148-
pub(crate) fn mir_body_recover(
2148+
pub(crate) fn mir_body_cycle_result(
21492149
_db: &dyn HirDatabase,
2150-
_cycle: &Cycle,
21512150
_def: DefWithBodyId,
21522151
) -> Result<Arc<MirBody>> {
21532152
Err(MirLowerError::Loop)

crates/hir-ty/src/mir/monomorphization.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,8 @@ pub fn monomorphized_mir_body_query(
313313
Ok(Arc::new(body))
314314
}
315315

316-
pub(crate) fn monomorphized_mir_body_recover(
317-
_: &dyn HirDatabase,
318-
_: &salsa::Cycle,
316+
pub(crate) fn monomorphized_mir_body_cycle_result(
317+
_db: &dyn HirDatabase,
319318
_: DefWithBodyId,
320319
_: Substitution,
321320
_: Arc<crate::TraitEnvironment>,

0 commit comments

Comments
 (0)