Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 9 additions & 9 deletions compiler/rustc_metadata/src/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@ impl<'a> CrateLocator<'a> {
}
if let Some(matches) = spf.query(prefix, suffix) {
for (hash, spf) in matches {
info!("lib candidate: {}", spf.path.display());
let spf_path = spf.path(&search_path.dir);
info!("lib candidate: {}", spf_path.display());

let (rlibs, rmetas, dylibs, interfaces) =
candidates.entry(hash).or_default();
Expand All @@ -447,21 +448,20 @@ impl<'a> CrateLocator<'a> {
// ones we've already seen. This allows us to ignore crates
// we know are exactual equal to ones we've already found.
// Going to the same crate through different symlinks does not change the result.
let path = try_canonicalize(&spf.path)
.unwrap_or_else(|_| spf.path.to_path_buf());
let path =
try_canonicalize(&spf_path).unwrap_or_else(|_| spf_path.clone());
if seen_paths.contains(&path) {
continue;
};
seen_paths.insert(path);
}
// Use the original path (potentially with unresolved symlinks),
// filesystem code should not care, but this is nicer for diagnostics.
let path = spf.path.to_path_buf();
match kind {
CrateFlavor::Rlib => rlibs.insert(path),
CrateFlavor::Rmeta => rmetas.insert(path),
CrateFlavor::Dylib => dylibs.insert(path),
CrateFlavor::SDylib => interfaces.insert(path),
CrateFlavor::Rlib => rlibs.insert(spf_path),
CrateFlavor::Rmeta => rmetas.insert(spf_path),
CrateFlavor::Dylib => dylibs.insert(spf_path),
CrateFlavor::SDylib => interfaces.insert(spf_path),
};
}
}
Expand All @@ -472,7 +472,7 @@ impl<'a> CrateLocator<'a> {
{
for (_, spf) in static_matches {
crate_rejections.via_kind.push(CrateMismatch {
path: spf.path.to_path_buf(),
path: spf.path(&search_path.dir),
got: "static".to_string(),
});
}
Expand Down
34 changes: 17 additions & 17 deletions compiler/rustc_session/src/search_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct SearchPath {

/// [FilesIndex] contains paths that can be efficiently looked up with (prefix, suffix) pairs.
#[derive(Clone, Debug)]
pub struct FilesIndex(Vec<(Arc<str>, SearchPathFile)>);
pub struct FilesIndex(Vec<SearchPathFile>);

impl FilesIndex {
/// Look up [SearchPathFile] by (prefix, suffix) pair.
Expand All @@ -25,15 +25,15 @@ impl FilesIndex {
prefix: &str,
suffix: &str,
) -> Option<impl Iterator<Item = (String, &'s SearchPathFile)>> {
let start = self.0.partition_point(|(k, _)| **k < *prefix);
let start = self.0.partition_point(|v| *v.file_name_str < *prefix);
if start == self.0.len() {
return None;
}
let end = self.0[start..].partition_point(|(k, _)| k.starts_with(prefix));
let end = self.0[start..].partition_point(|v| v.file_name_str.starts_with(prefix));
let prefixed_items = &self.0[start..][..end];

let ret = prefixed_items.into_iter().filter_map(move |(k, v)| {
k.ends_with(suffix).then(|| {
let ret = prefixed_items.into_iter().filter_map(move |v| {
v.file_name_str.ends_with(suffix).then(|| {
(
String::from(
&v.file_name_str[prefix.len()..v.file_name_str.len() - suffix.len()],
Expand All @@ -45,7 +45,7 @@ impl FilesIndex {
Some(ret)
}
pub fn retain(&mut self, prefixes: &[&str]) {
self.0.retain(|(k, _)| prefixes.iter().any(|prefix| k.starts_with(prefix)));
self.0.retain(|v| prefixes.iter().any(|prefix| v.file_name_str.starts_with(prefix)));
}
}
/// The obvious implementation of `SearchPath::files` is a `Vec<PathBuf>`. But
Expand All @@ -61,8 +61,14 @@ impl FilesIndex {
/// UTF-8, and so a non-UTF-8 filename couldn't be one we're looking for.)
#[derive(Clone, Debug)]
pub struct SearchPathFile {
pub path: Arc<Path>,
pub file_name_str: Arc<str>,
file_name_str: Arc<str>,
}

impl SearchPathFile {
/// Constructs the full path to the file.
pub fn path(&self, dir: &Path) -> PathBuf {
dir.join(&*self.file_name_str)
}
}

#[derive(PartialEq, Clone, Copy, Debug, Hash, Eq, Encodable, Decodable, HashStable_Generic)]
Expand Down Expand Up @@ -134,20 +140,14 @@ impl SearchPath {
Ok(files) => files
.filter_map(|e| {
e.ok().and_then(|e| {
e.file_name().to_str().map(|s| {
let file_name_str: Arc<str> = s.into();
(
Arc::clone(&file_name_str),
SearchPathFile { path: e.path().into(), file_name_str },
)
})
e.file_name().to_str().map(|s| SearchPathFile { file_name_str: s.into() })
})
})
.collect::<Vec<_>>(),
.collect::<Vec<SearchPathFile>>(),

Err(..) => Default::default(),
};
files.sort_by(|(lhs, _), (rhs, _)| lhs.cmp(rhs));
files.sort_unstable_by(|lhs, rhs| lhs.file_name_str.cmp(&rhs.file_name_str));
Copy link
Member

Choose a reason for hiding this comment

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

Is there no possibility of two files with the same file_name_str?

Copy link
Member

Choose a reason for hiding this comment

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

Although I guess that would result in either one being picked deterministically (if it is the only matching one), which one is picked not mattering (if both files having the same crate hash) or an error about multiple candidates getting emitted.

Copy link
Member Author

Choose a reason for hiding this comment

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

We sorted (and searched) by the UTF-8 name before anyway, so there shouldn't hopefully be any change in behavior.

let files = FilesIndex(files);
SearchPath { kind, dir, files }
}
Expand Down
Loading