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[salsa part 2]: Setup semantic DB and Jar #11837

Merged
merged 5 commits into from
Jun 13, 2024

Conversation

MichaReiser
Copy link
Member

Summary

This PR sets up an empty Salsa Jar and Db. This is mostly boring template code but I thought it's worth separating it form an actual interesting PR ;)

Test Plan

cargo build

@MichaReiser MichaReiser changed the base branch from main to salsa-files-vfs June 11, 2024 14:07
@MichaReiser MichaReiser added the red-knot Multi-file analysis & type inference label Jun 11, 2024
Copy link
Contributor

github-actions bot commented Jun 11, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@MichaReiser MichaReiser force-pushed the salsa-2-semantic-jar branch 2 times, most recently from 2138b7b to b81e1f3 Compare June 12, 2024 06:47
Base automatically changed from salsa-files-vfs to main June 12, 2024 07:06
Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still have some concerns about having this code just mixed in directly with the rest of the modules in ruff_python_semantic and using only features to distinguish what is red-knot, but otherwise this PR looks fine, and I assume we will revisit that structure as follow-up, not on this PR, for rebase-conflict reasons.

Comment on lines +79 to +80
db.file_system_mut().write_file(path, "x = 20".to_string());
file.set_revision(&mut db).to(FileTime::now().into());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's surprising to me that we have to manually update the revision here; should write_file do that itself?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FileSystem that I have in mind should be independent of the vfs and salsa db. It's just an abstraction over std::fs. What I have in mind to avoid the set_revision call here is that we have an apply_changes method where we pass all file changes (adds, remove, modified) that updates the vfs state. It's probably the FileSystem's or the host's responsibility to collect all made changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, and would address my concern: I don't want to expose/use APIs that make it easy to change a file's contents but forget to bump its revision.

I think this also gets back to what I find confusing about the Vfs and FileSystem structure, which is that there is no single entity which really encapsulates our virtual file system. Where does this apply_changes method live? I guess it is just a free function that takes a Db and some changes to apply?

Probably this is just something I have to get used to with Salsa, that the Db owns all the state, so most API that we use for managing state is just a function that takes a Db.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this apply_changes method live? I guess it is just a free function that takes a Db and some changes to apply?

It would probably be a free standing function that takes &mut Db. And yes, the fact that it is a free standing function takes some time to get used to. An alternative is to make it a method in Vfs, but I think that won't work because it would require holding a mutable reference to Db and a read only reference to FileSystem.

Probably this is just something I have to get used to with Salsa, that the Db owns all the state, so most API that we use for managing state is just a function that takes a Db.

yes, that takes some time to get used to. It's also something I'm still figuring out

crates/ruff_db/src/lib.rs Outdated Show resolved Hide resolved
@MichaReiser
Copy link
Member Author

I still have some concerns about having this code just mixed in directly with the rest of the modules in ruff_python_semantic and using only features to distinguish what is red-knot, but otherwise this PR looks fine, and I assume we will revisit that structure as follow-up, not on this PR, for rebase-conflict reasons.

I think it's easiest if we discuss this in person in our planning meeting on Friday.

@MichaReiser MichaReiser merged commit efbf7b1 into main Jun 13, 2024
20 checks passed
@MichaReiser MichaReiser deleted the salsa-2-semantic-jar branch June 13, 2024 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants