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

[move-ide] Added virtualized source file reader #16213

Closed
wants to merge 11 commits into from

Conversation

awelc
Copy link
Contributor

@awelc awelc commented Feb 13, 2024

Description

This PR adds support for virtualized source file reader, allowing the compiler to build a package from files kept by the IDE in memory.

It also fixes an existing bug (move-language/move#1082) where source files used in the symbolicator (obtained from resolution graph) and source files used by the compiler could be modified between the two uses resulting in different file hashes which can ultimately lead to crash when translating diagnostics (generated by the compiler and using "compiler file hashes") using symbolicator source files (and "symbolicator file hashes")

Test Plan

All existing tests must pass.

@awelc awelc self-assigned this Feb 13, 2024
Copy link

vercel bot commented Feb 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-core ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 16, 2024 4:31am
sui-typescript-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 16, 2024 4:31am
4 Ignored Deployments
Name Status Preview Comments Updated (UTC)
explorer ⬜️ Ignored (Inspect) Visit Preview Feb 16, 2024 4:31am
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Feb 16, 2024 4:31am
mysten-ui ⬜️ Ignored (Inspect) Visit Preview Feb 16, 2024 4:31am
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Feb 16, 2024 4:31am

Comment on lines 1006 to 1004
build_plan.compile_with_driver(Some(Box::new(vfs)), &mut std::io::sink(), |compiler| {
// extract expansion AST
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't you just set the vfs inside here with set_source_file_reader?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is what I had here initially, but since I have to use it before/after compiler_with_driver call to retrieve file sources for the symbolicator to use, I could not figure out how to avoid copying/cloning of vfs. In particular, I can't make the closure into the move one as we have things that we need to copy out of it. It's likely a gap in my Rust skills, so suggestions welcome!

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure that I follow. I don't see it being used after compile_with_driver. And before shouldn't matter ?

Copy link
Contributor Author

@awelc awelc Feb 14, 2024

Choose a reason for hiding this comment

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

I tried to respond why it seems to matter in #16213 (comment) but I may be misunderstanding what Rust is trying to tell me...

@@ -54,6 +54,8 @@ pub struct Compiler<'a> {
known_warning_filters: Vec<(/* Prefix */ Option<Symbol>, Vec<WarningFilter>)>,
package_configs: BTreeMap<Symbol, PackageConfig>,
default_config: Option<PackageConfig>,
/// Abstracted source file reader
source_file_reader: Box<dyn SourceFileReader>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, make this a Option, and assert it is None when being set so that it is not set more than once

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did it in a similar style to how other Options in the compiler are handled, but I am not sure if it's the most elegant (though at least consistent). Another alternative perhaps would be to make Option<Box<dyn SourceFileReader>> an argument to from_package_paths.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think just making this an Option here would be fine, and would match the other ones like interface_files_dir_opt, pre_compiled_lib, or package_configs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is indeed the solution I went for.

// Source file reader
//**************************************************************************************************

pub trait SourceFileReader {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit on the name, why not just FileReader?

@@ -278,14 +286,20 @@ impl<'a> Compiler<'a> {
known_warning_filters,
package_configs,
default_config,
source_file_reader,
} = self;
generate_interface_files_for_deps(
Copy link
Contributor

Choose a reason for hiding this comment

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

It makes me a bit uneasy that we don't use the vfs for interface files. That is, I don't particularly like the split of some reads being directly from Path::is_file and others being through the vfs

Also not necessary now, but worth considering writes too

Copy link
Contributor

Choose a reason for hiding this comment

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

Folks asked long ago that we don't stick these interface files in /tmp since it makes running the compiler difficult in some environments

@@ -54,6 +54,8 @@ pub struct Compiler<'a> {
known_warning_filters: Vec<(/* Prefix */ Option<Symbol>, Vec<WarningFilter>)>,
package_configs: BTreeMap<Symbol, PackageConfig>,
default_config: Option<PackageConfig>,
/// Abstracted source file reader
source_file_reader: Box<dyn SourceFileReader>,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think just making this an Option here would be fine, and would match the other ones like interface_files_dir_opt, pre_compiled_lib, or package_configs

Comment on lines 1006 to 1004
build_plan.compile_with_driver(Some(Box::new(vfs)), &mut std::io::sink(), |compiler| {
// extract expansion AST
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure that I follow. I don't see it being used after compile_with_driver. And before shouldn't matter ?

@@ -986,7 +1003,7 @@ pub fn get_symbols(
let mut parsed_ast = None;
let mut typed_ast = None;
let mut diagnostics = None;
build_plan.compile_with_driver(&mut std::io::sink(), |compiler| {
build_plan.compile_with_driver(Some(Box::new(vfs)), &mut std::io::sink(), |compiler| {
Copy link
Contributor

Choose a reason for hiding this comment

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

Concretely what I'm suggesting

Suggested change
build_plan.compile_with_driver(Some(Box::new(vfs)), &mut std::io::sink(), |compiler| {
build_plan.compile_with_driver(&mut std::io::sink(), |compiler| {
let compiler = compiler.set_file_reader(Box::new(vfs));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understood what the suggestion was, particularly that I tried this myself. The problem here (at least as I understand it) is that Rust needs to copy vfs into the closure, which would involve making a copy of all source files read from the file system before compile_with_driver is invoked. I am trying to avoid it by passing vfs by-value to the function itself.

@@ -28,7 +28,7 @@ use move_compiler::{
compiled_unit::{AnnotatedCompiledUnit, CompiledUnit, NamedCompiledModule},
diagnostics::FilesSourceText,
editions::Flavor,
shared::{NamedAddressMap, NumericalAddress, PackageConfig, PackagePaths},
shared::{NamedAddressMap, NumericalAddress, PackageConfig, PackagePaths, SourceFileReader},
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm also wondering if we should add this to the BuildConfig or anything?
Like sure the source files can be virtual, but the toml file isn't.

I'm
A) not sure we want/need this
B) not sure how difficult it would be

mostly flagging as a concern since the compiler would now have one view of IO and the package system another

Copy link
Contributor

Choose a reason for hiding this comment

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

Any thoughts @tzakian

@awelc
Copy link
Contributor Author

awelc commented Feb 20, 2024

Superseded by #16298

@awelc awelc closed this Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants