Skip to content

Bump salsa #19923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
438 changes: 218 additions & 220 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ debug = 2

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

# salsa = { path = "../salsa" }
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
2 changes: 1 addition & 1 deletion crates/base-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ macro_rules! impl_intern_key {
impl ::std::fmt::Debug for $id {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
f.debug_tuple(stringify!($id))
.field(&format_args!("{:04x}", self.0.as_u32()))
.field(&format_args!("{:04x}", self.0.index()))
.finish()
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-def/src/expr_store/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub enum Path {
// This type is being used a lot, make sure it doesn't grow unintentionally.
#[cfg(target_arch = "x86_64")]
const _: () = {
assert!(size_of::<Path>() == 16);
assert!(size_of::<Option<Path>>() == 16);
assert!(size_of::<Path>() == 24);
assert!(size_of::<Option<Path>>() == 24);
};

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/hir/type_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub enum TypeRef {
}

#[cfg(target_arch = "x86_64")]
const _: () = assert!(size_of::<TypeRef>() == 16);
const _: () = assert!(size_of::<TypeRef>() == 24);

pub type TypeRefId = Idx<TypeRef>;

Expand Down
35 changes: 24 additions & 11 deletions crates/hir-ty/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,6 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
#[salsa::interned]
fn intern_callable_def(&self, callable_def: CallableDefId) -> InternedCallableDefId;

#[salsa::interned]
fn intern_type_or_const_param_id(
&self,
param_id: TypeOrConstParamId,
) -> InternedTypeOrConstParamId;

#[salsa::interned]
fn intern_lifetime_param_id(&self, param_id: LifetimeParamId) -> InternedLifetimeParamId;

#[salsa::interned]
fn intern_impl_trait_id(&self, id: ImplTraitId) -> InternedOpaqueTyId;

Expand Down Expand Up @@ -332,9 +323,31 @@ fn hir_database_is_dyn_compatible() {
fn _assert_dyn_compatible(_: &dyn HirDatabase) {}
}

impl_intern_key!(InternedTypeOrConstParamId, TypeOrConstParamId);
#[salsa_macros::interned(no_lifetime, revisions = usize::MAX)]
#[derive(PartialOrd, Ord)]
pub struct InternedTypeOrConstParamId {
pub loc: TypeOrConstParamId,
}
impl ::std::fmt::Debug for InternedTypeOrConstParamId {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
f.debug_tuple(stringify!(InternedTypeOrConstParamId))
.field(&format_args!("{:04x}", self.0.index()))
.finish()
}
}

impl_intern_key!(InternedLifetimeParamId, LifetimeParamId);
#[salsa_macros::interned(no_lifetime, revisions = usize::MAX)]
#[derive(PartialOrd, Ord)]
pub struct InternedLifetimeParamId {
pub loc: LifetimeParamId,
}
impl ::std::fmt::Debug for InternedLifetimeParamId {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
f.debug_tuple(stringify!(InternedLifetimeParamId))
.field(&format_args!("{:04x}", self.0.index()))
.finish()
}
}

impl_intern_key!(InternedConstParamId, ConstParamId);

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 @@ -1432,10 +1432,10 @@ impl HirDisplay for Ty {
match f.closure_style {
ClosureStyle::Hide => return write!(f, "{TYPE_HINT_TRUNCATION}"),
ClosureStyle::ClosureWithId => {
return write!(f, "{{closure#{:?}}}", id.0.as_u32());
return write!(f, "{{closure#{:?}}}", id.0.index());
}
ClosureStyle::ClosureWithSubst => {
write!(f, "{{closure#{:?}}}", id.0.as_u32())?;
write!(f, "{{closure#{:?}}}", id.0.index())?;
return hir_fmt_generics(f, substs.as_slice(Interner), None, None);
}
_ => (),
Expand Down
21 changes: 12 additions & 9 deletions crates/hir-ty/src/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use salsa::{

use crate::{
AssocTypeId, CallableDefId, ChalkTraitId, FnDefId, ForeignDefId, Interner, OpaqueTyId,
PlaceholderIndex, chalk_db, db::HirDatabase,
PlaceholderIndex, chalk_db,
db::{HirDatabase, InternedLifetimeParamId, InternedTypeOrConstParamId},
};

pub(crate) trait ToChalk {
Expand Down Expand Up @@ -137,30 +138,32 @@ pub fn from_assoc_type_id(id: AssocTypeId) -> TypeAliasId {
pub fn from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> TypeOrConstParamId {
assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT);
// SAFETY: We cannot really encapsulate this unfortunately, so just hope this is sound.
let interned_id = FromId::from_id(unsafe { Id::from_u32(idx.idx.try_into().unwrap()) });
db.lookup_intern_type_or_const_param_id(interned_id)
let interned_id =
InternedTypeOrConstParamId::from_id(unsafe { Id::from_index(idx.idx.try_into().unwrap()) });
interned_id.loc(db)
}

pub fn to_placeholder_idx(db: &dyn HirDatabase, id: TypeOrConstParamId) -> PlaceholderIndex {
let interned_id = db.intern_type_or_const_param_id(id);
let interned_id = InternedTypeOrConstParamId::new(db, id);
PlaceholderIndex {
ui: chalk_ir::UniverseIndex::ROOT,
idx: interned_id.as_id().as_u32() as usize,
idx: interned_id.as_id().index() as usize,
}
}

pub fn lt_from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> LifetimeParamId {
assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT);
// SAFETY: We cannot really encapsulate this unfortunately, so just hope this is sound.
let interned_id = FromId::from_id(unsafe { Id::from_u32(idx.idx.try_into().unwrap()) });
db.lookup_intern_lifetime_param_id(interned_id)
let interned_id =
InternedLifetimeParamId::from_id(unsafe { Id::from_index(idx.idx.try_into().unwrap()) });
interned_id.loc(db)
}

pub fn lt_to_placeholder_idx(db: &dyn HirDatabase, id: LifetimeParamId) -> PlaceholderIndex {
let interned_id = db.intern_lifetime_param_id(id);
let interned_id = InternedLifetimeParamId::new(db, id);
PlaceholderIndex {
ui: chalk_ir::UniverseIndex::ROOT,
idx: interned_id.as_id().as_u32() as usize,
idx: interned_id.as_id().index() as usize,
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/ide-db/src/prime_caches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,5 @@ fn crate_name(db: &RootDatabase, krate: Crate) -> Symbol {
.display_name
.as_deref()
.cloned()
.unwrap_or_else(|| Symbol::integer(salsa::plumbing::AsId::as_id(&krate).as_u32() as usize))
.unwrap_or_else(|| Symbol::integer(salsa::plumbing::AsId::as_id(&krate).index() as usize))
}
2 changes: 1 addition & 1 deletion crates/ide/src/view_crate_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<'a> dot::Labeller<'a, Crate, Edge<'a>> for DotCrateGraph<'_> {
}

fn node_id(&'a self, n: &Crate) -> Id<'a> {
let id = n.as_id().as_u32();
let id = n.as_id().index();
Id::new(format!("_{id:?}")).unwrap()
}

Expand Down
5 changes: 1 addition & 4 deletions crates/rust-analyzer/src/handlers/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{

use ide_db::base_db::{
DbPanicContext,
salsa::{self, Cancelled, UnexpectedCycle},
salsa::{self, Cancelled},
};
use lsp_server::{ExtractError, Response, ResponseError};
use serde::{Serialize, de::DeserializeOwned};
Expand Down Expand Up @@ -350,9 +350,6 @@ where
if let Some(panic_message) = panic_message {
message.push_str(": ");
message.push_str(panic_message);
} else if let Some(cycle) = panic.downcast_ref::<UnexpectedCycle>() {
tracing::error!("{cycle}");
message.push_str(": unexpected cycle");
} else if let Ok(cancelled) = panic.downcast::<Cancelled>() {
tracing::error!("Cancellation propagated out of salsa! This is a bug");
return Err(HandlerCancelledError::Inner(*cancelled));
Expand Down
5 changes: 3 additions & 2 deletions crates/span/src/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const _: () = {
const LOCATION: salsa::plumbing::Location =
salsa::plumbing::Location { file: file!(), line: line!() };
const DEBUG_NAME: &'static str = "SyntaxContextData";
const REVISIONS: std::num::NonZeroUsize = std::num::NonZeroUsize::MAX;
type Fields<'a> = SyntaxContextData;
type Struct<'a> = SyntaxContext;
}
Expand Down Expand Up @@ -326,14 +327,14 @@ impl<'db> SyntaxContext {
None
} else {
// SAFETY: By our invariant, this is either a root (which we verified it's not) or a valid `salsa::Id`.
unsafe { Some(salsa::Id::from_u32(self.0)) }
unsafe { Some(salsa::Id::from_index(self.0)) }
}
}

#[inline]
fn from_salsa_id(id: salsa::Id) -> Self {
// SAFETY: This comes from a Salsa ID.
unsafe { Self::from_u32(id.as_u32()) }
unsafe { Self::from_u32(id.index()) }
}

#[inline]
Expand Down
Loading