Skip to content

Commit 7c3fc86

Browse files
authored
Merge pull request #22119 from Veykril/veykril/push-nkqzszrqyumu
Less conjuration magic
2 parents 100d2af + 7059575 commit 7c3fc86

17 files changed

Lines changed: 67 additions & 58 deletions

File tree

crates/hir-ty/src/builtin_derive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ pub fn predicates(db: &dyn HirDatabase, impl_: BuiltinDeriveImplId) -> GenericPr
193193
else {
194194
// Malformed derive.
195195
return GenericPredicates::from_explicit_own_predicates(StoredEarlyBinder::bind(
196-
Clauses::default().store(),
196+
Clauses::empty(interner).store(),
197197
));
198198
};
199199
let duplicated_bounds =

crates/hir-ty/src/display.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ fn render_const_scalar<'db>(
780780
memory_map: &MemoryMap<'db>,
781781
ty: Ty<'db>,
782782
) -> Result {
783-
let param_env = ParamEnv::empty();
783+
let param_env = ParamEnv::empty(f.interner);
784784
let infcx = f.interner.infer_ctxt().build(TypingMode::PostAnalysis);
785785
let ty = infcx.at(&ObligationCause::dummy(), param_env).deeply_normalize(ty).unwrap_or(ty);
786786
render_const_scalar_inner(f, b, memory_map, ty, param_env)
@@ -1065,7 +1065,7 @@ fn render_const_scalar_from_valtree<'db>(
10651065
ty: Ty<'db>,
10661066
valtree: ValTree<'db>,
10671067
) -> Result {
1068-
let param_env = ParamEnv::empty();
1068+
let param_env = ParamEnv::empty(f.interner);
10691069
let infcx = f.interner.infer_ctxt().build(TypingMode::PostAnalysis);
10701070
let ty = infcx.at(&ObligationCause::dummy(), param_env).deeply_normalize(ty).unwrap_or(ty);
10711071
render_const_scalar_from_valtree_inner(f, ty, valtree, param_env)

crates/hir-ty/src/infer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2438,8 +2438,8 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
24382438
};
24392439
let args =
24402440
path_ctx.substs_from_path_segment(it.into(), true, None, false, node.into());
2441+
let interner = path_ctx.interner();
24412442
drop(ctx);
2442-
let interner = DbInterner::conjure();
24432443
let ty = self.db.ty(it.into()).instantiate(interner, args).skip_norm_wip();
24442444
let ty = self.insert_type_vars(ty);
24452445

crates/hir-ty/src/lower.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub trait TyLoweringInferVarsCtx<'db> {
198198

199199
pub struct TyLoweringContext<'db, 'a> {
200200
pub db: &'db dyn HirDatabase,
201-
interner: DbInterner<'db>,
201+
pub(crate) interner: DbInterner<'db>,
202202
types: &'db crate::next_solver::DefaultAny<'db>,
203203
lang_items: &'db LangItems,
204204
resolver: &'a Resolver<'db>,
@@ -2072,12 +2072,12 @@ impl<'db> GenericPredicates {
20722072

20732073
/// A cycle can occur from malformed code.
20742074
fn generic_predicates_cycle_result(
2075-
_db: &dyn HirDatabase,
2075+
db: &dyn HirDatabase,
20762076
_: salsa::Id,
20772077
_def: GenericDefId,
20782078
) -> TyLoweringResult<GenericPredicates> {
20792079
TyLoweringResult::empty(GenericPredicates::from_explicit_own_predicates(
2080-
StoredEarlyBinder::bind(Clauses::default().store()),
2080+
StoredEarlyBinder::bind(Clauses::empty(DbInterner::new_no_crate(db)).store()),
20812081
))
20822082
}
20832083

@@ -2086,7 +2086,7 @@ impl GenericPredicates {
20862086
pub fn empty() -> &'static GenericPredicates {
20872087
static EMPTY: OnceLock<GenericPredicates> = OnceLock::new();
20882088
EMPTY.get_or_init(|| GenericPredicates {
2089-
predicates: StoredEarlyBinder::bind(Clauses::default().store()),
2089+
predicates: StoredEarlyBinder::bind(Clauses::new_from_slice(&[]).store()),
20902090
has_trait_implied_predicate: false,
20912091
parent_explicit_self_predicates_start: 0,
20922092
own_predicates_start: 0,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,10 @@ impl<'a, 'b, 'db> PathLoweringContext<'a, 'b, 'db> {
994994
})
995995
})
996996
}
997+
998+
pub(crate) fn interner(&self) -> DbInterner<'db> {
999+
self.ctx.interner
1000+
}
9971001
}
9981002

