Skip to content

Commit

Permalink
Merge pull request #1050 from sbillig/salsa-update
Browse files Browse the repository at this point in the history
Bump salsa to latest (includes accumulator bugfix), and use salsa::tracked methods instead of separate _impl fns
  • Loading branch information
micahscopes authored Jan 27, 2025
2 parents 1469529 + f975424 commit 93f181d
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 235 deletions.
14 changes: 11 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dir-test = "0.4"
rustc-hash = "2.1.0"
num-bigint = "0.4"
paste = "1.0.15"
salsa = { git = "https://github.com/salsa-rs/salsa", rev = "e4d65a656fc68d0fb759b292ceae2aff2c785c5d" }
salsa = { git = "https://github.com/salsa-rs/salsa", rev = "d32b3c1995b632d894250a667adb79c846b3da02" }
smallvec = { version = "1.13.2", features = ["union"] }
wasm-bindgen-test = "0.3"
glob = "0.3.2"
Expand Down
41 changes: 17 additions & 24 deletions crates/hir-analysis/src/ty/ty_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ pub struct TyId<'db> {
pub data: TyData<'db>,
}

#[salsa::tracked]
impl<'db> TyId<'db> {
/// Returns the kind of the type.
pub fn kind(self, db: &'db dyn HirAnalysisDb) -> &'db Kind {
ty_kind(db, self)
#[salsa::tracked(return_ref)]
pub fn kind(self, db: &'db dyn HirAnalysisDb) -> Kind {
self.data(db).kind(db)
}

/// Returns the current arguments of the type.
Expand Down Expand Up @@ -133,8 +135,17 @@ impl<'db> TyId<'db> {
!matches!(self.kind(db), Kind::Abs(_, _))
}

pub fn pretty_print(self, db: &'db dyn HirAnalysisDb) -> &'db str {
pretty_print_ty(db, self)
#[salsa::tracked(return_ref)]
pub fn pretty_print(self, db: &'db dyn HirAnalysisDb) -> String {
match self.data(db) {
TyData::TyVar(var) => var.pretty_print(),
TyData::TyParam(param) => param.pretty_print(db),
TyData::TyApp(_, _) => pretty_print_ty_app(db, self),
TyData::TyBase(ty_con) => ty_con.pretty_print(db),
TyData::ConstTy(const_ty) => const_ty.pretty_print(db),
TyData::Never => "!".to_string(),
TyData::Invalid(..) => "<invalid>".to_string(),
}
}

pub fn is_inherent_impl_allowed(self, db: &dyn HirAnalysisDb, ingot: IngotId) -> bool {
Expand Down Expand Up @@ -610,11 +621,6 @@ pub struct ApplicableTyProp<'db> {
pub const_ty: Option<TyId<'db>>,
}

#[salsa::tracked(return_ref)]
pub fn ty_kind<'db>(db: &'db dyn HirAnalysisDb, ty: TyId<'db>) -> Kind {
ty.data(db).kind(db)
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum TyData<'db> {
/// Type variable.
Expand Down Expand Up @@ -1084,7 +1090,7 @@ impl HasKind for AdtDef<'_> {
fn kind(&self, db: &dyn HirAnalysisDb) -> Kind {
let mut kind = Kind::Star;
for param in self.params(db).iter().rev() {
kind = Kind::abs(ty_kind(db, *param).clone(), kind);
kind = Kind::abs(param.kind(db).clone(), kind);
}

kind
Expand All @@ -1095,7 +1101,7 @@ impl HasKind for FuncDef<'_> {
fn kind(&self, db: &dyn HirAnalysisDb) -> Kind {
let mut kind = Kind::Star;
for param in self.params(db).iter().rev() {
kind = Kind::abs(ty_kind(db, *param).clone(), kind);
kind = Kind::abs(param.kind(db).clone(), kind);
}

kind
Expand Down Expand Up @@ -1164,19 +1170,6 @@ where
collector.keys
}

#[salsa::tracked(return_ref)]
pub(crate) fn pretty_print_ty<'db>(db: &'db dyn HirAnalysisDb, ty: TyId<'db>) -> String {
match ty.data(db) {
TyData::TyVar(var) => var.pretty_print(),
TyData::TyParam(param) => param.pretty_print(db),
TyData::TyApp(_, _) => pretty_print_ty_app(db, ty),
TyData::TyBase(ty_con) => ty_con.pretty_print(db),
TyData::ConstTy(const_ty) => const_ty.pretty_print(db),
TyData::Never => "!".to_string(),
TyData::Invalid(..) => "<invalid>".to_string(),
}
}

fn pretty_print_ty_app<'db>(db: &'db dyn HirAnalysisDb, ty: TyId<'db>) -> String {
use PrimTy::*;
use TyBase::*;
Expand Down
Loading

0 comments on commit 93f181d

Please sign in to comment.