Skip to content
This repository was archived by the owner on Mar 1, 2019. It is now read-only.

Commit 0dd939c

Browse files
committed
Address feedback
1 parent d028b89 commit 0dd939c

File tree

7 files changed

+33
-21
lines changed

7 files changed

+33
-21
lines changed

benches/std_api_crate.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
// Copyright 2017 The RLS Project Developers.
2+
//
3+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6+
// option. This file may not be copied, modified, or distributed
7+
// except according to those terms.
8+
19
#![feature(test)]
210

311
extern crate rls_analysis;
@@ -33,7 +41,7 @@ impl AnalysisLoader for TestAnalysisLoader {
3341
panic!();
3442
}
3543

36-
fn paths(&self) -> Vec<PathBuf> { vec![self.path.clone()] }
44+
fn search_directories(&self) -> Vec<PathBuf> { vec![self.path.clone()] }
3745
}
3846

3947
lazy_static! {

src/analysis.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ pub struct PerCrateAnalysis {
3737
pub globs: HashMap<Span, Glob>,
3838
pub impls: HashMap<Id, Vec<Span>>,
3939

40-
pub crate_id: CrateId,
4140
pub root_id: Option<Id>,
4241
pub timestamp: SystemTime,
4342
}
@@ -79,7 +78,7 @@ pub struct Glob {
7978

8079

8180
impl PerCrateAnalysis {
82-
pub fn new(crate_id: CrateId, timestamp: SystemTime) -> PerCrateAnalysis {
81+
pub fn new(timestamp: SystemTime) -> PerCrateAnalysis {
8382
PerCrateAnalysis {
8483
def_id_for_span: HashMap::new(),
8584
defs: HashMap::new(),
@@ -89,7 +88,6 @@ impl PerCrateAnalysis {
8988
ref_spans: HashMap::new(),
9089
globs: HashMap::new(),
9190
impls: HashMap::new(),
92-
crate_id,
9391
root_id: None,
9492
timestamp,
9593
}
@@ -109,7 +107,7 @@ impl Analysis {
109107
pub fn timestamps(&self) -> HashMap<CrateId, SystemTime> {
110108
self.per_crate
111109
.iter()
112-
.map(|(id,c)| (id.clone(), c.timestamp.clone()))
110+
.map(|(id, c)| (id.clone(), c.timestamp.clone()))
113111
.collect()
114112
}
115113

src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,10 @@ impl<L: AnalysisLoader> AnalysisHost<L> {
162162
}
163163

164164
let timestamps = self.analysis.lock()?.as_ref().unwrap().timestamps();
165-
let loader = self.loader.lock()?;
166-
let raw_analysis = read_analysis_from_files(&*loader, timestamps, blacklist);
165+
let raw_analysis = {
166+
let loader = self.loader.lock()?;
167+
read_analysis_from_files(&*loader, timestamps, blacklist)
168+
};
167169

168170
lowering::lower(raw_analysis, base_dir, self, |host, per_crate, id| {
169171
let mut a = host.analysis.lock()?;
@@ -273,7 +275,12 @@ impl<L: AnalysisLoader> AnalysisHost<L> {
273275
pub fn def_roots(&self) -> AResult<Vec<(Id, String)>> {
274276
self.with_analysis(|a| {
275277
Some(
276-
a.for_all_crates(|c| c.root_id.map(|id| vec![(id, c.crate_id.name.clone())])),
278+
a.per_crate
279+
.iter()
280+
.filter_map(|(crate_id, data)| {
281+
data.root_id.map(|id| (id, crate_id.name.clone()))
282+
})
283+
.collect()
277284
)
278285
})
279286
}

src/loader.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ pub trait AnalysisLoader: Sized {
4040
fn fresh_host(&self) -> AnalysisHost<Self>;
4141
fn set_path_prefix(&mut self, path_prefix: &Path);
4242
fn abs_path_prefix(&self) -> Option<PathBuf>;
43-
/// Returns every directory in which paths are to be considered.
44-
/// TODO: Can it also return files?
45-
fn paths(&self) -> Vec<PathBuf>;
43+
/// Returns every directory in which analysis files are to be considered.
44+
fn search_directories(&self) -> Vec<PathBuf>;
4645
}
4746

4847
impl AnalysisLoader for CargoAnalysisLoader {
@@ -66,7 +65,7 @@ impl AnalysisLoader for CargoAnalysisLoader {
6665
.map(|s| Path::new(s).canonicalize().unwrap().to_owned())
6766
}
6867

69-
fn paths(&self) -> Vec<PathBuf> {
68+
fn search_directories(&self) -> Vec<PathBuf> {
7069
let path_prefix = self.path_prefix.as_ref().unwrap();
7170
let target = self.target.to_string();
7271

src/lowering.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
//! For processing the raw save-analysis data from rustc into rustw's
9+
//! For processing the raw save-analysis data from rustc into the rls
1010
//! in-memory representation.
1111
1212
use analysis::{Def, Glob, PerCrateAnalysis};
@@ -146,15 +146,15 @@ impl CrateReader {
146146
base_dir,
147147
);
148148

149-
let mut per_crate = PerCrateAnalysis::new(krate.id.clone(), krate.timestamp);
149+
let mut per_crate = PerCrateAnalysis::new(krate.timestamp);
150150

151151
let is_distro_crate = krate.analysis.config.distro_crate;
152152
reader.read_defs(krate.analysis.defs, &mut per_crate, is_distro_crate);
153153
reader.read_imports(krate.analysis.imports, &mut per_crate, project_analysis);
154154
reader.read_refs(krate.analysis.refs, &mut per_crate, project_analysis);
155155
reader.read_impls(krate.analysis.relations, &mut per_crate, project_analysis);
156156

157-
(per_crate, krate.id.clone())
157+
(per_crate, krate.id)
158158
}
159159

160160
fn read_imports<L: AnalysisLoader>(

src/raw.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn read_analysis_from_files<L: AnalysisLoader>(
4444
) -> Vec<Crate> {
4545
let mut result = vec![];
4646

47-
loader.paths()
47+
loader.search_directories()
4848
.iter()
4949
.inspect(|path| trace!("Considering analysis files at {}", path.display()))
5050
.filter_map(|p| DirectoryListing::from_path(p).ok().map(|list| (p, list)))
@@ -59,10 +59,10 @@ pub fn read_analysis_from_files<L: AnalysisLoader>(
5959
}
6060

6161
let path = p.join(&l.name);
62-
// TODO: Bring back path-based timestamps?
63-
// This would speed up a bit reloading time, since non-blacklisted
64-
// can be older than the ones loaded, so don't waste time
65-
// reading the file and deserializing
62+
// TODO: Bring back path-based timestamps, so we can discard
63+
// stale data before reading the file and attempting the
64+
// deserialization, as it can take a considerate amount of time
65+
// for big analysis data files.
6666
//let is_fresh = timestamps.get(&path).map_or(true, |t| time > t);
6767
read_crate_data(&path).map(|analysis| {
6868
let is_fresh = {

src/test/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl AnalysisLoader for TestAnalysisLoader {
3131
panic!();
3232
}
3333

34-
fn paths(&self) -> Vec<PathBuf> { vec![self.path.clone()] }
34+
fn search_directories(&self) -> Vec<PathBuf> { vec![self.path.clone()] }
3535
}
3636

3737
#[test]

0 commit comments

Comments
 (0)