9991003
/// A const that were parsed like a type.

crates/hir-ty/src/next_solver/infer/traits.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ impl<'db> PredicateObligation<'db> {
161161
/// Flips the polarity of the inner predicate.
162162
///
163163
/// Given `T: Trait` predicate it returns `T: !Trait` and given `T: !Trait` returns `T: Trait`.
164-
pub fn flip_polarity(&self, _interner: DbInterner<'db>) -> Option<PredicateObligation<'db>> {
164+
pub fn flip_polarity(&self, interner: DbInterner<'db>) -> Option<PredicateObligation<'db>> {
165165
Some(PredicateObligation {
166166
cause: self.cause,
167167
param_env: self.param_env,
168-
predicate: self.predicate.flip_polarity()?,
168+
predicate: self.predicate.flip_polarity(interner)?,
169169
recursion_depth: self.recursion_depth,
170170
})
171171
}

crates/hir-ty/src/next_solver/interner.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ unsafe impl Sync for DbInterner<'_> {}
330330

331331
impl<'db> DbInterner<'db> {
332332
// FIXME(next-solver): remove this method
333+
#[doc(hidden)]
333334
pub fn conjure() -> DbInterner<'db> {
334335
// Here we can not reinit the cache since we do that when we attach the db.
335336
crate::with_attached_db(|db| DbInterner {

crates/hir-ty/src/next_solver/predicate.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl<'db> Predicate<'db> {
229229
/// Flips the polarity of a Predicate.
230230
///
231231
/// Given `T: Trait` predicate it returns `T: !Trait` and given `T: !Trait` returns `T: Trait`.
232-
pub fn flip_polarity(self) -> Option<Predicate<'db>> {
232+
pub fn flip_polarity(self, interner: DbInterner<'db>) -> Option<Predicate<'db>> {
233233
let kind = self
234234
.kind()
235235
.map_bound(|kind| match kind {
@@ -245,7 +245,7 @@ impl<'db> Predicate<'db> {
245245
})
246246
.transpose()?;
247247

248-
Some(Predicate::new(DbInterner::conjure(), kind))
248+
Some(Predicate::new(interner, kind))
249249
}
250250
}
251251

@@ -355,13 +355,6 @@ impl<'db> rustc_type_ir::inherent::SliceLike for Clauses<'db> {
355355
}
356356
}
357357

358-
impl<'db> Default for Clauses<'db> {
359-
#[inline]
360-
fn default() -> Self {
361-
Clauses::empty(DbInterner::conjure())
362-
}
363-
}
364-
365358
impl<'db> rustc_type_ir::inherent::Clauses<DbInterner<'db>> for Clauses<'db> {}
366359

367360
impl<'db> rustc_type_ir::TypeSuperFoldable<DbInterner<'db>> for Clauses<'db> {
@@ -444,8 +437,8 @@ pub struct ParamEnv<'db> {
444437
}
445438

446439
impl<'db> ParamEnv<'db> {
447-
pub fn empty() -> Self {
448-
ParamEnv { clauses: Clauses::empty(DbInterner::conjure()) }
440+
pub fn empty(interner: DbInterner<'db>) -> Self {
441+
ParamEnv { clauses: Clauses::empty(interner) }
449442
}
450443

451444
pub fn clauses(self) -> Clauses<'db> {

crates/hir/src/lib.rs

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,9 +1665,11 @@ impl Enum {
16651665

16661666
/// The type of the enum variant bodies.
16671667
pub fn variant_body_ty<'db>(self, db: &'db dyn HirDatabase) -> Type<'db> {
1668-
let interner = DbInterner::new_no_crate(db);
1668+
let krate = self.id.lookup(db).container.krate(db);
1669+
let interner = DbInterner::new_with(db, krate);
16691670
Type::new_for_crate(
1670-
self.id.lookup(db).container.krate(db),
1671+
db,
1672+
krate,
16711673
match EnumSignature::variant_body_type(db, self.id) {
16721674
layout::IntegerType::Pointer(sign) => match sign {
16731675
true => Ty::new_int(interner, rustc_type_ir::IntTy::Isize),
@@ -2267,8 +2269,11 @@ impl DefWithBody {
22672269
mir::MirSpan::Unknown => continue,
22682270
};
22692271
acc.push(
2270-
MovedOutOfRef { ty: Type::new_for_crate(krate, moof.ty.as_ref()), span }
2271-
.into(),
2272+
MovedOutOfRef {
2273+
ty: Type::new_for_crate(db, krate, moof.ty.as_ref()),
2274+
span,
2275+
}
2276+
.into(),
22722277
)
22732278
}
22742279
let mol = &borrowck_result.mutability_of_locals;
@@ -3485,7 +3490,7 @@ impl BuiltinType {
34853490
pub fn ty<'db>(self, db: &'db dyn HirDatabase) -> Type<'db> {
34863491
let core = Crate::core(db).map(|core| core.id).unwrap_or_else(|| all_crates(db)[0]);
34873492
let interner = DbInterner::new_no_crate(db);
3488-
Type::new_for_crate(core, Ty::from_builtin_type(interner, self.inner))
3493+
Type::new_for_crate(db, core, Ty::from_builtin_type(interner, self.inner))
34893494
}
34903495

34913496
pub fn name(self) -> Name {
@@ -5534,8 +5539,13 @@ impl<'db> Type<'db> {
55345539
Type { env: environment, ty }
55355540
}
55365541

5537-
pub(crate) fn new_for_crate(krate: base_db::Crate, ty: Ty<'db>) -> Self {
5538-
Type { env: empty_param_env(krate), ty }
5542+
pub(crate) fn new_for_crate(
5543+
db: &'db dyn HirDatabase,
5544+
krate: base_db::Crate,
5545+
ty: Ty<'db>,
5546+
) -> Self {
5547+
let interner = DbInterner::new_with(db, krate);
5548+
Type { env: ParamEnvAndCrate { param_env: ParamEnv::empty(interner), krate }, ty }
55395549
}
55405550

55415551
fn new(db: &'db dyn HirDatabase, lexical_env: impl HasResolver, ty: Ty<'db>) -> Self {
@@ -5588,15 +5598,18 @@ impl<'db> Type<'db> {
55885598
Type::new(db, def, ty.instantiate(interner, args).skip_norm_wip())
55895599
}
55905600

5591-
pub fn new_slice(ty: Self) -> Self {
5592-
let interner = DbInterner::conjure();
5601+
pub fn new_slice(db: &'db dyn HirDatabase, ty: Self) -> Self {
5602+
let interner = DbInterner::new_no_crate(db);
55935603
Type { env: ty.env, ty: Ty::new_slice(interner, ty.ty) }
55945604
}
55955605

5596-
pub fn new_tuple(krate: base_db::Crate, tys: &[Self]) -> Self {
5606+
pub fn new_tuple(db: &'db dyn HirDatabase, krate: base_db::Crate, tys: &[Self]) -> Self {
55975607
let tys = tys.iter().map(|it| it.ty);
5598-
let interner = DbInterner::conjure();
5599-
Type { env: empty_param_env(krate), ty: Ty::new_tup_from_iter(interner, tys) }
5608+
let interner = DbInterner::new_with(db, krate);
5609+
Type {
5610+
env: ParamEnvAndCrate { param_env: ParamEnv::empty(interner), krate },
5611+
ty: Ty::new_tup_from_iter(interner, tys),
5612+
}
56005613
}
56015614

56025615
pub fn is_unit(&self) -> bool {
@@ -5708,8 +5721,8 @@ impl<'db> Type<'db> {
57085721
Some((self.derived(ty), m))
57095722
}
57105723

5711-
pub fn add_reference(&self, mutability: Mutability) -> Self {
5712-
let interner = DbInterner::conjure();
5724+
pub fn add_reference(&self, db: &'db dyn HirDatabase, mutability: Mutability) -> Self {
5725+
let interner = DbInterner::new_no_crate(db);
57135726
let ty_mutability = match mutability {
57145727
Mutability::Shared => hir_ty::next_solver::Mutability::Not,
57155728
Mutability::Mut => hir_ty::next_solver::Mutability::Mut,
@@ -6012,9 +6025,9 @@ impl<'db> Type<'db> {
60126025
}
60136026
}
60146027

6015-
pub fn fingerprint_for_trait_impl(&self) -> Option<SimplifiedType> {
6028+
pub fn fingerprint_for_trait_impl(&self, db: &'db dyn HirDatabase) -> Option<SimplifiedType> {
60166029
fast_reject::simplify_type(
6017-
DbInterner::conjure(),
6030+
DbInterner::new_no_crate(db),
60186031
self.ty,
60196032
fast_reject::TreatParams::AsRigid,
60206033
)
@@ -7430,9 +7443,10 @@ fn param_env_from_resolver<'db>(
74307443
resolver: &Resolver<'_>,
74317444
) -> ParamEnvAndCrate<'db> {
74327445
ParamEnvAndCrate {
7433-
param_env: resolver
7434-
.generic_def()
7435-
.map_or_else(ParamEnv::empty, |generic_def| db.trait_environment(generic_def.into())),
7446+
param_env: resolver.generic_def().map_or_else(
7447+
|| ParamEnv::empty(DbInterner::new_no_crate(db)),
7448+
|generic_def| db.trait_environment(generic_def.into()),
7449+
),
74367450
krate: resolver.krate(),
74377451
}
74387452
}
@@ -7451,10 +7465,6 @@ fn body_param_env_from_has_crate<'db>(
74517465
ParamEnvAndCrate { param_env: db.trait_environment(id.into()), krate: id.krate(db) }
74527466
}
74537467

7454-
fn empty_param_env<'db>(krate: base_db::Crate) -> ParamEnvAndCrate<'db> {
7455-
ParamEnvAndCrate { param_env: ParamEnv::empty(), krate }
7456-
}
7457-
74587468
// FIXME: We probably don't want to expose this.
74597469
pub trait MacroCallIdExt {
74607470
fn loc(self, db: &dyn HirDatabase) -> hir_expand::MacroCallLoc;

crates/hir/src/source_analyzer.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,14 @@ impl<'db> SourceAnalyzer<'db> {
330330
}
331331

332332
fn trait_environment(&self, db: &'db dyn HirDatabase) -> ParamEnvAndCrate<'db> {
333-
self.param_and(self.body_or_sig.as_ref().map_or_else(ParamEnv::empty, |body_or_sig| {
334-
match *body_or_sig {
333+
self.param_and(self.body_or_sig.as_ref().map_or_else(
334+
|| ParamEnv::empty(DbInterner::new_no_crate(db)),
335+
|body_or_sig| match *body_or_sig {
335336
BodyOrSig::Body { def, .. } => db.trait_environment(def.into()),
336337
BodyOrSig::VariantFields { def, .. } => db.trait_environment(def.into()),
337338
BodyOrSig::Sig { def, .. } => db.trait_environment(def.into()),
338-
}
339-
}))
339+
},
340+
))
340341
}
341342

342343
pub(crate) fn expr_id(&self, expr: ast::Expr) -> Option<ExprOrPatId> {

0 commit comments

Comments
 (0)