gccrs: Mark types used as generic arguments as live
gccrs: Fixes dead code linting for types used only in generic arguments.
This commit resolves a bug in gccrs’ dead code detection where types used solely as generic arguments were incorrectly flagged as never constructed. The MarkLive::visit_path_segment function has been updated to also mark these generic type arguments as ‘live’. This ensures that the compiler correctly identifies types that are in use, preventing false positives in the dead code lint. Three existing tests had their false positive warnings removed.
In Details
The rust-lint-marklive.cc file in gccrs implements the liveness analysis pass, which is crucial for detecting dead code. A bug existed where visit_path_segment would mark the resolved node of a path segment as live, but it failed to do the same for any generic arguments associated with that segment. Consequently, types appearing exclusively within generic parameters (e.g., Vec<MyType>) were not considered live, leading to spurious dead code warnings for MyType. This patch modifies visit_path_segment to resolve and mark generic type arguments as live within the 'Types' namespace *bef…
- generic arguments
- In Rust, placeholders (like
TinVec<T>) used in generic types or functions. When a specific type (e.g.,i32) is provided for a generic argument, it instantiates a concrete version of the generic type (e.g.,Vec<i32>). - liveness analysis
- A compiler analysis that determines which variables or data are 'live' (i.e., will be used in the future) at each point in a program. This is used for optimizations like dead code elimination and register allocation.
- dead code detection
- A compiler process that identifies and flags or removes code that can never be executed or whose results are never used. This helps in reducing code size and potentially improving performance.
- HIR (High-level Intermediate Representation)
- An intermediate representation of Rust code used by the compiler after initial parsing and some semantic analysis. It is a more structured representation than the AST and is used for further analysis and transformations.