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
2 changes: 1 addition & 1 deletion crates/hir-ty/src/builtin_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub fn predicates(db: &dyn HirDatabase, impl_: BuiltinDeriveImplId) -> GenericPr
else {
// Malformed derive.
return GenericPredicates::from_explicit_own_predicates(StoredEarlyBinder::bind(
Clauses::empty(interner).store(),
Clauses::empty().store(),
));
};
let duplicated_bounds =
Expand Down
14 changes: 6 additions & 8 deletions crates/hir-ty/src/consteval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ pub fn try_const_usize<'db>(db: &'db dyn HirDatabase, c: Const<'db>) -> Option<u
}
},
ConstKind::Value(val) => {
if val.ty == default_types(db).types.usize {
if val.ty == default_types().types.usize {
Some(val.value.inner().to_leaf().to_uint_unchecked())
} else {
None
Expand Down Expand Up @@ -291,7 +291,7 @@ pub fn try_const_isize<'db>(db: &'db dyn HirDatabase, c: Const<'db>) -> Option<i
}
},
ConstKind::Value(val) => {
if val.ty == default_types(db).types.isize {
if val.ty == default_types().types.isize {
Some(val.value.inner().to_leaf().to_int_unchecked())
} else {
None
Expand Down Expand Up @@ -347,7 +347,7 @@ pub(crate) fn path_to_const<'a, 'db>(
| ValueNs::StructId(_)
| ValueNs::EnumVariantId(_) => return Err(CreateConstError::ResolveToNonConst),
};
let args = GenericArgs::empty(interner);
let args = GenericArgs::empty();
Ok(Const::new_unevaluated(interner, UnevaluatedConst { def: konst.into(), args }))
}

Expand Down Expand Up @@ -411,7 +411,7 @@ pub(crate) fn create_anon_const<'a, 'db>(
let args = if allow_using_generic_params {
GenericArgs::identity_for_item(interner, owner.generic_def(interner.db).into())
} else {
GenericArgs::empty(interner)
GenericArgs::empty()
};
Ok(Const::new_unevaluated(
interner,
Expand All @@ -426,7 +426,6 @@ pub(crate) fn const_eval_discriminant_variant<'db>(
db: &'db dyn HirDatabase,
variant_id: EnumVariantId,
) -> Result<i128, ConstEvalError<'db>> {
let interner = DbInterner::new_no_crate(db);
let def = variant_id.into();
let body = Body::of(db, def);
let loc = variant_id.lookup(db);
Expand All @@ -446,7 +445,7 @@ pub(crate) fn const_eval_discriminant_variant<'db>(

let mir_body = db.monomorphized_mir_body(
def.into(),
GenericArgs::empty(interner).store(),
GenericArgs::empty().store(),
ParamEnvAndCrate {
param_env: db.trait_environment(def.generic_def(db)),
krate: def.krate(db),
Expand Down Expand Up @@ -561,10 +560,9 @@ pub(crate) fn const_eval_static<'db>(
db: &'db dyn HirDatabase,
def: StaticId,
) -> Result<StoredAllocation, ConstEvalError<'db>> {
let interner = DbInterner::new_no_crate(db);
let body = db.monomorphized_mir_body(
def.into(),
GenericArgs::empty(interner).store(),
GenericArgs::empty().store(),
ParamEnvAndCrate { param_env: db.trait_environment(def.into()), krate: def.krate(db) }
.store(),
)?;
Expand Down
5 changes: 2 additions & 3 deletions crates/hir-ty/src/consteval/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
db::HirDatabase,
display::DisplayTarget,
mir::{IsSigned, pad16},
next_solver::{Allocation, DbInterner, GenericArgs},
next_solver::{Allocation, GenericArgs},
setup_tracing,
test_db::TestDB,
};
Expand Down Expand Up @@ -120,7 +120,6 @@ fn pretty_print_err(e: ConstEvalError<'_>, db: &TestDB) -> String {

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));
let def_map = module_id.def_map(db);
let scope = &def_map[module_id].scope;
Expand All @@ -143,7 +142,7 @@ fn eval_goal(db: &TestDB, file_id: EditionedFileId) -> Result<Allocation<'_>, Co
_ => None,
})
.expect("No const named GOAL found in the test");
db.const_eval(const_id, GenericArgs::empty(interner), None)
db.const_eval(const_id, GenericArgs::empty(), None)
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-ty/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ fn render_const_scalar<'db>(
memory_map: &MemoryMap<'db>,
ty: Ty<'db>,
) -> Result {
let param_env = ParamEnv::empty(f.interner);
let param_env = ParamEnv::empty();
let infcx = f.interner.infer_ctxt().build(TypingMode::PostAnalysis);
let ty = infcx.at(&ObligationCause::dummy(), param_env).deeply_normalize(ty).unwrap_or(ty);
render_const_scalar_inner(f, b, memory_map, ty, param_env)
Expand Down Expand Up @@ -1086,7 +1086,7 @@ fn render_const_scalar_from_valtree<'db>(
ty: Ty<'db>,
valtree: ValTree<'db>,
) -> Result {
let param_env = ParamEnv::empty(f.interner);
let param_env = ParamEnv::empty();
let infcx = f.interner.infer_ctxt().build(TypingMode::PostAnalysis);
let ty = infcx.at(&ObligationCause::dummy(), param_env).deeply_normalize(ty).unwrap_or(ty);
render_const_scalar_from_valtree_inner(f, ty, valtree, param_env)
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ impl<'db> InferenceContext<'db> {
) -> Self {
let trait_env = db.trait_environment(generic_def);
let table = unify::InferenceTable::new(db, trait_env, resolver.krate(), owner);
let types = crate::next_solver::default_types(db);
let types = crate::next_solver::default_types();
InferenceContext {
result: InferenceResult::new(types.types.error),
return_ty: types.types.error, // set in collect_* calls
Expand Down
8 changes: 4 additions & 4 deletions crates/hir-ty/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> {
db,
// Can provide no block since we don't use it for trait solving.
interner,
types: crate::next_solver::default_types(db),
types: crate::next_solver::default_types(),
lang_items: interner.lang_items(),
resolver,
def,
Expand Down Expand Up @@ -635,7 +635,7 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> {
// place even if we encounter more opaque types while
// lowering the bounds
let idx = self.impl_trait_mode.opaque_type_data.alloc(ImplTrait {
predicates: StoredEarlyBinder::bind(Clauses::empty(interner).store()),
predicates: StoredEarlyBinder::bind(Clauses::empty().store()),
assoc_ty_bounds_start: 0,
});

Expand Down Expand Up @@ -2372,12 +2372,12 @@ impl<'db> GenericPredicates {

/// A cycle can occur from malformed code.
fn generic_predicates_cycle_result<'db>(
db: &'db dyn HirDatabase,
_db: &'db dyn HirDatabase,
_: salsa::Id,
_def: GenericDefId,
) -> TyLoweringResult<'db, GenericPredicates> {
TyLoweringResult::empty(GenericPredicates::from_explicit_own_predicates(
StoredEarlyBinder::bind(Clauses::empty(DbInterner::new_no_crate(db)).store()),
StoredEarlyBinder::bind(Clauses::empty().store()),
))
}

Expand Down
3 changes: 1 addition & 2 deletions crates/hir-ty/src/lower/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,6 @@ impl<'a, 'b, 'db> PathLoweringContext<'a, 'b, 'db> {
lowering_assoc_type_generics: bool,
span: Span,
) -> GenericArgs<'db> {
let interner = self.ctx.interner;
let prev_current_segment_idx = self.current_segment_idx;
let prev_current_segment = self.current_or_prev_segment;

Expand All @@ -586,7 +585,7 @@ impl<'a, 'b, 'db> PathLoweringContext<'a, 'b, 'db> {
ValueTyDefId::UnionId(it) => it.into(),
ValueTyDefId::ConstId(it) => it.into(),
ValueTyDefId::StaticId(_) => {
return GenericArgs::empty(interner);
return GenericArgs::empty();
}
ValueTyDefId::EnumVariantId(var) => {
// the generic args for an enum variant may be either specified
Expand Down
3 changes: 1 addition & 2 deletions crates/hir-ty/src/mir/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1503,8 +1503,7 @@ impl<'a, 'db> Evaluator<'a, 'db> {
)?)
}
AggregateKind::Union(it, f) => {
let layout =
self.layout_adt((*it).into(), GenericArgs::empty(self.interner()))?;
let layout = self.layout_adt((*it).into(), GenericArgs::empty())?;
let offset = layout
.fields
.offset(u32::from(f.local_id.into_raw()) as usize)
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/mir/eval/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ impl<'a, 'db> Evaluator<'a, 'db> {
def,
&args,
// FIXME: wrong for manual impls of `FnOnce`
GenericArgs::empty(self.interner()),
GenericArgs::empty(),
locals,
destination,
None,
Expand Down
11 changes: 3 additions & 8 deletions crates/hir-ty/src/mir/eval/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@ use syntax::{TextRange, TextSize};
use test_fixture::WithFixture;

use crate::{
db::HirDatabase,
display::DisplayTarget,
mir::MirLowerError,
next_solver::{DbInterner, GenericArgs},
setup_tracing,
test_db::TestDB,
db::HirDatabase, display::DisplayTarget, mir::MirLowerError, next_solver::GenericArgs,
setup_tracing, test_db::TestDB,
};

use super::{MirEvalError, interpret_mir};

fn eval_main(db: &TestDB, file_id: EditionedFileId) -> Result<(String, String), MirEvalError<'_>> {
crate::attach_db(db, || {
let interner = DbInterner::new_no_crate(db);
let module_id = db.module_for_file(file_id.file_id(db));
let def_map = module_id.def_map(db);
let scope = &def_map[module_id].scope;
Expand All @@ -39,7 +34,7 @@ fn eval_main(db: &TestDB, file_id: EditionedFileId) -> Result<(String, String),
let body = db
.monomorphized_mir_body(
func_id.into(),
GenericArgs::empty(interner).store(),
GenericArgs::empty().store(),
crate::ParamEnvAndCrate {
param_env: db.trait_environment(func_id.into()),
krate: func_id.krate(db),
Expand Down
9 changes: 3 additions & 6 deletions crates/hir-ty/src/mir/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ impl<'a, 'db> MirLowerCtx<'a, 'db> {
db,
infer,
store,
types: crate::next_solver::default_types(db),
types: crate::next_solver::default_types(),
owner,
store_owner,
resolver,
Expand Down Expand Up @@ -547,7 +547,7 @@ impl<'a, 'db> MirLowerCtx<'a, 'db> {
const_id.into(),
current,
place,
GenericArgs::empty(self.interner()),
GenericArgs::empty(),
expr_id.into(),
)?;
Ok(Some(current))
Expand Down Expand Up @@ -1377,10 +1377,7 @@ impl<'a, 'db> MirLowerCtx<'a, 'db> {
match pr {
ResolveValueResult::ValueNs(v) => {
if let ValueNs::ConstId(c) = v {
self.lower_const_to_operand(
GenericArgs::empty(self.interner()),
c.into(),
)
self.lower_const_to_operand(GenericArgs::empty(), c.into())
} else {
not_supported!("bad path in range pattern");
}
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/mir/lower/pattern_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ impl<'db> MirLowerCtx<'_, 'db> {
break 'b (c, x.1);
}
if let ResolveValueResult::ValueNs(ValueNs::ConstId(c)) = pr {
break 'b (c, GenericArgs::empty(self.interner()));
break 'b (c, GenericArgs::empty());
}
not_supported!("path in pattern position that is not const or variant")
};
Expand Down
10 changes: 4 additions & 6 deletions crates/hir-ty/src/next_solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ use rustc_type_ir::MayBeErased;
pub use solver::*;
pub use ty::*;

use crate::db::HirDatabase;
pub use crate::lower::ImplTraitIdx;
pub use rustc_ast_ir::Mutability;

Expand Down Expand Up @@ -143,25 +142,24 @@ impl std::fmt::Debug for DefaultAny<'_> {
}

#[inline]
pub fn default_types<'db>(db: &'db dyn HirDatabase) -> &'db DefaultAny<'db> {
pub fn default_types<'db>() -> &'db DefaultAny<'db> {
static TYPES: OnceLock<DefaultAny<'static>> = OnceLock::new();

let interner = DbInterner::new_no_crate(db);
TYPES.get_or_init(|| {
let create_ty = |kind| {
let ty = Ty::new(interner, kind);
let ty = Ty::new_without_interner(kind);
// We need to increase the refcount (forever), so that the types won't be freed.
let ty = ManuallyDrop::new(ty.store());
ty.as_ref()
};
let create_const = |kind| {
let ty = Const::new(interner, kind);
let ty = Const::new_without_interner(kind);
// We need to increase the refcount (forever), so that the types won't be freed.
let ty = ManuallyDrop::new(ty.store());
ty.as_ref()
};
let create_region = |kind| {
let ty = Region::new(interner, kind);
let ty = Region::new_without_interner(kind);
// We need to increase the refcount (forever), so that the types won't be freed.
let ty = ManuallyDrop::new(ty.store());
ty.as_ref()
Expand Down
9 changes: 8 additions & 1 deletion crates/hir-ty/src/next_solver/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ const _: () = {
};

impl<'db> Const<'db> {
pub fn new(_interner: DbInterner<'db>, kind: ConstKind<'db>) -> Self {
/// You should avoid using this if you can, since we want `Ty` to be defined in `rustc_type_ir` and then this method
/// will become more difficult to use.
#[inline]
pub fn new_without_interner(kind: ConstKind<'db>) -> Self {
let kind = unsafe { std::mem::transmute::<ConstKind<'db>, ConstKind<'static>>(kind) };
let flags = FlagComputation::for_const_kind(&kind);
let cached = WithCachedTypeInfo {
Expand All @@ -59,6 +62,10 @@ impl<'db> Const<'db> {
Self { interned: Interned::new_gc(ConstInterned(cached)) }
}

pub fn new(_interner: DbInterner<'db>, kind: ConstKind<'db>) -> Self {
Self::new_without_interner(kind)
}

pub fn inner(&self) -> &WithCachedTypeInfo<ConstKind<'db>> {
let inner = &self.interned.0;
unsafe {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ impl<'cx, 'db> Canonicalizer<'cx, 'db> {
{
let base = Canonical {
max_universe: UniverseIndex::ROOT,
var_kinds: CanonicalVarKinds::empty(tcx),
var_kinds: CanonicalVarKinds::empty(),
value: (),
};
Canonicalizer::canonicalize_with_base(
Expand Down
14 changes: 7 additions & 7 deletions crates/hir-ty/src/next_solver/interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ macro_rules! interned_slice {

impl<'db> $name<'db> {
#[inline]
pub fn empty(interner: DbInterner<'db>) -> Self {
interner.default_types().empty.$default_types_field
pub fn empty() -> Self {
$crate::next_solver::default_types().empty.$default_types_field
}

#[inline]
Expand Down Expand Up @@ -168,7 +168,7 @@ macro_rules! interned_slice {
impl<'db> Default for $name<'db> {
#[inline]
fn default() -> Self {
$name::empty(DbInterner::conjure())
$name::empty()
}
}

Expand Down Expand Up @@ -399,7 +399,7 @@ impl<'db> DbInterner<'db> {

#[inline]
pub fn default_types(&self) -> &'db crate::next_solver::DefaultAny<'db> {
crate::next_solver::default_types(self.db)
crate::next_solver::default_types()
}

#[inline]
Expand Down Expand Up @@ -1092,7 +1092,7 @@ impl<'db> Interner for DbInterner<'db> {
| SolverDefId::InternedCoroutineId(_)
| SolverDefId::InternedCoroutineClosureId(_)
| SolverDefId::AnonConstId(_) => {
return VariancesOf::empty(self);
return VariancesOf::empty();
}
};
self.db.variances_of(generic_def)
Expand Down Expand Up @@ -1345,7 +1345,7 @@ impl<'db> Interner for DbInterner<'db> {
let own_bounds: FxHashSet<_> =
self.item_self_bounds(def_id).skip_binder().into_iter().collect();
if all_bounds.len() == own_bounds.len() {
EarlyBinder::bind(Clauses::empty(self))
EarlyBinder::bind(Clauses::empty())
} else {
EarlyBinder::bind(Clauses::new_from_iter(
self,
Expand Down Expand Up @@ -2172,7 +2172,7 @@ impl<'db> Interner for DbInterner<'db> {
};
EarlyBinder::bind(Const::new_unevaluated(
self,
UnevaluatedConst { def: GeneralConstIdWrapper(id), args: GenericArgs::empty(self) },
UnevaluatedConst { def: GeneralConstIdWrapper(id), args: GenericArgs::empty() },
))
}

Expand Down
Loading
Loading