diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-03-19 20:51:10 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-03-19 20:51:10 -0400 |
| commit | dedf9d3593632faea7ccb2f78bd6517ce56bb06d (patch) | |
| tree | 4dce9ecd354050500f5b8f63c3a9fc97f0f17bfc /src/librustc_save_analysis/external_data.rs | |
| parent | 7471d9793cf21f89f672eff14e6c529e286c2d30 (diff) | |
| parent | 1d93a6cce0119dfb1248643c7fb701ff1f8d4a50 (diff) | |
Rollup merge of #40554 - nrc:rls-data, r=alexcrichton
Use rls-data crate This basically pulls out a bunch of data structures used by save-analysis for serialization into an external crate, and pulls that crate in using Rustbuild. The RLS can then share these data structures with the compiler which in some cases will allow more efficient communication between the compiler and the RLS (i.e., without serialisation). Along the way, I have to pull in rls-span, which is the RLS's way of defining spans (more type-safe than the compiler's built-in way). This is basically just to convert from compiler spans to RLS spans. I also pull in the crates.io version of rustc-serialize, which is a bit annoying, but seems to be the only way to have serialisable data in an external crate. To make this work, all of the save-analysis crate has to use this version too (cc #40527). Finally I pull in a line from #40347 to make the unstable crate checking stuff working. There are a lot of changes to save-analysis but they are all mechanical and trivial - changing from using `From` to `Into` (because of orphan rules) being the main thing. r? @alexcrichton
Diffstat (limited to 'src/librustc_save_analysis/external_data.rs')
| -rw-r--r-- | src/librustc_save_analysis/external_data.rs | 159 |
1 files changed, 66 insertions, 93 deletions
diff --git a/src/librustc_save_analysis/external_data.rs b/src/librustc_save_analysis/external_data.rs index f038c2dc298..6fd2de97767 100644 --- a/src/librustc_save_analysis/external_data.rs +++ b/src/librustc_save_analysis/external_data.rs @@ -18,6 +18,9 @@ use syntax_pos::Span; use data::{self, Visibility, SigElement}; +use rls_data::{SpanData, CratePreludeData, Attribute}; +use rls_span::{Column, Row}; + // FIXME: this should be pub(crate), but the current snapshot doesn't allow it yet pub trait Lower { type Target; @@ -35,41 +38,19 @@ pub fn null_def_id() -> DefId { } } -#[derive(Clone, Debug, RustcEncodable)] -pub struct SpanData { - pub file_name: String, - pub byte_start: u32, - pub byte_end: u32, - /// 1-based. - pub line_start: usize, - pub line_end: usize, - /// 1-based, character offset. - pub column_start: usize, - pub column_end: usize, -} - -impl SpanData { - pub fn from_span(span: Span, cm: &CodeMap) -> SpanData { - let start = cm.lookup_char_pos(span.lo); - let end = cm.lookup_char_pos(span.hi); - - SpanData { - file_name: start.file.name.clone(), - byte_start: span.lo.0, - byte_end: span.hi.0, - line_start: start.line, - line_end: end.line, - column_start: start.col.0 + 1, - column_end: end.col.0 + 1, - } - } -} +pub fn span_from_span(span: Span, cm: &CodeMap) -> SpanData { + let start = cm.lookup_char_pos(span.lo); + let end = cm.lookup_char_pos(span.hi); -/// Represent an arbitrary attribute on a code element -#[derive(Clone, Debug, RustcEncodable)] -pub struct Attribute { - value: String, - span: SpanData, + SpanData { + file_name: start.file.name.clone().into(), + byte_start: span.lo.0, + byte_end: span.hi.0, + line_start: Row::new_one_indexed(start.line as u32), + line_end: Row::new_one_indexed(end.line as u32), + column_start: Column::new_one_indexed(start.col.0 as u32 + 1), + column_end: Column::new_one_indexed(end.col.0 as u32 + 1), + } } impl Lower for Vec<ast::Attribute> { @@ -91,20 +72,12 @@ impl Lower for Vec<ast::Attribute> { Attribute { value: value, - span: SpanData::from_span(attr.span, tcx.sess.codemap()), + span: span_from_span(attr.span, tcx.sess.codemap()), } }).collect() } } -#[derive(Debug, RustcEncodable)] -pub struct CratePreludeData { - pub crate_name: String, - pub crate_root: String, - pub external_crates: Vec<data::ExternalCrateData>, - pub span: SpanData, -} - impl Lower for data::CratePreludeData { type Target = CratePreludeData; @@ -113,13 +86,13 @@ impl Lower for data::CratePreludeData { crate_name: self.crate_name, crate_root: self.crate_root, external_crates: self.external_crates, - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), } } } /// Data for enum declarations. -#[derive(Clone, Debug, RustcEncodable)] +#[derive(Clone, Debug)] pub struct EnumData { pub id: DefId, pub value: String, @@ -143,7 +116,7 @@ impl Lower for data::EnumData { name: self.name, value: self.value, qualname: self.qualname, - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), scope: make_def_id(self.scope, &tcx.hir), variants: self.variants.into_iter().map(|id| make_def_id(id, &tcx.hir)).collect(), visibility: self.visibility, @@ -155,7 +128,7 @@ impl Lower for data::EnumData { } /// Data for extern crates. -#[derive(Debug, RustcEncodable)] +#[derive(Debug)] pub struct ExternCrateData { pub id: DefId, pub name: String, @@ -174,14 +147,14 @@ impl Lower for data::ExternCrateData { name: self.name, crate_num: self.crate_num, location: self.location, - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), scope: make_def_id(self.scope, &tcx.hir), } } } /// Data about a function call. -#[derive(Debug, RustcEncodable)] +#[derive(Debug)] pub struct FunctionCallData { pub span: SpanData, pub scope: DefId, @@ -193,7 +166,7 @@ impl Lower for data::FunctionCallData { fn lower(self, tcx: TyCtxt) -> FunctionCallData { FunctionCallData { - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), scope: make_def_id(self.scope, &tcx.hir), ref_id: self.ref_id, } @@ -201,7 +174,7 @@ impl Lower for data::FunctionCallData { } /// Data for all kinds of functions and methods. -#[derive(Clone, Debug, RustcEncodable)] +#[derive(Clone, Debug)] pub struct FunctionData { pub id: DefId, pub name: String, @@ -226,7 +199,7 @@ impl Lower for data::FunctionData { name: self.name, qualname: self.qualname, declaration: self.declaration, - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), scope: make_def_id(self.scope, &tcx.hir), value: self.value, visibility: self.visibility, @@ -239,7 +212,7 @@ impl Lower for data::FunctionData { } /// Data about a function call. -#[derive(Debug, RustcEncodable)] +#[derive(Debug)] pub struct FunctionRefData { pub span: SpanData, pub scope: DefId, @@ -251,13 +224,13 @@ impl Lower for data::FunctionRefData { fn lower(self, tcx: TyCtxt) -> FunctionRefData { FunctionRefData { - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), scope: make_def_id(self.scope, &tcx.hir), ref_id: self.ref_id, } } } -#[derive(Debug, RustcEncodable)] +#[derive(Debug)] pub struct ImplData { pub id: DefId, pub span: SpanData, @@ -272,7 +245,7 @@ impl Lower for data::ImplData { fn lower(self, tcx: TyCtxt) -> ImplData { ImplData { id: make_def_id(self.id, &tcx.hir), - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), scope: make_def_id(self.scope, &tcx.hir), trait_ref: self.trait_ref, self_ref: self.self_ref, @@ -280,7 +253,7 @@ impl Lower for data::ImplData { } } -#[derive(Debug, RustcEncodable)] +#[derive(Debug)] pub struct InheritanceData { pub span: SpanData, pub base_id: DefId, @@ -292,7 +265,7 @@ impl Lower for data::InheritanceData { fn lower(self, tcx: TyCtxt) -> InheritanceData { InheritanceData { - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), base_id: self.base_id, deriv_id: make_def_id(self.deriv_id, &tcx.hir) } @@ -300,7 +273,7 @@ impl Lower for data::InheritanceData { } /// Data about a macro declaration. -#[derive(Debug, RustcEncodable)] +#[derive(Debug)] pub struct MacroData { pub span: SpanData, pub name: String, @@ -313,7 +286,7 @@ impl Lower for data::MacroData { fn lower(self, tcx: TyCtxt) -> MacroData { MacroData { - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), name: self.name, qualname: self.qualname, docs: self.docs, @@ -322,7 +295,7 @@ impl Lower for data::MacroData { } /// Data about a macro use. -#[derive(Debug, RustcEncodable)] +#[derive(Debug)] pub struct MacroUseData { pub span: SpanData, pub name: String, @@ -338,17 +311,17 @@ impl Lower for data::MacroUseData { fn lower(self, tcx: TyCtxt) -> MacroUseData { MacroUseData { - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), name: self.name, qualname: self.qualname, - callee_span: SpanData::from_span(self.callee_span, tcx.sess.codemap()), + callee_span: span_from_span(self.callee_span, tcx.sess.codemap()), scope: make_def_id(self.scope, &tcx.hir), } } } /// Data about a method call. -#[derive(Debug, RustcEncodable)] +#[derive(Debug)] pub struct MethodCallData { pub span: SpanData, pub scope: DefId, @@ -361,7 +334,7 @@ impl Lower for data::MethodCallData { fn lower(self, tcx: TyCtxt) -> MethodCallData { MethodCallData { - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), scope: make_def_id(self.scope, &tcx.hir), ref_id: self.ref_id, decl_id: self.decl_id, @@ -370,7 +343,7 @@ impl Lower for data::MethodCallData { } /// Data for method declarations (methods with a body are treated as functions). -#[derive(Clone, Debug, RustcEncodable)] +#[derive(Clone, Debug)] pub struct MethodData { pub id: DefId, pub name: String, @@ -391,7 +364,7 @@ impl Lower for data::MethodData { fn lower(self, tcx: TyCtxt) -> MethodData { MethodData { - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), name: self.name, scope: make_def_id(self.scope, &tcx.hir), id: make_def_id(self.id, &tcx.hir), @@ -408,7 +381,7 @@ impl Lower for data::MethodData { } /// Data for modules. -#[derive(Debug, RustcEncodable)] +#[derive(Debug)] pub struct ModData { pub id: DefId, pub name: String, @@ -431,7 +404,7 @@ impl Lower for data::ModData { id: make_def_id(self.id, &tcx.hir), name: self.name, qualname: self.qualname, - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), scope: make_def_id(self.scope, &tcx.hir), filename: self.filename, items: self.items.into_iter().map(|id| make_def_id(id, &tcx.hir)).collect(), @@ -444,7 +417,7 @@ impl Lower for data::ModData { } /// Data for a reference to a module. -#[derive(Debug, RustcEncodable)] +#[derive(Debug)] pub struct ModRefData { pub span: SpanData, pub scope: DefId, @@ -457,7 +430,7 @@ impl Lower for data::ModRefData { fn lower(self, tcx: TyCtxt) -> ModRefData { ModRefData { - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), scope: make_def_id(self.scope, &tcx.hir), ref_id: self.ref_id, qualname: self.qualname, @@ -465,7 +438,7 @@ impl Lower for data::ModRefData { } } -#[derive(Debug, RustcEncodable)] +#[derive(Debug)] pub struct StructData { pub span: SpanData, pub name: String, @@ -486,7 +459,7 @@ impl Lower for data::StructData { fn lower(self, tcx: TyCtxt) -> StructData { StructData { - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), name: self.name, id: make_def_id(self.id, &tcx.hir), ctor_id: make_def_id(self.ctor_id, &tcx.hir), @@ -502,7 +475,7 @@ impl Lower for data::StructData { } } -#[derive(Debug, RustcEncodable)] +#[derive(Debug)] pub struct StructVariantData { pub span: SpanData, pub name: String, @@ -522,7 +495,7 @@ impl Lower for data::StructVariantData { fn lower(self, tcx: TyCtxt) -> StructVariantData { StructVariantData { - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), name: self.name, id: make_def_id(self.id, &tcx.hir), qualname: self.qualname, @@ -537,7 +510,7 @@ impl Lower for data::StructVariantData { } } -#[derive(Debug, RustcEncodable)] +#[derive(Debug)] pub struct TraitData { pub span: SpanData, pub name: String, @@ -557,7 +530,7 @@ impl Lower for data::TraitData { fn lower(self, tcx: TyCtxt) -> TraitData { TraitData { - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), name: self.name, id: make_def_id(self.id, &tcx.hir), qualname: self.qualname, @@ -572,7 +545,7 @@ impl Lower for data::TraitData { } } -#[derive(Debug, RustcEncodable)] +#[derive(Debug)] pub struct TupleVariantData { pub span: SpanData, pub id: DefId, @@ -592,7 +565,7 @@ impl Lower for data::TupleVariantData { fn lower(self, tcx: TyCtxt) -> TupleVariantData { TupleVariantData { - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), id: make_def_id(self.id, &tcx.hir), name: self.name, qualname: self.qualname, @@ -608,7 +581,7 @@ impl Lower for data::TupleVariantData { } /// Data for a typedef. -#[derive(Debug, RustcEncodable)] +#[derive(Debug)] pub struct TypeDefData { pub id: DefId, pub name: String, @@ -629,7 +602,7 @@ impl Lower for data::TypeDefData { TypeDefData { id: make_def_id(self.id, &tcx.hir), name: self.name, - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), qualname: self.qualname, value: self.value, visibility: self.visibility, @@ -642,7 +615,7 @@ impl Lower for data::TypeDefData { } /// Data for a reference to a type or trait. -#[derive(Clone, Debug, RustcEncodable)] +#[derive(Clone, Debug)] pub struct TypeRefData { pub span: SpanData, pub scope: DefId, @@ -655,7 +628,7 @@ impl Lower for data::TypeRefData { fn lower(self, tcx: TyCtxt) -> TypeRefData { TypeRefData { - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), scope: make_def_id(self.scope, &tcx.hir), ref_id: self.ref_id, qualname: self.qualname, @@ -663,7 +636,7 @@ impl Lower for data::TypeRefData { } } -#[derive(Debug, RustcEncodable)] +#[derive(Debug)] pub struct UseData { pub id: DefId, pub span: SpanData, @@ -679,7 +652,7 @@ impl Lower for data::UseData { fn lower(self, tcx: TyCtxt) -> UseData { UseData { id: make_def_id(self.id, &tcx.hir), - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), name: self.name, mod_id: self.mod_id, scope: make_def_id(self.scope, &tcx.hir), @@ -688,7 +661,7 @@ impl Lower for data::UseData { } } -#[derive(Debug, RustcEncodable)] +#[derive(Debug)] pub struct UseGlobData { pub id: DefId, pub span: SpanData, @@ -703,7 +676,7 @@ impl Lower for data::UseGlobData { fn lower(self, tcx: TyCtxt) -> UseGlobData { UseGlobData { id: make_def_id(self.id, &tcx.hir), - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), names: self.names, scope: make_def_id(self.scope, &tcx.hir), visibility: self.visibility, @@ -712,7 +685,7 @@ impl Lower for data::UseGlobData { } /// Data for local and global variables (consts and statics). -#[derive(Debug, RustcEncodable)] +#[derive(Debug)] pub struct VariableData { pub id: DefId, pub name: String, @@ -738,7 +711,7 @@ impl Lower for data::VariableData { kind: self.kind, name: self.name, qualname: self.qualname, - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), scope: make_def_id(self.scope, &tcx.hir), value: self.value, type_value: self.type_value, @@ -753,7 +726,7 @@ impl Lower for data::VariableData { /// Data for the use of some item (e.g., the use of a local variable, which /// will refer to that variables declaration (by ref_id)). -#[derive(Debug, RustcEncodable)] +#[derive(Debug)] pub struct VariableRefData { pub name: String, pub span: SpanData, @@ -767,14 +740,14 @@ impl Lower for data::VariableRefData { fn lower(self, tcx: TyCtxt) -> VariableRefData { VariableRefData { name: self.name, - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), scope: make_def_id(self.scope, &tcx.hir), ref_id: self.ref_id, } } } -#[derive(Clone, Debug, RustcEncodable)] +#[derive(Clone, Debug)] pub struct Signature { pub span: SpanData, pub text: String, @@ -791,7 +764,7 @@ impl Lower for data::Signature { fn lower(self, tcx: TyCtxt) -> Signature { Signature { - span: SpanData::from_span(self.span, tcx.sess.codemap()), + span: span_from_span(self.span, tcx.sess.codemap()), text: self.text, ident_start: self.ident_start, ident_end: self.ident_end, |
