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
469 changes: 217 additions & 252 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ rayon = "1.10.0"
rowan = "=0.15.15"
# Ideally we'd not enable the macros feature but unfortunately the `tracked` attribute does not work
# on impls without it
salsa = { version = "0.23.0", default-features = true, features = [
salsa = { version = "0.24.0", default-features = true, features = [
"rayon",
"salsa_unstable",
"macros",
] }
salsa-macros = "0.23.0"
salsa-macros = "0.24.0"
semver = "1.0.26"
serde = { version = "1.0.219" }
serde_derive = { version = "1.0.219" }
Expand Down
6 changes: 1 addition & 5 deletions crates/cfg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ intern.workspace = true
[dev-dependencies]
expect-test = "1.5.1"
oorandom = "11.1.5"
# We depend on both individually instead of using `features = ["derive"]` to microoptimize the
# build graph: if the feature was enabled, syn would be built early on in the graph if `smolstr`
# supports `arbitrary`. This way, we avoid feature unification.
arbitrary = "1.4.1"
derive_arbitrary = "1.4.1"
arbitrary = { version = "1.4.1", features = ["derive"] }

# local deps
syntax-bridge.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/cfg/src/cfg_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl fmt::Display for CfgAtom {
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(test, derive(derive_arbitrary::Arbitrary))]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arbitrary now enables additional code in the main crate for the derive, so we cannot depend on them separately, unfortunately.

#[cfg_attr(test, derive(arbitrary::Arbitrary))]
pub enum CfgExpr {
Invalid,
Atom(CfgAtom),
Expand Down
5 changes: 2 additions & 3 deletions crates/hir-def/src/test_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use base_db::{
SourceDatabase, SourceRoot, SourceRootId, SourceRootInput,
};
use hir_expand::{InFile, files::FilePosition};
use salsa::{AsDynDatabase, Durability};
use salsa::Durability;
use span::FileId;
use syntax::{AstNode, algo, ast};
use triomphe::Arc;
Expand Down Expand Up @@ -303,8 +303,7 @@ impl TestDB {
// This is pretty horrible, but `Debug` is the only way to inspect
// QueryDescriptor at the moment.
salsa::EventKind::WillExecute { database_key } => {
let ingredient = self
.as_dyn_database()
let ingredient = (self as &dyn salsa::Database)
.ingredient_debug_name(database_key.ingredient_index());
Some(ingredient.to_string())
}
Expand Down
10 changes: 6 additions & 4 deletions crates/hir-ty/src/consteval/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn check_fail(
error: impl FnOnce(ConstEvalError<'_>) -> bool,
) {
let (db, file_id) = TestDB::with_single_file(ra_fixture);
salsa::attach(&db, || match eval_goal(&db, file_id) {
crate::attach_db(&db, || match eval_goal(&db, file_id) {
Ok(_) => panic!("Expected fail, but it succeeded"),
Err(e) => {
assert!(error(simplify(e.clone())), "Actual error was: {}", pretty_print_err(e, &db))
Expand Down Expand Up @@ -79,7 +79,7 @@ fn check_answer(
check: impl FnOnce(&[u8], &MemoryMap<'_>),
) {
let (db, file_ids) = TestDB::with_many_files(ra_fixture);
salsa::attach(&db, || {
crate::attach_db(&db, || {
let file_id = *file_ids.last().unwrap();
let r = match eval_goal(&db, file_id) {
Ok(t) => t,
Expand Down Expand Up @@ -2506,8 +2506,10 @@ fn enums() {
const GOAL: E = E::A;
"#,
);
let r = eval_goal(&db, file_id).unwrap();
assert_eq!(try_const_usize(&db, &r), Some(1));
crate::attach_db(&db, || {
let r = eval_goal(&db, file_id).unwrap();
assert_eq!(try_const_usize(&db, &r), Some(1));
})
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/dyn_compatibility/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn check_dyn_compatibility<'a>(
};
let mut osvs = FxHashSet::default();
let db = &db;
salsa::attach(db, || {
crate::attach_db(db, || {
_ = dyn_compatibility_with_callback(db, trait_id, &mut |osv| {
osvs.insert(match osv {
DynCompatibilityViolation::SizedSelf => SizedSelf,
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/infer/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ fn pointer_kind<'db>(
Ok(Some(PointerKind::Thin))
}
}
TyKind::Tuple(subst) => match subst.iter().last() {
TyKind::Tuple(subst) => match subst.iter().next_back() {
None => Ok(Some(PointerKind::Thin)),
Some(ty) => pointer_kind(ty, ctx),
},
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ fn struct_tail_erasing_lifetimes<'a>(db: &'a dyn HirDatabase, pointee: Ty<'a>) -
}
}
TyKind::Tuple(tys) => {
if let Some(last_field_ty) = tys.iter().last() {
if let Some(last_field_ty) = tys.iter().next_back() {
struct_tail_erasing_lifetimes(db, last_field_ty)
} else {
pointee
Expand Down
53 changes: 29 additions & 24 deletions crates/hir-ty/src/layout/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn eval_goal(
Some(adt_or_type_alias_id)
})
.unwrap();
salsa::attach(&db, || {
crate::attach_db(&db, || {
let interner = DbInterner::new_with(&db, None, None);
let goal_ty = match adt_or_type_alias_id {
Either::Left(adt_id) => crate::next_solver::Ty::new_adt(
Expand Down Expand Up @@ -112,29 +112,34 @@ fn eval_expr(
);

let (db, file_id) = TestDB::with_single_file(&ra_fixture);
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.local_id].scope;
let function_id = scope
.declarations()
.find_map(|x| match x {
hir_def::ModuleDefId::FunctionId(x) => {
let name =
db.function_signature(x).name.display_no_db(file_id.edition(&db)).to_smolstr();
(name == "main").then_some(x)
}
_ => None,
})
.unwrap();
let hir_body = db.body(function_id.into());
let b = hir_body
.bindings()
.find(|x| x.1.name.display_no_db(file_id.edition(&db)).to_smolstr() == "goal")
.unwrap()
.0;
let infer = db.infer(function_id.into());
let goal_ty = infer.type_of_binding[b];
salsa::attach(&db, || db.layout_of_ty(goal_ty, db.trait_environment(function_id.into())))
crate::attach_db(&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.local_id].scope;
let function_id = scope
.declarations()
.find_map(|x| match x {
hir_def::ModuleDefId::FunctionId(x) => {
let name = db
.function_signature(x)
.name
.display_no_db(file_id.edition(&db))
.to_smolstr();
(name == "main").then_some(x)
}
_ => None,
})
.unwrap();
let hir_body = db.body(function_id.into());
let b = hir_body
.bindings()
.find(|x| x.1.name.display_no_db(file_id.edition(&db)).to_smolstr() == "goal")
.unwrap()
.0;
let infer = db.infer(function_id.into());
let goal_ty = infer.type_of_binding[b];
db.layout_of_ty(goal_ty, db.trait_environment(function_id.into()))
})
}

#[track_caller]
Expand Down
1 change: 1 addition & 0 deletions crates/hir-ty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ pub use mapping::{
to_foreign_def_id, to_placeholder_idx, to_placeholder_idx_no_index,
};
pub use method_resolution::check_orphan_rules;
pub use next_solver::interner::{attach_db, attach_db_allow_change, with_attached_db};
pub use target_feature::TargetFeatures;
pub use traits::TraitEnvironment;
pub use utils::{
Expand Down
8 changes: 4 additions & 4 deletions crates/hir-ty/src/mir/eval/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
use super::{MirEvalError, interpret_mir};

fn eval_main(db: &TestDB, file_id: EditionedFileId) -> Result<(String, String), MirEvalError<'_>> {
salsa::attach(db, || {
crate::attach_db(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.local_id].scope;
Expand Down Expand Up @@ -56,7 +56,7 @@ fn check_pass_and_stdio(
) {
let _tracing = setup_tracing();
let (db, file_ids) = TestDB::with_many_files(ra_fixture);
salsa::attach(&db, || {
crate::attach_db(&db, || {
let file_id = *file_ids.last().unwrap();
let x = eval_main(&db, file_id);
match x {
Expand Down Expand Up @@ -102,7 +102,7 @@ fn check_pass_and_stdio(

fn check_panic(#[rust_analyzer::rust_fixture] ra_fixture: &str, expected_panic: &str) {
let (db, file_ids) = TestDB::with_many_files(ra_fixture);
salsa::attach(&db, || {
crate::attach_db(&db, || {
let file_id = *file_ids.last().unwrap();
let e = eval_main(&db, file_id).unwrap_err();
assert_eq!(
Expand All @@ -117,7 +117,7 @@ fn check_error_with(
expect_err: impl FnOnce(MirEvalError<'_>) -> bool,
) {
let (db, file_ids) = TestDB::with_many_files(ra_fixture);
salsa::attach(&db, || {
crate::attach_db(&db, || {
let file_id = *file_ids.last().unwrap();
let e = eval_main(&db, file_id).unwrap_err();
assert!(expect_err(e));
Expand Down
33 changes: 18 additions & 15 deletions crates/hir-ty/src/mir/lower/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,24 @@ fn lower_mir(
) -> FxHashMap<String, Result<Arc<MirBody>, ()>> {
let _tracing = setup_tracing();
let (db, file_ids) = TestDB::with_many_files(ra_fixture);
let file_id = *file_ids.last().unwrap();
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.local_id].scope;
let funcs = scope.declarations().filter_map(|x| match x {
hir_def::ModuleDefId::FunctionId(it) => Some(it),
_ => None,
});
funcs
.map(|func| {
let name = db.function_signature(func).name.display(&db, Edition::CURRENT).to_string();
let mir = db.mir_body(func.into());
(name, mir.map_err(drop))
})
.collect()
crate::attach_db(&db, || {
let file_id = *file_ids.last().unwrap();
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.local_id].scope;
let funcs = scope.declarations().filter_map(|x| match x {
hir_def::ModuleDefId::FunctionId(it) => Some(it),
_ => None,
});
funcs
.map(|func| {
let name =
db.function_signature(func).name.display(&db, Edition::CURRENT).to_string();
let mir = db.mir_body(func.into());
(name, mir.map_err(drop))
})
.collect()
})
}

#[test]
Expand Down
9 changes: 3 additions & 6 deletions crates/hir-ty/src/next_solver/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@ impl<'db> Const<'db> {
}

pub fn inner(&self) -> &WithCachedTypeInfo<ConstKind<'db>> {
salsa::with_attached_database(|db| {
crate::with_attached_db(|db| {
let inner = &self.kind_(db).0;
// SAFETY: The caller already has access to a `Const<'db>`, so borrowchecking will
// make sure that our returned value is valid for the lifetime `'db`.
unsafe { std::mem::transmute(inner) }
})
.unwrap()
}

pub fn error(interner: DbInterner<'db>) -> Self {
Expand Down Expand Up @@ -197,21 +196,19 @@ pub struct Valtree<'db> {

impl<'db> Valtree<'db> {
pub fn new(bytes: ConstBytes<'db>) -> Self {
salsa::with_attached_database(|db| unsafe {
crate::with_attached_db(|db| unsafe {
// SAFETY: ¯\_(ツ)_/¯
std::mem::transmute(Valtree::new_(db, bytes))
})
.unwrap()
}

pub fn inner(&self) -> &ConstBytes<'db> {
salsa::with_attached_database(|db| {
crate::with_attached_db(|db| {
let inner = self.bytes_(db);
// SAFETY: The caller already has access to a `Valtree<'db>`, so borrowchecking will
// make sure that our returned value is valid for the lifetime `'db`.
unsafe { std::mem::transmute(inner) }
})
.unwrap()
}
}

Expand Down
Loading