Skip to content
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
27 changes: 9 additions & 18 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ debug = 2

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

# salsa = { path = "../salsa" }
# salsa-macros = { path = "../salsa/components/salsa-macros" }
# salsa-macro-rules = { path = "../salsa/components/salsa-macro-rules" }
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 Expand Up @@ -139,7 +139,7 @@ salsa = { version = "0.27.0", default-features = false, features = [
"rayon",
"salsa_unstable",
"macros",
"inventory",
"inventory","triomphe"
] }
salsa-macros = "0.27.0"
semver = "1.0.26"
Expand Down
57 changes: 12 additions & 45 deletions crates/base-db/src/editioned_file_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,24 @@ pub struct EditionedFileId {
field: span::EditionedFileId,
}

// Currently does not work due to a salsa bug
// #[salsa::tracked]
// impl EditionedFileId {
// #[salsa::tracked(lru = 128)]
// pub fn parse(self, db: &dyn SourceDatabase) -> syntax::Parse<ast::SourceFile> {
// let _p = tracing::info_span!("parse", ?self).entered();
// let (file_id, edition) = self.unpack(db);
// let text = db.file_text(file_id).text(db);
// ast::SourceFile::parse(text, edition)
// }

// // firewall query
// #[salsa::tracked(returns(as_deref))]
// pub fn parse_errors(self, db: &dyn SourceDatabase) -> Option<Box<[SyntaxError]>> {
// let errors = self.parse(db).errors();
// match &*errors {
// [] => None,
// [..] => Some(errors.into()),
// }
// }
// }

#[salsa::tracked]
impl EditionedFileId {
#[salsa::tracked(lru = 128)]
pub fn parse(self, db: &dyn SourceDatabase) -> syntax::Parse<ast::SourceFile> {
#[salsa::tracked(lru = 128)]
pub fn parse(
db: &dyn SourceDatabase,
file_id: EditionedFileId,
) -> syntax::Parse<ast::SourceFile> {
let _p = tracing::info_span!("parse", ?file_id).entered();
let (file_id, edition) = file_id.unpack(db);
let text = db.file_text(file_id).text(db);
ast::SourceFile::parse(text, edition)
}
parse(db, self)
let _p = tracing::info_span!("parse", ?self).entered();
let (file_id, edition) = self.unpack(db);
let text = db.file_text(file_id).text(db);
ast::SourceFile::parse(text, edition)
}

// firewall query
pub fn parse_errors(self, db: &dyn SourceDatabase) -> Option<&[SyntaxError]> {
#[salsa::tracked(returns(as_deref))]
pub fn parse_errors(
db: &dyn SourceDatabase,
file_id: EditionedFileId,
) -> Option<Box<[SyntaxError]>> {
let errors = file_id.parse(db).errors();
match &*errors {
[] => None,
[..] => Some(errors.into()),
}
#[salsa::tracked(returns(as_deref))]
pub fn parse_errors(self, db: &dyn SourceDatabase) -> Option<Box<[SyntaxError]>> {
let errors = self.parse(db).errors();
match &*errors {
[] => None,
[..] => Some(errors.into()),
}
parse_errors(db, self)
}
}

Expand Down
59 changes: 35 additions & 24 deletions crates/base-db/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
//! base_db defines basic database traits. The concrete DB is defined by ide.
// FIXME: Rename this crate, base db is non descriptive

#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]

#[cfg(feature = "in-rust-tree")]
extern crate rustc_driver as _;

pub use salsa;
pub mod salsa {
pub use salsa::*;

// Adjusted from `salsa::update_fallback` to work with database owned T
/// "Fallback" for maybe-update that is suitable for database owned T
/// that implement `Eq`. In this version, we update only if the new value
/// is not `Eq` to the old one. Note that given `Eq` impls that are not just
/// structurally comparing fields, this may cause us not to update even if
/// the value has changed (presumably because this change is not semantically
/// significant).
///
/// # Safety
///
/// See `Update::maybe_update`, additionally, `'db` is required to be `'static` or the lifetime
/// of the database `T` belongs to.
pub unsafe fn update_fallback_db<'db, T>(old_pointer: *mut T, new_value: T) -> bool
where
T: 'db + PartialEq,
{
// SAFETY: Because everything is owned, this ref is simply a valid `&mut`
let old_ref: &mut T = unsafe { &mut *old_pointer };

if *old_ref != new_value {
*old_ref = new_value;
true
} else {
// Subtle but important: Eq impls can be buggy or define equality
// in surprising ways. If it says that the value has not changed,
// we do not modify the existing value, and thus do not have to
// update the revision, as downstream code will not see the new value.
false
}
}
}
pub use salsa_macros;
use span::TextSize;

// FIXME: Rename this crate, base db is non descriptive
mod change;
mod editioned_file_id;
mod input;
Expand Down Expand Up @@ -65,28 +98,6 @@ macro_rules! impl_intern_key {
};
}

/// # SAFETY
///
/// `old_pointer` must be valid for unique writes
pub unsafe fn unsafe_update_eq<T>(old_pointer: *mut T, new_value: T) -> bool
where
T: PartialEq,
{
// SAFETY: Caller obligation
let old_ref: &mut T = unsafe { &mut *old_pointer };

if *old_ref != new_value {
*old_ref = new_value;
true
} else {
// Subtle but important: Eq impls can be buggy or define equality
// in surprising ways. If it says that the value has not changed,
// we do not modify the existing value, and thus do not have to
// update the revision, as downstream code will not see the new value.
false
}
}

pub const DEFAULT_FILE_TEXT_LRU_CAP: u16 = 16;
pub const DEFAULT_PARSE_LRU_CAP: u16 = 128;
pub const DEFAULT_BORROWCK_LRU_CAP: u16 = 2024;
Expand Down
14 changes: 7 additions & 7 deletions crates/hir-ty/src/autoderef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ impl<'db> AutoderefCtx<'db> for DefaultAutoderefCtx<'_, 'db> {
}
}

