提交 c4803863 编写于 作者: N Nick Cameron

dump refs for path segments in save-analysis

Requires adding path segments to the hir map
上级 609d0bd8
......@@ -1861,6 +1861,7 @@ fn lower_path_segment(
let def = self.expect_full_def(segment.id);
hir::PathSegment::new(
segment.ident,
Some(segment.id),
Some(def),
generic_args,
infer_types,
......
......@@ -392,6 +392,13 @@ fn visit_stmt(&mut self, stmt: &'hir Stmt) {
});
}
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'hir PathSegment) {
if let Some(id) = path_segment.id {
self.insert(id, Node::PathSegment(path_segment));
}
intravisit::walk_path_segment(self, path_span, path_segment);
}
fn visit_ty(&mut self, ty: &'hir Ty) {
self.insert(ty.id, Node::Ty(ty));
......
......@@ -204,7 +204,7 @@ pub fn read(&self, id: NodeId) {
if let Some(entry) = self.map[id.as_usize()] {
self.dep_graph.read_index(entry.dep_node);
} else {
bug!("called `HirMap::read()` with invalid `NodeId`")
bug!("called `HirMap::read()` with invalid `NodeId`: {:?}", id)
}
}
......@@ -344,6 +344,7 @@ pub fn describe_def(&self, node_id: NodeId) -> Option<Def> {
Node::AnonConst(_) |
Node::Expr(_) |
Node::Stmt(_) |
Node::PathSegment(_) |
Node::Ty(_) |
Node::TraitRef(_) |
Node::Pat(_) |
......@@ -884,6 +885,7 @@ pub fn span(&self, id: NodeId) -> Span {
Some(Node::AnonConst(constant)) => self.body(constant.body).value.span,
Some(Node::Expr(expr)) => expr.span,
Some(Node::Stmt(stmt)) => stmt.span,
Some(Node::PathSegment(seg)) => seg.ident.span,
Some(Node::Ty(ty)) => ty.span,
Some(Node::TraitRef(tr)) => tr.path.span,
Some(Node::Binding(pat)) => pat.span,
......@@ -1098,6 +1100,7 @@ pub fn print_node(&mut self, node: Node<'_>) -> io::Result<()> {
Node::AnonConst(a) => self.print_anon_const(&a),
Node::Expr(a) => self.print_expr(&a),
Node::Stmt(a) => self.print_stmt(&a),
Node::PathSegment(_) => bug!("cannot print PathSegment"),
Node::Ty(a) => self.print_type(&a),
Node::TraitRef(a) => self.print_trait_ref(&a),
Node::Binding(a) |
......@@ -1215,6 +1218,9 @@ fn node_id_to_string(map: &Map<'_>, id: NodeId, include_id: bool) -> String {
Some(Node::Stmt(_)) => {
format!("stmt {}{}", map.node_to_pretty_string(id), id_str)
}
Some(Node::PathSegment(_)) => {
format!("path segment {}{}", map.node_to_pretty_string(id), id_str)
}
Some(Node::Ty(_)) => {
format!("type {}{}", map.node_to_pretty_string(id), id_str)
}
......
......@@ -347,6 +347,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
pub struct PathSegment {
/// The identifier portion of this path segment.
pub ident: Ident,
pub id: Option<NodeId>,
pub def: Option<Def>,
/// Type/lifetime parameters attached to this path. They come in
......@@ -368,15 +369,23 @@ impl PathSegment {
pub fn from_ident(ident: Ident) -> PathSegment {
PathSegment {
ident,
id: None,
def: None,
infer_types: true,
args: None,
}
}
pub fn new(ident: Ident, def: Option<Def>, args: GenericArgs, infer_types: bool) -> Self {
pub fn new(
ident: Ident,
id: Option<NodeId>,
def: Option<Def>,
args: GenericArgs,
infer_types: bool,
) -> Self {
PathSegment {
ident,
id,
def,
infer_types,
args: if args.is_empty() {
......@@ -2514,6 +2523,7 @@ pub enum Node<'hir> {
AnonConst(&'hir AnonConst),
Expr(&'hir Expr),
Stmt(&'hir Stmt),
PathSegment(&'hir PathSegment),
Ty(&'hir Ty),
TraitRef(&'hir TraitRef),
Binding(&'hir Pat),
......
......@@ -174,6 +174,7 @@ fn hash_stable<W: StableHasherResult>(&self,
impl_stable_hash_for!(struct hir::PathSegment {
ident -> (ident.name),
id,
def,
infer_types,
args
......
......@@ -392,18 +392,18 @@ fn build_reduced_graph_for_use_tree(
e.emit();
}
for &(ref tree, id) in items {
let prefix = ast::Path {
segments: module_path.iter()
.map(|ident| {
let mut seg = ast::PathSegment::from_ident(ident.0);
seg.id = self.session.next_node_id();
seg
})
.collect(),
span: path.span,
};
let prefix = ast::Path {
segments: module_path.into_iter()
.map(|(ident, id)| {
let mut seg = ast::PathSegment::from_ident(ident);
seg.id = id.expect("Missing node id");
seg
})
.collect(),
span: path.span,
};
for &(ref tree, id) in items {
self.build_reduced_graph_for_use_tree(
root_use_tree,
root_id,
......
......@@ -3614,6 +3614,7 @@ fn resolve_path_with_parent_scope(
for (i, &(ident, id)) in path.iter().enumerate() {
debug!("resolve_path ident {} {:?}", i, ident);
let is_last = i == path.len() - 1;
let ns = if is_last { opt_ns.unwrap_or(TypeNS) } else { TypeNS };
let name = ident.name;
......@@ -3713,10 +3714,12 @@ fn resolve_path_with_parent_scope(
let maybe_assoc = opt_ns != Some(MacroNS) && PathSource::Type.is_expected(def);
if let Some(next_module) = binding.module() {
module = Some(ModuleOrUniformRoot::Module(next_module));
if !is_last && record_used {
if record_used {
if let Some(id) = id {
assert!(id != ast::DUMMY_NODE_ID, "Trying to resolve dummy id");
self.record_def(id, PathResolution::new(def));
if !self.def_map.contains_key(&id) {
assert!(id != ast::DUMMY_NODE_ID, "Trying to resolve dummy id");
self.record_def(id, PathResolution::new(def));
}
}
}
} else if def == Def::ToolMod && i + 1 != path.len() {
......
......@@ -812,9 +812,8 @@ fn process_struct_lit(
variant: &'l ty::VariantDef,
base: &'l Option<P<ast::Expr>>,
) {
self.write_sub_paths_truncated(path);
if let Some(struct_lit_data) = self.save_ctxt.get_expr_data(ex) {
self.write_sub_paths_truncated(path);
down_cast_data!(struct_lit_data, RefData, ex.span);
if !generated_code(ex.span) {
self.dumper.dump_ref(struct_lit_data);
......@@ -1232,8 +1231,8 @@ fn process_use_tree(&mut self,
value: String::new(),
parent,
});
self.write_sub_paths_truncated(&path);
}
self.write_sub_paths_truncated(&path);
}
ast::UseTreeKind::Glob => {
let path = ast::Path {
......@@ -1268,8 +1267,8 @@ fn process_use_tree(&mut self,
value: names.join(", "),
parent,
});
self.write_sub_paths(&path);
}
self.write_sub_paths(&path);
}
ast::UseTreeKind::Nested(ref nested_items) => {
let prefix = ast::Path {
......
......@@ -632,6 +632,10 @@ pub fn get_path_def(&self, id: NodeId) -> HirDef {
Node::Visibility(&Spanned {
node: hir::VisibilityKind::Restricted { ref path, .. }, .. }) => path.def,
Node::PathSegment(seg) => match seg.def {
Some(def) => def,
None => HirDef::Err,
},
Node::Expr(&hir::Expr {
node: hir::ExprKind::Struct(ref qpath, ..),
..
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册