Skip to content

Commit f7652bf

Browse files
committed
save-analysis-json: lower def ids
1 parent e1d61cb commit f7652bf

File tree

1 file changed

+63
-62
lines changed

1 file changed

+63
-62
lines changed

src/librustc_save_analysis/json_dumper.rs

Lines changed: 63 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ use std::io::Write;
1313
use rustc_serialize::json::as_json;
1414
use syntax::codemap::CodeMap;
1515

16-
use rustc::hir::def_id::DefId;
17-
use syntax::ast::{CrateNum, NodeId};
16+
use syntax::ast::CrateNum;
1817

1918
use super::data::{self, SpanData};
2019
use super::dump::Dump;
@@ -92,6 +91,8 @@ trait Lower {
9291
fn lower(self, cm: &CodeMap) -> Self::Target;
9392
}
9493

94+
pub type Id = u32;
95+
9596
#[derive(Debug, RustcEncodable)]
9697
pub struct CratePreludeData {
9798
pub crate_name: String,
@@ -116,11 +117,11 @@ impl Lower for data::CratePreludeData {
116117
/// Data for enum declarations.
117118
#[derive(Clone, Debug, RustcEncodable)]
118119
pub struct EnumData {
119-
pub id: NodeId,
120+
pub id: Id,
120121
pub value: String,
121122
pub qualname: String,
122123
pub span: SpanData,
123-
pub scope: NodeId,
124+
pub scope: Id,
124125
}
125126

126127
impl Lower for data::EnumData {
@@ -140,12 +141,12 @@ impl Lower for data::EnumData {
140141
/// Data for extern crates.
141142
#[derive(Debug, RustcEncodable)]
142143
pub struct ExternCrateData {
143-
pub id: NodeId,
144+
pub id: Id,
144145
pub name: String,
145146
pub crate_num: CrateNum,
146147
pub location: String,
147148
pub span: SpanData,
148-
pub scope: NodeId,
149+
pub scope: Id,
149150
}
150151

151152
impl Lower for data::ExternCrateData {
@@ -167,8 +168,8 @@ impl Lower for data::ExternCrateData {
167168
#[derive(Debug, RustcEncodable)]
168169
pub struct FunctionCallData {
169170
pub span: SpanData,
170-
pub scope: NodeId,
171-
pub ref_id: DefId,
171+
pub scope: Id,
172+
pub ref_id: Id,
172173
}
173174

174175
impl Lower for data::FunctionCallData {
@@ -178,20 +179,20 @@ impl Lower for data::FunctionCallData {
178179
FunctionCallData {
179180
span: SpanData::from_span(self.span, cm),
180181
scope: self.scope,
181-
ref_id: self.ref_id,
182+
ref_id: self.ref_id.index.as_u32(),
182183
}
183184
}
184185
}
185186

186187
/// Data for all kinds of functions and methods.
187188
#[derive(Clone, Debug, RustcEncodable)]
188189
pub struct FunctionData {
189-
pub id: NodeId,
190+
pub id: Id,
190191
pub name: String,
191192
pub qualname: String,
192-
pub declaration: Option<DefId>,
193+
pub declaration: Option<Id>,
193194
pub span: SpanData,
194-
pub scope: NodeId,
195+
pub scope: Id,
195196
}
196197

197198
impl Lower for data::FunctionData {
@@ -202,7 +203,7 @@ impl Lower for data::FunctionData {
202203
id: self.id,
203204
name: self.name,
204205
qualname: self.qualname,
205-
declaration: self.declaration,
206+
declaration: self.declaration.map(|id| id.index.as_u32()),
206207
span: SpanData::from_span(self.span, cm),
207208
scope: self.scope,
208209
}
@@ -213,8 +214,8 @@ impl Lower for data::FunctionData {
213214
#[derive(Debug, RustcEncodable)]
214215
pub struct FunctionRefData {
215216
pub span: SpanData,
216-
pub scope: NodeId,
217-
pub ref_id: DefId,
217+
pub scope: Id,
218+
pub ref_id: Id,
218219
}
219220

220221
impl Lower for data::FunctionRefData {
@@ -224,17 +225,17 @@ impl Lower for data::FunctionRefData {
224225
FunctionRefData {
225226
span: SpanData::from_span(self.span, cm),
226227
scope: self.scope,
227-
ref_id: self.ref_id,
228+
ref_id: self.ref_id.index.as_u32(),
228229
}
229230
}
230231
}
231232
#[derive(Debug, RustcEncodable)]
232233
pub struct ImplData {
233-
pub id: NodeId,
234+
pub id: Id,
234235
pub span: SpanData,
235-
pub scope: NodeId,
236-
pub trait_ref: Option<DefId>,
237-
pub self_ref: Option<DefId>,
236+
pub scope: Id,
237+
pub trait_ref: Option<Id>,
238+
pub self_ref: Option<Id>,
238239
}
239240

240241
impl Lower for data::ImplData {
@@ -245,17 +246,17 @@ impl Lower for data::ImplData {
245246
id: self.id,
246247
span: SpanData::from_span(self.span, cm),
247248
scope: self.scope,
248-
trait_ref: self.trait_ref,
249-
self_ref: self.self_ref,
249+
trait_ref: self.trait_ref.map(|id| id.index.as_u32()),
250+
self_ref: self.self_ref.map(|id| id.index.as_u32()),
250251
}
251252
}
252253
}
253254

254255
#[derive(Debug, RustcEncodable)]
255256
pub struct InheritanceData {
256257
pub span: SpanData,
257-
pub base_id: DefId,
258-
pub deriv_id: NodeId
258+
pub base_id: Id,
259+
pub deriv_id: Id
259260
}
260261

261262
impl Lower for data::InheritanceData {
@@ -264,7 +265,7 @@ impl Lower for data::InheritanceData {
264265
fn lower(self, cm: &CodeMap) -> InheritanceData {
265266
InheritanceData {
266267
span: SpanData::from_span(self.span, cm),
267-
base_id: self.base_id,
268+
base_id: self.base_id.index.as_u32(),
268269
deriv_id: self.deriv_id
269270
}
270271
}
@@ -299,7 +300,7 @@ pub struct MacroUseData {
299300
// Because macro expansion happens before ref-ids are determined,
300301
// we use the callee span to reference the associated macro definition.
301302
pub callee_span: SpanData,
302-
pub scope: NodeId,
303+
pub scope: Id,
303304
pub imported: bool,
304305
}
305306

@@ -322,9 +323,9 @@ impl Lower for data::MacroUseData {
322323
#[derive(Debug, RustcEncodable)]
323324
pub struct MethodCallData {
324325
pub span: SpanData,
325-
pub scope: NodeId,
326-
pub ref_id: Option<DefId>,
327-
pub decl_id: Option<DefId>,
326+
pub scope: Id,
327+
pub ref_id: Option<Id>,
328+
pub decl_id: Option<Id>,
328329
}
329330

330331
impl Lower for data::MethodCallData {
@@ -334,19 +335,19 @@ impl Lower for data::MethodCallData {
334335
MethodCallData {
335336
span: SpanData::from_span(self.span, cm),
336337
scope: self.scope,
337-
ref_id: self.ref_id,
338-
decl_id: self.decl_id,
338+
ref_id: self.ref_id.map(|id| id.index.as_u32()),
339+
decl_id: self.decl_id.map(|id| id.index.as_u32()),
339340
}
340341
}
341342
}
342343

343344
/// Data for method declarations (methods with a body are treated as functions).
344345
#[derive(Clone, Debug, RustcEncodable)]
345346
pub struct MethodData {
346-
pub id: NodeId,
347+
pub id: Id,
347348
pub qualname: String,
348349
pub span: SpanData,
349-
pub scope: NodeId,
350+
pub scope: Id,
350351
}
351352

352353
impl Lower for data::MethodData {
@@ -365,11 +366,11 @@ impl Lower for data::MethodData {
365366
/// Data for modules.
366367
#[derive(Debug, RustcEncodable)]
367368
pub struct ModData {
368-
pub id: NodeId,
369+
pub id: Id,
369370
pub name: String,
370371
pub qualname: String,
371372
pub span: SpanData,
372-
pub scope: NodeId,
373+
pub scope: Id,
373374
pub filename: String,
374375
}
375376

@@ -392,8 +393,8 @@ impl Lower for data::ModData {
392393
#[derive(Debug, RustcEncodable)]
393394
pub struct ModRefData {
394395
pub span: SpanData,
395-
pub scope: NodeId,
396-
pub ref_id: Option<DefId>,
396+
pub scope: Id,
397+
pub ref_id: Option<Id>,
397398
pub qualname: String
398399
}
399400

@@ -404,7 +405,7 @@ impl Lower for data::ModRefData {
404405
ModRefData {
405406
span: SpanData::from_span(self.span, cm),
406407
scope: self.scope,
407-
ref_id: self.ref_id,
408+
ref_id: self.ref_id.map(|id| id.index.as_u32()),
408409
qualname: self.qualname,
409410
}
410411
}
@@ -413,10 +414,10 @@ impl Lower for data::ModRefData {
413414
#[derive(Debug, RustcEncodable)]
414415
pub struct StructData {
415416
pub span: SpanData,
416-
pub id: NodeId,
417-
pub ctor_id: NodeId,
417+
pub id: Id,
418+
pub ctor_id: Id,
418419
pub qualname: String,
419-
pub scope: NodeId,
420+
pub scope: Id,
420421
pub value: String
421422
}
422423

@@ -438,11 +439,11 @@ impl Lower for data::StructData {
438439
#[derive(Debug, RustcEncodable)]
439440
pub struct StructVariantData {
440441
pub span: SpanData,
441-
pub id: NodeId,
442+
pub id: Id,
442443
pub qualname: String,
443444
pub type_value: String,
444445
pub value: String,
445-
pub scope: NodeId
446+
pub scope: Id
446447
}
447448

448449
impl Lower for data::StructVariantData {
@@ -463,9 +464,9 @@ impl Lower for data::StructVariantData {
463464
#[derive(Debug, RustcEncodable)]
464465
pub struct TraitData {
465466
pub span: SpanData,
466-
pub id: NodeId,
467+
pub id: Id,
467468
pub qualname: String,
468-
pub scope: NodeId,
469+
pub scope: Id,
469470
pub value: String
470471
}
471472

@@ -486,12 +487,12 @@ impl Lower for data::TraitData {
486487
#[derive(Debug, RustcEncodable)]
487488
pub struct TupleVariantData {
488489
pub span: SpanData,
489-
pub id: NodeId,
490+
pub id: Id,
490491
pub name: String,
491492
pub qualname: String,
492493
pub type_value: String,
493494
pub value: String,
494-
pub scope: NodeId,
495+
pub scope: Id,
495496
}
496497

497498
impl Lower for data::TupleVariantData {
@@ -513,7 +514,7 @@ impl Lower for data::TupleVariantData {
513514
/// Data for a typedef.
514515
#[derive(Debug, RustcEncodable)]
515516
pub struct TypedefData {
516-
pub id: NodeId,
517+
pub id: Id,
517518
pub span: SpanData,
518519
pub qualname: String,
519520
pub value: String,
@@ -536,8 +537,8 @@ impl Lower for data::TypedefData {
536537
#[derive(Clone, Debug, RustcEncodable)]
537538
pub struct TypeRefData {
538539
pub span: SpanData,
539-
pub scope: NodeId,
540-
pub ref_id: Option<DefId>,
540+
pub scope: Id,
541+
pub ref_id: Option<Id>,
541542
pub qualname: String,
542543
}
543544

@@ -548,19 +549,19 @@ impl Lower for data::TypeRefData {
548549
TypeRefData {
549550
span: SpanData::from_span(self.span, cm),
550551
scope: self.scope,
551-
ref_id: self.ref_id,
552+
ref_id: self.ref_id.map(|id| id.index.as_u32()),
552553
qualname: self.qualname,
553554
}
554555
}
555556
}
556557

557558
#[derive(Debug, RustcEncodable)]
558559
pub struct UseData {
559-
pub id: NodeId,
560+
pub id: Id,
560561
pub span: SpanData,
561562
pub name: String,
562-
pub mod_id: Option<DefId>,
563-
pub scope: NodeId
563+
pub mod_id: Option<Id>,
564+
pub scope: Id
564565
}
565566

566567
impl Lower for data::UseData {
@@ -571,18 +572,18 @@ impl Lower for data::UseData {
571572
id: self.id,
572573
span: SpanData::from_span(self.span, cm),
573574
name: self.name,
574-
mod_id: self.mod_id,
575+
mod_id: self.mod_id.map(|id| id.index.as_u32()),
575576
scope: self.scope,
576577
}
577578
}
578579
}
579580

580581
#[derive(Debug, RustcEncodable)]
581582
pub struct UseGlobData {
582-
pub id: NodeId,
583+
pub id: Id,
583584
pub span: SpanData,
584585
pub names: Vec<String>,
585-
pub scope: NodeId
586+
pub scope: Id
586587
}
587588

588589
impl Lower for data::UseGlobData {
@@ -601,11 +602,11 @@ impl Lower for data::UseGlobData {
601602
/// Data for local and global variables (consts and statics).
602603
#[derive(Debug, RustcEncodable)]
603604
pub struct VariableData {
604-
pub id: NodeId,
605+
pub id: Id,
605606
pub name: String,
606607
pub qualname: String,
607608
pub span: SpanData,
608-
pub scope: NodeId,
609+
pub scope: Id,
609610
pub value: String,
610611
pub type_value: String,
611612
}
@@ -632,8 +633,8 @@ impl Lower for data::VariableData {
632633
pub struct VariableRefData {
633634
pub name: String,
634635
pub span: SpanData,
635-
pub scope: NodeId,
636-
pub ref_id: DefId,
636+
pub scope: Id,
637+
pub ref_id: Id,
637638
}
638639

639640
impl Lower for data::VariableRefData {
@@ -644,7 +645,7 @@ impl Lower for data::VariableRefData {
644645
name: self.name,
645646
span: SpanData::from_span(self.span, cm),
646647
scope: self.scope,
647-
ref_id: self.ref_id,
648+
ref_id: self.ref_id.index.as_u32(),
648649
}
649650
}
650651
}

0 commit comments

Comments
 (0)