aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-07-13 11:33:26 +0000
committerGitHub <noreply@github.com>2021-07-13 11:33:26 +0000
commitb4ea3a19464b9bc79dad9cf5bb9bffc660718632 (patch)
tree5f51ad082be6cb31d191648b548a93f00cef4fa6 /gcc
parent9415a4b712371706d7f130695fd959fddb6506cc (diff)
parent29d84b2c1477769100559f9427028001fd07b113 (diff)
downloadgcc-b4ea3a19464b9bc79dad9cf5bb9bffc660718632.zip
gcc-b4ea3a19464b9bc79dad9cf5bb9bffc660718632.tar.gz
gcc-b4ea3a19464b9bc79dad9cf5bb9bffc660718632.tar.bz2
Merge #562
562: add some comments about how scan dead code pass handle PathInExpression and PathExprSegment r=philberty a=thomasyonug Add some comments about how scan dead code pass handles PathInExpression and PathExprSegment. Co-authored-by: Thomas Young <wenzhang5800@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/lint/rust-lint-marklive.cc11
1 files changed, 11 insertions, 0 deletions
diff --git a/gcc/rust/lint/rust-lint-marklive.cc b/gcc/rust/lint/rust-lint-marklive.cc
index d436f1a..8339345 100644
--- a/gcc/rust/lint/rust-lint-marklive.cc
+++ b/gcc/rust/lint/rust-lint-marklive.cc
@@ -106,6 +106,8 @@ MarkLive::go (HIR::Crate &crate)
void
MarkLive::visit (HIR::PathInExpression &expr)
{
+ // We should iterate every path segment in order to mark the function which is
+ // called in the expression
expr.iterate_path_segments ([&] (HIR::PathExprSegment &seg) -> bool {
return visit_path_segment (seg);
});
@@ -121,6 +123,7 @@ MarkLive::visit (HIR::MethodCallExpr &expr)
return true;
});
+ // Trying to find the method definition and mark it alive.
NodeId ast_node_id = expr.get_mappings ().get_nodeid ();
NodeId ref_node_id = UNKNOWN_NODEID;
find_ref_node_id (ast_node_id, ref_node_id, expr.get_locus (),
@@ -140,6 +143,14 @@ MarkLive::visit_path_segment (HIR::PathExprSegment seg)
NodeId ast_node_id = seg.get_mappings ().get_nodeid ();
NodeId ref_node_id = UNKNOWN_NODEID;
+ // There are two different kinds of segment for us.
+ // 1. function segment
+ // like the symbol "foo" in expression `foo()`.
+ // 2. type segment
+ // like the symbol "Foo" in expression `Foo{a: 1, b: 2}`
+ //
+ // We should mark them alive all and ignoring other kind of segments.
+ // If the segment we dont care then just return false is fine
if (resolver->lookup_resolved_name (ast_node_id, &ref_node_id))
{
Resolver::Definition def;