Skip to content

Commit c613d26

Browse files
committed
Auto merge of #55521 - nrc:rls-fix, r=petrochenkov
save-analysis: bug fix and optimisation. The first commit fixes a bug in name resolution and save-analysis (introduced in #54145) and removes an unused parameter. This fixes the RLS tests, which are currently blocking distribution of the RLS. The second commit removes macro uses from save-analysis data, since these are never used, they just take up space. r? @petrochenkov
2 parents de9666f + 435d832 commit c613d26

File tree

4 files changed

+33
-31
lines changed

4 files changed

+33
-31
lines changed

src/librustc/hir/lowering.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -1754,7 +1754,6 @@ impl<'a> LoweringContext<'a> {
17541754
&mut self,
17551755
def: Def,
17561756
p: &Path,
1757-
ident: Option<Ident>,
17581757
param_mode: ParamMode,
17591758
explicit_owner: Option<NodeId>,
17601759
) -> hir::Path {
@@ -1773,15 +1772,14 @@ impl<'a> LoweringContext<'a> {
17731772
explicit_owner,
17741773
)
17751774
})
1776-
.chain(ident.map(|ident| hir::PathSegment::from_ident(ident)))
17771775
.collect(),
17781776
span: p.span,
17791777
}
17801778
}
17811779

17821780
fn lower_path(&mut self, id: NodeId, p: &Path, param_mode: ParamMode) -> hir::Path {
17831781
let def = self.expect_full_def(id);
1784-
self.lower_path_extra(def, p, None, param_mode, None)
1782+
self.lower_path_extra(def, p, param_mode, None)
17851783
}
17861784

