Skip to content
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

[red-knot]: Add a VendoredFileSystem implementation #11863

Merged
merged 43 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
41a1aff
Refactor `file` and `vendored` methods and make them standalone funct…
MichaReiser Jun 10, 2024
d3c8e83
Make `file_system_path_to_file` return an Option
MichaReiser Jun 10, 2024
1a69745
Improve documentation, rewrite inline comment, rename `file_system_pa…
MichaReiser Jun 13, 2024
43fa7bf
Update crates/ruff_db/src/vfs.rs
MichaReiser Jun 13, 2024
b054315
Don't use non-platform agnostic `is_absolute` method
MichaReiser Jun 13, 2024
383691e
Add `ModuleName` struct with tests
MichaReiser Jun 10, 2024
5a1da62
Module resolver
MichaReiser Jun 10, 2024
01041cd
Port module resolver to salsa
MichaReiser Jun 11, 2024
f16c045
Add `remove_file` and `remove_directory` tests
MichaReiser Jun 11, 2024
56f2caf
Suppress warning about unused `Os` file system that are only used on …
MichaReiser Jun 11, 2024
bcaea19
Change `ModuleName::new` to return an `Option`
MichaReiser Jun 13, 2024
4df3bea
Use `touch` over `set_permission` and `set_revision` in Tests
MichaReiser Jun 13, 2024
4441c9e
[red-knot]: Add a `VendoredFileSystem` implementation
AlexWaygood Jun 13, 2024
ae49c71
Fix many easily addressed review comments
AlexWaygood Jun 14, 2024
bd94c60
More relatively easily addressed comments
AlexWaygood Jun 14, 2024
43e3626
Just use the file hash for `FileRevision`
AlexWaygood Jun 14, 2024
13ee2d2
simplify
AlexWaygood Jun 14, 2024
05846ae
Refactor `file` and `vendored` methods and make them standalone funct…
MichaReiser Jun 10, 2024
88a6aa4
Make `file_system_path_to_file` return an Option
MichaReiser Jun 10, 2024
64b67ef
Improve documentation, rewrite inline comment, rename `file_system_pa…
MichaReiser Jun 13, 2024
cbb8992
Update crates/ruff_db/src/vfs.rs
MichaReiser Jun 13, 2024
00477c7
Add `ModuleName` struct with tests
MichaReiser Jun 10, 2024
de1ec29
Module resolver
MichaReiser Jun 10, 2024
92b3465
Port module resolver to salsa
MichaReiser Jun 11, 2024
2ee6973
Add `remove_file` and `remove_directory` tests
MichaReiser Jun 11, 2024
96d75a7
Suppress warning about unused `Os` file system that are only used on …
MichaReiser Jun 11, 2024
e5e8da6
Change `ModuleName::new` to return an `Option`
MichaReiser Jun 13, 2024
2348fe6
Use `touch` over `set_permission` and `set_revision` in Tests
MichaReiser Jun 13, 2024
eea6023
Merge branch 'salsa-memory-resolver' into vendored-filesystem
AlexWaygood Jun 14, 2024
07e5a80
Reduce clones and make them more explicit
AlexWaygood Jun 15, 2024
514e9b6
Use interior mutability to avoid cloning when unnecessary
AlexWaygood Jun 15, 2024
1f68832
Do not implement `FileSystem`
AlexWaygood Jun 16, 2024
035ea53
Simplify normalization logic
AlexWaygood Jun 17, 2024
5c33610
Update crates/ruff_db/src/vendored.rs
AlexWaygood Jun 17, 2024
ecf97a9
Get rid of unneeded methods
AlexWaygood Jun 17, 2024
be8f952
Return `Result` from `read()`
AlexWaygood Jun 17, 2024
f4f97d4
Replace a wrapper type with a type alias
AlexWaygood Jun 17, 2024
df248ce
fix tests
AlexWaygood Jun 17, 2024
f05bcb2
Bring back some notion of vendored-stub-file "metadata"
AlexWaygood Jun 17, 2024
89ebc91
Merge remote-tracking branch 'upstream/main' into vendored-filesystem
AlexWaygood Jun 18, 2024
13c2802
add some newlines
AlexWaygood Jun 18, 2024
5d511bb
More docs etc.
AlexWaygood Jun 18, 2024
3127ff6
See if bumping `zstd-sys` changes anything
AlexWaygood Jun 18, 2024
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
Prev Previous commit
Next Next commit
Improve documentation, rewrite inline comment, rename `file_system_pa…
…th_to_file`
  • Loading branch information
