Skip to content

Commit

Permalink
Rename File to VfsFile, remove FileSystem, too many unknowns
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Jun 10, 2024
1 parent 70b3285 commit 8cd8e6d
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 444 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

102 changes: 0 additions & 102 deletions crates/ruff_db/src/file.rs

This file was deleted.

40 changes: 14 additions & 26 deletions crates/ruff_db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,24 @@ use std::hash::BuildHasherDefault;
use rustc_hash::FxHasher;
use salsa::DbWithJar;

pub use file::{File, FileStatus, Files};
use crate::vfs::VfsFile;

use crate::vfs::{Vfs, VfsPath};

mod file;
pub mod vfs;

pub(crate) type FxDashMap<K, V> = dashmap::DashMap<K, V, BuildHasherDefault<FxHasher>>;

#[salsa::jar(db=Db)]
pub struct Jar(File);
pub struct Jar(VfsFile);

pub trait Db: DbWithJar<Jar> {
/// Returns the virtual filesystem used by the database to read files.
fn vfs(&self) -> &dyn Vfs;

/// Interns a file path and returns a salsa `File` ingredient.
///
/// The operation is guaranteed to always succeed, even if the path doesn't exist, isn't accessible, or if the path points to a directory.
/// In these cases, a file with status [`FileStatus::Deleted`] is returned.
fn file(&self, path: VfsPath) -> File;
fn file(&self, path: &camino::Utf8Path) -> VfsFile;

/// Interns a path to a vendored file and returns a salsa `File` ingredient.
fn vendored_file(&self, path: &camino::Utf8Path) -> Option<VfsFile>;
}

/// Trait for upcasting a reference to a base trait object.
Expand All @@ -33,43 +30,35 @@ pub trait Upcast<T: ?Sized> {

#[cfg(test)]
mod tests {
use crate::vfs::{MemoryFs, Vfs, VfsPath};
use crate::{Db, File, Files, Jar};
use crate::vfs::Vfs;
use crate::{Db, Jar, VfsFile};

/// Database that can be used for testing.
///
/// Uses an in memory filesystem.
#[salsa::db(Jar)]
pub struct TestDb {
storage: salsa::Storage<Self>,
files: Files,
vfs: MemoryFs,
vfs: Vfs,
}

impl TestDb {
#[allow(unused)]
pub fn new() -> Self {
Self {
storage: salsa::Storage::default(),
files: Files::default(),
vfs: MemoryFs::default(),
vfs: Vfs::default(),
}
}

/// Gives mutable access to the in memory filesystem.
#[allow(unused)]
pub fn vfs_mut(&mut self) -> &mut MemoryFs {
&mut self.vfs
}
}

impl Db for TestDb {
fn vfs(&self) -> &dyn Vfs {
&self.vfs
fn file(&self, path: &camino::Utf8Path) -> VfsFile {
self.vfs.fs(self, path)
}

fn file(&self, path: VfsPath) -> File {
self.files.lookup(self, path)
fn vendored_file(&self, path: &camino::Utf8Path) -> Option<VfsFile> {
self.vfs.vendored(self, path)
}
}

Expand All @@ -79,7 +68,6 @@ mod tests {
fn snapshot(&self) -> salsa::Snapshot<Self> {
salsa::Snapshot::new(Self {
storage: self.storage.snapshot(),
files: self.files.snapshot(),
vfs: self.vfs.snapshot(),
})
}
Expand Down
Loading

0 comments on commit 8cd8e6d

Please sign in to comment.