pub(crate) struct InferenceContextAutoderefCtx<'a, 'b, 'db>(&'a mut InferenceContext<'b, 'db>);
impl<'db> AutoderefCtx<'db> for InferenceContextAutoderefCtx<'_, '_, 'db> {
pub(crate) struct InferenceContextAutoderefCtx<'a, 'db>(&'a mut InferenceContext<'db>);
impl<'db> AutoderefCtx<'db> for InferenceContextAutoderefCtx<'_, 'db> {
#[inline]
fn infcx(&self) -> &InferCtxt<'db> {
&self.0.table.infer_ctxt
Expand Down Expand Up @@ -160,8 +160,8 @@ pub(crate) struct GeneralAutoderef<'db, Ctx, Steps = Vec<(Ty<'db>, AutoderefKind

pub(crate) type Autoderef<'a, 'db, Steps = Vec<(Ty<'db>, AutoderefKind)>> =
GeneralAutoderef<'db, DefaultAutoderefCtx<'a, 'db>, Steps>;
pub(crate) type InferenceContextAutoderef<'a, 'b, 'db, Steps = Vec<(Ty<'db>, AutoderefKind)>> =
GeneralAutoderef<'db, InferenceContextAutoderefCtx<'a, 'b, 'db>, Steps>;
pub(crate) type InferenceContextAutoderef<'a, 'db, Steps = Vec<(Ty<'db>, AutoderefKind)>> =
GeneralAutoderef<'db, InferenceContextAutoderefCtx<'a, 'db>, Steps>;

impl<'db, Ctx, Steps> Iterator for GeneralAutoderef<'db, Ctx, Steps>
where
Expand Down Expand Up @@ -239,18 +239,18 @@ impl<'a, 'db> Autoderef<'a, 'db> {
}
}

impl<'a, 'b, 'db> InferenceContextAutoderef<'a, 'b, 'db> {
impl<'a, 'db> InferenceContextAutoderef<'a, 'db> {
#[inline]
pub(crate) fn new_from_inference_context(
ctx: &'a mut InferenceContext<'b, 'db>,
ctx: &'a mut InferenceContext<'db>,
base_ty: Ty<'db>,
span: Span,
) -> Self {
Self::new_impl(InferenceContextAutoderefCtx(ctx), base_ty, span)
}

#[inline]
pub(crate) fn ctx(&mut self) -> &mut InferenceContext<'b, 'db> {
pub(crate) fn ctx(&mut self) -> &mut InferenceContext<'db> {
self.ctx.0
}
}
Expand Down
Loading
Loading