Hi,

I'm doing the dead-code elimination pass for a school project, which
comprises of two parts: (a) do a warning pass for dead code and (b)
eliminate dead code generation. For part (a), the approach I'm taking
is reuse reachable.rs to mark live codes, since the set of live codes
is essentially a superset reachable codes, and the propagation logic
is similar. Then I do another walk to check for items that are not in
the live codes set and warn that they are dead. Though outdated, you
can see my PR and how I approach it here:

https://github.com/mozilla/rust/pull/10477/files

In doing this, I ran into a few questions that I would like answers
to:

1. Is doing part (b) necessary? That is, does LLVM's optimization
already eliminate unused code?

2. My code marks `RuntimeGlue` struct in libstd/task/spawn.rs as dead.
This is because the struct is private and never used directly.
Instead, it contains static methods that are used, so it's not
desirable to warn it. Currently, when my code sees, e.g.,
`RuntimeGlue::kill_task`, it would mark the `kill_task` method
definition as live. What I would like to do in addition is mark the
`RuntimeGlue` struct definition as live, but I'm unable to find a way
to look up a struct given its method. How do I do that?

3. My code also marks the function `load_argc_and_argv` in
libstd/os.rs as dead when in fact it isn't. I would guess it's because
that function is only used when compiling the rustc source code on
Mac, whereas I'm compiling it on Linux. How do I modify my code to
take account of that?

4. I'm unable to finish compiling rustc because my addition spots a
number of dead codes in rustc source code. Assuming they are not false
positive, I then have three options: (i) remove the dead code, (ii)
comment it out, or (iii) put an `#[allow(dead_code)];` at the top of
the module. As I'm unfamiliar with the codebase, it's hard to decide
what to do in each case (I'm thankful to dbaupp for much help in this
area). When in doubt, which would be best to do?

Sincerely,
Kiet Tran
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to