MichaReiser committed Jun 14, 2024
commit 64b67efc1fc2378e3d93b59a7ca85f5110b75cfb
6 changes: 3 additions & 3 deletions crates/ruff_db/src/parsed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ mod tests {
use crate::parsed::parsed_module;
use crate::tests::TestDb;
use crate::vfs::VendoredPath;
use crate::vfs::{file_system_path_to_file, vendored_path_to_file};
use crate::vfs::{system_path_to_file, vendored_path_to_file};

#[test]
fn python_file() -> crate::file_system::Result<()> {
Expand All @@ -80,7 +80,7 @@ mod tests {
db.file_system_mut()
.write_file(path, "x = 10".to_string())?;

let file = file_system_path_to_file(&db, path).unwrap();
let file = system_path_to_file(&db, path).unwrap();

let parsed = parsed_module(&db, file);

Expand All @@ -97,7 +97,7 @@ mod tests {
db.file_system_mut()
.write_file(path, "%timeit a = b".to_string())?;

let file = file_system_path_to_file(&db, path).unwrap();
let file = system_path_to_file(&db, path).unwrap();

let parsed = parsed_module(&db, file);

Expand Down
8 changes: 4 additions & 4 deletions crates/ruff_db/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ mod tests {
use crate::file_system::FileSystemPath;
use crate::source::{line_index, source_text};
use crate::tests::TestDb;
use crate::vfs::file_system_path_to_file;
use crate::vfs::system_path_to_file;

#[test]
fn re_runs_query_when_file_revision_changes() -> crate::file_system::Result<()> {
Expand All @@ -73,7 +73,7 @@ mod tests {
db.file_system_mut()
.write_file(path, "x = 10".to_string())?;

let file = file_system_path_to_file(&db, path).unwrap();
let file = system_path_to_file(&db, path).unwrap();

assert_eq!(&*source_text(&db, file), "x = 10");

Expand All @@ -95,7 +95,7 @@ mod tests {
db.file_system_mut()
.write_file(path, "x = 10".to_string())?;

let file = file_system_path_to_file(&db, path).unwrap();
let file = system_path_to_file(&db, path).unwrap();

assert_eq!(&*source_text(&db, file), "x = 10");

Expand All @@ -122,7 +122,7 @@ mod tests {
db.file_system_mut()
.write_file(path, "x = 10\ny = 20".to_string())?;

let file = file_system_path_to_file(&db, path).unwrap();
let file = system_path_to_file(&db, path).unwrap();
let index = line_index(&db, file);
let text = source_text(&db, file);

Expand Down
22 changes: 11 additions & 11 deletions crates/ruff_db/src/vfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ mod path;
///
/// Returns `None` if the path doesn't exist, isn't accessible, or if the path points to a directory.
#[inline]
pub fn file_system_path_to_file(db: &dyn Db, path: impl AsRef<FileSystemPath>) -> Option<VfsFile> {
pub fn system_path_to_file(db: &dyn Db, path: impl AsRef<FileSystemPath>) -> Option<VfsFile> {
let file = db.vfs().file_system(db, path.as_ref());

// Query the status of the file to determine if it exists.
// It's important that the `.file_system` method always returns a file and that the status is queried here
// to ensure that salsa knows which queries depend on the existence of this file, even if it doesn't exist
// yet or doesn't exist anymore.
// It's important that `vfs.file_system` creates a `VfsFile` even for files that don't exist or don't
// exist anymore so that Salsa can track that the caller of this function depends on the existence of
// that file. This function filters out file that don't exist, but Salsa will know that it must
// re-run the calling query whenever the `file`'s status changes (because of the `.status` call here).
match file.status(db) {
FileStatus::Exists => Some(file),
FileStatus::Deleted => None,
}
}

/// Interns a vendored file path. Returns `None` if no such vendored file exists and `Some` otherwise.
/// Interns a vendored file path. Returns `Some` if the vendored file for `path` exists and `None` otherwise.
#[inline]
pub fn vendored_path_to_file(db: &dyn Db, path: impl AsRef<VendoredPath>) -> Option<VfsFile> {
db.vfs().vendored(db, path.as_ref())
Expand All @@ -38,11 +38,11 @@ pub fn vendored_path_to_file(db: &dyn Db, path: impl AsRef<VendoredPath>) -> Opt
///
/// Returns `Some` if a file for `path` exists and is accessible by the user. Returns `None` otherwise.
///
/// See [`file_system_path_to_file`] and [`vendored_path_to_file`] if you always have either a file system or vendored path.
/// See [`system_path_to_file`] and [`vendored_path_to_file`] if you always have either a file system or vendored path.
#[inline]
pub fn vfs_path_to_file(db: &dyn Db, path: &VfsPath) -> Option<VfsFile> {
match path {
VfsPath::FileSystem(path) => file_system_path_to_file(db, path),
VfsPath::FileSystem(path) => system_path_to_file(db, path),
VfsPath::Vendored(path) => vendored_path_to_file(db, path),
}
}
Expand Down Expand Up @@ -303,7 +303,7 @@ mod private {
mod tests {
use crate::file_system::FileRevision;
use crate::tests::TestDb;
use crate::vfs::{file_system_path_to_file, vendored_path_to_file};
use crate::vfs::{system_path_to_file, vendored_path_to_file};

#[test]
fn file_system_existing_file() -> crate::file_system::Result<()> {
Expand All @@ -312,7 +312,7 @@ mod tests {
db.file_system_mut()
.write_files([("test.py", "print('Hello world')")])?;

let test = file_system_path_to_file(&db, "test.py").expect("File to exist.");
let test = system_path_to_file(&db, "test.py").expect("File to exist.");

assert_eq!(test.permissions(&db), Some(0o755));
assert_ne!(test.revision(&db), FileRevision::zero());
Expand All @@ -325,7 +325,7 @@ mod tests {
fn file_system_non_existing_file() {
let db = TestDb::new();

let test = file_system_path_to_file(&db, "test.py");
let test = system_path_to_file(&db, "test.py");

assert_eq!(test, None);
}
Expand Down