Skip to content

Commit

Permalink
Auto merge of #45468 - Xanewok:crate-source, r=nrc
Browse files Browse the repository at this point in the history
Emit crate disambiguators in save-analysis data

Needed for rust-dev-tools/rls-analysis#93.
Blocked by rust-dev-tools/rls-data#11. (For now, this pulls my branch [rls-data/crate-source](https://github.com/Xanewok/rls-data/tree/crate-source))

This will allow to disambiguate different crates types/versions when indexing resulting save-analysis data (most importantly allow to support bin+lib and different crate versions).

r? @nrc
  • Loading branch information
bors committed Nov 2, 2017
2 parents d5b69d4 + b4ffede commit 2379faa
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 43 deletions.
42 changes: 13 additions & 29 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/librustc/ich/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ impl Fingerprint {
self.0
}

#[inline]
pub fn as_value(&self) -> (u64, u64) {
(self.0, self.1)
}

#[inline]
pub fn combine(self, other: Fingerprint) -> Fingerprint {
// See https://stackoverflow.com/a/27952689 on why this function is
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rustc_data_structures = { path = "../librustc_data_structures" }
rustc_typeck = { path = "../librustc_typeck" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
rls-data = "0.11"
rls-data = "0.12"
rls-span = "0.4"
# FIXME(#40527) should move rustc serialize out of tree
rustc-serialize = "0.3"
10 changes: 7 additions & 3 deletions src/librustc_save_analysis/dump_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ use json_dumper::{JsonDumper, DumpOutput};
use span_utils::SpanUtils;
use sig;

use rls_data::{CratePreludeData, Import, ImportKind, SpanData, Ref, RefKind,
Def, DefKind, Relation, RelationKind};
use rls_data::{CratePreludeData, GlobalCrateId, Import, ImportKind, SpanData,
Ref, RefKind, Def, DefKind, Relation, RelationKind};

macro_rules! down_cast_data {
($id:ident, $kind:ident, $sp:expr) => {
Expand Down Expand Up @@ -131,7 +131,11 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
});

let data = CratePreludeData {
crate_name: name.into(),
crate_id: GlobalCrateId {
name: name.into(),
disambiguator: self.tcx.sess.local_crate_disambiguator()
.to_fingerprint().as_value(),
},
crate_root: crate_root.unwrap_or("<no source>".to_owned()),
external_crates: self.save_ctxt.get_external_crates(),
span: self.span_from_span(krate.span),
Expand Down
18 changes: 9 additions & 9 deletions src/librustc_save_analysis/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ use dump_visitor::DumpVisitor;
use span_utils::SpanUtils;

use rls_data::{Ref, RefKind, SpanData, MacroRef, Def, DefKind, Relation, RelationKind,
ExternalCrateData};
ExternalCrateData, GlobalCrateId};
use rls_data::config::Config;


Expand All @@ -82,10 +82,6 @@ pub enum Data {
RelationData(Relation),
}

macro_rules! option_try(
($e:expr) => (match $e { Some(e) => e, None => return None })
);

impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
fn span_from_span(&self, span: Span) -> SpanData {
use rls_span::{Row, Column};
Expand Down Expand Up @@ -119,9 +115,13 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
};
let lo_loc = self.span_utils.sess.codemap().lookup_char_pos(span.lo());
result.push(ExternalCrateData {
name: self.tcx.crate_name(n).to_string(),
num: n.as_u32(),
file_name: SpanUtils::make_path_string(&lo_loc.file.name),
num: n.as_u32(),
id: GlobalCrateId {
name: self.tcx.crate_name(n).to_string(),
disambiguator: self.tcx.crate_disambiguator(n)
.to_fingerprint().as_value(),
},
});
}

Expand Down Expand Up @@ -728,8 +728,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
// macro uses.
let callsite = span.source_callsite();
let callsite_span = self.span_from_span(callsite);
let callee = option_try!(span.source_callee());
let callee_span = option_try!(callee.span);
let callee = span.source_callee()?;
let callee_span = callee.span?;

// Ignore attribute macros, their spans are usually mangled
if let MacroAttribute(_) = callee.format {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rls
Submodule rls updated from e03485 to 48fd42

0 comments on commit 2379faa

Please sign in to comment.