Skip to content

Commit

Permalink
Move to the mapped files impl
Browse files Browse the repository at this point in the history
  • Loading branch information
cgswords committed Jun 20, 2024
1 parent da7dc32 commit 199b5ea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
28 changes: 4 additions & 24 deletions external-crates/move/crates/move-analyzer/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ impl Symbols {
self.references.entry(k).or_default().extend(v);
}
self.file_use_defs.extend(other.file_use_defs);
self.files.extend(other.files);
self.files.extend_with_duplicates(other.files);
self.def_info.extend(other.def_info);
}

Expand Down Expand Up @@ -1141,23 +1141,6 @@ fn has_precompiled_deps(
pkg_deps.contains_key(pkg_path)
}

/// Mirrors implementation of MappedFiles::extend but allows duplicate
/// hashes without throwing a debug assertion
fn mapped_files_extend(files: &mut MappedFiles, other: MappedFiles) {
for (file_hash, file_id) in other.file_mapping() {
let Ok(file) = other.files().get(*file_id) else {
debug_assert!(false, "Found a file without a file entry");
continue;
};
let Some(path) = other.file_name_mapping().get(file_hash) else {
debug_assert!(false, "Found a file without a path entry");
continue;
};
let fname = format!("{}", path.to_string_lossy());
files.add(*file_hash, fname.into(), file.source().clone());
}
}

/// Main driver to get symbols for the whole package. Returned symbols is an option as only the
/// correctly computed symbols should be a replacement for the old set - if symbols are not
/// actually (re)computed and the diagnostics are returned, the old symbolic information should
Expand Down Expand Up @@ -1249,7 +1232,7 @@ pub fn get_symbols(
&& deps_hash == d.deps_hash =>
{
eprintln!("found pre-compiled libs for {:?}", pkg_path);
mapped_files_extend(&mut mapped_files, d.deps.files.clone());
mapped_files.extend_with_duplicates(d.deps.files.clone());
Some(d.deps.clone())
}
_ => construct_pre_compiled_lib(
Expand All @@ -1262,7 +1245,7 @@ pub fn get_symbols(
.and_then(|pprog_and_comments_res| pprog_and_comments_res.ok())
.map(|libs| {
eprintln!("created pre-compiled libs for {:?}", pkg_path);
mapped_files_extend(&mut mapped_files, libs.files.clone());
mapped_files.extend_with_duplicates(libs.files.clone());
let deps = Arc::new(libs);
pkg_deps.insert(
pkg_path.to_path_buf(),
Expand Down Expand Up @@ -1304,10 +1287,7 @@ pub fn get_symbols(
eprintln!("compiled to parsed AST");
let (compiler, parsed_program) = compiler.into_ast();
parsed_ast = Some(parsed_program.clone());
mapped_files_extend(
&mut mapped_files,
compiler.compilation_env_ref().mapped_files().clone(),
);
mapped_files.extend_with_duplicates(compiler.compilation_env_ref().mapped_files().clone());

// extract typed AST
let compilation_result = compiler.at_parser(parsed_program).run::<PASS_TYPING>();
Expand Down
13 changes: 11 additions & 2 deletions external-crates/move/crates/move-compiler/src/shared/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl MappedFiles {
}
}

pub fn extend(&mut self, other: Self) {
fn extend_(&mut self, other: Self, allow_duplicates: bool) {
for (file_hash, file_id) in other.file_mapping {
let Ok(file) = other.files.get(file_id) else {
debug_assert!(false, "Found a file without a file entry");
Expand All @@ -109,14 +109,23 @@ impl MappedFiles {
continue;
};
debug_assert!(
!self.file_mapping.contains_key(&file_hash),
allow_duplicates || !self.file_mapping.contains_key(&file_hash),
"Found a repeat file hash"
);
let fname = format!("{}", path.to_string_lossy());
self.add(file_hash, fname.into(), file.source().clone());
}
}


pub fn extend(&mut self, other: Self) {
self.extend_(other, false)
}

pub fn extend_with_duplicates(&mut self, other: Self) {
self.extend_(other, true)
}

pub fn add(&mut self, fhash: FileHash, fname: FileName, source: Arc<str>) {
let id = self.files.add(fname, source);
self.file_mapping.insert(fhash, id);
Expand Down

0 comments on commit 199b5ea

Please sign in to comment.