17871785
fn lower_path_segment(
@@ -3014,7 +3012,7 @@ impl<'a> LoweringContext<'a> {
30143012
self.with_hir_id_owner(new_node_id, |this| {
30153013
let new_id = this.lower_node_id(new_node_id);
30163014
let path =
3017-
this.lower_path_extra(def, &path, None, ParamMode::Explicit, None);
3015+
this.lower_path_extra(def, &path, ParamMode::Explicit, None);
30183016
let item = hir::ItemKind::Use(P(path), hir::UseKind::Single);
30193017
let vis_kind = match vis.node {
30203018
hir::VisibilityKind::Public => hir::VisibilityKind::Public,
@@ -3053,7 +3051,7 @@ impl<'a> LoweringContext<'a> {
30533051
}
30543052

30553053
let path =
3056-
P(self.lower_path_extra(ret_def, &path, None, ParamMode::Explicit, None));
3054+
P(self.lower_path_extra(ret_def, &path, ParamMode::Explicit, None));
30573055
hir::ItemKind::Use(path, hir::UseKind::Single)
30583056
}
30593057
UseTreeKind::Glob => {
@@ -3140,7 +3138,7 @@ impl<'a> LoweringContext<'a> {
31403138
// the stability of `use a::{};`, to avoid it showing up as
31413139
// a re-export by accident when `pub`, e.g. in documentation.
31423140
let def = self.expect_full_def_from_use(id).next().unwrap_or(Def::Err);
3143-
let path = P(self.lower_path_extra(def, &prefix, None, ParamMode::Explicit, None));
3141+
let path = P(self.lower_path_extra(def, &prefix, ParamMode::Explicit, None));
31443142
*vis = respan(prefix.span.shrink_to_lo(), hir::VisibilityKind::Inherited);
31453143
hir::ItemKind::Use(path, hir::UseKind::ListStem)
31463144
}
@@ -4550,7 +4548,6 @@ impl<'a> LoweringContext<'a> {
45504548
path: P(self.lower_path_extra(
45514549
def,
45524550
path,
4553-
None,
45544551
ParamMode::Explicit,
45554552
explicit_owner,
45564553
)),

src/librustc_resolve/lib.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -3589,7 +3589,17 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
35893589
);
35903590

35913591
for (i, &Segment { ident, id }) in path.iter().enumerate() {
3592-
debug!("resolve_path ident {} {:?}", i, ident);
3592+
debug!("resolve_path ident {} {:?} {:?}", i, ident, id);
3593+
let record_segment_def = |this: &mut Self, def| {
3594+
if record_used {
3595+
if let Some(id) = id {
3596+
if !this.def_map.contains_key(&id) {
3597+
assert!(id != ast::DUMMY_NODE_ID, "Trying to resolve dummy id");
3598+
this.record_def(id, PathResolution::new(def));
3599+
}
3600+
}
3601+
}
3602+
};
35933603

35943604
let is_last = i == path.len() - 1;
35953605
let ns = if is_last { opt_ns.unwrap_or(TypeNS) } else { TypeNS };
@@ -3673,6 +3683,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
36733683
// we found a local variable or type param
36743684
Some(LexicalScopeBinding::Def(def))
36753685
if opt_ns == Some(TypeNS) || opt_ns == Some(ValueNS) => {
3686+
record_segment_def(self, def);
36763687
return PathResult::NonModule(PathResolution::with_unresolved_segments(
36773688
def, path.len() - 1
36783689
));
@@ -3690,14 +3701,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
36903701
let maybe_assoc = opt_ns != Some(MacroNS) && PathSource::Type.is_expected(def);
36913702
if let Some(next_module) = binding.module() {
36923703
module = Some(ModuleOrUniformRoot::Module(next_module));
3693-
if record_used {
3694-
if let Some(id) = id {
3695-
if !self.def_map.contains_key(&id) {
3696-
assert!(id != ast::DUMMY_NODE_ID, "Trying to resolve dummy id");
3697-
self.record_def(id, PathResolution::new(def));
3698-
}
3699-
}
3700-
}
3704+
record_segment_def(self, def);
37013705
} else if def == Def::ToolMod && i + 1 != path.len() {
37023706
let def = Def::NonMacroAttr(NonMacroAttrKind::Tool);
37033707
return PathResult::NonModule(PathResolution::new(def));

src/librustc_save_analysis/dump_visitor.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub struct DumpVisitor<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> {
9292
// we only write one macro def per unique macro definition, and
9393
// one macro use per unique callsite span.
9494
// mac_defs: FxHashSet<Span>,
95-
macro_calls: FxHashSet<Span>,
95+
// macro_calls: FxHashSet<Span>,
9696
}
9797

9898
impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
@@ -108,7 +108,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
108108
span: span_utils,
109109
cur_scope: CRATE_NODE_ID,
110110
// mac_defs: FxHashSet::default(),
111-
macro_calls: FxHashSet::default(),
111+
// macro_calls: FxHashSet::default(),
112112
}
113113
}
114114

@@ -771,8 +771,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
771771
}
772772

773773
fn process_path(&mut self, id: NodeId, path: &'l ast::Path) {
774-
debug!("process_path {:?}", path);
775-
if generated_code(path.span) {
774+
if self.span.filter_generated(path.span) {
776775
return;
777776
}
778777
self.dump_path_ref(id, path);
@@ -1031,18 +1030,20 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
10311030
/// If the span is not macro-generated, do nothing, else use callee and
10321031
/// callsite spans to record macro definition and use data, using the
10331032
/// mac_uses and mac_defs sets to prevent multiples.
1034-
fn process_macro_use(&mut self, span: Span) {
1035-
let source_span = span.source_callsite();
1036-
if !self.macro_calls.insert(source_span) {
1037-
return;
1038-
}
1033+
fn process_macro_use(&mut self, _span: Span) {
1034+
// FIXME if we're not dumping the defs (see below), there is no point
1035+
// dumping refs either.
1036+
// let source_span = span.source_callsite();
1037+
// if !self.macro_calls.insert(source_span) {
1038+
// return;
1039+
// }
10391040

1040-
let data = match self.save_ctxt.get_macro_use_data(span) {
1041-
None => return,
1042-
Some(data) => data,
1043-
};
1041+
// let data = match self.save_ctxt.get_macro_use_data(span) {
1042+
// None => return,
1043+
// Some(data) => data,
1044+
// };
10441045

1045-
self.dumper.macro_use(data);
1046+
// self.dumper.macro_use(data);
10461047

10471048
// FIXME write the macro def
10481049
// let mut hasher = DefaultHasher::new();

src/librustc_save_analysis/json_dumper.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl<'b, O: DumpOutput + 'b> JsonDumper<O> {
9393
self.result.compilation = Some(data);
9494
}
9595

96-
pub fn macro_use(&mut self, data: MacroRef) {
96+
pub fn _macro_use(&mut self, data: MacroRef) {
9797
if self.config.pub_only || self.config.reachable_only {
9898
return;
9999
}

0 commit comments

Comments
 (0)